2021-07-09 05:25:57 +02:00
|
|
|
package org.thoughtcrime.securesms.groups
|
2021-05-19 02:56:23 +02:00
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import androidx.annotation.WorkerThread
|
2021-05-21 07:02:34 +02:00
|
|
|
import okhttp3.HttpUrl
|
2021-05-19 02:56:23 +02:00
|
|
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
2022-08-10 10:17:48 +02:00
|
|
|
import org.session.libsession.messaging.open_groups.GroupMemberRole
|
|
|
|
import org.session.libsession.messaging.open_groups.OpenGroup
|
|
|
|
import org.session.libsession.messaging.open_groups.OpenGroupApi
|
|
|
|
import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPoller
|
2022-08-22 01:27:35 +02:00
|
|
|
import org.session.libsignal.utilities.Log
|
2021-05-19 02:56:23 +02:00
|
|
|
import org.session.libsignal.utilities.ThreadUtils
|
2021-10-04 09:51:19 +02:00
|
|
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
2021-05-19 02:56:23 +02:00
|
|
|
import java.util.concurrent.Executors
|
|
|
|
|
|
|
|
object OpenGroupManager {
|
|
|
|
private val executorService = Executors.newScheduledThreadPool(4)
|
2022-08-10 10:17:48 +02:00
|
|
|
private var pollers = mutableMapOf<String, OpenGroupPoller>() // One for each server
|
2021-05-19 02:56:23 +02:00
|
|
|
private var isPolling = false
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
private val pollUpdaterLock = Any()
|
2021-05-19 02:56:23 +02:00
|
|
|
|
2021-05-21 06:55:06 +02:00
|
|
|
val isAllCaughtUp: Boolean
|
|
|
|
get() {
|
|
|
|
pollers.values.forEach { poller ->
|
2021-05-24 08:21:24 +02:00
|
|
|
val jobID = poller.secondToLastJob?.id
|
2021-05-21 06:55:06 +02:00
|
|
|
jobID?.let {
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-05-24 08:21:24 +02:00
|
|
|
if (storage.getMessageReceiveJob(jobID) == null) {
|
|
|
|
// If the second to last job is done, it means we are now handling the last job
|
2021-05-21 06:55:06 +02:00
|
|
|
poller.isCaughtUp = true
|
2021-05-24 08:21:24 +02:00
|
|
|
poller.secondToLastJob = null
|
2021-05-21 06:55:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!poller.isCaughtUp) { return false }
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2021-05-19 09:01:53 +02:00
|
|
|
|
2021-05-19 02:56:23 +02:00
|
|
|
fun startPolling() {
|
|
|
|
if (isPolling) { return }
|
|
|
|
isPolling = true
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2022-08-10 10:17:48 +02:00
|
|
|
val servers = storage.getAllOpenGroups().values.map { it.server }.toSet()
|
2023-06-07 05:31:22 +02:00
|
|
|
synchronized(pollUpdaterLock) {
|
|
|
|
servers.forEach { server ->
|
|
|
|
pollers[server]?.stop() // Shouldn't be necessary
|
|
|
|
val poller = OpenGroupPoller(server, executorService)
|
|
|
|
poller.startIfNeeded()
|
|
|
|
pollers[server] = poller
|
|
|
|
}
|
2021-05-19 02:56:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun stopPolling() {
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
synchronized(pollUpdaterLock) {
|
|
|
|
pollers.forEach { it.value.stop() }
|
|
|
|
pollers.clear()
|
|
|
|
isPolling = false
|
|
|
|
}
|
2021-05-19 02:56:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@WorkerThread
|
2023-01-09 05:22:29 +01:00
|
|
|
fun add(server: String, room: String, publicKey: String, context: Context): OpenGroupApi.RoomInfo? {
|
2021-05-19 02:56:23 +02:00
|
|
|
val openGroupID = "$server.$room"
|
2023-06-07 05:31:22 +02:00
|
|
|
val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
|
2021-05-19 02:56:23 +02:00
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-10-04 09:51:19 +02:00
|
|
|
val threadDB = DatabaseComponent.get(context).lokiThreadDatabase()
|
2021-05-19 02:56:23 +02:00
|
|
|
// Check it it's added already
|
|
|
|
val existingOpenGroup = threadDB.getOpenGroupChat(threadID)
|
2023-01-09 05:22:29 +01:00
|
|
|
if (existingOpenGroup != null) { return null }
|
2021-05-19 02:56:23 +02:00
|
|
|
// Clear any existing data if needed
|
2021-05-21 07:02:34 +02:00
|
|
|
storage.removeLastDeletionServerID(room, server)
|
|
|
|
storage.removeLastMessageServerID(room, server)
|
2022-08-10 10:17:48 +02:00
|
|
|
storage.removeLastInboxMessageId(server)
|
|
|
|
storage.removeLastOutboxMessageId(server)
|
2021-05-19 02:56:23 +02:00
|
|
|
// Store the public key
|
2022-08-22 01:27:35 +02:00
|
|
|
storage.setOpenGroupPublicKey(server, publicKey)
|
2023-01-09 05:22:29 +01:00
|
|
|
// Get capabilities & room info
|
|
|
|
val (capabilities, info) = OpenGroupApi.getCapabilitiesAndRoomInfo(room, server).get()
|
2022-08-10 10:17:48 +02:00
|
|
|
storage.setServerCapabilities(server, capabilities.capabilities)
|
2021-12-15 07:11:55 +01:00
|
|
|
// Create the group locally if not available already
|
2021-05-19 02:56:23 +02:00
|
|
|
if (threadID < 0) {
|
2023-06-07 05:31:22 +02:00
|
|
|
GroupManager.createOpenGroup(openGroupID, context, null, info.name)
|
2021-05-19 02:56:23 +02:00
|
|
|
}
|
2023-06-07 05:31:22 +02:00
|
|
|
OpenGroupPoller.handleRoomPollInfo(
|
|
|
|
server = server,
|
|
|
|
roomToken = room,
|
|
|
|
pollInfo = info.toPollInfo(),
|
|
|
|
createGroupIfMissingWithPublicKey = publicKey
|
|
|
|
)
|
2023-01-09 05:22:29 +01:00
|
|
|
return info
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fun restartPollerForServer(server: String) {
|
2021-05-19 02:56:23 +02:00
|
|
|
// Start the poller if needed
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
synchronized(pollUpdaterLock) {
|
|
|
|
pollers[server]?.stop()
|
|
|
|
pollers[server]?.startIfNeeded() ?: run {
|
2022-08-10 10:17:48 +02:00
|
|
|
val poller = OpenGroupPoller(server, executorService)
|
2022-08-22 01:27:35 +02:00
|
|
|
Log.d("Loki", "Starting poller for open group: $server")
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
pollers[server] = poller
|
|
|
|
poller.startIfNeeded()
|
|
|
|
}
|
2021-05-19 02:56:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun delete(server: String, room: String, context: Context) {
|
|
|
|
val storage = MessagingModuleConfiguration.shared.storage
|
2021-10-04 09:51:19 +02:00
|
|
|
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
2021-05-19 02:56:23 +02:00
|
|
|
val openGroupID = "$server.$room"
|
|
|
|
val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
|
2021-05-25 01:17:06 +02:00
|
|
|
val recipient = threadDB.getRecipientForThreadId(threadID) ?: return
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
threadDB.setThreadArchived(threadID)
|
2021-05-25 01:17:06 +02:00
|
|
|
val groupID = recipient.address.serialize()
|
2021-05-19 02:56:23 +02:00
|
|
|
// Stop the poller if needed
|
2022-08-10 10:17:48 +02:00
|
|
|
val openGroups = storage.getAllOpenGroups().filter { it.value.server == server }
|
2021-05-19 02:56:23 +02:00
|
|
|
if (openGroups.count() == 1) {
|
Performance improvements and bug fixes (#869)
* refactor: fail on testSnode instead of recursively using up snode list. add call timeout on http client
* refactor: refactoring batch message receives and pollers
* refactor: reduce thread utils pool count to a 2 thread fixed pool. Do a check against pubkey instead of room names for oxenHostedOpenGroup
* refactor: caching lib with potential loader fixes and no-cache for giphy
* refactor: remove store and instead use ConcurrentHashMap with a backing update coroutine
* refactor: queue trim thread jobs instead of add every message processed
* fix: wrapping auth token and initial sync for open groups in a threadutils queued runnable, getting initial sync times down
* fix: fixing the user contacts cache in ConversationAdapter.kt
* refactor: improve polling and initial sync, move group joins from config messages into a background job fetching image.
* refactor: improving the job queuing for open groups, replacing placeholder avatar generation with a custom glide loader and archiving initial sync of open groups
* feat: add OpenGroupDeleteJob.kt
* feat: add open group delete job to process deletions after batch adding
* feat: add vacuum and fix job queue re-adding jobs forever, only try to set message hash values in DB if they have changed
* refactor: remove redundant inflation for profile image views throughout app
* refactor(wip): reducing layout inflation and starting to refactor the open group deletion issues taking a long time
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* refactor(wip): refactoring group deletion to not iterate through and delete messages individually
* fix: group deletion optimisation
* build: bump build number
* build: bump build number and fix batch message receive retry logic
* fix: clear out open group deletes
* fix: update visible ConversationAdapter.kt binding for initial contact fetching and better traces for debugging background jobs
* fix: add in check for / force sync latest encryption key pair from linked devices if we already have that closed group
* Rename .java to .kt
* refactor: change MmsDatabase to kotlin to make list operations easier
* fix: nullable type
* fix: compilation issues and constants in .kt instead of .java
* fix: bug fix expiration timer on closed group recipient
* feat: use the job queue properly across executors
* feat: start on open group dispatcher-specific logic, probably a queue factory based on openGroupId if that is the same across new message and deletion jobs to ensure consistent entry and removal
* refactor: removing redundant code and fixing jobqueue per opengroup
* fix: allow attachments in note to self
* fix: make the minWidth in quote view bind max of text / title and body, wrapped ?
* fix: fixing up layouts and code view layouts
* fix: remove TODO, remove timestamp binding
* feat: fix view logic, avatars and padding, downloading attachments lazily (on bind), fixing potential crash, add WindowDebouncer.kt
* fix: NPE on viewModel recipient from removed thread while tearing down the Recipient observer in ConversationActivityV2.kt
* refactor: replace conversation notification debouncer handler with handlerthread, same as conversation list debouncer
* refactor: UI for groups and poller improvements
* fix: revert some changes in poller
* feat: add header back in for message requests
* refactor: remove Trace calls, add more conditions to the HomeDiffUtil for updating more efficiently
* feat: try update the home adapter if we get a profile picture modified event
* feat: bump build numbers
* fix: try to start with list in homeViewModel if we don't have already, render quotes to be width of attachment slide view instead of fixed
* fix: set channel to be conflated instead of no buffer
* fix: set unreads based off last local user message vs incrementing unreads to be all amount
* feat: add profile update flag, update build number
* fix: link preview thumbnails download on bind
* fix: centercrop placeholder in glide request
* feat: recycle the contact selection list and profile image in unbind
* fix: try to prevent user KP crash at weird times
* fix: remove additional log, improve attachment download success rate, fix share logs dialog issue
2022-06-08 09:12:34 +02:00
|
|
|
synchronized(pollUpdaterLock) {
|
|
|
|
val poller = pollers[server]
|
|
|
|
poller?.stop()
|
|
|
|
pollers.remove(server)
|
|
|
|
}
|
2021-05-19 02:56:23 +02:00
|
|
|
}
|
|
|
|
// Delete
|
2021-05-26 07:22:19 +02:00
|
|
|
storage.removeLastDeletionServerID(room, server)
|
|
|
|
storage.removeLastMessageServerID(room, server)
|
2022-08-10 10:17:48 +02:00
|
|
|
storage.removeLastInboxMessageId(server)
|
|
|
|
storage.removeLastOutboxMessageId(server)
|
2021-10-04 09:51:19 +02:00
|
|
|
val lokiThreadDB = DatabaseComponent.get(context).lokiThreadDatabase()
|
2021-05-26 07:22:19 +02:00
|
|
|
lokiThreadDB.removeOpenGroupChat(threadID)
|
2021-05-19 02:56:23 +02:00
|
|
|
ThreadUtils.queue {
|
2021-07-09 01:38:45 +02:00
|
|
|
threadDB.deleteConversation(threadID) // Must be invoked on a background thread
|
2021-05-19 02:56:23 +02:00
|
|
|
GroupManager.deleteGroup(groupID, context) // Must be invoked on a background thread
|
|
|
|
}
|
|
|
|
}
|
2021-05-21 07:02:34 +02:00
|
|
|
|
2023-01-09 05:22:29 +01:00
|
|
|
fun addOpenGroup(urlAsString: String, context: Context): OpenGroupApi.RoomInfo? {
|
|
|
|
val url = HttpUrl.parse(urlAsString) ?: return null
|
2022-08-10 10:17:48 +02:00
|
|
|
val server = OpenGroup.getServer(urlAsString)
|
2023-01-09 05:22:29 +01:00
|
|
|
val room = url.pathSegments().firstOrNull() ?: return null
|
|
|
|
val publicKey = url.queryParameter("public_key") ?: return null
|
|
|
|
|
|
|
|
return add(server.toString().removeSuffix("/"), room, publicKey, context) // assume migrated from calling function
|
2021-05-21 07:02:34 +02:00
|
|
|
}
|
2022-08-10 10:17:48 +02:00
|
|
|
|
|
|
|
fun updateOpenGroup(openGroup: OpenGroup, context: Context) {
|
|
|
|
val threadDB = DatabaseComponent.get(context).lokiThreadDatabase()
|
|
|
|
val openGroupID = "${openGroup.server}.${openGroup.room}"
|
|
|
|
val threadID = GroupManager.getOpenGroupThreadID(openGroupID, context)
|
|
|
|
threadDB.setOpenGroupChat(openGroup, threadID)
|
|
|
|
}
|
|
|
|
|
|
|
|
fun isUserModerator(context: Context, groupId: String, standardPublicKey: String, blindedPublicKey: String? = null): Boolean {
|
|
|
|
val memberDatabase = DatabaseComponent.get(context).groupMemberDatabase()
|
|
|
|
val standardRoles = memberDatabase.getGroupMemberRoles(groupId, standardPublicKey)
|
|
|
|
val blindedRoles = blindedPublicKey?.let { memberDatabase.getGroupMemberRoles(groupId, it) } ?: emptyList()
|
|
|
|
|
2022-08-17 03:06:02 +02:00
|
|
|
// roles to check against
|
|
|
|
val moderatorRoles = listOf(
|
|
|
|
GroupMemberRole.MODERATOR, GroupMemberRole.ADMIN,
|
|
|
|
GroupMemberRole.HIDDEN_MODERATOR, GroupMemberRole.HIDDEN_ADMIN
|
|
|
|
)
|
|
|
|
return standardRoles.any { it in moderatorRoles } || blindedRoles.any { it in moderatorRoles }
|
2022-08-10 10:17:48 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 02:56:23 +02:00
|
|
|
}
|