fix(core): remote sync

This commit is contained in:
rhunk 2024-01-23 18:23:52 +01:00
parent 546aa00c74
commit 54d3010970
2 changed files with 31 additions and 29 deletions

View File

@ -131,6 +131,7 @@ class SnapEnhance {
reloadConfig()
actionManager.init()
initConfigListener()
initWidgetListener()
initNative()
scope.launch(Dispatchers.IO) {
translation.userLocale = getConfigLocale()
@ -224,7 +225,35 @@ class SnapEnhance {
}
})
}
}
private fun initWidgetListener() {
appContext.event.subscribe(SnapWidgetBroadcastReceiveEvent::class) { event ->
if (event.action != ReceiversConfig.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
)
}
val friends = feedEntries.filter { it.friendUserId != null }.map {
MessagingFriendInfo(
it.friendUserId!!,
it.friendDisplayName,
it.friendDisplayUsername!!.split("|")[1],
it.bitmojiAvatarId,
it.bitmojiSelfieId,
streaks = null
)
}
appContext.bridgeClient.passGroupsAndFriends(groups, friends)
}
}
private fun syncRemote() {
@ -258,33 +287,6 @@ class SnapEnhance {
}
}
})
event.subscribe(SnapWidgetBroadcastReceiveEvent::class) { event ->
if (event.action != ReceiversConfig.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
)
}
val friends = feedEntries.filter { it.friendUserId != null }.map {
MessagingFriendInfo(
it.friendUserId!!,
it.friendDisplayName,
it.friendDisplayUsername!!.split("|")[1],
it.bitmojiAvatarId,
it.bitmojiSelfieId,
streaks = null
)
}
bridgeClient.passGroupsAndFriends(groups, friends)
}
}
}

View File

@ -204,7 +204,7 @@ class EventDispatcher(
val responseUnaryCallEvent = UnaryCallEvent(
uri = uri,
buffer = array
)
).also { it.context = context}
event.callbacks.forEach { callback ->
callback(responseUnaryCallEvent)
@ -215,7 +215,7 @@ class EventDispatcher(
return@ephemeralHookObjectMethod
}
methodParam.setArg(0, ByteBuffer.wrap(event.buffer))
methodParam.setArg(0, ByteBuffer.wrap(responseUnaryCallEvent.buffer))
}
}