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