fix: Do not update lastEvent with state events
This commit is contained in:
parent
faae7935b5
commit
9d9865a1a1
|
|
@ -2435,8 +2435,7 @@ class Client extends MatrixApi {
|
|||
|
||||
// If last event is null or not a valid room preview event anyway,
|
||||
// just use this:
|
||||
if (room.lastEvent == null ||
|
||||
!roomPreviewLastEvents.contains(room.lastEvent?.type)) {
|
||||
if (room.lastEvent == null) {
|
||||
room.lastEvent = event;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class Room {
|
|||
summary: RoomSummary.fromJson(Map<String, dynamic>.from(json['summary'])),
|
||||
);
|
||||
if (json['last_event'] != null) {
|
||||
room._lastEvent = Event.fromJson(json['last_event'], room);
|
||||
room.lastEvent = Event.fromJson(json['last_event'], room);
|
||||
}
|
||||
return room;
|
||||
}
|
||||
|
|
@ -365,33 +365,7 @@ class Room {
|
|||
/// Wheither this is a direct chat or not
|
||||
bool get isDirectChat => directChatMatrixID != null;
|
||||
|
||||
Event? _lastEvent;
|
||||
|
||||
set lastEvent(Event? event) {
|
||||
_lastEvent = event;
|
||||
}
|
||||
|
||||
Event? get lastEvent {
|
||||
if (_lastEvent != null) return _lastEvent;
|
||||
|
||||
// Just pick the newest state event as an indicator for when the last
|
||||
// activity was in this room. This is better than nothing:
|
||||
var lastTime = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
Event? lastEvent;
|
||||
|
||||
states.forEach((final String key, final entry) {
|
||||
final state = entry[''];
|
||||
if (state == null) return;
|
||||
if (state is! Event) return;
|
||||
if (state.originServerTs.millisecondsSinceEpoch >
|
||||
lastTime.millisecondsSinceEpoch) {
|
||||
lastTime = state.originServerTs;
|
||||
lastEvent = state;
|
||||
}
|
||||
});
|
||||
|
||||
return lastEvent;
|
||||
}
|
||||
Event? lastEvent;
|
||||
|
||||
/// Returns a list of all current typing users.
|
||||
List<User> get typingUsers {
|
||||
|
|
@ -416,9 +390,8 @@ class Room {
|
|||
required this.client,
|
||||
Map<String, BasicRoomEvent>? roomAccountData,
|
||||
RoomSummary? summary,
|
||||
Event? lastEvent,
|
||||
this.lastEvent,
|
||||
}) : roomAccountData = roomAccountData ?? <String, BasicRoomEvent>{},
|
||||
_lastEvent = lastEvent,
|
||||
summary = summary ??
|
||||
RoomSummary.fromJson({
|
||||
'm.joined_member_count': 0,
|
||||
|
|
|
|||
|
|
@ -323,26 +323,31 @@ void main() {
|
|||
.timeout(const Duration(seconds: 5));
|
||||
client.rooms.add(room);
|
||||
// we build up an encrypted message so that we can test if it successfully decrypted afterwards
|
||||
room.setState(
|
||||
Event(
|
||||
senderId: '@test:example.com',
|
||||
type: 'm.room.encrypted',
|
||||
room: room,
|
||||
eventId: '12345',
|
||||
originServerTs: DateTime.now(),
|
||||
content: {
|
||||
'algorithm': AlgorithmTypes.megolmV1AesSha2,
|
||||
'ciphertext': session.encrypt(json.encode({
|
||||
'type': 'm.room.message',
|
||||
'content': {'msgtype': 'm.text', 'body': 'foxies'},
|
||||
})),
|
||||
'device_id': client.deviceID,
|
||||
'sender_key': client.identityKey,
|
||||
'session_id': sessionId,
|
||||
},
|
||||
stateKey: '',
|
||||
),
|
||||
);
|
||||
await client.handleSync(SyncUpdate(
|
||||
nextBatch: '',
|
||||
rooms: RoomsUpdate(join: {
|
||||
room.id: JoinedRoomUpdate(
|
||||
timeline: TimelineUpdate(events: [
|
||||
Event(
|
||||
senderId: '@test:example.com',
|
||||
type: 'm.room.encrypted',
|
||||
room: room,
|
||||
eventId: '12345',
|
||||
originServerTs: DateTime.now(),
|
||||
content: {
|
||||
'algorithm': AlgorithmTypes.megolmV1AesSha2,
|
||||
'ciphertext': session.encrypt(json.encode({
|
||||
'type': 'm.room.message',
|
||||
'content': {'msgtype': 'm.text', 'body': 'foxies'},
|
||||
})),
|
||||
'device_id': client.deviceID,
|
||||
'sender_key': client.identityKey,
|
||||
'session_id': sessionId,
|
||||
},
|
||||
stateKey: '',
|
||||
)
|
||||
]))
|
||||
})));
|
||||
expect(room.lastEvent?.type, 'm.room.encrypted');
|
||||
// set a payload...
|
||||
var sessionPayload = <String, dynamic>{
|
||||
|
|
|
|||
Loading…
Reference in New Issue