Skip to content

Commit

Permalink
Fix give read receipt error
Browse files Browse the repository at this point in the history
  • Loading branch information
Terzer Caroline authored and Hannich Matthias committed Aug 8, 2023
1 parent e660a85 commit fc471ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
19 changes: 3 additions & 16 deletions lib/pages/chat/events/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:matrix/matrix.dart';
import 'package:swipe_to_action/swipe_to_action.dart';

import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat/read_receipt/read_receipt_extension.dart';
import 'package:fluffychat/utils/date_time_extension.dart';
import 'package:fluffychat/utils/string_color.dart';
import 'package:fluffychat/widgets/avatar.dart';
Expand Down Expand Up @@ -120,22 +121,8 @@ class Message extends StatelessWidget {
: Theme.of(context).colorScheme.primary;
}

// add reading receipt for edu
final requiresReadReceipt = event
.aggregatedEvents(timeline, RelationshipTypes.readReceiptRequired)
.isNotEmpty;

final readReceiptGiven = event
.aggregatedEvents(timeline, RelationshipTypes.readReceipt)
.where(
(e) =>
e.content
.tryGetMap<String, dynamic>('m.relates_to')
?.tryGet<String>('user_id') ==
client.userID,
)
.toList()
.isNotEmpty;
final requiresReadReceipt = event.requiresReadReceipt(timeline);
final readReceiptGiven = event.readReceiptGiven(timeline, client.userID);

final rowChildren = <Widget>[
if (requiresReadReceipt && !ownMessage)
Expand Down
40 changes: 30 additions & 10 deletions lib/pages/chat/read_receipt/read_receipt_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,42 @@ extension ReadReceiptExtension on Event {
.isNotEmpty;

if (requiresReadReceipt && userID != null) {
final userReadReceipt =
aggregatedEvents(timeline, RelationshipTypes.readReceipt)
.where(
(e) =>
e.content
.tryGetMap<String, dynamic>('m.relates_to')
?.tryGet<String>('user_id') ==
userID,
)
.toList();
final userReadReceipt = userReadReceipts(timeline, userID);

if (userReadReceipt.isEmpty) {
readReceiptEventId = await room.sendReadReceipt(eventId, userID);

if (readReceiptEventId == null) {
// something went wrong - read receipt was not send
Logs().e(
"Read receipt for user $userID and event $eventId wasn't sent.");
}
}
}

return readReceiptEventId;
}

List<Event> userReadReceipts(timeline, userId) {
return aggregatedEvents(timeline, RelationshipTypes.readReceipt)
.where(
(e) =>
e.content
.tryGetMap<String, dynamic>('m.relates_to')
?.tryGet<String>('user_id') ==
userId &&
e.status != EventStatus.error &&
e.status != EventStatus.removed,
)
.toList();
}

bool requiresReadReceipt(Timeline timeline) {
return aggregatedEvents(timeline, RelationshipTypes.readReceiptRequired)
.isNotEmpty;
}

bool readReceiptGiven(Timeline timeline, String? userId) {
return userReadReceipts(timeline, userId).isNotEmpty;
}
}
3 changes: 1 addition & 2 deletions lib/pages/read_receipt_overview/read_receipt_overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,9 @@ class ReadReceiptOverviewController extends State<ReadReceiptOverviewPage> {
await _client!.updateOpenReadReceipts(panelItem.room!.id);
_updateOpenReadReceipt(panelItem);
_sortPanelItems();

message.isReadReceiptGiving = false;
}

message.isReadReceiptGiving = false;
setState(() {
message;
});
Expand Down

0 comments on commit fc471ea

Please # to comment.