Merge branch 'main' of https://gitlab.com/famedly/famedlysdk into yiffed

This commit is contained in:
Inex Code 2020-10-11 17:50:05 +03:00
commit 145500e938
11 changed files with 52 additions and 33 deletions

View File

@ -11,16 +11,19 @@ coverage:
dependencies: []
script:
- apt update
- apt install -y curl gnupg2 git
- curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list
- apt install -y curl gnupg2 git unzip
- git clone https://github.com/flutter/flutter.git -b stable
- export PATH="$PATH:`pwd`/flutter/bin"
- sed -i s/#//g pubspec.yaml
- flutter doctor
- 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/
- useradd -m test
- chown -R 'test:' '.'
- chmod +x ./prepare.sh
- chmod +x ./test.sh
- rm -r example
- su -c ./prepare.sh test
- su -c ./test.sh test
artifacts:
@ -125,4 +128,4 @@ pages:
paths:
- public
only:
- main
- main

View File

@ -762,6 +762,8 @@ class Client extends MatrixApi {
_sortRooms();
}
prevBatch = syncResp.nextBatch;
await database?.deleteOldFiles(
DateTime.now().subtract(Duration(days: 30)).millisecondsSinceEpoch);
await _updateUserDeviceKeys();
if (encryptionEnabled) {
encryption.onSync();

View File

@ -164,8 +164,8 @@ class Database extends _$Database {
Future<DbClient> getClient(String name) async {
final res = await dbGetClient(name).get();
if (res.isEmpty) return null;
await markPendingEventsAsError(res.first.clientId);
return res.first;
await markPendingEventsAsError(res.single.clientId);
return res.single;
}
Future<Map<String, sdk.DeviceKeysList>> getUserDeviceKeys(
@ -216,7 +216,7 @@ class Database extends _$Database {
if (res.isEmpty) {
return null;
}
return res.first;
return res.single;
}
Future<List<DbInboundGroupSession>> getDbInboundGroupSessions(
@ -231,7 +231,7 @@ class Database extends _$Database {
if (res.isEmpty) {
return null;
}
return res.first;
return res.single;
}
Future<DbSSSSCache> getSSSSCache(int clientId, String type) async {
@ -239,7 +239,7 @@ class Database extends _$Database {
if (res.isEmpty) {
return null;
}
return res.first;
return res.single;
}
Future<List<sdk.Room>> getRoomList(sdk.Client client,
@ -563,7 +563,7 @@ class Database extends _$Database {
if (event.isEmpty) {
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 {
@ -649,7 +649,7 @@ class Database extends _$Database {
if (res.isEmpty) {
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 {
@ -673,6 +673,6 @@ class Database extends _$Database {
Future<Uint8List> getFile(String mxcUri) async {
final res = await dbGetFile(mxcUri).get();
if (res.isEmpty) return null;
return res.first.bytes;
return res.single.bytes;
}
}

View File

@ -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
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
@override

View File

@ -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);
dbGetFile: SELECT * FROM files WHERE mxc_uri = :mxc_uri;
markPendingEventsAsError: UPDATE events SET status = -1 WHERE client_id = :client_id AND status = 0;
deleteOldFiles: DELETE FROM files WHERE saved_at < :saved_at;

View File

@ -234,7 +234,7 @@ class Event extends MatrixEvent {
String get messageType => type == EventTypes.Sticker
? MessageTypes.Sticker
: content['msgtype'] ?? MessageTypes.Text;
: (content['msgtype'] is String ? content['msgtype'] : MessageTypes.Text);
void setRedactionEvent(Event redactedBecause) {
unsigned = {
@ -281,10 +281,11 @@ class Event extends MatrixEvent {
}
/// 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.
String get formattedText => content['formatted_body'] ?? '';
String get formattedText =>
content['formatted_body'] is String ? content['formatted_body'] : '';
/// Use this to get the 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.
/// This is useful to determine if stand-alone emotes should be displayed bigger.
bool get onlyEmotes => isRichMessage
? _onlyEmojiEmoteRegex.hasMatch(content['formatted_body'])
: _onlyEmojiRegex.hasMatch(content['body'] ?? '');
? _onlyEmojiEmoteRegex.hasMatch(formattedText)
: _onlyEmojiRegex.hasMatch(text);
/// 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
/// only emotes. Use `event.onlyEmotes` for that!
int get numberEmotes => isRichMessage
? _countEmojiEmoteRegex.allMatches(content['formatted_body']).length
: _countEmojiRegex.allMatches(content['body'] ?? '').length;
? _countEmojiEmoteRegex.allMatches(formattedText).length
: _countEmojiRegex.allMatches(text).length;
}

View File

@ -174,7 +174,8 @@ class Room {
StreamController.broadcast();
/// 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']
: '';
@ -205,14 +206,15 @@ class Room {
}
/// 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']
: '';
/// The avatar of the room if set by a participant.
Uri get avatar {
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']);
}
if (mHeroes != null && mHeroes.length == 1 && states[mHeroes[0]] != null) {

View File

@ -20,4 +20,8 @@ cmake --build .
cd ..
fi
pub get
if which flutter >/dev/null; then
flutter pub get
else
pub get
fi

View File

@ -30,8 +30,5 @@ dev_dependencies:
moor_generator: ^3.0.0
build_runner: ^1.5.2
pedantic: ^1.9.0
moor_ffi: ^0.5.0
dependency_overrides:
# See https://github.com/flutter/flutter/issues/62240
analyzer: '0.39.14'
#flutter_test:
# sdk: flutter

View File

@ -1,6 +1,6 @@
#!/bin/sh -e
# pub run test -p vm
pub run test_coverage --print-test-output
pub global activate remove_from_coverage
pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$'
flutter test --coverage
flutter pub global activate remove_from_coverage
flutter pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$'
genhtml -o coverage coverage/lcov.info || true

View File

@ -18,7 +18,7 @@
import 'package:famedlysdk/famedlysdk.dart';
import 'package:moor/moor.dart';
import 'package:moor_ffi/moor_ffi.dart' as moor;
import 'package:moor/ffi.dart' as moor;
Database getDatabase() {
moorRuntimeOptions.dontWarnAboutMultipleDatabases = true;