|
|
|
|
@ -65,7 +65,8 @@ data class Message(val id: Long, val author: String, val text: String, val ts: L
|
|
|
|
|
val voiceDurationMs: Int = 0, val fileSize: Long = 0, |
|
|
|
|
val imageWidth: Int = 0, val imageHeight: Int = 0, |
|
|
|
|
val videoWidth: Int = 0, val videoHeight: Int = 0, val videoDurationMs: Int = 0, |
|
|
|
|
val downloadState: String = "" /* "", "downloading", "downloaded", "error" */) |
|
|
|
|
val downloadState: String = "", /* "", "downloading", "downloaded", "error" */ |
|
|
|
|
val deliveryStatus: String = "") |
|
|
|
|
|
|
|
|
|
data class ChatMember(val nodeId: Long, val name: String, val online: Boolean = false, |
|
|
|
|
val isAdmin: Boolean = false, val isSuper: Boolean = false, |
|
|
|
|
@ -537,10 +538,10 @@ class ChatRepository {
|
|
|
|
|
|
|
|
|
|
fun dmSend(convId: String, text: String) = NativeLib.dmSend(convId, text) |
|
|
|
|
|
|
|
|
|
fun getDmConversations(): List<DmConversation> { |
|
|
|
|
fun parseDmConversations(json: String): List<DmConversation> { |
|
|
|
|
val list = mutableListOf<DmConversation>() |
|
|
|
|
try { |
|
|
|
|
val arr = JSONArray(NativeLib.dmListConversations()) |
|
|
|
|
val arr = JSONArray(json) |
|
|
|
|
for (i in 0 until arr.length()) { |
|
|
|
|
val obj = arr.getJSONObject(i) |
|
|
|
|
list.add(DmConversation( |
|
|
|
|
@ -554,14 +555,26 @@ class ChatRepository {
|
|
|
|
|
return list |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun getDmMessages(convId: String, peerName: String = "", limit: Int = 50): List<Message> { |
|
|
|
|
fun parseDmMessages(json: String, peerName: String = ""): List<Message> { |
|
|
|
|
val list = mutableListOf<Message>() |
|
|
|
|
try { |
|
|
|
|
val arr = JSONArray(NativeLib.dmListMessages(convId, limit, 0)) |
|
|
|
|
val arr = JSONArray(json) |
|
|
|
|
for (i in 0 until arr.length()) { |
|
|
|
|
val obj = arr.getJSONObject(i) |
|
|
|
|
val dir = obj.optInt("dir", 0) |
|
|
|
|
val outgoing = dir == 1 |
|
|
|
|
val file = obj.optString("ct") == "file" |
|
|
|
|
val status = obj.optString("media_status") |
|
|
|
|
val path = obj.optString("media_path") |
|
|
|
|
val delivery = if (file) when { |
|
|
|
|
status == "delivered" -> "Доставлено" |
|
|
|
|
status == "expired" -> "Срок хранения истёк" |
|
|
|
|
outgoing -> "Ожидает доставки" |
|
|
|
|
path.isNotEmpty() -> "Получено" |
|
|
|
|
else -> "Загрузка…" |
|
|
|
|
} else if (outgoing) { |
|
|
|
|
if (obj.optBoolean("pending")) "Ожидает доставки" else "Доставлено" |
|
|
|
|
} else "" |
|
|
|
|
val author = if (outgoing) "Вы" else peerName.ifBlank { "0x%016x".format(obj.optLong("author", 0)) } |
|
|
|
|
list.add(Message( |
|
|
|
|
id = obj.optLong("seq", 0), |
|
|
|
|
@ -569,7 +582,11 @@ class ChatRepository {
|
|
|
|
|
text = obj.optString("data", ""), |
|
|
|
|
ts = obj.optLong("ts", 0), |
|
|
|
|
isOutgoing = outgoing, |
|
|
|
|
contentType = obj.optString("ct", "text/plain") |
|
|
|
|
contentType = if (file) "file" else "text/plain", |
|
|
|
|
filePath = path, |
|
|
|
|
fileSize = obj.optLong("media_size"), |
|
|
|
|
downloadState = if (!file) "" else if (path.isNotEmpty()) "downloaded" else if (status == "expired") "error" else "downloading", |
|
|
|
|
deliveryStatus = delivery |
|
|
|
|
)) |
|
|
|
|
} |
|
|
|
|
} catch (e: Exception) { Log.w("utun-gui", "getDmMessages error", e) } |
|
|
|
|
|