Keep PM drafts until the core confirms persistence
This commit is contained in:
1 parent
8cb80fd7be
commit
b4164ff1de
3 files changed
+14
-16
No files matched your search
@@ -209,8 +209,6 @@ fun cleanSocketName(raw: String): String =
|
||||
raw.removePrefix("as_").replace(Regex("_v[46]_(tcp|udp)$"), " $1")
|
||||
|
||||
class ChatRepository {
|
||||
private val myNodeId: Long = NativeLib.getMyNodeId()
|
||||
|
||||
fun getChannels(): List<Channel> {
|
||||
val list = mutableListOf<Channel>()
|
||||
try {
|
||||
@@ -536,7 +534,8 @@ class ChatRepository {
|
||||
fun dmStart(nodeId: Long, sourceChId: String, peerName: String) =
|
||||
NativeLib.dmStart(nodeId, sourceChId, peerName)
|
||||
|
||||
fun dmSend(convId: String, text: String, generation: Long) = NativeLib.dmSend(convId, text, generation)
|
||||
fun dmSend(convId: String, text: String, generation: Long, requestId: Long): Boolean =
|
||||
NativeLib.dmSend(convId, text, generation, requestId)
|
||||
|
||||
fun parseDmConversations(json: String): List<DmConversation> {
|
||||
val list = mutableListOf<DmConversation>()
|
||||
|
||||
+2
-2
@@ -67,7 +67,7 @@ fun ConversationComposer(target: ConversationTarget, viewModel: ChatViewModel,
|
||||
val sendFailed by viewModel.messageSendFailed.collectAsState()
|
||||
val submitting by viewModel.submittingChannels.collectAsState()
|
||||
val deletingDm by viewModel.dmDeleting.collectAsState()
|
||||
val pending = if (target is ConversationTarget.Channel) target.id in submitting else target.id in deletingDm
|
||||
val pending = target.nativeId in submitting || (target is ConversationTarget.Pm && target.id in deletingDm)
|
||||
if (sendFailed) AlertDialog(onDismissRequest = viewModel::dismissMessageSendError,
|
||||
text = { Text(stringResource(R.string.message_send_failed)) },
|
||||
confirmButton = { TextButton(onClick = viewModel::dismissMessageSendError) { Text(stringResource(R.string.close)) } })
|
||||
@@ -184,7 +184,7 @@ fun ConversationComposer(target: ConversationTarget, viewModel: ChatViewModel,
|
||||
if (sentText.isNotBlank()) {
|
||||
textSaved = if (target is ConversationTarget.Channel)
|
||||
viewModel.sendChannelText(target, sentText, capturedReply).await()
|
||||
else viewModel.sendDmText(target as ConversationTarget.Pm, sentText)
|
||||
else viewModel.sendDmText(target as ConversationTarget.Pm, sentText).await()
|
||||
if (textSaved && textRevision == revision) { text = TextFieldValue(); textRevision++ }
|
||||
}
|
||||
if (attachmentSaved && textSaved) viewModel.finishReply(capturedReply)
|
||||
|
||||
@@ -48,7 +48,7 @@ class ChatViewModel : ViewModel() {
|
||||
fun cancelEdit(edit: ChannelEdit) { if (_editing.value == edit) _editing.value = null }
|
||||
|
||||
fun saveEdit(edit: ChannelEdit, text: String): Deferred<Boolean> = viewModelScope.async {
|
||||
submitChannel(edit.channelId, null, reportError = false) {
|
||||
submitMessage(edit.channelId, null, reportError = false) {
|
||||
NativeLib.editMessage(edit.channelId, edit.message.messageId, edit.message.version, text, it)
|
||||
}.also { if (it) cancelEdit(edit) }
|
||||
}
|
||||
@@ -112,7 +112,7 @@ class ChatViewModel : ViewModel() {
|
||||
result.complete(success)
|
||||
}
|
||||
|
||||
private suspend fun submitChannel(channel: String, reply: ChannelReply?, reportError: Boolean = true,
|
||||
private suspend fun submitMessage(channel: String, reply: ChannelReply?, reportError: Boolean = true,
|
||||
queue: (Long) -> Boolean): Boolean {
|
||||
if (reply != null && reply.channelId != channel) {
|
||||
LogManager.addLog("ERROR", "Reply", "target mismatch ch=$channel reply=${reply.channelId}")
|
||||
@@ -143,7 +143,7 @@ class ChatViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun sendChannelText(target: ConversationTarget.Channel, text: String, reply: ChannelReply?): Deferred<Boolean> = viewModelScope.async {
|
||||
submitChannel(target.id, reply) { NativeLib.sendMessage(target.id, text, reply?.message?.messageId.orEmpty(), it) }
|
||||
submitMessage(target.id, reply) { NativeLib.sendMessage(target.id, text, reply?.message?.messageId.orEmpty(), it) }
|
||||
}
|
||||
|
||||
data class PmInviteState(val peer: Long, val name: String, val source: String, val groups: List<Channel>,
|
||||
@@ -1324,11 +1324,10 @@ class ChatViewModel : ViewModel() {
|
||||
return true
|
||||
}
|
||||
|
||||
fun sendDmText(target: ConversationTarget.Pm, text: String): Boolean {
|
||||
val r = repo ?: return false
|
||||
if (text.isBlank() || !dmTargetCurrent(target)) return false
|
||||
r.dmSend(target.id, text, target.generation)
|
||||
return true
|
||||
fun sendDmText(target: ConversationTarget.Pm, text: String): Deferred<Boolean> = viewModelScope.async {
|
||||
val r = repo ?: return@async false
|
||||
if (text.isBlank() || !dmTargetCurrent(target)) return@async false
|
||||
submitMessage(target.nativeId, null) { r.dmSend(target.id, text, target.generation, it) }
|
||||
}
|
||||
|
||||
fun deleteDmConversation(dm: DmConversation) {
|
||||
@@ -1634,7 +1633,7 @@ class ChatViewModel : ViewModel() {
|
||||
}
|
||||
return@async accepted
|
||||
}
|
||||
submitChannel(target.id, reply) { request ->
|
||||
submitMessage(target.id, reply) { request ->
|
||||
NativeLib.attachmentSend(target.id, filePath, reply?.message?.messageId.orEmpty(), request)
|
||||
}
|
||||
}
|
||||
@@ -1666,7 +1665,7 @@ class ChatViewModel : ViewModel() {
|
||||
} else NativeLib.videoSend(target.nativeId, filePath, meta.first, meta.second, meta.third,
|
||||
reply?.message?.messageId.orEmpty(), request, (target as? ConversationTarget.Pm)?.generation ?: 0).also { accepted = it }
|
||||
}
|
||||
saved = if (target is ConversationTarget.Channel) submitChannel(target.id, reply, queue = queue) else queue(0)
|
||||
saved = if (target is ConversationTarget.Channel) submitMessage(target.id, reply, queue = queue) else queue(0)
|
||||
if (!saved && job !in discardedPreparationJobs) _messageSendFailed.value = true
|
||||
if (saved && clearReply) finishReply(reply)
|
||||
} catch (e: kotlinx.coroutines.CancellationException) { throw e }
|
||||
@@ -1699,7 +1698,7 @@ class ChatViewModel : ViewModel() {
|
||||
} else NativeLib.photoSend(target.nativeId, filePath, meta.width, meta.height, meta.mime,
|
||||
reply?.message?.messageId.orEmpty(), request, (target as? ConversationTarget.Pm)?.generation ?: 0).also { accepted = it }
|
||||
}
|
||||
saved = if (target is ConversationTarget.Channel) submitChannel(target.id, reply, queue = queue) else queue(0)
|
||||
saved = if (target is ConversationTarget.Channel) submitMessage(target.id, reply, queue = queue) else queue(0)
|
||||
completed = true
|
||||
if (!saved) _messageSendFailed.value = true
|
||||
if (saved && clearReply) finishReply(reply)
|
||||
|
||||
Reference in new issue
Block a user