Merge branch 'krille/do-not-display-seen-events' into 'main'
fix: Do not show seen events in push notification See merge request famedly/company/frontend/famedlysdk!1048
This commit is contained in:
commit
a38d726c6b
|
|
@ -1036,10 +1036,13 @@ class Client extends MatrixApi {
|
||||||
/// initalized, it will only fetch the necessary parts of the database. This
|
/// initalized, it will only fetch the necessary parts of the database. This
|
||||||
/// should make it possible to run this parallel to another client with the
|
/// should make it possible to run this parallel to another client with the
|
||||||
/// same client name.
|
/// same client name.
|
||||||
|
/// This also checks if the given event has a readmarker and returns null
|
||||||
|
/// in this case.
|
||||||
Future<Event?> getEventByPushNotification(
|
Future<Event?> getEventByPushNotification(
|
||||||
PushNotification notification, {
|
PushNotification notification, {
|
||||||
bool storeInDatabase = true,
|
bool storeInDatabase = true,
|
||||||
Duration timeoutForServerRequests = const Duration(seconds: 8),
|
Duration timeoutForServerRequests = const Duration(seconds: 8),
|
||||||
|
bool returnNullIfSeen = true,
|
||||||
}) async {
|
}) async {
|
||||||
// Get access token if necessary:
|
// Get access token if necessary:
|
||||||
final database = _database ??= await databaseBuilder?.call(this);
|
final database = _database ??= await databaseBuilder?.call(this);
|
||||||
|
|
@ -1111,6 +1114,7 @@ class Client extends MatrixApi {
|
||||||
matrixEvent ??= await database
|
matrixEvent ??= await database
|
||||||
?.getEventById(eventId, room)
|
?.getEventById(eventId, room)
|
||||||
.timeout(timeoutForServerRequests);
|
.timeout(timeoutForServerRequests);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
matrixEvent ??= await getOneRoomEvent(roomId, eventId)
|
matrixEvent ??= await getOneRoomEvent(roomId, eventId)
|
||||||
.timeout(timeoutForServerRequests);
|
.timeout(timeoutForServerRequests);
|
||||||
|
|
@ -1128,6 +1132,28 @@ class Client extends MatrixApi {
|
||||||
throw Exception('Unable to find event for this push notification!');
|
throw Exception('Unable to find event for this push notification!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the event was already in database, check if it has a read marker
|
||||||
|
// before displaying it.
|
||||||
|
if (returnNullIfSeen) {
|
||||||
|
if (room.fullyRead == matrixEvent.eventId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final readMarkerEvent = await database
|
||||||
|
?.getEventById(room.fullyRead, room)
|
||||||
|
.timeout(timeoutForServerRequests);
|
||||||
|
if (readMarkerEvent != null &&
|
||||||
|
readMarkerEvent.originServerTs.isAfter(
|
||||||
|
matrixEvent.originServerTs
|
||||||
|
// As origin server timestamps are not always correct data in
|
||||||
|
// a federated environment, we add 10 minutes to the calculation
|
||||||
|
// to reduce the possibility that an event is marked as read which
|
||||||
|
// isn't.
|
||||||
|
..add(Duration(minutes: 10)),
|
||||||
|
)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Load the sender of this event
|
// Load the sender of this event
|
||||||
try {
|
try {
|
||||||
await room
|
await room
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue