fix: Has new messages compares ts
This compares the origin server timestamp which might not map to the real sort order of the timeline. But it is the best solution for now.
This commit is contained in:
		
							parent
							
								
									788f8ea2a1
								
							
						
					
					
						commit
						01dfdb29fd
					
				|  | @ -508,6 +508,8 @@ class Room { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /// Checks if the last event has a read marker of the user. |   /// Checks if the last event has a read marker of the user. | ||||||
|  |   /// Warning: This compares the origin server timestamp which might not map | ||||||
|  |   /// to the real sort order of the timeline. | ||||||
|   bool get hasNewMessages { |   bool get hasNewMessages { | ||||||
|     final lastEvent = this.lastEvent; |     final lastEvent = this.lastEvent; | ||||||
| 
 | 
 | ||||||
|  | @ -522,7 +524,13 @@ class Room { | ||||||
|       return false; |       return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return true; |     final readAtMilliseconds = roomAccountData['m.receipt'] | ||||||
|  |             ?.content | ||||||
|  |             .tryGetMap<String, dynamic>(client.userID!) | ||||||
|  |             ?.tryGet<int>('ts') ?? | ||||||
|  |         0; | ||||||
|  | 
 | ||||||
|  |     return readAtMilliseconds < lastEvent.originServerTs.millisecondsSinceEpoch; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /// Returns true if this room is unread. To check if there are new messages |   /// Returns true if this room is unread. To check if there are new messages | ||||||
|  |  | ||||||
|  | @ -185,6 +185,7 @@ void main() { | ||||||
|           stateKey: '', |           stateKey: '', | ||||||
|         ), |         ), | ||||||
|       ); |       ); | ||||||
|  |       expect(room.hasNewMessages, true); | ||||||
|       expect(room.lastEvent?.body, 'cd'); |       expect(room.lastEvent?.body, 'cd'); | ||||||
|       room.setState( |       room.setState( | ||||||
|         Event( |         Event( | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue