Update Android PM screens from asynchronous core events
This commit is contained in:
1 parent
52e38ff5d6
commit
1457275139
1 file changed
+24
-17
@@ -511,6 +511,20 @@ class ChatViewModel : ViewModel() {
|
||||
if (cur != null && cur.convId == convId) refreshDmMessages()
|
||||
refreshDmConversations()
|
||||
}
|
||||
41 -> { /* DM_MESSAGES: [conv_len:1][conv:utf8][JSON:utf8] */
|
||||
if (data == null || data.isEmpty()) return
|
||||
val length = data[0].toInt() and 0xFF
|
||||
if (data.size <= 1 + length) return
|
||||
val dm = _currentDm.value ?: return
|
||||
val conv = String(data, 1, length, Charsets.UTF_8)
|
||||
if (conv != dm.convId) return
|
||||
val json = String(data, 1 + length, data.size - 1 - length, Charsets.UTF_8)
|
||||
_dmMessages.value = repo?.parseDmMessages(json, dm.peerName) ?: emptyList()
|
||||
}
|
||||
45 -> {
|
||||
if (data == null) return
|
||||
_dmConversations.value = repo?.parseDmConversations(String(data, Charsets.UTF_8)) ?: emptyList()
|
||||
}
|
||||
43 -> { /* RADIO_TALK: [group_id:8][src:8][stream:2][on:1] */
|
||||
if (data == null || data.size < 19) return
|
||||
val bb = java.nio.ByteBuffer.wrap(data, 0, 19).order(java.nio.ByteOrder.LITTLE_ENDIAN)
|
||||
@@ -737,7 +751,7 @@ class ChatViewModel : ViewModel() {
|
||||
val r = repo ?: return
|
||||
viewModelScope.launch {
|
||||
_channels.value = withContext(Dispatchers.IO) { r.getChannels() }
|
||||
_dmConversations.value = withContext(Dispatchers.IO) { r.getDmConversations() }
|
||||
refreshDmConversations()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,18 +785,12 @@ class ChatViewModel : ViewModel() {
|
||||
/* ── DM (личные сообщения) ── */
|
||||
|
||||
fun refreshDmConversations() {
|
||||
val r = repo ?: return
|
||||
viewModelScope.launch {
|
||||
_dmConversations.value = withContext(Dispatchers.IO) { r.getDmConversations() }
|
||||
}
|
||||
if (repo != null) NativeLib.dmRequestConversations()
|
||||
}
|
||||
|
||||
fun refreshDmMessages() {
|
||||
val r = repo ?: return
|
||||
val dm = _currentDm.value ?: return
|
||||
viewModelScope.launch {
|
||||
_dmMessages.value = withContext(Dispatchers.IO) { r.getDmMessages(dm.convId, dm.peerName) }
|
||||
}
|
||||
if (repo != null) NativeLib.dmRequestMessages(dm.convId)
|
||||
}
|
||||
|
||||
fun startDm(channelId: String, nodeId: Long, name: String) {
|
||||
@@ -796,12 +804,11 @@ class ChatViewModel : ViewModel() {
|
||||
fun consumeDmOpen() { _dmOpen.value = null }
|
||||
|
||||
fun openDm(convId: String, peerNodeId: Long, peerName: String) {
|
||||
val r = repo ?: return
|
||||
if (repo == null) return
|
||||
val dm = DmConversation(convId = convId, peerNodeId = peerNodeId, peerName = peerName)
|
||||
_currentDm.value = dm
|
||||
viewModelScope.launch {
|
||||
_dmMessages.value = withContext(Dispatchers.IO) { r.getDmMessages(convId, peerName) }
|
||||
}
|
||||
_dmMessages.value = emptyList()
|
||||
refreshDmMessages()
|
||||
}
|
||||
|
||||
fun closeDm() {
|
||||
@@ -814,10 +821,10 @@ class ChatViewModel : ViewModel() {
|
||||
val dm = _currentDm.value ?: return
|
||||
if (text.isBlank()) return
|
||||
r.dmSend(dm.convId, text)
|
||||
viewModelScope.launch {
|
||||
_dmMessages.value = withContext(Dispatchers.IO) { r.getDmMessages(dm.convId, dm.peerName) }
|
||||
refreshDmConversations()
|
||||
}
|
||||
}
|
||||
|
||||
fun sendDmFile(convId: String, path: String, name: String) {
|
||||
if (repo != null) NativeLib.dmSendFile(convId, path, name)
|
||||
}
|
||||
|
||||
fun refreshMembers(chId: String) {
|
||||
|
||||
Reference in new issue
Block a user