fix: Do not set messages as state events anymore
We had this as a workaround and forgot to remove it after the database migration to the new way how to store the last message.
This commit is contained in:
parent
763bb0ba00
commit
79960d1be3
|
|
@ -2421,11 +2421,8 @@ class Client extends MatrixApi {
|
|||
final event = Event.fromJson(eventUpdate.content, room);
|
||||
|
||||
// Update the room state:
|
||||
if (!room.partial ||
|
||||
// make sure we do overwrite events we have already loaded.
|
||||
room.states[event.type]?.containsKey(event.stateKey ?? '') ==
|
||||
true ||
|
||||
importantStateEvents.contains(event.type)) {
|
||||
if (event.stateKey != null &&
|
||||
(!room.partial || importantStateEvents.contains(event.type))) {
|
||||
room.setState(event);
|
||||
}
|
||||
if (eventUpdate.type != EventUpdateType.timeline) break;
|
||||
|
|
|
|||
|
|
@ -176,8 +176,9 @@ class Room {
|
|||
// the room ID:
|
||||
if (state is Event) {
|
||||
final roomId = state.roomId;
|
||||
if (roomId == null || roomId != id) {
|
||||
if (roomId != id) {
|
||||
Logs().wtf('Tried to set state event for wrong room!');
|
||||
assert(roomId == id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -186,6 +187,7 @@ class Room {
|
|||
Logs().w(
|
||||
'Tried to set a non state event with type "${state.type}" as state event for a room',
|
||||
);
|
||||
assert(stateKey != null);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ void main() {
|
|||
room2.setState(Event(
|
||||
type: 'm.room.power_levels',
|
||||
content: {},
|
||||
room: room,
|
||||
room: room2,
|
||||
stateKey: '',
|
||||
senderId: client.userID!,
|
||||
eventId: '\$fakeid3:fakeServer.notExisting',
|
||||
|
|
@ -61,7 +61,7 @@ void main() {
|
|||
room2.setState(Event(
|
||||
type: 'm.room.member',
|
||||
content: {'membership': 'join'},
|
||||
room: room,
|
||||
room: room2,
|
||||
stateKey: client.userID,
|
||||
senderId: '@fakeuser:fakeServer.notExisting',
|
||||
eventId: '\$fakeid4:fakeServer.notExisting',
|
||||
|
|
|
|||
|
|
@ -496,6 +496,7 @@ void main() {
|
|||
eventId: '12',
|
||||
originServerTs: DateTime.now(),
|
||||
content: {'body': 'brainfarts'},
|
||||
stateKey: '',
|
||||
),
|
||||
);
|
||||
expect(room.lastEvent?.body, '* BBB');
|
||||
|
|
@ -1079,18 +1080,20 @@ void main() {
|
|||
|
||||
test('setState', () async {
|
||||
// not set non-state-events
|
||||
room.setState(Event.fromJson(
|
||||
{
|
||||
'content': {'history_visibility': 'shared'},
|
||||
'event_id': '\$143273582443PhrSn:example.org',
|
||||
'origin_server_ts': 1432735824653,
|
||||
'room_id': '!jEsUZKDJdhlrceRyVU:example.org',
|
||||
'sender': '@example:example.org',
|
||||
'type': 'm.custom',
|
||||
'unsigned': {'age': 1234}
|
||||
},
|
||||
room,
|
||||
));
|
||||
try {
|
||||
room.setState(Event.fromJson(
|
||||
{
|
||||
'content': {'history_visibility': 'shared'},
|
||||
'event_id': '\$143273582443PhrSn:example.org',
|
||||
'origin_server_ts': 1432735824653,
|
||||
'room_id': '!jEsUZKDJdhlrceRyVU:example.org',
|
||||
'sender': '@example:example.org',
|
||||
'type': 'm.custom',
|
||||
'unsigned': {'age': 1234},
|
||||
},
|
||||
room,
|
||||
));
|
||||
} catch (_) {}
|
||||
expect(room.getState('m.custom') != null, false);
|
||||
|
||||
// set state events
|
||||
|
|
@ -1110,18 +1113,20 @@ void main() {
|
|||
expect(room.getState('m.custom') != null, true);
|
||||
|
||||
// sets messages as state events
|
||||
room.setState(Event.fromJson(
|
||||
{
|
||||
'content': {'history_visibility': 'shared'},
|
||||
'event_id': '\$143273582443PhrSn:example.org',
|
||||
'origin_server_ts': 1432735824653,
|
||||
'room_id': '!jEsUZKDJdhlrceRyVU:example.org',
|
||||
'sender': '@example:example.org',
|
||||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
},
|
||||
room,
|
||||
));
|
||||
try {
|
||||
room.setState(Event.fromJson(
|
||||
{
|
||||
'content': {'history_visibility': 'shared'},
|
||||
'event_id': '\$143273582443PhrSn:example.org',
|
||||
'origin_server_ts': 1432735824653,
|
||||
'room_id': '!jEsUZKDJdhlrceRyVU:example.org',
|
||||
'sender': '@example:example.org',
|
||||
'type': 'm.room.message',
|
||||
'unsigned': {'age': 1234}
|
||||
},
|
||||
room,
|
||||
));
|
||||
} catch (_) {}
|
||||
expect(room.getState('m.room.message') == null, true);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue