mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-22 16:07:30 +00:00
Cleanup
This commit is contained in:
parent
2e50dc08bb
commit
398b5bf7b4
@ -43,18 +43,15 @@ class ContextMenuList(recyclerView: RecyclerView, onItemClick: () -> Unit) {
|
||||
mappingAdapter.submitList(items.toAdapterItems())
|
||||
}
|
||||
|
||||
private fun List<ActionItem>.toAdapterItems(): List<DisplayItem> {
|
||||
return this.mapIndexed { index, item ->
|
||||
val displayType: DisplayType = when {
|
||||
this.size == 1 -> DisplayType.ONLY
|
||||
private fun List<ActionItem>.toAdapterItems(): List<DisplayItem> =
|
||||
mapIndexed { index, item ->
|
||||
when {
|
||||
size == 1 -> DisplayType.ONLY
|
||||
index == 0 -> DisplayType.TOP
|
||||
index == this.size - 1 -> DisplayType.BOTTOM
|
||||
index == size - 1 -> DisplayType.BOTTOM
|
||||
else -> DisplayType.MIDDLE
|
||||
}
|
||||
|
||||
DisplayItem(item, displayType)
|
||||
}.let { DisplayItem(item, it) }
|
||||
}
|
||||
}
|
||||
|
||||
private data class DisplayItem(
|
||||
val item: ActionItem,
|
||||
@ -94,9 +91,7 @@ class ContextMenuList(recyclerView: RecyclerView, onItemClick: () -> Unit) {
|
||||
color?.let(title::setTextColor)
|
||||
color?.let(subtitle::setTextColor)
|
||||
subtitle.isGone = true
|
||||
item.subtitle?.let {
|
||||
startSubtitleJob(subtitle, it)
|
||||
}
|
||||
item.subtitle?.let { startSubtitleJob(subtitle, it) }
|
||||
itemView.setOnClickListener {
|
||||
item.action.run()
|
||||
onItemClick()
|
||||
|
@ -5,9 +5,7 @@ import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.DimenRes
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.marginEnd
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
@ -21,6 +19,7 @@ import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
||||
import org.session.libsession.messaging.open_groups.OpenGroup
|
||||
import org.session.libsession.utilities.ExpirationUtil
|
||||
import org.session.libsession.utilities.modifyLayoutParams
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilities
|
||||
import org.thoughtcrime.securesms.database.GroupDatabase
|
||||
@ -28,12 +27,14 @@ import org.thoughtcrime.securesms.database.LokiAPIDatabase
|
||||
import org.thoughtcrime.securesms.util.DateUtils
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ConversationActionBarView : LinearLayout {
|
||||
|
||||
private lateinit var binding: ViewConversationActionBarBinding
|
||||
class ConversationActionBarView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
private val binding = ViewConversationActionBarBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
|
||||
@Inject lateinit var lokiApiDb: LokiAPIDatabase
|
||||
@Inject lateinit var groupDb: GroupDatabase
|
||||
@ -46,12 +47,7 @@ class ConversationActionBarView : LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(context: Context) : super(context) { initialize() }
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
|
||||
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
|
||||
|
||||
private fun initialize() {
|
||||
binding = ViewConversationActionBarBinding.inflate(LayoutInflater.from(context), this, true)
|
||||
init {
|
||||
var previousState: Int
|
||||
var currentState = 0
|
||||
binding.settingsPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
|
||||
@ -68,8 +64,7 @@ class ConversationActionBarView : LinearLayout {
|
||||
}
|
||||
})
|
||||
binding.settingsPager.adapter = settingsAdapter
|
||||
val mediator = TabLayoutMediator(binding.settingsTabLayout, binding.settingsPager) { _, _ -> }
|
||||
mediator.attach()
|
||||
TabLayoutMediator(binding.settingsTabLayout, binding.settingsPager) { _, _ -> }.attach()
|
||||
}
|
||||
|
||||
fun bind(
|
||||
@ -80,42 +75,32 @@ class ConversationActionBarView : LinearLayout {
|
||||
openGroup: OpenGroup? = null
|
||||
) {
|
||||
this.delegate = delegate
|
||||
@DimenRes val sizeID: Int = if (recipient.isClosedGroupRecipient) {
|
||||
R.dimen.medium_profile_picture_size
|
||||
} else {
|
||||
R.dimen.small_profile_picture_size
|
||||
}
|
||||
val size = resources.getDimension(sizeID).roundToInt()
|
||||
binding.profilePictureView.layoutParams = LayoutParams(size, size)
|
||||
binding.profilePictureView.layoutParams = resources.getDimensionPixelSize(
|
||||
if (recipient.isClosedGroupRecipient) R.dimen.medium_profile_picture_size else R.dimen.small_profile_picture_size
|
||||
).let { LayoutParams(it, it) }
|
||||
MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(threadId, context)
|
||||
update(recipient, openGroup, config)
|
||||
}
|
||||
|
||||
fun update(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
|
||||
binding.profilePictureView.update(recipient)
|
||||
binding.conversationTitleView.text = when {
|
||||
recipient.isLocalNumber -> context.getString(R.string.note_to_self)
|
||||
else -> recipient.toShortString()
|
||||
}
|
||||
binding.conversationTitleView.text = recipient.takeUnless { it.isLocalNumber }?.toShortString() ?: context.getString(R.string.note_to_self)
|
||||
updateSubtitle(recipient, openGroup, config)
|
||||
|
||||
binding.conversationTitleContainer.apply {
|
||||
layoutParams = (layoutParams as MarginLayoutParams).apply {
|
||||
marginEnd = if (recipient.showCallMenu()) 0 else binding.profilePictureView.width
|
||||
}
|
||||
binding.conversationTitleContainer.modifyLayoutParams<MarginLayoutParams> {
|
||||
marginEnd = if (recipient.showCallMenu()) 0 else binding.profilePictureView.width
|
||||
}
|
||||
}
|
||||
|
||||
fun updateSubtitle(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
|
||||
val settings = mutableListOf<ConversationSetting>()
|
||||
if (config?.isEnabled == true) {
|
||||
val prefix = if (config.expiryMode is ExpiryMode.AfterRead) {
|
||||
context.getString(R.string.expiration_type_disappear_after_read)
|
||||
} else {
|
||||
context.getString(R.string.expiration_type_disappear_after_send)
|
||||
}
|
||||
val prefix = when (config.expiryMode) {
|
||||
is ExpiryMode.AfterRead -> R.string.expiration_type_disappear_after_read
|
||||
else -> R.string.expiration_type_disappear_after_send
|
||||
}.let(context::getString)
|
||||
settings += ConversationSetting(
|
||||
"$prefix - ${ExpirationUtil.getExpirationAbbreviatedDisplayValue(context, config.expiryMode.expirySeconds)}" ,
|
||||
"$prefix - ${ExpirationUtil.getExpirationAbbreviatedDisplayValue(context, config.expiryMode.expirySeconds)}",
|
||||
ConversationSettingType.EXPIRATION,
|
||||
R.drawable.ic_timer,
|
||||
resources.getString(R.string.AccessibilityId_disappearing_messages_type_and_time)
|
||||
@ -123,11 +108,9 @@ class ConversationActionBarView : LinearLayout {
|
||||
}
|
||||
if (recipient.isMuted) {
|
||||
settings += ConversationSetting(
|
||||
if (recipient.mutedUntil != Long.MAX_VALUE) {
|
||||
context.getString(R.string.ConversationActivity_muted_until_date, DateUtils.getFormattedDateTime(recipient.mutedUntil, "EEE, MMM d, yyyy HH:mm", Locale.getDefault()))
|
||||
} else {
|
||||
context.getString(R.string.ConversationActivity_muted_forever)
|
||||
},
|
||||
recipient.mutedUntil.takeUnless { it == Long.MAX_VALUE }
|
||||
?.let { context.getString(R.string.ConversationActivity_muted_until_date, DateUtils.getFormattedDateTime(it, "EEE, MMM d, yyyy HH:mm", Locale.getDefault())) }
|
||||
?: context.getString(R.string.ConversationActivity_muted_forever),
|
||||
ConversationSettingType.NOTIFICATION,
|
||||
R.drawable.ic_outline_notifications_off_24
|
||||
)
|
||||
@ -174,23 +157,15 @@ class ConversationActionBarView : LinearLayout {
|
||||
binding.leftArrowImageView.isVisible = itemCount > 1
|
||||
binding.rightArrowImageView.isVisible = itemCount > 1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class SettingsDiffer: DiffUtil.ItemCallback<ConversationSetting>() {
|
||||
override fun areItemsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean {
|
||||
return oldItem.settingType === newItem.settingType
|
||||
}
|
||||
override fun areContentsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
override fun areItemsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean = oldItem.settingType === newItem.settingType
|
||||
override fun areContentsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean = oldItem == newItem
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun interface ConversationActionBarDelegate {
|
||||
fun onDisappearingMessagesClicked()
|
||||
}
|
||||
@ -206,4 +181,4 @@ enum class ConversationSettingType {
|
||||
EXPIRATION,
|
||||
MEMBER_COUNT,
|
||||
NOTIFICATION
|
||||
}
|
||||
}
|
||||
|
@ -45,11 +45,10 @@ class DisappearingMessages @Inject constructor(
|
||||
|
||||
fun showFollowSettingDialog(context: Context, message: MessageRecord) = context.showSessionDialog {
|
||||
title(R.string.dialog_disappearing_messages_follow_setting_title)
|
||||
if (message.expiresIn == 0L) {
|
||||
text(R.string.dialog_disappearing_messages_follow_setting_off_body)
|
||||
text(if (message.expiresIn == 0L) {
|
||||
context.getString(R.string.dialog_disappearing_messages_follow_setting_off_body)
|
||||
} else {
|
||||
text(
|
||||
context.getString(
|
||||
context.getString(
|
||||
R.string.dialog_disappearing_messages_follow_setting_on_body,
|
||||
ExpirationUtil.getExpirationDisplayValue(
|
||||
context,
|
||||
@ -57,8 +56,7 @@ class DisappearingMessages @Inject constructor(
|
||||
),
|
||||
context.getExpirationTypeDisplayValue(message.isNotDisappearAfterRead)
|
||||
)
|
||||
)
|
||||
}
|
||||
})
|
||||
destructiveButton(
|
||||
text = if (message.expiresIn == 0L) R.string.dialog_disappearing_messages_follow_setting_confirm else R.string.dialog_disappearing_messages_follow_setting_set,
|
||||
contentDescription = if (message.expiresIn == 0L) R.string.AccessibilityId_confirm else R.string.AccessibilityId_set_button
|
||||
|
@ -60,8 +60,8 @@ class DisappearingMessagesActivity: PassphraseRequiredActionBarActivity() {
|
||||
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
viewModel.state.collect { state ->
|
||||
supportActionBar?.subtitle = state.subtitle(this@DisappearingMessagesActivity)
|
||||
viewModel.state.collect {
|
||||
supportActionBar?.subtitle = it.subtitle(this@DisappearingMessagesActivity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,8 +63,8 @@ class DisappearingMessagesViewModel(
|
||||
val groupRecord = recipient?.takeIf { it.isClosedGroupRecipient }
|
||||
?.run { groupDb.getGroup(address.toGroupString()).orNull() }
|
||||
|
||||
_state.update { state ->
|
||||
state.copy(
|
||||
_state.update {
|
||||
it.copy(
|
||||
address = recipient?.address,
|
||||
isGroup = groupRecord != null,
|
||||
isNoteToSelf = recipient?.address?.serialize() == textSecurePreferences.getLocalNumber(),
|
||||
|
@ -470,7 +470,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
storage.markConversationAsRead(viewModel.threadId, it)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.d(TAG, "bufferedLastSeenChannel collectLatest", e)
|
||||
Log.e(TAG, "bufferedLastSeenChannel collectLatest", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -486,8 +486,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
true,
|
||||
screenshotObserver
|
||||
)
|
||||
val recipient = viewModel.recipient ?: return
|
||||
binding?.toolbarContent?.update(recipient, viewModel.openGroup, viewModel.expirationConfiguration)
|
||||
viewModel.run {
|
||||
binding?.toolbarContent?.update(recipient ?: return, openGroup, expirationConfiguration)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -504,8 +505,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
override fun dispatchIntent(body: (Context) -> Intent?) {
|
||||
val intent = body(this) ?: return
|
||||
push(intent, false)
|
||||
body(this)?.let { push(it, false) }
|
||||
}
|
||||
|
||||
override fun showDialog(dialogFragment: DialogFragment, tag: String?) {
|
||||
@ -684,21 +684,18 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
private fun getLatestOpenGroupInfoIfNeeded() {
|
||||
viewModel.openGroup?.let { openGroup ->
|
||||
OpenGroupApi.getMemberCount(openGroup.room, openGroup.server).successUi {
|
||||
binding?.toolbarContent?.updateSubtitle(viewModel.recipient!!, openGroup, viewModel.expirationConfiguration)
|
||||
maybeUpdateToolbar(viewModel.recipient!!)
|
||||
}
|
||||
val openGroup = viewModel.openGroup ?: return
|
||||
OpenGroupApi.getMemberCount(openGroup.room, openGroup.server) successUi {
|
||||
binding?.toolbarContent?.updateSubtitle(viewModel.recipient!!, openGroup, viewModel.expirationConfiguration)
|
||||
maybeUpdateToolbar(viewModel.recipient!!)
|
||||
}
|
||||
}
|
||||
|
||||
// called from onCreate
|
||||
private fun setUpBlockedBanner() {
|
||||
val recipient = viewModel.recipient ?: return
|
||||
if (recipient.isGroupRecipient) { return }
|
||||
val recipient = viewModel.recipient?.takeUnless { it.isGroupRecipient } ?: return
|
||||
val sessionID = recipient.address.toString()
|
||||
val contact = sessionContactDb.getContactWithSessionID(sessionID)
|
||||
val name = contact?.displayName(Contact.ContactContext.REGULAR) ?: sessionID
|
||||
val name = sessionContactDb.getContactWithSessionID(sessionID)?.displayName(Contact.ContactContext.REGULAR) ?: sessionID
|
||||
binding?.blockedBannerTextView?.text = resources.getString(R.string.activity_conversation_blocked_banner_text, name)
|
||||
binding?.blockedBanner?.isVisible = recipient.isBlocked
|
||||
binding?.blockedBanner?.setOnClickListener { viewModel.unblock() }
|
||||
@ -790,7 +787,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
this
|
||||
)
|
||||
}
|
||||
viewModel.recipient?.let { maybeUpdateToolbar(it) }
|
||||
maybeUpdateToolbar(recipient)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -829,14 +826,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
}
|
||||
|
||||
private fun showOrHideInputIfNeeded() {
|
||||
val recipient = viewModel.recipient
|
||||
if (recipient != null && recipient.isClosedGroupRecipient) {
|
||||
val group = groupDb.getGroup(recipient.address.toGroupString()).orNull()
|
||||
val isActive = (group?.isActive == true)
|
||||
binding?.inputBar?.showInput = isActive
|
||||
} else {
|
||||
binding?.inputBar?.showInput = true
|
||||
}
|
||||
binding?.inputBar?.showInput = viewModel.recipient?.takeIf { it.isClosedGroupRecipient }
|
||||
?.run { address.toGroupString().let(groupDb::getGroup).orNull()?.isActive == true }
|
||||
?: true
|
||||
}
|
||||
|
||||
private fun setUpMessageRequestsBar() {
|
||||
|
@ -27,6 +27,7 @@ import org.session.libsession.messaging.sending_receiving.attachments.Attachment
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
|
||||
import org.session.libsession.utilities.ThemeUtil
|
||||
import org.session.libsession.utilities.getColorFromAttr
|
||||
import org.session.libsession.utilities.modifyLayoutParams
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
|
||||
import org.thoughtcrime.securesms.conversation.v2.ModalUrlBottomSheet
|
||||
@ -198,9 +199,9 @@ class VisibleMessageContentView : ConstraintLayout {
|
||||
isStart = isStartOfMessageCluster,
|
||||
isEnd = isEndOfMessageCluster
|
||||
)
|
||||
val layoutParams = binding.albumThumbnailView.root.layoutParams as ConstraintLayout.LayoutParams
|
||||
layoutParams.horizontalBias = if (message.isOutgoing) 1f else 0f
|
||||
binding.albumThumbnailView.root.layoutParams = layoutParams
|
||||
binding.albumThumbnailView.root.modifyLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
horizontalBias = if (message.isOutgoing) 1f else 0f
|
||||
}
|
||||
onContentClick.add { event ->
|
||||
binding.albumThumbnailView.root.calculateHitObject(event, message, thread, onAttachmentNeedsDownload)
|
||||
}
|
||||
@ -233,9 +234,9 @@ class VisibleMessageContentView : ConstraintLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
val layoutParams = binding.contentParent.layoutParams as ConstraintLayout.LayoutParams
|
||||
layoutParams.horizontalBias = if (message.isOutgoing) 1f else 0f
|
||||
binding.contentParent.layoutParams = layoutParams
|
||||
binding.contentParent.modifyLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
horizontalBias = if (message.isOutgoing) 1f else 0f
|
||||
}
|
||||
}
|
||||
|
||||
private val onContentClick: MutableList<((event: MotionEvent) -> Unit)> = mutableListOf()
|
||||
@ -306,17 +307,9 @@ class VisibleMessageContentView : ConstraintLayout {
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun getTextColor(context: Context, message: MessageRecord): Int {
|
||||
val colorAttribute = if (message.isOutgoing) {
|
||||
// sent
|
||||
R.attr.message_sent_text_color
|
||||
} else {
|
||||
// received
|
||||
R.attr.message_received_text_color
|
||||
}
|
||||
return context.getColorFromAttr(colorAttribute)
|
||||
}
|
||||
fun getTextColor(context: Context, message: MessageRecord): Int = context.getColorFromAttr(
|
||||
if (message.isOutgoing) R.attr.message_sent_text_color else R.attr.message_received_text_color
|
||||
)
|
||||
}
|
||||
// endregion
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import org.session.libsession.snode.SnodeAPI
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.ViewUtil
|
||||
import org.session.libsession.utilities.getColorFromAttr
|
||||
import org.session.libsession.utilities.modifyLayoutParams
|
||||
import org.session.libsignal.utilities.IdPrefix
|
||||
import org.session.libsignal.utilities.ThreadUtils
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
@ -243,14 +244,12 @@ class VisibleMessageView : LinearLayout {
|
||||
private fun showStatusMessage(message: MessageRecord) {
|
||||
val disappearing = message.expiresIn > 0
|
||||
|
||||
binding.messageInnerLayout.apply {
|
||||
layoutParams = (layoutParams as FrameLayout.LayoutParams)
|
||||
.apply { gravity = if (message.isOutgoing) Gravity.END else Gravity.START }
|
||||
binding.messageInnerLayout.modifyLayoutParams<FrameLayout.LayoutParams> {
|
||||
gravity = if (message.isOutgoing) Gravity.END else Gravity.START
|
||||
}
|
||||
|
||||
binding.statusContainer.apply {
|
||||
layoutParams = (layoutParams as ConstraintLayout.LayoutParams)
|
||||
.apply { horizontalBias = if (message.isOutgoing) 1f else 0f }
|
||||
binding.statusContainer.modifyLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
horizontalBias = if (message.isOutgoing) 1f else 0f
|
||||
}
|
||||
|
||||
binding.expirationTimerView.isGone = true
|
||||
@ -356,7 +355,7 @@ class VisibleMessageView : LinearLayout {
|
||||
swipeToReplyIconRect.right = right
|
||||
swipeToReplyIconRect.bottom = bottom
|
||||
|
||||
if (translationX < 0 /*&& !binding.expirationTimerView.isVisible*/) {
|
||||
if (translationX < 0 && !binding.expirationTimerView.isVisible) {
|
||||
val threshold = swipeToReplyThreshold
|
||||
swipeToReplyIcon.bounds = swipeToReplyIconRect
|
||||
swipeToReplyIcon.alpha = (255.0f * (min(abs(translationX), threshold) / threshold)).roundToInt()
|
||||
|
@ -425,12 +425,10 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
database.endTransaction()
|
||||
}
|
||||
|
||||
override fun getLastLegacySenderAddress(threadRecipientAddress: String): String? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(LAST_LEGACY_MESSAGE_TABLE, LEGACY_THREAD_RECIPIENT_QUERY, wrap(threadRecipientAddress)) { cursor ->
|
||||
override fun getLastLegacySenderAddress(threadRecipientAddress: String): String? =
|
||||
databaseHelper.readableDatabase.get(LAST_LEGACY_MESSAGE_TABLE, LEGACY_THREAD_RECIPIENT_QUERY, wrap(threadRecipientAddress)) { cursor ->
|
||||
cursor.getString(LAST_LEGACY_SENDER_RECIPIENT)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setLastLegacySenderAddress(
|
||||
threadRecipientAddress: String,
|
||||
|
@ -305,8 +305,6 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
||||
}
|
||||
|
||||
override fun markExpireStarted(messageId: Long, startedTimestamp: Long) {
|
||||
Log.d(TAG, "markExpireStarted() called with: messageId = $messageId, startedTimestamp = $startedTimestamp")
|
||||
|
||||
val contentValues = ContentValues()
|
||||
contentValues.put(EXPIRE_STARTED, startedTimestamp)
|
||||
val db = databaseHelper.writableDatabase
|
||||
@ -886,8 +884,6 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
||||
}
|
||||
|
||||
override fun deleteMessage(messageId: Long): Boolean {
|
||||
Log.d(TAG, "deleteMessage() called with: messageId = $messageId")
|
||||
|
||||
val threadId = getThreadIdForMessage(messageId)
|
||||
val attachmentDatabase = get(context).attachmentDatabase()
|
||||
queue(Runnable { attachmentDatabase.deleteAttachmentsForMessage(messageId) })
|
||||
@ -1405,8 +1401,6 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
|
||||
private val TAG = MmsDatabase::class.java.simpleName
|
||||
const val TABLE_NAME: String = "mms"
|
||||
const val DATE_SENT: String = "date"
|
||||
|
@ -14,6 +14,7 @@ import network.loki.messenger.libsession_util.util.Conversation
|
||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import network.loki.messenger.libsession_util.util.GroupInfo
|
||||
import network.loki.messenger.libsession_util.util.UserPic
|
||||
import network.loki.messenger.libsession_util.util.afterSend
|
||||
import org.session.libsession.avatars.AvatarHelper
|
||||
import org.session.libsession.database.StorageProtocol
|
||||
import org.session.libsession.messaging.BlindedIdMapping
|
||||
@ -498,16 +499,11 @@ open class Storage(
|
||||
}
|
||||
|
||||
// Set or reset the shared library to use latest expiration config
|
||||
getThreadId(recipient)?.let { ourThread ->
|
||||
val currentExpiration = getExpirationConfiguration(ourThread)
|
||||
if (currentExpiration != null && currentExpiration.updatedTimestampMs > messageTimestamp) {
|
||||
setExpirationConfiguration(currentExpiration)
|
||||
} else {
|
||||
val expiration = ExpirationConfiguration(ourThread, userProfile.getNtsExpiry(), messageTimestamp)
|
||||
setExpirationConfiguration(expiration)
|
||||
}
|
||||
getThreadId(recipient)?.let {
|
||||
setExpirationConfiguration(
|
||||
getExpirationConfiguration(it)?.takeIf { it.updatedTimestampMs > messageTimestamp } ?: ExpirationConfiguration(it, userProfile.getNtsExpiry(), messageTimestamp)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun updateContacts(contacts: Contacts, messageTimestamp: Long) {
|
||||
@ -635,20 +631,11 @@ open class Storage(
|
||||
// Start polling
|
||||
ClosedGroupPollerV2.shared.startPolling(group.sessionId)
|
||||
}
|
||||
getThreadId(Address.fromSerialized(groupId))?.let { conversationThreadId ->
|
||||
|
||||
val currentExpiration = getExpirationConfiguration(conversationThreadId)
|
||||
if (currentExpiration != null && currentExpiration.updatedTimestampMs > messageTimestamp) {
|
||||
setExpirationConfiguration(currentExpiration)
|
||||
} else {
|
||||
val mode =
|
||||
if (group.disappearingTimer == 0L) ExpiryMode.NONE
|
||||
else ExpiryMode.AfterSend(group.disappearingTimer)
|
||||
val newConfig = ExpirationConfiguration(
|
||||
conversationThreadId, mode, messageTimestamp
|
||||
)
|
||||
setExpirationConfiguration(newConfig)
|
||||
}
|
||||
getThreadId(Address.fromSerialized(groupId))?.let {
|
||||
setExpirationConfiguration(
|
||||
getExpirationConfiguration(it)?.takeIf { it.updatedTimestampMs > messageTimestamp }
|
||||
?: ExpirationConfiguration(it, afterSend(group.disappearingTimer), messageTimestamp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1213,18 +1200,11 @@ open class Storage(
|
||||
setPinned(conversationThreadId, contact.priority == PRIORITY_PINNED)
|
||||
}
|
||||
}
|
||||
getThreadId(recipient)?.let { conversationThreadId ->
|
||||
val currentExpiration = getExpirationConfiguration(conversationThreadId)
|
||||
if (currentExpiration != null && currentExpiration.updatedTimestampMs > timestamp) {
|
||||
setExpirationConfiguration(currentExpiration)
|
||||
} else {
|
||||
val expiration = ExpirationConfiguration(
|
||||
conversationThreadId,
|
||||
contact.expiryMode,
|
||||
timestamp
|
||||
)
|
||||
setExpirationConfiguration(expiration)
|
||||
}
|
||||
getThreadId(recipient)?.let {
|
||||
setExpirationConfiguration(
|
||||
getExpirationConfiguration(it)?.takeIf { it.updatedTimestampMs > timestamp }
|
||||
?: ExpirationConfiguration(it, contact.expiryMode, timestamp)
|
||||
)
|
||||
}
|
||||
setRecipientHash(recipient, contact.hashCode().toString())
|
||||
}
|
||||
@ -1340,26 +1320,25 @@ open class Storage(
|
||||
}
|
||||
|
||||
override fun getLastLegacyRecipient(threadRecipient: String): String? =
|
||||
DatabaseComponent.get(context).lokiAPIDatabase().getLastLegacySenderAddress(threadRecipient)
|
||||
DatabaseComponent.get(context).lokiAPIDatabase().getLastLegacySenderAddress(threadRecipient)
|
||||
|
||||
override fun setLastLegacyRecipient(threadRecipient: String, senderRecipient: String?) {
|
||||
DatabaseComponent.get(context).lokiAPIDatabase().setLastLegacySenderAddress(threadRecipient, senderRecipient)
|
||||
}
|
||||
|
||||
override fun deleteConversation(threadID: Long) {
|
||||
val recipient = getRecipientForThread(threadID)
|
||||
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
||||
val groupDB = DatabaseComponent.get(context).groupDatabase()
|
||||
threadDB.deleteConversation(threadID)
|
||||
if (recipient != null) {
|
||||
if (recipient.isContactRecipient) {
|
||||
val recipient = getRecipientForThread(threadID) ?: return
|
||||
when {
|
||||
recipient.isContactRecipient -> {
|
||||
if (recipient.isLocalNumber) return
|
||||
val contacts = configFactory.contacts ?: return
|
||||
contacts.upsertContact(recipient.address.serialize()) {
|
||||
this.priority = PRIORITY_HIDDEN
|
||||
}
|
||||
contacts.upsertContact(recipient.address.serialize()) { priority = PRIORITY_HIDDEN }
|
||||
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context)
|
||||
} else if (recipient.isClosedGroupRecipient) {
|
||||
}
|
||||
recipient.isClosedGroupRecipient -> {
|
||||
// TODO: handle closed group
|
||||
val volatile = configFactory.convoVolatile ?: return
|
||||
val groups = configFactory.userGroups ?: return
|
||||
|
@ -28,21 +28,18 @@ class MarkReadReceiver : BroadcastReceiver() {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (CLEAR_ACTION != intent.action) return
|
||||
val threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA)
|
||||
if (threadIds != null) {
|
||||
NotificationManagerCompat.from(context)
|
||||
.cancel(intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1))
|
||||
object : AsyncTask<Void?, Void?, Void?>() {
|
||||
override fun doInBackground(vararg params: Void?): Void? {
|
||||
val currentTime = nowWithOffset
|
||||
threadIds.forEach {
|
||||
Log.i(TAG, "Marking as read: $it")
|
||||
shared.storage.markConversationAsRead(it, currentTime, true)
|
||||
}
|
||||
return null
|
||||
val threadIds = intent.getLongArrayExtra(THREAD_IDS_EXTRA) ?: return
|
||||
NotificationManagerCompat.from(context).cancel(intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1))
|
||||
object : AsyncTask<Void?, Void?, Void?>() {
|
||||
override fun doInBackground(vararg params: Void?): Void? {
|
||||
val currentTime = nowWithOffset
|
||||
threadIds.forEach {
|
||||
Log.i(TAG, "Marking as read: $it")
|
||||
shared.storage.markConversationAsRead(it, currentTime, true)
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
|
||||
}
|
||||
return null
|
||||
}
|
||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ -111,17 +108,17 @@ class MarkReadReceiver : BroadcastReceiver() {
|
||||
context: Context,
|
||||
markedReadMessages: List<MarkedMessageInfo>
|
||||
) {
|
||||
if (isReadReceiptsEnabled(context)) {
|
||||
markedReadMessages.map { it.syncMessageId }
|
||||
.filter { shouldSendReadReceipt(Recipient.from(context, it.address, false)) }
|
||||
.groupBy { it.address }
|
||||
.forEach { (address, messages) ->
|
||||
messages.map { it.timetamp }
|
||||
.let(::ReadReceipt)
|
||||
.apply { sentTimestamp = nowWithOffset }
|
||||
.let { send(it, address) }
|
||||
}
|
||||
}
|
||||
if (!isReadReceiptsEnabled(context)) return
|
||||
|
||||
markedReadMessages.map { it.syncMessageId }
|
||||
.filter { shouldSendReadReceipt(Recipient.from(context, it.address, false)) }
|
||||
.groupBy { it.address }
|
||||
.forEach { (address, messages) ->
|
||||
messages.map { it.timetamp }
|
||||
.let(::ReadReceipt)
|
||||
.apply { sentTimestamp = nowWithOffset }
|
||||
.let { send(it, address) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchUpdatedExpiriesAndScheduleDeletion(
|
||||
|
@ -154,7 +154,7 @@ class DefaultConversationRepository @Inject constructor(
|
||||
openGroupInvitation.url = openGroup.joinURL
|
||||
message.openGroupInvitation = openGroupInvitation
|
||||
val expirationConfig = storage.getExpirationConfiguration(threadId)
|
||||
val expiresInMillis = (expirationConfig?.expiryMode?.expiryMillis ?: 0)
|
||||
val expiresInMillis = expirationConfig?.expiryMode?.expiryMillis ?: 0
|
||||
val expireStartedAt = if (expirationConfig?.expiryMode is ExpiryMode.AfterSend) message.sentTimestamp!! else 0
|
||||
val outgoingTextMessage = OutgoingTextMessage.fromOpenGroupInvitation(
|
||||
openGroupInvitation,
|
||||
@ -225,14 +225,10 @@ class DefaultConversationRepository @Inject constructor(
|
||||
override fun buildUnsendRequest(recipient: Recipient, message: MessageRecord): UnsendRequest? {
|
||||
if (recipient.isOpenGroupRecipient) return null
|
||||
messageDataProvider.getServerHashForMessage(message.id, message.isMms) ?: return null
|
||||
return UnsendRequest().apply {
|
||||
author = if (message.isOutgoing) {
|
||||
textSecurePreferences.getLocalNumber()
|
||||
} else {
|
||||
message.individualRecipient.address.contactIdentifier()
|
||||
}
|
||||
return UnsendRequest(
|
||||
author = message.takeUnless { it.isOutgoing }?.run { individualRecipient.address.contactIdentifier() } ?: textSecurePreferences.getLocalNumber(),
|
||||
timestamp = message.timestamp
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun deleteMessageWithoutUnsendRequest(
|
||||
|
@ -48,8 +48,6 @@ class ExpiringMessageManager(context: Context) : MessageExpirationManagerProtoco
|
||||
private fun getDatabase(mms: Boolean) = if (mms) mmsDatabase else smsDatabase
|
||||
|
||||
fun scheduleDeletion(id: Long, mms: Boolean, startedAtTimestamp: Long, expiresInMillis: Long) {
|
||||
Log.d(TAG, "scheduleDeletion() called with: id = $id, mms = $mms, startedAtTimestamp = $startedAtTimestamp, expiresInMillis = $expiresInMillis")
|
||||
|
||||
if (startedAtTimestamp <= 0) return
|
||||
|
||||
val expiresAtMillis = startedAtTimestamp + expiresInMillis
|
||||
@ -67,7 +65,6 @@ class ExpiringMessageManager(context: Context) : MessageExpirationManagerProtoco
|
||||
message: ExpirationTimerUpdate,
|
||||
expireStartedAt: Long
|
||||
) {
|
||||
Log.d(TAG, "insertIncomingExpirationTimerMessage() called with: message = $message, expireStartedAt = $expireStartedAt")
|
||||
val senderPublicKey = message.sender
|
||||
val sentTimestamp = message.sentTimestamp
|
||||
val groupId = message.groupPublicKey
|
||||
@ -118,7 +115,6 @@ class ExpiringMessageManager(context: Context) : MessageExpirationManagerProtoco
|
||||
message: ExpirationTimerUpdate,
|
||||
expireStartedAt: Long
|
||||
) {
|
||||
Log.d(TAG, "insertOutgoingExpirationTimerMessage() called with: message = $message, expireStartedAt = $expireStartedAt")
|
||||
val sentTimestamp = message.sentTimestamp
|
||||
val groupId = message.groupPublicKey
|
||||
val duration = message.expiryMode.expiryMillis
|
||||
@ -152,7 +148,6 @@ class ExpiringMessageManager(context: Context) : MessageExpirationManagerProtoco
|
||||
|
||||
override fun insertExpirationTimerMessage(message: ExpirationTimerUpdate) {
|
||||
val expiryMode: ExpiryMode = message.expiryMode
|
||||
Log.d(TAG, "setExpirationTimer() called with: message = $message, expiryMode = $expiryMode")
|
||||
|
||||
val userPublicKey = getLocalNumber(context)
|
||||
val senderPublicKey = message.sender
|
||||
@ -171,12 +166,10 @@ class ExpiringMessageManager(context: Context) : MessageExpirationManagerProtoco
|
||||
}
|
||||
|
||||
override fun startAnyExpiration(timestamp: Long, author: String, expireStartedAt: Long) {
|
||||
Log.d(TAG, "startAnyExpiration() called with: timestamp = $timestamp, author = $author, expireStartedAt = $expireStartedAt")
|
||||
|
||||
mmsSmsDatabase.getMessageFor(timestamp, author)?.run {
|
||||
getDatabase(isMms()).markExpireStarted(getId(), expireStartedAt)
|
||||
scheduleDeletion(getId(), isMms(), expireStartedAt, expiresIn)
|
||||
} ?: Log.e(TAG, "no message record!!!")
|
||||
} ?: Log.e(TAG, "no message record!")
|
||||
}
|
||||
|
||||
private inner class LoadTask : Runnable {
|
||||
|
@ -14,3 +14,5 @@ sealed class ExpiryMode(val expirySeconds: Long) {
|
||||
|
||||
fun coerceSendToRead(coerce: Boolean = true) = if (coerce && this is AfterSend) AfterRead(expirySeconds) else this
|
||||
}
|
||||
|
||||
fun afterSend(seconds: Long) = seconds.takeIf { it > 0 }?.let(ExpiryMode::AfterSend) ?: ExpiryMode.NONE
|
@ -144,7 +144,6 @@ class BatchMessageReceiveJob(
|
||||
runBlocking(Dispatchers.IO) {
|
||||
|
||||
fun processMessages(threadId: Long, messages: List<ParsedMessage>) = async {
|
||||
Log.d(TAG, "processMessages() threadId = $threadId, messages = $messages")
|
||||
// The LinkedHashMap should preserve insertion order
|
||||
val messageIds = linkedMapOf<Long, Pair<Boolean, Boolean>>()
|
||||
val myLastSeen = storage.getLastSeen(threadId)
|
||||
|
@ -6,7 +6,6 @@ import org.session.libsession.database.StorageProtocol
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.GroupUtil
|
||||
import org.session.libsignal.protos.SignalServiceProtos
|
||||
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
||||
@ -43,13 +42,11 @@ abstract class Message {
|
||||
}
|
||||
}
|
||||
|
||||
open fun isValid(): Boolean {
|
||||
val sentTimestamp = sentTimestamp
|
||||
if (sentTimestamp != null && sentTimestamp <= 0) { return false }
|
||||
val receivedTimestamp = receivedTimestamp
|
||||
if (receivedTimestamp != null && receivedTimestamp <= 0) { return false }
|
||||
return sender != null && recipient != null
|
||||
}
|
||||
open fun isValid(): Boolean =
|
||||
sentTimestamp?.let { it > 0 } == true
|
||||
&& receivedTimestamp?.let { it > 0 } == true
|
||||
&& sender != null
|
||||
&& recipient != null
|
||||
|
||||
abstract fun toProto(): SignalServiceProtos.Content?
|
||||
|
||||
@ -60,18 +57,17 @@ abstract class Message {
|
||||
}.build()
|
||||
}
|
||||
|
||||
fun SignalServiceProtos.Content.Builder.applyExpiryMode(): SignalServiceProtos.Content.Builder {
|
||||
fun SignalServiceProtos.Content.Builder.applyExpiryMode() = apply {
|
||||
expirationTimer = expiryMode.expirySeconds.toInt()
|
||||
expirationType = when (expiryMode) {
|
||||
is ExpiryMode.AfterSend -> ExpirationType.DELETE_AFTER_SEND
|
||||
is ExpiryMode.AfterRead -> ExpirationType.DELETE_AFTER_READ
|
||||
else -> ExpirationType.UNKNOWN
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified M: Message> M.copyExpiration(proto: SignalServiceProtos.Content): M {
|
||||
inline fun <reified M: Message> M.copyExpiration(proto: SignalServiceProtos.Content): M = apply {
|
||||
(proto.takeIf { it.hasExpirationTimer() }?.expirationTimer ?: proto.dataMessage?.expireTimer)?.let { duration ->
|
||||
expiryMode = when (proto.expirationType.takeIf { duration > 0 }) {
|
||||
ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong())
|
||||
@ -79,23 +75,21 @@ inline fun <reified M: Message> M.copyExpiration(proto: SignalServiceProtos.Cont
|
||||
else -> ExpiryMode.NONE
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
fun SignalServiceProtos.Content.expiryMode(): ExpiryMode =
|
||||
(takeIf { it.hasExpirationTimer() }?.expirationTimer ?: dataMessage?.expireTimer)?.let { duration ->
|
||||
when (expirationType.takeIf { duration > 0 }) {
|
||||
ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong())
|
||||
ExpirationType.DELETE_AFTER_READ -> ExpiryMode.AfterRead(duration.toLong())
|
||||
else -> ExpiryMode.NONE
|
||||
}
|
||||
} ?: ExpiryMode.NONE
|
||||
(takeIf { it.hasExpirationTimer() }?.expirationTimer ?: dataMessage?.expireTimer)?.let { duration ->
|
||||
when (expirationType.takeIf { duration > 0 }) {
|
||||
ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong())
|
||||
ExpirationType.DELETE_AFTER_READ -> ExpiryMode.AfterRead(duration.toLong())
|
||||
else -> ExpiryMode.NONE
|
||||
}
|
||||
} ?: ExpiryMode.NONE
|
||||
|
||||
/**
|
||||
* Apply ExpiryMode from the current setting.
|
||||
*/
|
||||
inline fun <reified M: Message> M.applyExpiryMode(thread: Long): M {
|
||||
inline fun <reified M: Message> M.applyExpiryMode(thread: Long): M = apply {
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
expiryMode = storage.getExpirationConfiguration(thread)?.expiryMode?.coerceSendToRead(coerceDisappearAfterSendToRead) ?: ExpiryMode.NONE
|
||||
return this
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ import org.session.libsession.messaging.messages.copyExpiration
|
||||
import org.session.libsignal.protos.SignalServiceProtos
|
||||
import org.session.libsignal.utilities.Log
|
||||
|
||||
class UnsendRequest(): ControlMessage() {
|
||||
var timestamp: Long? = null
|
||||
var author: String? = null
|
||||
class UnsendRequest(var timestamp: Long? = null, var author: String? = null): ControlMessage() {
|
||||
|
||||
override val isSelfSendValid: Boolean = true
|
||||
|
||||
@ -20,18 +18,8 @@ class UnsendRequest(): ControlMessage() {
|
||||
companion object {
|
||||
const val TAG = "UnsendRequest"
|
||||
|
||||
fun fromProto(proto: SignalServiceProtos.Content): UnsendRequest? {
|
||||
val unsendRequestProto = if (proto.hasUnsendRequest()) proto.unsendRequest else return null
|
||||
val timestamp = unsendRequestProto.timestamp
|
||||
val author = unsendRequestProto.author
|
||||
return UnsendRequest(timestamp, author)
|
||||
.copyExpiration(proto)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(timestamp: Long, author: String) : this() {
|
||||
this.timestamp = timestamp
|
||||
this.author = author
|
||||
fun fromProto(proto: SignalServiceProtos.Content): UnsendRequest? =
|
||||
proto.takeIf { it.hasUnsendRequest() }?.unsendRequest?.run { UnsendRequest(timestamp, author) }?.copyExpiration(proto)
|
||||
}
|
||||
|
||||
override fun toProto(): SignalServiceProtos.Content? {
|
||||
|
@ -108,27 +108,23 @@ object GroupUtil {
|
||||
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
fun doubleDecodeGroupId(groupID: String): String {
|
||||
return Hex.toStringCondensed(getDecodedGroupIDAsData(getDecodedGroupID(groupID)))
|
||||
}
|
||||
fun doubleDecodeGroupId(groupID: String): String =
|
||||
Hex.toStringCondensed(getDecodedGroupIDAsData(getDecodedGroupID(groupID)))
|
||||
|
||||
@JvmStatic
|
||||
fun addressToGroupSessionId(address: Address): String {
|
||||
return doubleDecodeGroupId(address.toGroupString())
|
||||
}
|
||||
fun addressToGroupSessionId(address: Address): String =
|
||||
doubleDecodeGroupId(address.toGroupString())
|
||||
|
||||
fun createConfigMemberMap(
|
||||
members: Collection<String>,
|
||||
admins: Collection<String>
|
||||
): Map<String, Boolean> {
|
||||
// Start with admins
|
||||
val memberMap = admins.associate {
|
||||
it to true
|
||||
}.toMutableMap()
|
||||
val memberMap = admins.associateWith { true }.toMutableMap()
|
||||
|
||||
// Add the remaining members (there may be duplicates, so only add ones that aren't already in there from admins)
|
||||
for (member in members) {
|
||||
if (!memberMap.contains(member)) {
|
||||
if (member !in memberMap) {
|
||||
memberMap[member] = false
|
||||
}
|
||||
}
|
||||
|
@ -46,8 +46,6 @@ class SSKEnvironment(
|
||||
fun startAnyExpiration(timestamp: Long, author: String, expireStartedAt: Long)
|
||||
|
||||
fun maybeStartExpiration(message: Message, startDisappearAfterRead: Boolean = false) {
|
||||
Log.d("MessageExpirationManagerProtocol", "maybeStartExpiration() called with: message = $message, startDisappearAfterRead = $startDisappearAfterRead")
|
||||
|
||||
if (message is ExpirationTimerUpdate && message.isGroup) return
|
||||
|
||||
maybeStartExpiration(
|
||||
@ -59,8 +57,6 @@ class SSKEnvironment(
|
||||
}
|
||||
|
||||
fun startDisappearAfterRead(timestamp: Long, sender: String) {
|
||||
Log.d("MessageExpirationManagerProtocol", "startDisappearAfterRead() called with: timestamp = $timestamp, sender = $sender")
|
||||
|
||||
startAnyExpiration(
|
||||
timestamp,
|
||||
sender,
|
||||
@ -69,8 +65,6 @@ class SSKEnvironment(
|
||||
}
|
||||
|
||||
fun maybeStartExpiration(timestamp: Long, sender: String, mode: ExpiryMode, startDisappearAfterRead: Boolean = false) {
|
||||
Log.d("MessageExpirationManagerProtocol", "maybeStartExpiration() called with: timestamp = $timestamp, sender = $sender, mode = $mode, startDisappearAfterRead = $startDisappearAfterRead")
|
||||
|
||||
val expireStartedAt = when (mode) {
|
||||
is ExpiryMode.AfterSend -> timestamp
|
||||
is ExpiryMode.AfterRead -> if (startDisappearAfterRead) nowWithOffset.coerceAtLeast(timestamp + 1) else return
|
||||
|
@ -2,6 +2,8 @@ package org.session.libsession.utilities
|
||||
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
|
||||
@ -14,3 +16,7 @@ fun Context.getColorFromAttr(
|
||||
theme.resolveAttribute(attrColor, typedValue, resolveRefs)
|
||||
return typedValue.data
|
||||
}
|
||||
|
||||
inline fun <reified LP: ViewGroup.LayoutParams> View.modifyLayoutParams(function: LP.() -> Unit) {
|
||||
layoutParams = (layoutParams as LP).apply { function() }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user