2021-06-18 03:00:52 +02:00
|
|
|
package org.thoughtcrime.securesms.conversation.v2.input_bar.mentions
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.widget.RelativeLayout
|
2022-01-14 06:56:15 +01:00
|
|
|
import network.loki.messenger.databinding.ViewMentionCandidateV2Binding
|
2021-06-18 03:00:52 +02:00
|
|
|
import org.session.libsession.messaging.mentions.Mention
|
2022-08-10 10:17:48 +02:00
|
|
|
import org.thoughtcrime.securesms.groups.OpenGroupManager
|
2021-06-18 03:00:52 +02:00
|
|
|
import org.thoughtcrime.securesms.mms.GlideRequests
|
|
|
|
|
2022-01-14 06:56:15 +01:00
|
|
|
class MentionCandidateView : RelativeLayout {
|
|
|
|
private lateinit var binding: ViewMentionCandidateV2Binding
|
2021-06-18 03:00:52 +02:00
|
|
|
var candidate = Mention("", "")
|
|
|
|
set(newValue) { field = newValue; update() }
|
|
|
|
var glide: GlideRequests? = null
|
|
|
|
var openGroupServer: String? = null
|
|
|
|
var openGroupRoom: String? = null
|
|
|
|
|
|
|
|
constructor(context: Context) : this(context, null)
|
2022-01-14 06:56:15 +01:00
|
|
|
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
|
|
|
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
|
2021-06-18 03:00:52 +02:00
|
|
|
|
2022-01-14 06:56:15 +01:00
|
|
|
private fun initialize() {
|
|
|
|
binding = ViewMentionCandidateV2Binding.inflate(LayoutInflater.from(context), this, true)
|
2021-06-18 03:00:52 +02:00
|
|
|
}
|
|
|
|
|
2022-01-14 06:56:15 +01:00
|
|
|
private fun update() = with(binding) {
|
2021-06-18 03:00:52 +02:00
|
|
|
mentionCandidateNameTextView.text = candidate.displayName
|
2023-06-30 03:31:57 +02:00
|
|
|
profilePictureView.publicKey = candidate.publicKey
|
|
|
|
profilePictureView.displayName = candidate.displayName
|
|
|
|
profilePictureView.additionalPublicKey = null
|
|
|
|
profilePictureView.update()
|
2021-06-18 03:00:52 +02:00
|
|
|
if (openGroupServer != null && openGroupRoom != null) {
|
2022-08-10 10:17:48 +02:00
|
|
|
val isUserModerator = OpenGroupManager.isUserModerator(context, "$openGroupRoom.$openGroupServer", candidate.publicKey)
|
2021-06-18 03:00:52 +02:00
|
|
|
moderatorIconImageView.visibility = if (isUserModerator) View.VISIBLE else View.GONE
|
|
|
|
} else {
|
|
|
|
moderatorIconImageView.visibility = View.GONE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|