feat: Implement ignore list
This commit is contained in:
parent
3187275ed7
commit
a77e776479
|
@ -1519,6 +1519,52 @@ sort order of ${prevState.sortOrder}. This should never happen...''');
|
|||
}
|
||||
}
|
||||
|
||||
/// Clear all local cached messages and perform a new clean sync.
|
||||
Future<void> clearLocalCachedMessages() async {
|
||||
prevBatch = null;
|
||||
rooms.forEach((r) => r.prev_batch = null);
|
||||
await database?.clearCache(id);
|
||||
}
|
||||
|
||||
/// A list of mxids of users who are ignored.
|
||||
List<String> get ignoredUsers =>
|
||||
accountData.containsKey('m.ignored_user_list')
|
||||
? accountData['m.ignored_user_list'].content['ignored_users']
|
||||
: [];
|
||||
|
||||
/// Ignore another user. This will clear the local cached messages to
|
||||
/// hide all previous messages from this user.
|
||||
Future<void> ignoreUser(String userId) async {
|
||||
if (!userId.isValidMatrixId) {
|
||||
throw Exception('$userId is not a valid mxid!');
|
||||
}
|
||||
await setAccountData(
|
||||
userID,
|
||||
'm.ignored_user_list',
|
||||
{'ignored_users': ignoredUsers..add(userId)},
|
||||
);
|
||||
await clearLocalCachedMessages();
|
||||
return;
|
||||
}
|
||||
|
||||
/// Unignore a user. This will clear the local cached messages and request
|
||||
/// them again from the server to avoid gaps in the timeline.
|
||||
Future<void> unignoreUser(String userId) async {
|
||||
if (!userId.isValidMatrixId) {
|
||||
throw Exception('$userId is not a valid mxid!');
|
||||
}
|
||||
if (!ignoredUsers.contains(userId)) {
|
||||
throw Exception('$userId is not in the ignore list!');
|
||||
}
|
||||
await setAccountData(
|
||||
userID,
|
||||
'm.ignored_user_list',
|
||||
{'ignored_users': ignoredUsers..remove(userId)},
|
||||
);
|
||||
await clearLocalCachedMessages();
|
||||
return;
|
||||
}
|
||||
|
||||
bool _disposed = false;
|
||||
Future _currentTransaction = Future.sync(() => {});
|
||||
|
||||
|
|
|
@ -421,6 +421,18 @@ void main() {
|
|||
test('changePassword', () async {
|
||||
await matrix.changePassword('1234', oldPassword: '123456');
|
||||
});
|
||||
test('ignoredUsers', () async {
|
||||
expect(matrix.ignoredUsers, []);
|
||||
matrix.accountData['m.ignored_user_list'] =
|
||||
BasicEvent(type: 'm.ignored_user_list', content: {
|
||||
'ignored_users': ['@charley:stupid.abc']
|
||||
});
|
||||
expect(matrix.ignoredUsers, ['@charley:stupid.abc']);
|
||||
});
|
||||
test('ignoredUsers', () async {
|
||||
await matrix.ignoreUser('@charley2:stupid.abc');
|
||||
await matrix.unignoreUser('@charley:stupid.abc');
|
||||
});
|
||||
|
||||
test('dispose', () async {
|
||||
await matrix.dispose(closeDatabase: true);
|
||||
|
|
|
@ -1982,6 +1982,8 @@ class FakeMatrixApi extends MockClient {
|
|||
'/client/unstable/room_keys/version': (var reqI) => {'version': '5'},
|
||||
},
|
||||
'PUT': {
|
||||
'/client/r0/user/%40test%3AfakeServer.notExisting/account_data/m.ignored_user_list':
|
||||
(var req) => {},
|
||||
'/client/r0/presence/${Uri.encodeComponent('@alice:example.com')}/status':
|
||||
(var req) => {},
|
||||
'/client/r0/pushrules/global/content/nocake/enabled': (var req) => {},
|
||||
|
|
Loading…
Reference in a new issue