commit 54d3010970857027ffb51f44c7522945fec5af71
parent 546aa00c74dbadae12c7096274e6e4d6e2452441
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Tue, 23 Jan 2024 18:23:52 +0100
fix(core): remote sync
Diffstat:
2 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/SnapEnhance.kt
@@ -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)
- }
}
}
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/event/EventDispatcher.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/event/EventDispatcher.kt
@@ -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))
}
}