feat: implement caching for group invite info and enhance message bubble layout for group invites
This commit is contained in:
@@ -16,6 +16,7 @@ import com.rosetta.messenger.network.PacketGroupLeave
|
||||
import com.rosetta.messenger.network.ProtocolManager
|
||||
import java.security.SecureRandom
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import kotlin.coroutines.resume
|
||||
@@ -27,6 +28,8 @@ class GroupRepository private constructor(context: Context) {
|
||||
private val messageDao = db.messageDao()
|
||||
private val dialogDao = db.dialogDao()
|
||||
|
||||
private val inviteInfoCache = ConcurrentHashMap<String, GroupInviteInfoResult>()
|
||||
|
||||
companion object {
|
||||
private const val GROUP_PREFIX = "#group:"
|
||||
private const val GROUP_INVITE_PASSWORD = "rosetta_group"
|
||||
@@ -159,6 +162,20 @@ class GroupRepository private constructor(context: Context) {
|
||||
return response.members
|
||||
}
|
||||
|
||||
fun getCachedInviteInfo(groupId: String): GroupInviteInfoResult? {
|
||||
val normalized = normalizeGroupId(groupId)
|
||||
return inviteInfoCache[normalized]
|
||||
}
|
||||
|
||||
fun cacheInviteInfo(groupId: String, status: GroupStatus, membersCount: Int) {
|
||||
val normalized = normalizeGroupId(groupId)
|
||||
inviteInfoCache[normalized] = GroupInviteInfoResult(
|
||||
groupId = normalized,
|
||||
membersCount = membersCount,
|
||||
status = status
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun requestInviteInfo(groupPublicKeyOrId: String): GroupInviteInfoResult? {
|
||||
val groupId = normalizeGroupId(groupPublicKeyOrId)
|
||||
if (groupId.isBlank()) return null
|
||||
@@ -176,11 +193,13 @@ class GroupRepository private constructor(context: Context) {
|
||||
) { incoming -> normalizeGroupId(incoming.groupId) == groupId }
|
||||
?: return null
|
||||
|
||||
return GroupInviteInfoResult(
|
||||
val result = GroupInviteInfoResult(
|
||||
groupId = groupId,
|
||||
membersCount = response.membersCount.coerceAtLeast(0),
|
||||
status = response.groupStatus
|
||||
)
|
||||
inviteInfoCache[groupId] = result
|
||||
return result
|
||||
}
|
||||
|
||||
suspend fun createGroup(
|
||||
|
||||
Reference in New Issue
Block a user