mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
fix: open group threads and avatar downloads
This commit is contained in:
parent
c5299c1010
commit
78d1e9d387
@ -52,6 +52,13 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
}
|
||||
}
|
||||
|
||||
fun getThreadId(openGroup: OpenGroup): Long? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.get(publicChatTable, "$publicChat = ?", arrayOf(JsonUtil.toJson(openGroup.toJson()))) { cursor ->
|
||||
cursor.getLong(threadID)
|
||||
}
|
||||
}
|
||||
|
||||
fun setOpenGroupChat(openGroup: OpenGroup, threadID: Long) {
|
||||
if (threadID < 0) {
|
||||
return
|
||||
|
@ -83,6 +83,7 @@ import org.thoughtcrime.securesms.database.model.ReactionRecord
|
||||
import org.thoughtcrime.securesms.dependencies.ConfigFactory
|
||||
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
||||
import org.thoughtcrime.securesms.groups.ClosedGroupManager
|
||||
import org.thoughtcrime.securesms.groups.GroupManager
|
||||
import org.thoughtcrime.securesms.groups.OpenGroupManager
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority
|
||||
@ -95,6 +96,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
ThreadDatabase.ConversationThreadUpdateListener {
|
||||
|
||||
override fun threadCreated(address: Address, threadId: Long) {
|
||||
Log.wtf("Loki", "Create thread for $address\ncontext:\n${Thread.currentThread().stackTrace.joinToString("\n")}")
|
||||
val localUserAddress = getUserPublicKey() ?: return
|
||||
if (!getRecipientApproved(address) && localUserAddress != address.serialize()) return // don't store unapproved / message requests
|
||||
|
||||
@ -136,7 +138,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
}
|
||||
|
||||
override fun threadDeleted(address: Address, threadId: Long) {
|
||||
|
||||
Log.wtf("Loki", "Delete thread for $address\ncontext:\n${Thread.currentThread().stackTrace.joinToString("\n")}")
|
||||
val volatile = configFactory.convoVolatile ?: return
|
||||
if (address.isGroup) {
|
||||
val groups = configFactory.userGroups ?: return
|
||||
@ -1062,8 +1064,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
}
|
||||
|
||||
override fun getThreadId(openGroup: OpenGroup): Long? {
|
||||
val address = fromSerialized("${openGroup.server}.${openGroup.room}")
|
||||
return getThreadId(address)
|
||||
return GroupManager.getOpenGroupThreadID("${openGroup.server.removeSuffix("/")}.${openGroup.room}", context)
|
||||
}
|
||||
|
||||
override fun getThreadId(address: Address): Long? {
|
||||
@ -1140,6 +1141,8 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
if (key.size != ProfileKeyUtil.PROFILE_KEY_BYTES) return@forEach
|
||||
profileManager.setProfilePicture(context, recipient, url, key)
|
||||
profileManager.setUnidentifiedAccessMode(context, recipient, Recipient.UnidentifiedAccessMode.UNKNOWN)
|
||||
} else {
|
||||
profileManager.setProfilePicture(context, recipient, null, null)
|
||||
}
|
||||
if (contact.priority == PRIORITY_HIDDEN) {
|
||||
getThreadId(fromSerialized(contact.id))?.let { conversationThreadId ->
|
||||
|
@ -43,6 +43,7 @@ object OpenGroupManager {
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
val (serverGroups, toDelete) = storage.getAllOpenGroups().values.partition { storage.getThreadId(it) != null }
|
||||
toDelete.forEach { openGroup ->
|
||||
Log.w("Loki", "Need to delete a group")
|
||||
delete(openGroup.server, openGroup.room, MessagingModuleConfiguration.shared.context)
|
||||
}
|
||||
|
||||
@ -116,7 +117,7 @@ object OpenGroupManager {
|
||||
val groupID = recipient.address.serialize()
|
||||
// Stop the poller if needed
|
||||
val openGroups = storage.getAllOpenGroups().filter { it.value.server == server }
|
||||
if (openGroups.count() == 1) {
|
||||
if (openGroups.isNotEmpty()) {
|
||||
synchronized(pollUpdaterLock) {
|
||||
val poller = pollers[server]
|
||||
poller?.stop()
|
||||
|
@ -85,10 +85,10 @@ public class RetrieveProfileAvatarJob extends BaseJob {
|
||||
return;
|
||||
}
|
||||
|
||||
if (AvatarHelper.avatarFileExists(context, recipient.resolve().getAddress()) && Util.equals(profileAvatar, recipient.resolve().getProfileAvatar())) {
|
||||
Log.w(TAG, "Already retrieved profile avatar: " + profileAvatar);
|
||||
return;
|
||||
}
|
||||
// if (AvatarHelper.avatarFileExists(context, recipient.resolve().getAddress()) && Util.equals(profileAvatar, recipient.resolve().getProfileAvatar())) {
|
||||
// Log.w(TAG, "Already retrieved profile avatar: " + profileAvatar);
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (TextUtils.isEmpty(profileAvatar)) {
|
||||
Log.w(TAG, "Removing profile avatar for: " + recipient.getAddress().serialize());
|
||||
|
@ -7,7 +7,7 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord
|
||||
|
||||
fun ConversationVolatileConfig.getConversationUnread(thread: ThreadRecord): Boolean {
|
||||
val recipient = thread.recipient
|
||||
if (recipient.isContactRecipient) {
|
||||
if (recipient.isContactRecipient && recipient.isOpenGroupInboxRecipient) {
|
||||
return getOneToOne(recipient.address.serialize())?.unread == true
|
||||
} else if (recipient.isClosedGroupRecipient) {
|
||||
return getLegacyClosedGroup(GroupUtil.doubleDecodeGroupId(recipient.address.toGroupString()))?.unread == true
|
||||
|
@ -21,6 +21,7 @@ inline jobject serialize_contact(JNIEnv *env, session::config::contact_info info
|
||||
approved = info.approved;
|
||||
approvedMe = info.approved_me;
|
||||
blocked = info.blocked;
|
||||
auto created = info.created;
|
||||
jobject profilePic = util::serialize_user_pic(env, info.profile_picture);
|
||||
jobject returnObj = env->NewObject(contactClass, constructor, id, name, nickname, approved,
|
||||
approvedMe, blocked, profilePic, info.priority,
|
||||
|
@ -9,5 +9,5 @@ data class Contact(
|
||||
var blocked: Boolean = false,
|
||||
var profilePicture: UserPic = UserPic.DEFAULT,
|
||||
var priority: Int = 0,
|
||||
var expiryMode: ExpiryMode
|
||||
var expiryMode: ExpiryMode,
|
||||
)
|
@ -263,6 +263,8 @@ fun MessageReceiver.handleVisibleMessage(
|
||||
if ((profileKeyValid && profileKeyChanged) || (profileKeyValid && needsProfilePicture)) {
|
||||
profileManager.setProfilePicture(context, recipient, profile.profilePictureURL, newProfileKey)
|
||||
profileManager.setUnidentifiedAccessMode(context, recipient, Recipient.UnidentifiedAccessMode.UNKNOWN)
|
||||
} else if (newProfileKey == null || newProfileKey.isEmpty() || profile.profilePictureURL.isNullOrEmpty()) {
|
||||
profileManager.setProfilePicture(context, recipient, null, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -227,6 +227,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
|
||||
// in case we had null configs, the array won't be fully populated
|
||||
// index of the sparse array key iterator should be the request index, with the key being the namespace
|
||||
configDebouncer.publish {
|
||||
// TODO: add in specific ordering of config namespaces for processing
|
||||
requestSparseArray.keyIterator().withIndex().forEach { (requestIndex, key) ->
|
||||
responseList.getOrNull(requestIndex)?.let { rawResponse ->
|
||||
if (rawResponse["code"] as? Int != 200) {
|
||||
|
Loading…
Reference in New Issue
Block a user