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.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")
}

View File

@ -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);