Merge branch 'main' of https://gitlab.com/famedly/famedlysdk into yiffed
This commit is contained in:
commit
145500e938
|
@ -11,16 +11,19 @@ coverage:
|
||||||
dependencies: []
|
dependencies: []
|
||||||
script:
|
script:
|
||||||
- apt update
|
- apt update
|
||||||
- apt install -y curl gnupg2 git
|
- apt install -y curl gnupg2 git unzip
|
||||||
- curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
|
- git clone https://github.com/flutter/flutter.git -b stable
|
||||||
- curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list
|
- export PATH="$PATH:`pwd`/flutter/bin"
|
||||||
|
- sed -i s/#//g pubspec.yaml
|
||||||
|
- flutter doctor
|
||||||
- apt update
|
- apt update
|
||||||
- apt install -y dart chromium lcov libolm3 sqlite3 libsqlite3-dev
|
- apt install -y chromium lcov libolm3 sqlite3 libsqlite3-dev
|
||||||
- ln -s /usr/lib/dart/bin/pub /usr/bin/
|
- ln -s /usr/lib/dart/bin/pub /usr/bin/
|
||||||
- useradd -m test
|
- useradd -m test
|
||||||
- chown -R 'test:' '.'
|
- chown -R 'test:' '.'
|
||||||
- chmod +x ./prepare.sh
|
- chmod +x ./prepare.sh
|
||||||
- chmod +x ./test.sh
|
- chmod +x ./test.sh
|
||||||
|
- rm -r example
|
||||||
- su -c ./prepare.sh test
|
- su -c ./prepare.sh test
|
||||||
- su -c ./test.sh test
|
- su -c ./test.sh test
|
||||||
artifacts:
|
artifacts:
|
||||||
|
@ -125,4 +128,4 @@ pages:
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
only:
|
only:
|
||||||
- main
|
- main
|
||||||
|
|
|
@ -762,6 +762,8 @@ class Client extends MatrixApi {
|
||||||
_sortRooms();
|
_sortRooms();
|
||||||
}
|
}
|
||||||
prevBatch = syncResp.nextBatch;
|
prevBatch = syncResp.nextBatch;
|
||||||
|
await database?.deleteOldFiles(
|
||||||
|
DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch);
|
||||||
await _updateUserDeviceKeys();
|
await _updateUserDeviceKeys();
|
||||||
if (encryptionEnabled) {
|
if (encryptionEnabled) {
|
||||||
encryption.onSync();
|
encryption.onSync();
|
||||||
|
|
|
@ -164,8 +164,8 @@ class Database extends _$Database {
|
||||||
Future<DbClient> getClient(String name) async {
|
Future<DbClient> getClient(String name) async {
|
||||||
final res = await dbGetClient(name).get();
|
final res = await dbGetClient(name).get();
|
||||||
if (res.isEmpty) return null;
|
if (res.isEmpty) return null;
|
||||||
await markPendingEventsAsError(res.first.clientId);
|
await markPendingEventsAsError(res.single.clientId);
|
||||||
return res.first;
|
return res.single;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, sdk.DeviceKeysList>> getUserDeviceKeys(
|
Future<Map<String, sdk.DeviceKeysList>> getUserDeviceKeys(
|
||||||
|
@ -216,7 +216,7 @@ class Database extends _$Database {
|
||||||
if (res.isEmpty) {
|
if (res.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return res.first;
|
return res.single;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<DbInboundGroupSession>> getDbInboundGroupSessions(
|
Future<List<DbInboundGroupSession>> getDbInboundGroupSessions(
|
||||||
|
@ -231,7 +231,7 @@ class Database extends _$Database {
|
||||||
if (res.isEmpty) {
|
if (res.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return res.first;
|
return res.single;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<DbSSSSCache> getSSSSCache(int clientId, String type) async {
|
Future<DbSSSSCache> getSSSSCache(int clientId, String type) async {
|
||||||
|
@ -239,7 +239,7 @@ class Database extends _$Database {
|
||||||
if (res.isEmpty) {
|
if (res.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return res.first;
|
return res.single;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<sdk.Room>> getRoomList(sdk.Client client,
|
Future<List<sdk.Room>> getRoomList(sdk.Client client,
|
||||||
|
@ -563,7 +563,7 @@ class Database extends _$Database {
|
||||||
if (event.isEmpty) {
|
if (event.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return sdk.Event.fromDb(event.first, room);
|
return sdk.Event.fromDb(event.single, room);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> redactMessage(int clientId, sdk.EventUpdate eventUpdate) async {
|
Future<bool> redactMessage(int clientId, sdk.EventUpdate eventUpdate) async {
|
||||||
|
@ -649,7 +649,7 @@ class Database extends _$Database {
|
||||||
if (res.isEmpty) {
|
if (res.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return sdk.Event.fromDb(res.first, room).asUser;
|
return sdk.Event.fromDb(res.single, room).asUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<sdk.User>> getUsers(int clientId, sdk.Room room) async {
|
Future<List<sdk.User>> getUsers(int clientId, sdk.Room room) async {
|
||||||
|
@ -673,6 +673,6 @@ class Database extends _$Database {
|
||||||
Future<Uint8List> getFile(String mxcUri) async {
|
Future<Uint8List> getFile(String mxcUri) async {
|
||||||
final res = await dbGetFile(mxcUri).get();
|
final res = await dbGetFile(mxcUri).get();
|
||||||
if (res.isEmpty) return null;
|
if (res.isEmpty) return null;
|
||||||
return res.first.bytes;
|
return res.single.bytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6892,6 +6892,15 @@ abstract class _$Database extends GeneratedDatabase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> deleteOldFiles(int saved_at) {
|
||||||
|
return customUpdate(
|
||||||
|
'DELETE FROM files WHERE saved_at < :saved_at',
|
||||||
|
variables: [Variable.withInt(saved_at)],
|
||||||
|
updates: {files},
|
||||||
|
updateKind: UpdateKind.delete,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
|
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -234,3 +234,4 @@ removeSuccessfulRoomEvents: DELETE FROM events WHERE client_id = :client_id AND
|
||||||
storeFile: INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time);
|
storeFile: INSERT OR REPLACE INTO files (mxc_uri, bytes, saved_at) VALUES (:mxc_uri, :bytes, :time);
|
||||||
dbGetFile: SELECT * FROM files WHERE mxc_uri = :mxc_uri;
|
dbGetFile: SELECT * FROM files WHERE mxc_uri = :mxc_uri;
|
||||||
markPendingEventsAsError: UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0;
|
markPendingEventsAsError: UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0;
|
||||||
|
deleteOldFiles: DELETE FROM files WHERE saved_at < :saved_at;
|
||||||
|
|
|
@ -234,7 +234,7 @@ class Event extends MatrixEvent {
|
||||||
|
|
||||||
String get messageType => type == EventTypes.Sticker
|
String get messageType => type == EventTypes.Sticker
|
||||||
? MessageTypes.Sticker
|
? MessageTypes.Sticker
|
||||||
: content['msgtype'] ?? MessageTypes.Text;
|
: (content['msgtype'] is String ? content['msgtype'] : MessageTypes.Text);
|
||||||
|
|
||||||
void setRedactionEvent(Event redactedBecause) {
|
void setRedactionEvent(Event redactedBecause) {
|
||||||
unsigned = {
|
unsigned = {
|
||||||
|
@ -281,10 +281,11 @@ class Event extends MatrixEvent {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the body of this event if it has a body.
|
/// Returns the body of this event if it has a body.
|
||||||
String get text => content['body'] ?? '';
|
String get text => content['body'] is String ? content['body'] : '';
|
||||||
|
|
||||||
/// Returns the formatted boy of this event if it has a formatted body.
|
/// Returns the formatted boy of this event if it has a formatted body.
|
||||||
String get formattedText => content['formatted_body'] ?? '';
|
String get formattedText =>
|
||||||
|
content['formatted_body'] is String ? content['formatted_body'] : '';
|
||||||
|
|
||||||
/// Use this to get the body.
|
/// Use this to get the body.
|
||||||
String get body {
|
String get body {
|
||||||
|
@ -800,13 +801,13 @@ class Event extends MatrixEvent {
|
||||||
/// Returns if a given event only has emotes, emojis or whitespace as content.
|
/// Returns if a given event only has emotes, emojis or whitespace as content.
|
||||||
/// This is useful to determine if stand-alone emotes should be displayed bigger.
|
/// This is useful to determine if stand-alone emotes should be displayed bigger.
|
||||||
bool get onlyEmotes => isRichMessage
|
bool get onlyEmotes => isRichMessage
|
||||||
? _onlyEmojiEmoteRegex.hasMatch(content['formatted_body'])
|
? _onlyEmojiEmoteRegex.hasMatch(formattedText)
|
||||||
: _onlyEmojiRegex.hasMatch(content['body'] ?? '');
|
: _onlyEmojiRegex.hasMatch(text);
|
||||||
|
|
||||||
/// Gets the number of emotes in a given message. This is useful to determine if
|
/// Gets the number of emotes in a given message. This is useful to determine if
|
||||||
/// emotes should be displayed bigger. WARNING: This does **not** test if there are
|
/// emotes should be displayed bigger. WARNING: This does **not** test if there are
|
||||||
/// only emotes. Use `event.onlyEmotes` for that!
|
/// only emotes. Use `event.onlyEmotes` for that!
|
||||||
int get numberEmotes => isRichMessage
|
int get numberEmotes => isRichMessage
|
||||||
? _countEmojiEmoteRegex.allMatches(content['formatted_body']).length
|
? _countEmojiEmoteRegex.allMatches(formattedText).length
|
||||||
: _countEmojiRegex.allMatches(content['body'] ?? '').length;
|
: _countEmojiRegex.allMatches(text).length;
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,8 @@ class Room {
|
||||||
StreamController.broadcast();
|
StreamController.broadcast();
|
||||||
|
|
||||||
/// The name of the room if set by a participant.
|
/// The name of the room if set by a participant.
|
||||||
String get name => states[EventTypes.RoomName] != null
|
String get name => states[EventTypes.RoomName] != null &&
|
||||||
|
states[EventTypes.RoomName].content['name'] is String
|
||||||
? states[EventTypes.RoomName].content['name']
|
? states[EventTypes.RoomName].content['name']
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
|
@ -205,14 +206,15 @@ class Room {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The topic of the room if set by a participant.
|
/// The topic of the room if set by a participant.
|
||||||
String get topic => states[EventTypes.RoomTopic] != null
|
String get topic => states[EventTypes.RoomTopic] != null &&
|
||||||
|
states[EventTypes.RoomTopic].content['topic'] is String
|
||||||
? states[EventTypes.RoomTopic].content['topic']
|
? states[EventTypes.RoomTopic].content['topic']
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
/// The avatar of the room if set by a participant.
|
/// The avatar of the room if set by a participant.
|
||||||
Uri get avatar {
|
Uri get avatar {
|
||||||
if (states[EventTypes.RoomAvatar] != null &&
|
if (states[EventTypes.RoomAvatar] != null &&
|
||||||
states[EventTypes.RoomAvatar].content['url'] != null) {
|
states[EventTypes.RoomAvatar].content['url'] is String) {
|
||||||
return Uri.parse(states[EventTypes.RoomAvatar].content['url']);
|
return Uri.parse(states[EventTypes.RoomAvatar].content['url']);
|
||||||
}
|
}
|
||||||
if (mHeroes != null && mHeroes.length == 1 && states[mHeroes[0]] != null) {
|
if (mHeroes != null && mHeroes.length == 1 && states[mHeroes[0]] != null) {
|
||||||
|
|
|
@ -20,4 +20,8 @@ cmake --build .
|
||||||
cd ..
|
cd ..
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pub get
|
if which flutter >/dev/null; then
|
||||||
|
flutter pub get
|
||||||
|
else
|
||||||
|
pub get
|
||||||
|
fi
|
||||||
|
|
|
@ -30,8 +30,5 @@ dev_dependencies:
|
||||||
moor_generator: ^3.0.0
|
moor_generator: ^3.0.0
|
||||||
build_runner: ^1.5.2
|
build_runner: ^1.5.2
|
||||||
pedantic: ^1.9.0
|
pedantic: ^1.9.0
|
||||||
moor_ffi: ^0.5.0
|
#flutter_test:
|
||||||
|
# sdk: flutter
|
||||||
dependency_overrides:
|
|
||||||
# See https://github.com/flutter/flutter/issues/62240
|
|
||||||
analyzer: '0.39.14'
|
|
||||||
|
|
6
test.sh
6
test.sh
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh -e
|
#!/bin/sh -e
|
||||||
# pub run test -p vm
|
# pub run test -p vm
|
||||||
pub run test_coverage --print-test-output
|
flutter test --coverage
|
||||||
pub global activate remove_from_coverage
|
flutter pub global activate remove_from_coverage
|
||||||
pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$'
|
flutter pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$'
|
||||||
genhtml -o coverage coverage/lcov.info || true
|
genhtml -o coverage coverage/lcov.info || true
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:moor/moor.dart';
|
import 'package:moor/moor.dart';
|
||||||
import 'package:moor_ffi/moor_ffi.dart' as moor;
|
import 'package:moor/ffi.dart' as moor;
|
||||||
|
|
||||||
Database getDatabase() {
|
Database getDatabase() {
|
||||||
moorRuntimeOptions.dontWarnAboutMultipleDatabases = true;
|
moorRuntimeOptions.dontWarnAboutMultipleDatabases = true;
|
||||||
|
|
Loading…
Reference in New Issue