feat: scope tab base logic

This commit is contained in:
rhunk
2023-08-19 20:09:35 +02:00
parent 2db332c3cd
commit 6cabb92c04
10 changed files with 331 additions and 141 deletions

View File

@ -130,49 +130,51 @@ class SnapEnhance {
private fun syncRemote() {
val database = appContext.database
appContext.bridgeClient.sync(object : SyncCallback.Stub() {
override fun syncFriend(uuid: String): String? {
return database.getFriendInfo(uuid)?.toJson()
}
appContext.executeAsync {
appContext.bridgeClient.sync(object : SyncCallback.Stub() {
override fun syncFriend(uuid: String): String? {
return database.getFriendInfo(uuid)?.toJson()
}
override fun syncGroup(uuid: String): String? {
return database.getFeedEntryByConversationId(uuid)?.let {
override fun syncGroup(uuid: String): String? {
return database.getFeedEntryByConversationId(uuid)?.let {
MessagingGroupInfo(
it.key!!,
it.feedDisplayName!!,
it.participantsSize
).toJson()
}
}
})
appContext.event.subscribe(SnapWidgetBroadcastReceiveEvent::class) { event ->
if (event.action != BridgeClient.BRIDGE_SYNC_ACTION) return@subscribe
event.canceled = true
val feedEntries = appContext.database.getFeedEntries(Int.MAX_VALUE)
val groups = feedEntries.filter { it.friendUserId == null }.map {
MessagingGroupInfo(
it.key!!,
it.feedDisplayName!!,
it.participantsSize
).toJson()
)
}
}
})
appContext.event.subscribe(SnapWidgetBroadcastReceiveEvent::class) { event ->
if (event.action != BridgeClient.BRIDGE_SYNC_ACTION) return@subscribe
event.canceled = true
val feedEntries = appContext.database.getFeedEntries(Int.MAX_VALUE)
val friends = feedEntries.filter { it.friendUserId != null }.map {
MessagingFriendInfo(
it.friendUserId!!,
it.friendDisplayName,
it.friendDisplayUsername!!.split("|")[1],
it.bitmojiAvatarId,
it.bitmojiSelfieId
)
}
val groups = feedEntries.filter { it.friendUserId == null }.map {
MessagingGroupInfo(
it.key!!,
it.feedDisplayName!!,
it.participantsSize
appContext.bridgeClient.passGroupsAndFriends(
groups.map { it.toJson() },
friends.map { it.toJson() }
)
}
val friends = feedEntries.filter { it.friendUserId != null }.map {
MessagingFriendInfo(
it.friendUserId!!,
it.friendDisplayName,
it.friendDisplayUsername!!.split("|")[1],
it.bitmojiAvatarId,
it.bitmojiSelfieId
)
}
appContext.bridgeClient.passGroupsAndFriends(
groups.map { it.toJson() },
friends.map { it.toJson() }
)
}
}
}

View File

@ -16,7 +16,7 @@ import me.rhunk.snapenhance.bridge.types.BridgeFileType
import me.rhunk.snapenhance.bridge.types.FileActionType
import me.rhunk.snapenhance.core.BuildConfig
import me.rhunk.snapenhance.core.messaging.MessagingRule
import me.rhunk.snapenhance.core.messaging.RuleScope
import me.rhunk.snapenhance.core.messaging.MessagingScope
import me.rhunk.snapenhance.data.LocalePair
import me.rhunk.snapenhance.util.SerializableDataObject
import java.util.concurrent.CompletableFuture
@ -136,7 +136,7 @@ class BridgeClient(
fun passGroupsAndFriends(groups: List<String>, friends: List<String>) = service.passGroupsAndFriends(groups, friends)
fun getRulesFromId(type: RuleScope, targetUuid: String): List<MessagingRule> {
fun getRulesFromId(type: MessagingScope, targetUuid: String): List<MessagingRule> {
return service.getRules(type.name, targetUuid).map {
SerializableDataObject.fromJson(it, MessagingRule::class.java)
}.toList()

View File

@ -8,18 +8,18 @@ enum class Mode {
WHITELIST
}
enum class RuleScope {
enum class MessagingScope {
FRIEND,
GROUP
}
enum class ConversationFeature(
val value: String,
val ruleScope: RuleScope,
val messagingScope: MessagingScope,
) {
DOWNLOAD("download", RuleScope.FRIEND),
STEALTH("stealth", RuleScope.GROUP),
AUTO_SAVE("auto_save", RuleScope.GROUP);
DOWNLOAD("download", MessagingScope.FRIEND),
STEALTH("stealth", MessagingScope.GROUP),
AUTO_SAVE("auto_save", MessagingScope.GROUP);
}
data class FriendStreaks(
@ -47,7 +47,7 @@ data class MessagingFriendInfo(
data class MessagingRule(
val id: Int,
val ruleScope: RuleScope,
val messagingScope: MessagingScope,
val targetUuid: String,
val enabled: Boolean,
val mode: Mode?,