diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index 4be84d2191..25877c2a55 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.database import android.content.Context import android.net.Uri import network.loki.messenger.libsession_util.ConfigBase +import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_PINNED import network.loki.messenger.libsession_util.Contacts import network.loki.messenger.libsession_util.ConversationVolatileConfig import network.loki.messenger.libsession_util.UserGroupsConfig @@ -521,10 +522,10 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co if (groupBaseCommunity.fullUrl() !in existingJoinUrls) { // add it val (threadId, _) = OpenGroupManager.add(groupBaseCommunity.baseUrl, groupBaseCommunity.room, groupBaseCommunity.pubKeyHex, context) - threadDb.setPinned(threadId, groupInfo.priority >= 1) + threadDb.setPinned(threadId, groupInfo.priority == PRIORITY_PINNED) } else { val (threadId, _) = existingCommunities.entries.first { (_, v) -> v.joinURL == groupInfo.community.fullUrl() } - threadDb.setPinned(threadId, groupInfo.priority >= 1) + threadDb.setPinned(threadId, groupInfo.priority == PRIORITY_PINNED) } } @@ -962,9 +963,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co val pubKeyHex = Hex.toStringCondensed(pubKey) val communityInfo = groups.getOrConstructCommunityInfo(infoServer, infoRoom, pubKeyHex) groups.set(communityInfo) - val volatile = volatileConfig.getOrConstructCommunity(infoServer, infoRoom, pubKey).copy( - lastRead = SnodeAPI.nowWithOffset, - ) + val volatile = volatileConfig.getOrConstructCommunity(infoServer, infoRoom, pubKey) volatileConfig.set(volatile) } @@ -1087,6 +1086,10 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co getThreadId(fromSerialized(contact.id))?.let { conversationThreadId -> deleteConversation(conversationThreadId) } + } else { + getThreadId(fromSerialized(contact.id))?.let { conversationThreadId -> + setPinned(conversationThreadId, contact.priority == ConfigBase.PRIORITY_PINNED) + } } Log.d("Loki-DBG", "Updated contact $contact") } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java index 6244763661..c42d32c91a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -528,6 +528,10 @@ public class ThreadDatabase extends Database { public void setLastSeen(long threadId, long timestamp) { SQLiteDatabase db = databaseHelper.getWritableDatabase(); + + // edge case where we set the last seen time for a conversation before it loads messages (joining community for example) + if (getMessageCount(threadId) <= 0) return; + ContentValues contentValues = new ContentValues(1); long lastSeenTime = timestamp == -1 ? SnodeAPI.getNowWithOffset() : timestamp; contentValues.put(LAST_SEEN, lastSeenTime);