fix: don't assume element is a string
This commit is contained in:
parent
7e4096cc63
commit
ff586b06b1
|
|
@ -1,3 +1,6 @@
|
|||
## [0.9.6] - 16th May 2022
|
||||
- fix: Ignore invalid entries in `io.element.recent_emoji`
|
||||
|
||||
## [0.9.5] - 13th May 2022
|
||||
- fix: Fix deep copy issue in the fragmented timeline feature and restored it
|
||||
|
||||
|
|
|
|||
|
|
@ -22,14 +22,22 @@ extension RecentEmojiExtension on Client {
|
|||
///
|
||||
/// There's no corresponding standard or MSC, it's just the reverse-engineered
|
||||
/// API from New Vector Ltd.
|
||||
Map<String, int> get recentEmojis => Map.fromEntries(
|
||||
(accountData['io.element.recent_emoji']?.content['recent_emoji']
|
||||
as List<dynamic>? ??
|
||||
[])
|
||||
.map(
|
||||
(e) => MapEntry(e[0] as String, e[1] as int),
|
||||
),
|
||||
);
|
||||
Map<String, int> get recentEmojis {
|
||||
final recents = <String, int>{};
|
||||
|
||||
accountData['io.element.recent_emoji']
|
||||
?.content
|
||||
.tryGetList('recent_emoji')
|
||||
?.forEach((item) {
|
||||
if (item is List) {
|
||||
if (item.length > 1 && item[0] is String && item[1] is int) {
|
||||
recents[item[0]] = item[1];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return recents;
|
||||
}
|
||||
|
||||
/// +1 the stated emoji in the account data
|
||||
Future<void> addRecentEmoji(String emoji) async {
|
||||
|
|
@ -44,6 +52,7 @@ extension RecentEmojiExtension on Client {
|
|||
|
||||
/// sets the raw recent emoji account data. Use [addRecentEmoji] instead
|
||||
Future<void> setRecentEmojiData(Map<String, int> data) async {
|
||||
if (userID == null) return;
|
||||
final content = List.from(data.entries.map((e) => [e.key, e.value]));
|
||||
return setAccountData(
|
||||
userID!, 'io.element.recent_emoji', {'recent_emoji': content});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
name: matrix
|
||||
description: Matrix Dart SDK
|
||||
version: 0.9.5
|
||||
version: 0.9.6
|
||||
homepage: https://famedly.com
|
||||
repository: https://gitlab.com/famedly/company/frontend/famedlysdk.git
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ void main() {
|
|||
}
|
||||
expect(sync.nextBatch == matrix.prevBatch, true);
|
||||
|
||||
expect(matrix.accountData.length, 9);
|
||||
expect(matrix.accountData.length, 10);
|
||||
expect(matrix.getDirectChatFromUserId('@bob:example.com'),
|
||||
'!726s6s6q:example.com');
|
||||
expect(matrix.rooms[1].directChatMatrixID, '@bob:example.com');
|
||||
|
|
@ -153,7 +153,7 @@ void main() {
|
|||
expect(matrix.presences['@alice:example.com']?.presence,
|
||||
PresenceType.online);
|
||||
expect(presenceCounter, 1);
|
||||
expect(accountDataCounter, 9);
|
||||
expect(accountDataCounter, 10);
|
||||
await Future.delayed(Duration(milliseconds: 50));
|
||||
expect(matrix.userDeviceKeys.length, 4);
|
||||
expect(matrix.userDeviceKeys['@alice:example.com']?.outdated, false);
|
||||
|
|
@ -207,6 +207,18 @@ void main() {
|
|||
null);
|
||||
});
|
||||
|
||||
test('recentEmoji', () async {
|
||||
final emojis = matrix.recentEmojis;
|
||||
|
||||
expect(emojis.length, 2);
|
||||
|
||||
expect(emojis['👍️'], 1);
|
||||
expect(emojis['🖇️'], 0);
|
||||
|
||||
await matrix.addRecentEmoji('🦙');
|
||||
// To check if the emoji is properly added, we need to wait for a sync roundtrip
|
||||
});
|
||||
|
||||
test('Logout', () async {
|
||||
final loginStateFuture = matrix.onLoginStateChanged.stream.first;
|
||||
await matrix.logout();
|
||||
|
|
@ -322,15 +334,6 @@ void main() {
|
|||
await matrix.setAvatar(testFile);
|
||||
});
|
||||
|
||||
test('recentEmoji', () async {
|
||||
final client = await getClient();
|
||||
final emojis = client.recentEmojis;
|
||||
expect(emojis.isEmpty, isTrue);
|
||||
|
||||
await client.addRecentEmoji('🦙');
|
||||
expect(client.recentEmojis['🦙'], 1);
|
||||
});
|
||||
|
||||
test('setMuteAllPushNotifications', () async {
|
||||
await matrix.setMuteAllPushNotifications(false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -719,6 +719,18 @@ class FakeMatrixApi extends MockClient {
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'type': 'io.element.recent_emoji',
|
||||
'content': {
|
||||
'recent_emoji': [
|
||||
['👍️', 1],
|
||||
['🖇️', 0],
|
||||
['🙃', 'error'],
|
||||
[null, null],
|
||||
[1, '']
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -2195,6 +2207,8 @@ class FakeMatrixApi extends MockClient {
|
|||
'PUT': {
|
||||
'/client/r0/user/${Uri.encodeComponent('@alice:example.com')}/account_data/io.element.recent_emoji}':
|
||||
(var req) => {},
|
||||
'/client/r0/user/%40test%3AfakeServer.notExisting/account_data/io.element.recent_emoji':
|
||||
(var req) => {},
|
||||
'/client/r0/user/%40test%3AfakeServer.notExisting/account_data/m.ignored_user_list':
|
||||
(var req) => {},
|
||||
'/client/r0/presence/${Uri.encodeComponent('@alice:example.com')}/status':
|
||||
|
|
|
|||
Loading…
Reference in New Issue