fix: pinned status for communities and groups, group last read time being set to snodeapi.now on finish joining

This commit is contained in:
0x330a 2023-04-24 15:51:38 +10:00
parent c777c05456
commit 8e5a810135
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
2 changed files with 12 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.database
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import network.loki.messenger.libsession_util.ConfigBase 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.Contacts
import network.loki.messenger.libsession_util.ConversationVolatileConfig import network.loki.messenger.libsession_util.ConversationVolatileConfig
import network.loki.messenger.libsession_util.UserGroupsConfig 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) { if (groupBaseCommunity.fullUrl() !in existingJoinUrls) {
// add it // add it
val (threadId, _) = OpenGroupManager.add(groupBaseCommunity.baseUrl, groupBaseCommunity.room, groupBaseCommunity.pubKeyHex, context) 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 { } else {
val (threadId, _) = existingCommunities.entries.first { (_, v) -> v.joinURL == groupInfo.community.fullUrl() } 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 pubKeyHex = Hex.toStringCondensed(pubKey)
val communityInfo = groups.getOrConstructCommunityInfo(infoServer, infoRoom, pubKeyHex) val communityInfo = groups.getOrConstructCommunityInfo(infoServer, infoRoom, pubKeyHex)
groups.set(communityInfo) groups.set(communityInfo)
val volatile = volatileConfig.getOrConstructCommunity(infoServer, infoRoom, pubKey).copy( val volatile = volatileConfig.getOrConstructCommunity(infoServer, infoRoom, pubKey)
lastRead = SnodeAPI.nowWithOffset,
)
volatileConfig.set(volatile) volatileConfig.set(volatile)
} }
@ -1087,6 +1086,10 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
getThreadId(fromSerialized(contact.id))?.let { conversationThreadId -> getThreadId(fromSerialized(contact.id))?.let { conversationThreadId ->
deleteConversation(conversationThreadId) deleteConversation(conversationThreadId)
} }
} else {
getThreadId(fromSerialized(contact.id))?.let { conversationThreadId ->
setPinned(conversationThreadId, contact.priority == ConfigBase.PRIORITY_PINNED)
}
} }
Log.d("Loki-DBG", "Updated contact $contact") Log.d("Loki-DBG", "Updated contact $contact")
} }

View File

@ -528,6 +528,10 @@ public class ThreadDatabase extends Database {
public void setLastSeen(long threadId, long timestamp) { public void setLastSeen(long threadId, long timestamp) {
SQLiteDatabase db = databaseHelper.getWritableDatabase(); 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); ContentValues contentValues = new ContentValues(1);
long lastSeenTime = timestamp == -1 ? SnodeAPI.getNowWithOffset() : timestamp; long lastSeenTime = timestamp == -1 ? SnodeAPI.getNowWithOffset() : timestamp;
contentValues.put(LAST_SEEN, lastSeenTime); contentValues.put(LAST_SEEN, lastSeenTime);