fluffychat/lib/utils/matrix_sdk_extensions/filtered_timeline_extension.dart

46 lines
1.7 KiB
Dart
Raw Normal View History

import 'package:matrix/matrix.dart';
2020-12-23 10:23:19 +00:00
import '../../config/app_config.dart';
2020-12-23 10:23:19 +00:00
extension IsStateExtension on Event {
bool get isVisibleInGui =>
// always filter out edit and reaction relationships
!{RelationshipTypes.edit, RelationshipTypes.reaction}
.contains(relationshipType) &&
// always filter out m.key.* events
!type.startsWith('m.key.verification.') &&
// event types to hide: redaction and reaction events
// if a reaction has been redacted we also want it to be hidden in the timeline
!{EventTypes.Reaction, EventTypes.Redaction}.contains(type) &&
// if we enabled to hide all redacted events, don't show those
(!AppConfig.hideRedactedEvents || !redacted) &&
// if we enabled to hide all unknown events, don't show those
(!AppConfig.hideUnknownEvents || isEventTypeKnown) &&
// remove state events that we don't want to render
(isState || !AppConfig.hideAllStateEvents) &&
// hide unimportant state events
(!AppConfig.hideUnimportantStateEvents ||
!isState ||
importantStateEvents.contains(type)) &&
2022-10-15 09:11:36 +00:00
// hide simple join/leave member events in public rooms
(!AppConfig.hideUnimportantStateEvents ||
type != EventTypes.RoomMember ||
2022-10-15 09:11:36 +00:00
room.joinRules != JoinRules.public ||
content.tryGet<String>('membership') == 'ban' ||
stateKey != senderId);
2020-12-23 10:23:19 +00:00
static const Set<String> importantStateEvents = {
EventTypes.Encryption,
EventTypes.RoomCreate,
EventTypes.RoomMember,
EventTypes.RoomTombstone,
EventTypes.CallInvite,
};
bool get isState => !{
EventTypes.Message,
EventTypes.Sticker,
2023-08-18 05:24:31 +00:00
EventTypes.Encrypted,
}.contains(type);
}