Proper names for visible message view

pull/1710/head
ThomasSession 2 months ago
parent 2a7b08fe64
commit fb0dc85bff

@ -343,6 +343,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val adapter = ConversationAdapter(
this,
cursor,
viewModel.recipient,
storage.getLastSeen(viewModel.threadId),
reverseMessageList,
onItemPress = { message, position, view, event ->

@ -20,6 +20,8 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsignal.utilities.AccountId
import org.thoughtcrime.securesms.conversation.v2.messages.ControlMessageView
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageViewDelegate
@ -32,6 +34,7 @@ import kotlin.math.min
class ConversationAdapter(
context: Context,
cursor: Cursor,
conversation: Recipient?,
originalLastSeen: Long,
private val isReversed: Boolean,
private val onItemPress: (MessageRecord, Int, VisibleMessageView, MotionEvent) -> Unit,
@ -53,7 +56,10 @@ class ConversationAdapter(
private val contactCache = SparseArray<Contact>(100)
private val contactLoadedCache = SparseBooleanArray(100)
private val lastSeen = AtomicLong(originalLastSeen)
private var lastSentMessageId: Long = -1L
private val groupId = if(conversation?.isGroupV2Recipient == true)
AccountId(conversation.address.serialize())
else null
init {
lifecycleCoroutineScope.launch(IO) {
@ -134,11 +140,12 @@ class ConversationAdapter(
glide,
searchQuery,
contact,
// we pass in the groupId for groupV2 to use for determining the name of the members
groupId,
senderId,
lastSeen.get(),
visibleMessageViewDelegate,
onAttachmentNeedsDownload,
lastSentMessageId
onAttachmentNeedsDownload
)
if (!message.isDeleted) {

@ -61,8 +61,10 @@ import org.thoughtcrime.securesms.home.UserDetailsBottomSheet
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import network.loki.messenger.libsession_util.getOrNull
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.utilities.Address.Companion.fromSerialized
import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.truncateIdForDisplay
import org.session.libsignal.utilities.AccountId
import org.thoughtcrime.securesms.database.GroupDatabase
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
@ -152,11 +154,11 @@ class VisibleMessageView : FrameLayout {
glide: RequestManager = Glide.with(this),
searchQuery: String? = null,
contact: Contact? = null,
groupId: AccountId? = null,
senderAccountID: String,
lastSeen: Long,
delegate: VisibleMessageViewDelegate? = null,
onAttachmentNeedsDownload: (DatabaseAttachment) -> Unit,
lastSentMessageId: Long
onAttachmentNeedsDownload: (DatabaseAttachment) -> Unit
) {
replyDisabled = message.isOpenGroupInvitation
val threadID = message.threadId
@ -233,7 +235,12 @@ class VisibleMessageView : FrameLayout {
binding.senderNameTextView.isVisible = !message.isOutgoing && (isStartOfMessageCluster && (isGroupThread || snIsSelected))
val contactContext =
if (thread.isCommunityRecipient) ContactContext.OPEN_GROUP else ContactContext.REGULAR
binding.senderNameTextView.text = contact?.displayName(contactContext) ?: senderAccountID
binding.senderNameTextView.text = MessagingModuleConfiguration.shared.storage.getContactNameWithAccountID(
contact = contact,
accountID = senderAccountID,
contactContext = contactContext,
groupId = groupId
)
// Unread marker
val shouldShowUnreadMarker = lastSeen != -1L && message.timestamp > lastSeen && (previous == null || previous.timestamp <= lastSeen) && !message.isOutgoing

@ -1243,6 +1243,10 @@ open class Storage @Inject constructor(
override fun getContactNameWithAccountID(accountID: String, groupId: AccountId?, contactContext: Contact.ContactContext): String {
val contact = sessionContactDatabase.getContactWithAccountID(accountID)
return getContactNameWithAccountID(contact, accountID, groupId, contactContext)
}
override fun getContactNameWithAccountID(contact: Contact?, accountID: String, groupId: AccountId?, contactContext: Contact.ContactContext): String {
// first attempt to get the name from the contact
val userName: String? = contact?.displayName(contactContext)
?: if(groupId != null){

@ -210,6 +210,7 @@ interface StorageProtocol {
// Contacts
fun getContactWithAccountID(accountID: String): Contact?
fun getContactNameWithAccountID(accountID: String, groupId: AccountId? = null, contactContext: Contact.ContactContext = Contact.ContactContext.REGULAR): String
fun getContactNameWithAccountID(contact: Contact?, accountID: String, groupId: AccountId? = null, contactContext: Contact.ContactContext = Contact.ContactContext.REGULAR): String
fun getAllContacts(): Set<Contact>
fun setContact(contact: Contact)
fun getRecipientForThread(threadId: Long): Recipient?

Loading…
Cancel
Save