Expose member file commands through Android JNI
This commit is contained in:
1 parent
51e7f821e9
commit
e97885eb22
3 files changed
+110
-3
No files matched your search
@@ -14,6 +14,7 @@ import com.utun.chat.data.TelecomCallManager
|
||||
import com.utun.chat.data.ChatEventCallback
|
||||
import com.utun.chat.data.CallController
|
||||
import com.utun.chat.data.AvatarRepository
|
||||
import com.utun.chat.data.MemberFilesRepository
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -30,6 +31,7 @@ object AppEventHandler : ChatEventCallback {
|
||||
val events: SharedFlow<Pair<Int, ByteArray?>> = _events
|
||||
|
||||
override fun onEvent(type: Int, data: ByteArray?) {
|
||||
if (type == 13 || type in 49..50) mainHandler.post { ChatApplication.instance.memberFiles.onEvent(type, data) }
|
||||
if (type in listOf(4, 8, 9, 12, 13, 23, 24, 25, 31) || type in 49..53)
|
||||
mainHandler.post { ChatApplication.instance.avatars.onEvent(type, data) }
|
||||
if (type == 1 || type == 32) playMessageSound(type, data)
|
||||
@@ -61,6 +63,7 @@ class ChatApplication : Application() {
|
||||
lateinit var logManager: LogManager
|
||||
lateinit var configProvider: ConfigProvider
|
||||
lateinit var avatars: AvatarRepository
|
||||
lateinit var memberFiles: MemberFilesRepository
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
@@ -68,6 +71,7 @@ class ChatApplication : Application() {
|
||||
logManager = LogManager
|
||||
configProvider = ConfigProvider(this)
|
||||
avatars = AvatarRepository(this)
|
||||
memberFiles = MemberFilesRepository(this)
|
||||
|
||||
/* Notification sound state: global toggle + per-group mute */
|
||||
NotificationSound.enabled = configProvider.getSoundEnabled()
|
||||
|
||||
@@ -42,9 +42,12 @@ object NativeLib {
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
runBlocking(Dispatchers.Main.immediate) { CallController.reset(); ChatApplication.instance.avatars.stop() }
|
||||
runBlocking(Dispatchers.Main.immediate) {
|
||||
CallController.reset(); ChatApplication.instance.avatars.stop(); ChatApplication.instance.memberFiles.cancel()
|
||||
}
|
||||
if (!isReady()) return
|
||||
nativeStop()
|
||||
runBlocking(Dispatchers.Main.immediate) { ChatApplication.instance.memberFiles.coreStopped() }
|
||||
}
|
||||
|
||||
fun setEventCallback(cb: ChatEventCallback) {
|
||||
@@ -54,12 +57,17 @@ object NativeLib {
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
runBlocking(Dispatchers.Main.immediate) { CallController.reset(); ChatApplication.instance.avatars.stop() }
|
||||
runBlocking(Dispatchers.Main.immediate) {
|
||||
CallController.reset(); ChatApplication.instance.avatars.stop(); ChatApplication.instance.memberFiles.cancel()
|
||||
}
|
||||
nativeDestroy()
|
||||
runBlocking(Dispatchers.Main.immediate) { ChatApplication.instance.memberFiles.coreStopped() }
|
||||
}
|
||||
|
||||
fun restart(dbPath: String, controlPort: Int, configText: String): Boolean {
|
||||
runBlocking(Dispatchers.Main.immediate) { CallController.reset(); ChatApplication.instance.avatars.stop() }
|
||||
runBlocking(Dispatchers.Main.immediate) {
|
||||
CallController.reset(); ChatApplication.instance.avatars.stop(); ChatApplication.instance.memberFiles.cancel()
|
||||
}
|
||||
return nativeRestart(configText)
|
||||
}
|
||||
|
||||
@@ -137,6 +145,15 @@ object NativeLib {
|
||||
fun setGroupAvatar(id: Long, group: Long, data: ByteArray): Boolean =
|
||||
nativeAvatarOperation(6, id, group, 0, 0, null, null, data)
|
||||
fun cancelAvatar(id: Long): Boolean = nativeAvatarOperation(7, id, 0, 0, 0, null, null, null)
|
||||
fun fileRequest(group: Long, server: Long, wire: ByteArray): Boolean = nativeFileRequest(group, server, wire)
|
||||
fun fileTransfer(id: Long, group: Long, server: Long, owner: Long, remote: String, local: String,
|
||||
upload: Boolean, version: ByteArray): Boolean =
|
||||
nativeFileTransfer(id, group, server, owner, remote.toByteArray(), local.toByteArray(), upload, version)
|
||||
fun fileCancel(id: Long): Boolean = nativeFileCancel(id)
|
||||
private external fun nativeFileRequest(group: Long, server: Long, wire: ByteArray): Boolean
|
||||
private external fun nativeFileTransfer(id: Long, group: Long, server: Long, owner: Long, remote: ByteArray,
|
||||
local: ByteArray, upload: Boolean, version: ByteArray): Boolean
|
||||
private external fun nativeFileCancel(id: Long): Boolean
|
||||
fun getMemberDetail(channelId: String, nodeId: Long): String = nativeGetMemberDetail(channelId, nodeId) ?: "{}"
|
||||
fun setMemberNick(channelId: String, nodeId: Long, nick: String) { nativeSetMemberNick(channelId, nodeId, nick) }
|
||||
fun toggleMemberRadioMute(channelId: String, nodeId: Long): Boolean = nativeToggleMemberRadioMute(channelId, nodeId)
|
||||
|
||||
Reference in new issue
Block a user