From fa0253e08c140c3799a41a8e4b03aafe0f0a89c2 Mon Sep 17 00:00:00 2001
From: Pierre Nicolas <pierre.nicolas@savoirfairelinux.com>
Date: Mon, 26 Aug 2024 13:36:23 -0400
Subject: [PATCH] presence: don't show user presence

`AvatarDrawable.withContact` always display presence.
New function `AvatarDrawable.withUser` will not display presence.

GitLab: #1757
Change-Id: I55f437c6b13eabe4db834c57bbf8e7822db6b587
---
 .../main/java/cx/ring/views/AvatarDrawable.kt | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt b/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt
index b220e4a9d..b7815403d 100644
--- a/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt
+++ b/jami-android/app/src/main/java/cx/ring/views/AvatarDrawable.kt
@@ -220,6 +220,12 @@ class AvatarDrawable : Drawable {
         fun withNameData(profileName: String?, username: String?) =
             withName(if (profileName.isNullOrEmpty()) username else profileName)
 
+        fun withUser(user: ContactViewModel?) = if (user == null) this else
+            withPhoto(user.profile.avatar as? Bitmap?)
+                .withId(user.contact.uri.toString())
+                .withPresence(false)
+                .withNameData(user.profile.displayName, user.registeredName)
+
         fun withContact(contact: ContactViewModel?) = if (contact == null) this else
             withPhoto(contact.profile.avatar as? Bitmap?)
                 .withId(contact.contact.uri.toString())
@@ -237,8 +243,12 @@ class AvatarDrawable : Drawable {
             }
             val bitmaps: MutableList<Bitmap> = ArrayList(contacts.size)
             var notTheUser = 0
+            var user: ContactViewModel? = null
             for (contact in contacts) {
-                if (contact.contact.isUser) continue
+                if (contact.contact.isUser) {
+                    user = contact
+                    continue
+                }
                 notTheUser++
                 val bitmap = contact.profile.avatar as? Bitmap?
                 if (bitmap != null) {
@@ -251,13 +261,8 @@ class AvatarDrawable : Drawable {
                     if (!contact.contact.isUser) return withContact(contact)
                 }
             }
-            if (bitmaps.isEmpty()) {
-                // Fallback to the user avatar
-                for (contact in contacts) return withContact(contact)
-            } else {
-                return withPhotos(bitmaps)
-            }
-            return this
+            // If alone in group, fallback to the user avatar.
+            return if (bitmaps.isEmpty()) withUser(user) else withPhotos(bitmaps)
         }
 
         fun withConversation(conversation: Conversation, profile: Profile, contacts: List<ContactViewModel>): Builder =
-- 
GitLab