android: preserve avatar references in JSON refresh and live member snapshots
This commit is contained in:
1 parent
57888f8d9e
commit
15d0772a20
3 files changed
+29
-10
No files matched your search
@@ -424,6 +424,14 @@ class ChatRepository {
|
||||
val arr = JSONArray(NativeLib.getChannelMembers(channelId))
|
||||
for (i in 0 until arr.length()) {
|
||||
val obj = arr.getJSONObject(i)
|
||||
val userinfo = try { JSONObject(obj.optString("ui").ifEmpty { "{}" }) }
|
||||
catch (e: Exception) {
|
||||
LogManager.addLog("WARN", "Avatar", "Invalid userinfo group=$channelId owner=${obj.optLong("ni")}: ${e.message}")
|
||||
JSONObject()
|
||||
}
|
||||
val avatarFile = userinfo.optString("avatar_file")
|
||||
val avatarServer = AvatarProtocol.node(userinfo.optString("avatar_server"))
|
||||
val validAvatar = avatarServer != 0L && AvatarProtocol.validFile(avatarFile)
|
||||
list.add(ChatMember(
|
||||
nodeId = obj.getLong("ni"),
|
||||
name = obj.optString("n", ""),
|
||||
@@ -436,7 +444,10 @@ class ChatRepository {
|
||||
isDeleted = obj.optInt("dl", 0) != 0,
|
||||
nodeType = obj.optInt("tp", 0),
|
||||
rtt = obj.optInt("rt", 0),
|
||||
isSelf = obj.optInt("is", 0) != 0
|
||||
isSelf = obj.optInt("is", 0) != 0,
|
||||
avatarServer = if (validAvatar) avatarServer else 0,
|
||||
avatarFile = if (validAvatar) avatarFile else "",
|
||||
storageRole = obj.optInt("sr", 0) != 0
|
||||
))
|
||||
}
|
||||
} catch (e: Exception) { Log.w("utun-gui", "getMembers error", e) }
|
||||
|
||||
@@ -470,13 +470,14 @@ class ChatViewModel : ViewModel() {
|
||||
if (data.size != offset + count * MEMBER_WIRE_SIZE) {
|
||||
LogManager.addLog("ERROR", "VM", "MEMBER_LIST: invalid size ch=$chId count=$count bytes=${data.size}"); return
|
||||
}
|
||||
val radios = (0 until count).associate { i ->
|
||||
val snapshot = (0 until count).associate { i ->
|
||||
val w = requireNotNull(parseMemberWire(data, offset + i * MEMBER_WIRE_SIZE))
|
||||
w.nodeId to ((w.flags and 0x10) != 0)
|
||||
w.nodeId to w
|
||||
}
|
||||
val radios = snapshot.mapValues { (_, w) -> (w.flags and 0x10) != 0 }
|
||||
memberRadios[chId] = radios
|
||||
if (_currentChannel.value?.id == chId)
|
||||
_members.value = _members.value.map { it.copy(radioActive = radios[it.nodeId] == true) }
|
||||
_members.value = _members.value.map { snapshot[it.nodeId]?.toChatMember(it) ?: it }
|
||||
LogManager.addLog("DEBUG", "VM", "MEMBER_LIST: ch=$chId members=$count radios=${radios.values.count { it }}")
|
||||
}
|
||||
24 -> { /* MEMBER_UPDATED: [ch_id_len:1][ch_id:var][count:1][member:MEMBER_WIRE_SIZE] */
|
||||
@@ -952,6 +953,7 @@ class ChatViewModel : ViewModel() {
|
||||
NotificationSound.setMuted(channel.id, !_soundOn.value)
|
||||
r.connectChannel(channel.id)
|
||||
refreshMessages(channel.id)
|
||||
refreshMembers(channel.id)
|
||||
}
|
||||
|
||||
/* ── per-channel «play sound on message» ── */
|
||||
|
||||
Reference in new issue
Block a user