Responded to PR comments

This commit is contained in:
Morgan Pretty 2023-06-07 15:02:32 +10:00
parent 11c1fd382d
commit 7699e47f7b
3 changed files with 26 additions and 26 deletions

View File

@ -15,7 +15,7 @@ import java.util.concurrent.Executors
object OpenGroupManager {
private val executorService = Executors.newScheduledThreadPool(4)
private var pollers = mutableMapOf<String, OpenGroupPoller>() // One for each server
private val pollers = mutableMapOf<String, OpenGroupPoller>() // One for each server
private var isPolling = false
private val pollUpdaterLock = Any()
@ -44,9 +44,7 @@ object OpenGroupManager {
synchronized(pollUpdaterLock) {
servers.forEach { server ->
pollers[server]?.stop() // Shouldn't be necessary
val poller = OpenGroupPoller(server, executorService)
poller.startIfNeeded()
pollers[server] = poller
pollers[server] = OpenGroupPoller(server, executorService).apply { startIfNeeded() }
}
}
}

View File

@ -110,8 +110,7 @@ object OpenGroupApi {
val upload: Boolean = false,
val defaultUpload: Boolean = false,
) {
fun toPollInfo(): RoomPollInfo {
return RoomPollInfo(
fun toPollInfo() = RoomPollInfo(
token = token,
activeUsers = activeUsers,
admin = admin,
@ -128,7 +127,6 @@ object OpenGroupApi {
details = this
)
}
}
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
data class PinnedMessage(

View File

@ -40,7 +40,7 @@ class OpenGroupPoller(private val server: String, private val executorService: S
var isCaughtUp = false
var secondToLastJob: MessageReceiveJob? = null
private var future: ScheduledFuture<*>? = null
private var runId: UUID = UUID.randomUUID()
@Volatile private var runId: UUID = UUID.randomUUID()
companion object {
private const val pollInterval: Long = 4000L
@ -59,16 +59,20 @@ class OpenGroupPoller(private val server: String, private val executorService: S
// If we don't have an existing group and don't have a 'createGroupIfMissingWithPublicKey'
// value then don't process the poll info
val publicKey = ((existingOpenGroup?.publicKey ?: createGroupIfMissingWithPublicKey) ?: return)
val publicKey = existingOpenGroup?.publicKey ?: createGroupIfMissingWithPublicKey
val name = pollInfo.details?.name ?: existingOpenGroup?.name
val infoUpdates = pollInfo.details?.infoUpdates ?: existingOpenGroup?.infoUpdates
if (publicKey == null) return
val openGroup = OpenGroup(
server = server,
room = pollInfo.token,
name = ((pollInfo.details?.name ?: existingOpenGroup?.name) ?: ""),
name = name ?: "",
publicKey = publicKey,
imageId = (pollInfo.details?.imageId ?: existingOpenGroup?.imageId),
canWrite = pollInfo.write,
infoUpdates = ((pollInfo.details?.infoUpdates ?: existingOpenGroup?.infoUpdates) ?: 0)
infoUpdates = infoUpdates ?: 0
)
// - Open Group changes
storage.updateOpenGroup(openGroup)