Open group avatar DB record cleanup on deletion.

General cleanup.
This commit is contained in:
Anton Chekulaev 2020-09-28 19:56:40 +10:00
parent 70815e61d0
commit 2920e3e528
3 changed files with 38 additions and 44 deletions

View File

@ -340,22 +340,20 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
val threadID = thread.threadId val threadID = thread.threadId
val recipient = thread.recipient val recipient = thread.recipient
val threadDB = DatabaseFactory.getThreadDatabase(this) val threadDB = DatabaseFactory.getThreadDatabase(this)
val deleteThread = object : Runnable { val deleteThread = Runnable {
override fun run() {
AsyncTask.execute { AsyncTask.execute {
val publicChat = DatabaseFactory.getLokiThreadDatabase(this@HomeActivity).getPublicChat(threadID) val publicChat = DatabaseFactory.getLokiThreadDatabase(this@HomeActivity).getPublicChat(threadID)
if (publicChat != null) { if (publicChat != null) {
val apiDB = DatabaseFactory.getLokiAPIDatabase(this@HomeActivity) val apiDB = DatabaseFactory.getLokiAPIDatabase(this@HomeActivity)
apiDB.removeLastMessageServerID(publicChat.channel, publicChat.server) apiDB.removeLastMessageServerID(publicChat.channel, publicChat.server)
apiDB.removeLastDeletionServerID(publicChat.channel, publicChat.server) apiDB.removeLastDeletionServerID(publicChat.channel, publicChat.server)
apiDB.clearOpenGroupAvatarURL(publicChat.channel, publicChat.server)
ApplicationContext.getInstance(this@HomeActivity).publicChatAPI!!.leave(publicChat.channel, publicChat.server) ApplicationContext.getInstance(this@HomeActivity).publicChatAPI!!.leave(publicChat.channel, publicChat.server)
} }
threadDB.deleteConversation(threadID) threadDB.deleteConversation(threadID)
ApplicationContext.getInstance(this@HomeActivity).messageNotifier.updateNotification(this@HomeActivity) ApplicationContext.getInstance(this@HomeActivity).messageNotifier.updateNotification(this@HomeActivity)
} }
} }
}
val dialogMessage = if (recipient.isGroupRecipient) R.string.activity_home_leave_group_dialog_message else R.string.activity_home_delete_conversation_dialog_message val dialogMessage = if (recipient.isGroupRecipient) R.string.activity_home_leave_group_dialog_message else R.string.activity_home_delete_conversation_dialog_message
val dialog = AlertDialog.Builder(this) val dialog = AlertDialog.Builder(this)
dialog.setMessage(dialogMessage) dialog.setMessage(dialogMessage)

View File

@ -355,13 +355,19 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
}?.toString() }?.toString()
} }
override fun setOpenGroupAvatarURL(url: String, group: Long, server: String) { override fun setOpenGroupAvatarURL(group: Long, server: String, url: String) {
val database = databaseHelper.writableDatabase val database = databaseHelper.writableDatabase
val index = "$server.$group" val index = "$server.$group"
val row = wrap(mapOf(publicChatID to index, openGroupAvatar to url)) val row = wrap(mapOf(publicChatID to index, openGroupAvatar to url))
database.insertOrUpdate(openGroupAvatarCacheTable, row, "$publicChatID = ?", wrap(index)) database.insertOrUpdate(openGroupAvatarCacheTable, row, "$publicChatID = ?", wrap(index))
} }
fun clearOpenGroupAvatarURL(group: Long, server: String): Boolean {
val database = databaseHelper.writableDatabase
val index = "$server.$group"
return database.delete(openGroupAvatarCacheTable, "$publicChatID == ?", arrayOf(index)) > 0
}
// region Deprecated // region Deprecated
override fun getDeviceLinks(publicKey: String): Set<DeviceLink> { override fun getDeviceLinks(publicKey: String): Set<DeviceLink> {
return setOf() return setOf()

View File

@ -72,18 +72,7 @@ class ProfilePictureView : RelativeLayout {
return recipient.isOpenGroupRecipient && return recipient.isOpenGroupRecipient &&
DatabaseFactory.getGroupDatabase(context).hasAvatar(recipient.address.toString()) DatabaseFactory.getGroupDatabase(context).hasAvatar(recipient.address.toString())
} }
if (recipient.isGroupRecipient) { if (recipient.isGroupRecipient && !isOpenGroupWithAvatar(recipient)) {
if ("Session Public Chat" == recipient.name) {
publicKey = ""
displayName = ""
additionalPublicKey = null
isRSSFeed = true
} else if (isOpenGroupWithAvatar(recipient)) {
publicKey = recipient.address.toString()
displayName = getUserDisplayName(publicKey)
additionalPublicKey = null
isRSSFeed = false
} else {
val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toMutableList() ?: mutableListOf() val users = MentionsManager.shared.userPublicKeyCache[threadID]?.toMutableList() ?: mutableListOf()
users.remove(TextSecurePreferences.getLocalNumber(context)) users.remove(TextSecurePreferences.getLocalNumber(context))
val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context) val masterPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
@ -101,8 +90,9 @@ class ProfilePictureView : RelativeLayout {
val apk = randomUsers.getOrNull(1) ?: "" val apk = randomUsers.getOrNull(1) ?: ""
additionalPublicKey = apk additionalPublicKey = apk
additionalDisplayName = getUserDisplayName(apk) additionalDisplayName = getUserDisplayName(apk)
isRSSFeed = recipient.name == "Loki News" || recipient.name == "Session Updates" isRSSFeed = recipient.name == "Loki News" ||
} recipient.name == "Session Updates" ||
recipient.name == "Session Public Chat"
} else { } else {
publicKey = recipient.address.toString() publicKey = recipient.address.toString()
displayName = getUserDisplayName(publicKey) displayName = getUserDisplayName(publicKey)