Skip to content

Commit

Permalink
TW-499: filter invite yourself events when create new group chat
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Sep 19, 2023
1 parent 42eba43 commit adfb00a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/utils/matrix_sdk_extensions/filtered_timeline_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ extension IsStateExtension on Event {
type != EventTypes.RoomMember ||
room.joinRules != JoinRules.public ||
content.tryGet<String>('membership') == 'ban' ||
stateKey != senderId) &&
!isSomeoneChangeDisplayName() &&
!isSomeoneChangeAvatar() &&
!isGroupNameChangeWhenCreate() &&
!isGroupAvatarChangeWhenCreate() &&
!isJoinedByYourself() &&
!isActivateEndToEndEncryption() &&
!isInviteWhenCreate();

Expand All @@ -49,11 +51,13 @@ extension IsStateExtension on Event {
EventTypes.Sticker,
EventTypes.Encrypted
}.contains(type);

bool isSomeoneChangeDisplayName() {
return stateKey != null &&
prevContent?['displayname'] != null &&
prevContent!['displayname'] != content['displayname'];
}

bool isGroupNameChangeWhenCreate() {
return type == EventTypes.RoomName &&
content['name'] != null &&
Expand All @@ -65,12 +69,21 @@ extension IsStateExtension on Event {
content['url'] == null &&
prevContent?['url'] == null;
}

bool isJoinedByYourself() {
return type == EventTypes.RoomMember &&
content['membership'] == 'join' &&
senderId == stateKey &&
stateKey == room.client.userID;
}

bool isInviteWhenCreate() {
return type == EventTypes.RoomMember &&
content['membership'] != null &&
content['membership'] == 'invite' &&
content['reason'] == null;
}

bool isSomeoneChangeAvatar() {
return stateKey != null &&
prevContent?["membership"] == 'join' &&
Expand Down

0 comments on commit adfb00a

Please sign in to comment.