fix: Hide verification timeline events in lastEvent

This commit is contained in:
Christian Pauly 2021-01-13 13:30:47 +01:00
parent 56ec61b439
commit c94da38438
4 changed files with 22 additions and 20 deletions

View File

@ -141,8 +141,10 @@ class Room {
} }
} }
if (!(state.stateKey is String) && if (!(state.stateKey is String) &&
![EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted] ![EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted]
.contains(state.type)) { .contains(state.type) ||
(state.type == EventTypes.Message &&
state.messageType.startsWith('m.room.verification.'))) {
return; return;
} }
final oldStateEvent = getState(state.type, state.stateKey ?? ''); final oldStateEvent = getState(state.type, state.stateKey ?? '');
@ -367,7 +369,7 @@ class Room {
return 'Empty chat'; return 'Empty chat';
} }
/// The last message sent to this room. @Deprecated('Use [lastEvent.body] instead')
String get lastMessage { String get lastMessage {
if (lastEvent != null) { if (lastEvent != null) {
return lastEvent.body; return lastEvent.body;

View File

@ -342,7 +342,7 @@ void main() {
expect(archive[0].id, '!5345234234:example.com'); expect(archive[0].id, '!5345234234:example.com');
expect(archive[0].membership, Membership.leave); expect(archive[0].membership, Membership.leave);
expect(archive[0].name, 'The room name'); expect(archive[0].name, 'The room name');
expect(archive[0].lastMessage, 'This is an example text message'); expect(archive[0].lastEvent.body, 'This is an example text message');
expect(archive[0].roomAccountData.length, 1); expect(archive[0].roomAccountData.length, 1);
expect(archive[1].id, '!5345234235:example.com'); expect(archive[1].id, '!5345234235:example.com');
expect(archive[1].membership, Membership.leave); expect(archive[1].membership, Membership.leave);

View File

@ -177,7 +177,7 @@ void main() {
content: {'msgtype': 'm.text', 'body': 'test'}, content: {'msgtype': 'm.text', 'body': 'test'},
stateKey: ''); stateKey: '');
expect(room.lastEvent.eventId, '12345'); expect(room.lastEvent.eventId, '12345');
expect(room.lastMessage, 'test'); expect(room.lastEvent.body, 'test');
expect(room.timeCreated, room.lastEvent.originServerTs); expect(room.timeCreated, room.lastEvent.originServerTs);
}); });

View File

@ -149,10 +149,10 @@ void test() async {
/*assert(inviteRoom.client.encryption.keyManager /*assert(inviteRoom.client.encryption.keyManager
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') != .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastMessage == testMessage); assert(room.lastEvent.body == testMessage);
assert(inviteRoom.lastMessage == testMessage); assert(inviteRoom.lastEvent.body == testMessage);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent.body}' ++++");
Logs().i("++++ (Alice) Send again encrypted message: '$testMessage2' ++++"); Logs().i("++++ (Alice) Send again encrypted message: '$testMessage2' ++++");
await room.sendTextEvent(testMessage2); await room.sendTextEvent(testMessage2);
@ -176,10 +176,10 @@ void test() async {
/*assert(room.client.encryption.keyManager /*assert(room.client.encryption.keyManager
.getInboundGroupSession(room.id, currentSessionIdA, '') != .getInboundGroupSession(room.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastMessage == testMessage2); assert(room.lastEvent.body == testMessage2);
assert(inviteRoom.lastMessage == testMessage2); assert(inviteRoom.lastEvent.body == testMessage2);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent.body}' ++++");
Logs().i("++++ (Bob) Send again encrypted message: '$testMessage3' ++++"); Logs().i("++++ (Bob) Send again encrypted message: '$testMessage3' ++++");
await inviteRoom.sendTextEvent(testMessage3); await inviteRoom.sendTextEvent(testMessage3);
@ -209,10 +209,10 @@ void test() async {
inviteRoomOutboundGroupSession.outboundGroupSession.session_id(), inviteRoomOutboundGroupSession.outboundGroupSession.session_id(),
'') != '') !=
null);*/ null);*/
assert(inviteRoom.lastMessage == testMessage3); assert(inviteRoom.lastEvent.body == testMessage3);
assert(room.lastMessage == testMessage3); assert(room.lastEvent.body == testMessage3);
Logs().i( Logs().i(
"++++ (Alice) Received decrypted message: '${room.lastMessage}' ++++"); "++++ (Alice) Received decrypted message: '${room.lastEvent.body}' ++++");
Logs().i('++++ Login Bob in another client ++++'); Logs().i('++++ Login Bob in another client ++++');
var testClientC = Client('TestClientC', databaseBuilder: getDatabase); var testClientC = Client('TestClientC', databaseBuilder: getDatabase);
@ -256,10 +256,10 @@ void test() async {
/*assert(inviteRoom.client.encryption.keyManager /*assert(inviteRoom.client.encryption.keyManager
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') != .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastMessage == testMessage4); assert(room.lastEvent.body == testMessage4);
assert(inviteRoom.lastMessage == testMessage4); assert(inviteRoom.lastEvent.body == testMessage4);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent.body}' ++++");
Logs().i('++++ Logout Bob another client ++++'); Logs().i('++++ Logout Bob another client ++++');
await testClientC.dispose(closeDatabase: false); await testClientC.dispose(closeDatabase: false);
@ -292,10 +292,10 @@ void test() async {
/*assert(inviteRoom.client.encryption.keyManager /*assert(inviteRoom.client.encryption.keyManager
.getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') != .getInboundGroupSession(inviteRoom.id, currentSessionIdA, '') !=
null);*/ null);*/
assert(room.lastMessage == testMessage6); assert(room.lastEvent.body == testMessage6);
assert(inviteRoom.lastMessage == testMessage6); assert(inviteRoom.lastEvent.body == testMessage6);
Logs().i( Logs().i(
"++++ (Bob) Received decrypted message: '${inviteRoom.lastMessage}' ++++"); "++++ (Bob) Received decrypted message: '${inviteRoom.lastEvent.body}' ++++");
await room.leave(); await room.leave();
await room.forget(); await room.forget();