fix: Show reactions as last events and refactor hasNewMessage
Reactions are triggering push notifications and should therefore be displayed as last events in the room list of a client. The body should just display the reaction key. This fixes that rooms with new reactions can't set to read.
This commit is contained in:
parent
f8cea9e82b
commit
68fcee98cb
|
|
@ -190,6 +190,7 @@ class Client extends MatrixApi {
|
|||
EventTypes.Message,
|
||||
EventTypes.Encrypted,
|
||||
EventTypes.Sticker,
|
||||
EventTypes.Reaction,
|
||||
]);
|
||||
|
||||
// register all the default commands
|
||||
|
|
|
|||
|
|
@ -167,11 +167,7 @@ class Room {
|
|||
return;
|
||||
}
|
||||
|
||||
final isMessageEvent = [
|
||||
EventTypes.Message,
|
||||
EventTypes.Sticker,
|
||||
EventTypes.Encrypted,
|
||||
].contains(state.type);
|
||||
final isMessageEvent = client.roomPreviewLastEvents.contains(state.type);
|
||||
|
||||
// We ignore events editing events older than the current-latest here so
|
||||
// i.e. newly sent edits for older events don't show up in room preview
|
||||
|
|
@ -514,9 +510,19 @@ class Room {
|
|||
/// Checks if the last event has a read marker of the user.
|
||||
bool get hasNewMessages {
|
||||
final lastEvent = this.lastEvent;
|
||||
return lastEvent != null &&
|
||||
!lastEvent.receipts
|
||||
.any((receipt) => receipt.user.senderId == client.userID!);
|
||||
|
||||
// There is no known event or the last event is only a state fallback event,
|
||||
// we assume there is no new messages.
|
||||
if (lastEvent == null ||
|
||||
!client.roomPreviewLastEvents.contains(lastEvent.type)) return false;
|
||||
|
||||
// Read marker is on the last event so no new messages.
|
||||
if (lastEvent.receipts
|
||||
.any((receipt) => receipt.user.senderId == client.userID!)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns true if this room is unread. To check if there are new messages
|
||||
|
|
|
|||
|
|
@ -213,7 +213,12 @@ abstract class EventLocalizations {
|
|||
_localizedBodyNormalMessage(event, i18n, body),
|
||||
EventTypes.Message: (event, i18n, body) =>
|
||||
_localizedBodyNormalMessage(event, i18n, body),
|
||||
EventTypes.Reaction: (event, i18n, body) =>
|
||||
_localizedBodyNormalMessage(event, i18n, body),
|
||||
EventTypes.Reaction: (event, i18n, body) => i18n.sentReaction(
|
||||
event.sender.calcDisplayname(),
|
||||
event.content
|
||||
.tryGetMap<String, dynamic>('m.relates_to')
|
||||
?.tryGet<String>('key') ??
|
||||
body,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,6 +122,8 @@ abstract class MatrixLocalizations {
|
|||
|
||||
String sentAVideo(String senderName);
|
||||
|
||||
String sentReaction(String senderName, String reactionKey);
|
||||
|
||||
String sharedTheLocation(String senderName);
|
||||
|
||||
String couldNotDecryptMessage(String errorText);
|
||||
|
|
|
|||
|
|
@ -225,4 +225,9 @@ class MatrixDefaultLocalizations extends MatrixLocalizations {
|
|||
String startedACall(String senderName) {
|
||||
return 'startedACall';
|
||||
}
|
||||
|
||||
@override
|
||||
String sentReaction(String senderName, String reactionKey) {
|
||||
return '$senderName reacted with $reactionKey';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,6 +258,26 @@ void main() {
|
|||
expect(room.lastEvent?.eventId, '5');
|
||||
expect(room.lastEvent?.body, 'edited cdc');
|
||||
expect(room.lastEvent?.status, EventStatus.sent);
|
||||
// Are reactions coming through?
|
||||
room.setState(
|
||||
Event(
|
||||
senderId: '@test:example.com',
|
||||
type: EventTypes.Reaction,
|
||||
room: room,
|
||||
eventId: '123456',
|
||||
originServerTs: DateTime.now(),
|
||||
content: {
|
||||
'm.relates_to': {
|
||||
'rel_type': RelationshipTypes.reaction,
|
||||
'event_id': '1234',
|
||||
'key': ':-)',
|
||||
}
|
||||
},
|
||||
stateKey: '',
|
||||
),
|
||||
);
|
||||
expect(room.lastEvent?.eventId, '123456');
|
||||
expect(room.lastEvent?.type, EventTypes.Reaction);
|
||||
});
|
||||
test('lastEvent when reply parent edited', () async {
|
||||
room.setState(
|
||||
|
|
|
|||
Loading…
Reference in New Issue