Merge branch 'soru/no-in-memory-state-event-on-sync' into 'main'
fix: Only save state events from sync processing in-memory if they are... See merge request famedly/company/frontend/famedlysdk!922
This commit is contained in:
commit
b98b13d942
|
|
@ -1706,12 +1706,23 @@ class Client extends MatrixApi {
|
|||
),
|
||||
);
|
||||
} else {
|
||||
if (stateEvent.type != EventTypes.Message ||
|
||||
stateEvent.relationshipType != RelationshipTypes.edit ||
|
||||
stateEvent.relationshipEventId == room.lastEvent?.eventId ||
|
||||
((room.lastEvent?.relationshipType == RelationshipTypes.edit &&
|
||||
// We want to set state the in-memory cache for the room with the new event.
|
||||
// To do this, we have to respect to not save edits, unless they edit the
|
||||
// current last event.
|
||||
// Additionally, we only store the event in-memory if the room has either been
|
||||
// post-loaded or the event is animportant state event.
|
||||
final noMessageOrNoEdit = stateEvent.type != EventTypes.Message ||
|
||||
stateEvent.relationshipType != RelationshipTypes.edit;
|
||||
final editingLastEvent =
|
||||
stateEvent.relationshipEventId == room.lastEvent?.eventId;
|
||||
final consecutiveEdit =
|
||||
room.lastEvent?.relationshipType == RelationshipTypes.edit &&
|
||||
stateEvent.relationshipEventId ==
|
||||
room.lastEvent?.relationshipEventId))) {
|
||||
room.lastEvent?.relationshipEventId;
|
||||
final importantOrRoomLoaded =
|
||||
!room.partial || importantStateEvents.contains(stateEvent.type);
|
||||
if ((noMessageOrNoEdit || editingLastEvent || consecutiveEdit) &&
|
||||
importantOrRoomLoaded) {
|
||||
room.setState(stateEvent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,7 +188,9 @@ class Room {
|
|||
state.relationshipType == RelationshipTypes.edit &&
|
||||
lastEvent != null &&
|
||||
!state.matchesEventOrTransactionId(lastEvent.eventId) &&
|
||||
lastEvent.eventId != state.relationshipEventId) {
|
||||
lastEvent.eventId != state.relationshipEventId &&
|
||||
!(lastEvent.relationshipType == RelationshipTypes.edit &&
|
||||
lastEvent.relationshipEventId == state.relationshipEventId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -348,6 +348,186 @@ void main() {
|
|||
expect(archive[1].name, 'The room name 2');
|
||||
});
|
||||
|
||||
test('sync state event in-memory handling', () async {
|
||||
final roomId = '!726s6s6q:example.com';
|
||||
final room = matrix.getRoomById(roomId)!;
|
||||
// put an important state event in-memory
|
||||
await matrix.handleSync(SyncUpdate.fromJson({
|
||||
'next_batch': 'fakesync',
|
||||
'rooms': {
|
||||
'join': {
|
||||
roomId: {
|
||||
'state': {
|
||||
'events': [
|
||||
<String, dynamic>{
|
||||
'sender': '@alice:example.com',
|
||||
'type': 'm.room.name',
|
||||
'content': <String, dynamic>{'name': 'foxies'},
|
||||
'state_key': '',
|
||||
'origin_server_ts': 1417731086799,
|
||||
'event_id': '66697273743033:example.com'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
expect(room.getState('m.room.name')?.content['name'], 'foxies');
|
||||
|
||||
// drop an unimportant state event from in-memory handling
|
||||
await matrix.handleSync(SyncUpdate.fromJson({
|
||||
'next_batch': 'fakesync',
|
||||
'rooms': {
|
||||
'join': {
|
||||
roomId: {
|
||||
'state': {
|
||||
'events': [
|
||||
<String, dynamic>{
|
||||
'sender': '@alice:example.com',
|
||||
'type': 'com.famedly.custom',
|
||||
'content': <String, dynamic>{'name': 'foxies'},
|
||||
'state_key': '',
|
||||
'origin_server_ts': 1417731086799,
|
||||
'event_id': '66697273743033:example.com'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
expect(room.getState('com.famedly.custom'), null);
|
||||
|
||||
// persist normal room messages
|
||||
await matrix.handleSync(SyncUpdate.fromJson({
|
||||
'next_batch': 'fakesync',
|
||||
'rooms': {
|
||||
'join': {
|
||||
roomId: {
|
||||
'timeline': {
|
||||
'events': [
|
||||
<String, dynamic>{
|
||||
'sender': '@alice:example.com',
|
||||
'type': 'm.room.message',
|
||||
'content': <String, dynamic>{
|
||||
'msgtype': 'm.text',
|
||||
'body': 'meow'
|
||||
},
|
||||
'origin_server_ts': 1417731086799,
|
||||
'event_id': '\$last:example.com'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
expect(room.getState('m.room.message')!.content['body'], 'meow');
|
||||
|
||||
// ignore edits
|
||||
await matrix.handleSync(SyncUpdate.fromJson({
|
||||
'next_batch': 'fakesync',
|
||||
'rooms': {
|
||||
'join': {
|
||||
roomId: {
|
||||
'timeline': {
|
||||
'events': [
|
||||
<String, dynamic>{
|
||||
'sender': '@alice:example.com',
|
||||
'type': 'm.room.message',
|
||||
'content': <String, dynamic>{
|
||||
'msgtype': 'm.text',
|
||||
'body': '* floooof',
|
||||
'm.new_content': <String, dynamic>{
|
||||
'msgtype': 'm.text',
|
||||
'body': 'floooof',
|
||||
},
|
||||
'm.relates_to': <String, dynamic>{
|
||||
'rel_type': 'm.replace',
|
||||
'event_id': '\$other:example.com'
|
||||
},
|
||||
},
|
||||
'origin_server_ts': 1417731086799,
|
||||
'event_id': '\$edit:example.com'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
expect(room.getState('m.room.message')!.content['body'], 'meow');
|
||||
|
||||
// accept edits to the last event
|
||||
await matrix.handleSync(SyncUpdate.fromJson({
|
||||
'next_batch': 'fakesync',
|
||||
'rooms': {
|
||||
'join': {
|
||||
roomId: {
|
||||
'timeline': {
|
||||
'events': [
|
||||
<String, dynamic>{
|
||||
'sender': '@alice:example.com',
|
||||
'type': 'm.room.message',
|
||||
'content': <String, dynamic>{
|
||||
'msgtype': 'm.text',
|
||||
'body': '* floooof',
|
||||
'm.new_content': <String, dynamic>{
|
||||
'msgtype': 'm.text',
|
||||
'body': 'floooof',
|
||||
},
|
||||
'm.relates_to': <String, dynamic>{
|
||||
'rel_type': 'm.replace',
|
||||
'event_id': '\$last:example.com'
|
||||
},
|
||||
},
|
||||
'origin_server_ts': 1417731086799,
|
||||
'event_id': '\$edit:example.com'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
expect(room.getState('m.room.message')!.content['body'], '* floooof');
|
||||
|
||||
// accepts a consecutive edit
|
||||
await matrix.handleSync(SyncUpdate.fromJson({
|
||||
'next_batch': 'fakesync',
|
||||
'rooms': {
|
||||
'join': {
|
||||
roomId: {
|
||||
'timeline': {
|
||||
'events': [
|
||||
<String, dynamic>{
|
||||
'sender': '@alice:example.com',
|
||||
'type': 'm.room.message',
|
||||
'content': <String, dynamic>{
|
||||
'msgtype': 'm.text',
|
||||
'body': '* foxies',
|
||||
'm.new_content': <String, dynamic>{
|
||||
'msgtype': 'm.text',
|
||||
'body': 'foxies',
|
||||
},
|
||||
'm.relates_to': <String, dynamic>{
|
||||
'rel_type': 'm.replace',
|
||||
'event_id': '\$last:example.com'
|
||||
},
|
||||
},
|
||||
'origin_server_ts': 1417731086799,
|
||||
'event_id': '\$edit2:example.com'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
expect(room.getState('m.room.message')!.content['body'], '* foxies');
|
||||
});
|
||||
|
||||
test('getProfileFromUserId', () async {
|
||||
final profile = await matrix.getProfileFromUserId('@getme:example.com',
|
||||
getFromRooms: false);
|
||||
|
|
|
|||
Loading…
Reference in New Issue