Merge branch 'soru/better-read-indicator' into 'main'

fix: Respect hidden events when calculating read receipt message

See merge request ChristianPauly/fluffychat-flutter!310
This commit is contained in:
Sorunome 2020-12-19 15:37:58 +00:00
commit bce709f521
2 changed files with 25 additions and 17 deletions

View File

@ -3,17 +3,12 @@ import 'package:fluffychat/utils/matrix_locals.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import '../../app_config.dart';
class StateMessage extends StatelessWidget { class StateMessage extends StatelessWidget {
final Event event; final Event event;
const StateMessage(this.event); const StateMessage(this.event);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (event.type == EventTypes.Redaction || AppConfig.hideAllStateEvents) {
return Container();
}
return Padding( return Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
left: 8.0, left: 8.0,

View File

@ -154,20 +154,28 @@ class _ChatState extends State<_Chat> {
var seenByText = ''; var seenByText = '';
if (timeline.events.isNotEmpty) { if (timeline.events.isNotEmpty) {
var lastReceipts = List.from(timeline.events.first.receipts); final filteredEvents = getFilteredEvents();
lastReceipts.removeWhere((r) => final lastReceipts = <User>{};
r.user.id == room.client.userID || // now we iterate the timeline events until we hit the first rendered event
r.user.id == timeline.events.first.senderId); for (final event in timeline.events) {
lastReceipts.addAll(event.receipts.map((r) => r.user));
if (event.eventId == filteredEvents.first.eventId) {
break;
}
}
lastReceipts.removeWhere((user) =>
user.id == room.client.userID ||
user.id == filteredEvents.first.senderId);
if (lastReceipts.length == 1) { if (lastReceipts.length == 1) {
seenByText = L10n.of(context) seenByText =
.seenByUser(lastReceipts.first.user.calcDisplayname()); L10n.of(context).seenByUser(lastReceipts.first.calcDisplayname());
} else if (lastReceipts.length == 2) { } else if (lastReceipts.length == 2) {
seenByText = seenByText = L10n.of(context).seenByUserAndUser( seenByText = seenByText = L10n.of(context).seenByUserAndUser(
lastReceipts.first.user.calcDisplayname(), lastReceipts.first.calcDisplayname(),
lastReceipts[1].user.calcDisplayname()); lastReceipts.last.calcDisplayname());
} else if (lastReceipts.length > 2) { } else if (lastReceipts.length > 2) {
seenByText = L10n.of(context).seenByUserAndCountOthers( seenByText = L10n.of(context).seenByUserAndCountOthers(
lastReceipts.first.user.calcDisplayname(), lastReceipts.first.calcDisplayname(),
(lastReceipts.length - 1).toString()); (lastReceipts.length - 1).toString());
} }
} }
@ -438,12 +446,17 @@ class _ChatState extends State<_Chat> {
.contains(e.relationshipType) && .contains(e.relationshipType) &&
// always filter out m.key.* events // always filter out m.key.* events
!e.type.startsWith('m.key.verification.') && !e.type.startsWith('m.key.verification.') &&
// if a reaction has been redacted we also want it to appear in the timeline // event types to hide: redaction and reaction events
e.type != EventTypes.Reaction && // if a reaction has been redacted we also want it to be hidden in the timeline
!{EventTypes.Reaction, EventTypes.Redaction}.contains(e.type) &&
// if we enabled to hide all redacted events, don't show those // if we enabled to hide all redacted events, don't show those
(!AppConfig.hideRedactedEvents || !e.redacted) && (!AppConfig.hideRedactedEvents || !e.redacted) &&
// if we enabled to hide all unknown events, don't show those // if we enabled to hide all unknown events, don't show those
(!AppConfig.hideUnknownEvents || e.isEventTypeKnown)) (!AppConfig.hideUnknownEvents || e.isEventTypeKnown) &&
// remove state events that we don't want to render
(!{EventTypes.Message, EventTypes.Sticker, EventTypes.Encrypted}
.contains(e.type) ||
!AppConfig.hideAllStateEvents))
.toList(); .toList();
// Hide state events from the room creater right after the room created event // Hide state events from the room creater right after the room created event