diff --git a/src/org/thoughtcrime/securesms/ConversationListItem.java b/src/org/thoughtcrime/securesms/ConversationListItem.java index aabad17223..28b2e11254 100644 --- a/src/org/thoughtcrime/securesms/ConversationListItem.java +++ b/src/org/thoughtcrime/securesms/ConversationListItem.java @@ -272,7 +272,7 @@ public class ConversationListItem extends RelativeLayout } private @NonNull CharSequence getTrimmedSnippet(@NonNull CharSequence snippet) { - MentionManagerUtilities.INSTANCE.populateUserHexEncodedPublicKeyCacheIfNeeded(threadId, getContext()); // TODO: Terrible place to do this, but okay for now + MentionManagerUtilities.INSTANCE.populateUserPublicKeyCacheIfNeeded(threadId, getContext()); // TODO: Terrible place to do this, but okay for now snippet = MentionUtilities.highlightMentions(snippet, threadId, getContext()); return snippet.length() <= MAX_SNIPPET_LENGTH ? snippet : snippet.subSequence(0, MAX_SNIPPET_LENGTH); } diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index e3ebedc9b3..bab1f38ac8 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -463,7 +463,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity return Unit.INSTANCE; }); - MentionManagerUtilities.INSTANCE.populateUserHexEncodedPublicKeyCacheIfNeeded(threadId, this); + MentionManagerUtilities.INSTANCE.populateUserPublicKeyCacheIfNeeded(threadId, this); LokiPublicChat publicChat = DatabaseFactory.getLokiThreadDatabase(this).getPublicChat(threadId); if (publicChat != null) { diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index a91487c717..7da19119de 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -984,7 +984,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { InsertResult result = insertResult.get(); // Loki - Cache the user hex encoded public key (for mentions) - MentionManagerUtilities.INSTANCE.populateUserHexEncodedPublicKeyCacheIfNeeded(result.getThreadId(), context); + MentionManagerUtilities.INSTANCE.populateUserPublicKeyCacheIfNeeded(result.getThreadId(), context); MentionsManager.shared.cache(textMessage.getSender().serialize(), result.getThreadId()); // Loki - Store message server ID diff --git a/src/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt b/src/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt index f09bcfa65e..e237b933fd 100644 --- a/src/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt @@ -8,22 +8,28 @@ import org.whispersystems.signalservice.loki.protocol.mentions.MentionsManager object MentionManagerUtilities { - fun populateUserHexEncodedPublicKeyCacheIfNeeded(threadID: Long, context: Context) { - if (MentionsManager.shared.userHexEncodedPublicKeyCache[threadID] != null) { return } + fun populateUserPublicKeyCacheIfNeeded(threadID: Long, context: Context) { val result = mutableSetOf() - val messageDatabase = DatabaseFactory.getMmsSmsDatabase(context) - val reader = messageDatabase.readerFor(messageDatabase.getConversation(threadID)) - var record: MessageRecord? = reader.next - while (record != null) { - result.add(record.individualRecipient.address.serialize()) - try { - record = reader.next - } catch (exception: Exception) { - record = null + val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID) + if (recipient != null && recipient.address.isClosedGroup) { + val members = DatabaseFactory.getGroupDatabase(context).getGroupMembers(recipient.address.toGroupString(), false).map { it.address.serialize() } + result.addAll(members) + } else { + if (MentionsManager.shared.userPublicKeyCache[threadID] != null) { return } + val messageDatabase = DatabaseFactory.getMmsSmsDatabase(context) + val reader = messageDatabase.readerFor(messageDatabase.getConversation(threadID)) + var record: MessageRecord? = reader.next + while (record != null) { + result.add(record.individualRecipient.address.serialize()) + try { + record = reader.next + } catch (exception: Exception) { + record = null + } } + reader.close() + result.add(TextSecurePreferences.getLocalNumber(context)) } - reader.close() - result.add(TextSecurePreferences.getLocalNumber(context)) - MentionsManager.shared.userHexEncodedPublicKeyCache[threadID] = result + MentionsManager.shared.userPublicKeyCache[threadID] = result } } \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt b/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt index 6f9903c83a..375cd23a16 100644 --- a/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/ConversationView.kt @@ -9,7 +9,7 @@ import android.widget.LinearLayout import kotlinx.android.synthetic.main.view_conversation.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.database.model.ThreadRecord -import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities.populateUserHexEncodedPublicKeyCacheIfNeeded +import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded import org.thoughtcrime.securesms.loki.utilities.MentionUtilities.highlightMentions import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.util.DateUtils @@ -46,14 +46,14 @@ class ConversationView : LinearLayout { // region Updating fun bind(thread: ThreadRecord, isTyping: Boolean, glide: GlideRequests) { this.thread = thread - populateUserHexEncodedPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a terrible place to do this + populateUserPublicKeyCacheIfNeeded(thread.threadId, context) // FIXME: This is a terrible place to do this unreadMessagesIndicatorView.visibility = if (thread.unreadCount > 0) View.VISIBLE else View.INVISIBLE if (thread.recipient.isGroupRecipient) { if ("Session Public Chat" == thread.recipient.name) { profilePictureView.hexEncodedPublicKey = "" profilePictureView.isRSSFeed = true } else { - val users = MentionsManager.shared.userHexEncodedPublicKeyCache[thread.threadId]?.toList() ?: listOf() + val users = MentionsManager.shared.userPublicKeyCache[thread.threadId]?.toList() ?: listOf() val randomUsers = users.sorted() // Sort to provide a level of stability profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: "" profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: "" diff --git a/src/org/thoughtcrime/securesms/loki/views/UserView.kt b/src/org/thoughtcrime/securesms/loki/views/UserView.kt index 3fea58165d..16ffc77db4 100644 --- a/src/org/thoughtcrime/securesms/loki/views/UserView.kt +++ b/src/org/thoughtcrime/securesms/loki/views/UserView.kt @@ -53,7 +53,7 @@ class UserView : LinearLayout { profilePictureView.isRSSFeed = true } else { val threadID = GroupManager.getThreadIDFromGroupID(address, context) - val users = MentionsManager.shared.userHexEncodedPublicKeyCache[threadID]?.toList() ?: listOf() + val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toList() ?: listOf() val randomUsers = users.sorted() // Sort to provide a level of stability profilePictureView.hexEncodedPublicKey = randomUsers.getOrNull(0) ?: "" profilePictureView.additionalHexEncodedPublicKey = randomUsers.getOrNull(1) ?: ""