From a2a2015af6ee190b578a4a6a7092a73a52f0e24f Mon Sep 17 00:00:00 2001
From: Onuray Sahin <onurays@element.io>
Date: Tue, 10 Nov 2020 17:17:05 +0300
Subject: [PATCH] Exclude yourself when decorating rooms which are direct or
 don't have more than 2 users.

---
 CHANGES.md                                                    | 1 +
 .../sdk/internal/crypto/crosssigning/UpdateTrustWorker.kt     | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index fa30acabd5..d61c312fca 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -9,6 +9,7 @@ Improvements ๐Ÿ™Œ:
 
 Bugfix ๐Ÿ›:
  - Fix issue when updating the avatar of a room
+ - Exclude yourself when decorating rooms which are direct or don't have more than 2 users (#2370)
 
 Translations ๐Ÿ—ฃ:
  -
diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/UpdateTrustWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/UpdateTrustWorker.kt
index f28fe7d642..665d770e7f 100644
--- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/UpdateTrustWorker.kt
+++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/crosssigning/UpdateTrustWorker.kt
@@ -241,9 +241,9 @@ internal class UpdateTrustWorker(context: Context,
     private fun computeRoomShield(activeMemberUserIds: List<String>, roomSummaryEntity: RoomSummaryEntity): RoomEncryptionTrustLevel {
         Timber.d("## CrossSigning - computeRoomShield ${roomSummaryEntity.roomId} -> $activeMemberUserIds")
         // The set of โ€œall usersโ€ depends on the type of room:
-        // For regular / topic rooms, all users including yourself, are considered when decorating a room
+        // For regular / topic rooms which have more than 2 members (including yourself) are considered when decorating a room
         // For 1:1 and group DM rooms, all other users (i.e. excluding yourself) are considered when decorating a room
-        val listToCheck = if (roomSummaryEntity.isDirect) {
+        val listToCheck = if (roomSummaryEntity.isDirect || activeMemberUserIds.size <= 2) {
             activeMemberUserIds.filter { it != myUserId }
         } else {
             activeMemberUserIds