fix: stop crash by showing error message
fix #898 The segmentation fault occured because the RPC response returned json with an error message as oppossed to the usual data required to update the chat. Since the section of the code didn't handle this error message it caused the app to crash. I've handled this error to show an error alert box by emitting a event
This commit is contained in:
parent
b9d59f44cc
commit
ff5b972139
|
@ -66,6 +66,10 @@ proc handleChatEvents(self: ChatController) =
|
||||||
self.status.messages.trackMessage(msg.id, msg.channel)
|
self.status.messages.trackMessage(msg.id, msg.channel)
|
||||||
self.view.sendingMessage()
|
self.view.sendingMessage()
|
||||||
|
|
||||||
|
self.status.events.on("sendingMessageFailed") do(e:Args):
|
||||||
|
var msg = MessageArgs(e)
|
||||||
|
self.view.sendingMessageFailed()
|
||||||
|
|
||||||
self.status.events.on("messageSent") do(e:Args):
|
self.status.events.on("messageSent") do(e:Args):
|
||||||
var msg = MessageSentArgs(e)
|
var msg = MessageSentArgs(e)
|
||||||
self.view.markMessageAsSent(msg.chatId, msg.id)
|
self.view.markMessageAsSent(msg.chatId, msg.id)
|
||||||
|
|
|
@ -233,6 +233,8 @@ QtObject:
|
||||||
|
|
||||||
proc appReady*(self: ChatsView) {.signal.}
|
proc appReady*(self: ChatsView) {.signal.}
|
||||||
|
|
||||||
|
proc sendingMessageFailed*(self: ChatsView) {.signal.}
|
||||||
|
|
||||||
proc alias*(self: ChatsView, pubKey: string): string {.slot.} =
|
proc alias*(self: ChatsView, pubKey: string): string {.slot.} =
|
||||||
generateAlias(pubKey)
|
generateAlias(pubKey)
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,9 @@ proc setActiveChannel*(self: ChatModel, chatId: string) =
|
||||||
proc processMessageUpdateAfterSend(self: ChatModel, response: string): (seq[Chat], seq[Message]) =
|
proc processMessageUpdateAfterSend(self: ChatModel, response: string): (seq[Chat], seq[Message]) =
|
||||||
result = self.processChatUpdate(parseJson(response))
|
result = self.processChatUpdate(parseJson(response))
|
||||||
var (chats, messages) = result
|
var (chats, messages) = result
|
||||||
|
if chats.len == 0 or messages.len == 0:
|
||||||
|
self.events.emit("sendingMessageFailed", MessageArgs())
|
||||||
|
else:
|
||||||
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats, contacts: @[]))
|
self.events.emit("chatUpdate", ChatUpdateArgs(messages: messages, chats: chats, contacts: @[]))
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
self.events.emit("sendingMessage", MessageArgs(id: msg.id, channel: msg.chatId))
|
self.events.emit("sendingMessage", MessageArgs(id: msg.id, channel: msg.chatId))
|
||||||
|
|
|
@ -12,10 +12,10 @@ proc formatChatUpdate(response: JsonNode): (seq[Chat], seq[Message]) =
|
||||||
proc processChatUpdate(self: ChatModel, response: JsonNode): (seq[Chat], seq[Message]) =
|
proc processChatUpdate(self: ChatModel, response: JsonNode): (seq[Chat], seq[Message]) =
|
||||||
var chats: seq[Chat] = @[]
|
var chats: seq[Chat] = @[]
|
||||||
var messages: seq[Message] = @[]
|
var messages: seq[Message] = @[]
|
||||||
if response["result"]{"chats"} != nil:
|
if response{"result"}{"chats"} != nil:
|
||||||
for jsonMsg in response["result"]["messages"]:
|
for jsonMsg in response["result"]["messages"]:
|
||||||
messages.add(jsonMsg.toMessage)
|
messages.add(jsonMsg.toMessage)
|
||||||
if response["result"]{"chats"} != nil:
|
if response{"result"}{"chats"} != nil:
|
||||||
for jsonChat in response["result"]["chats"]:
|
for jsonChat in response["result"]["chats"]:
|
||||||
let chat = jsonChat.toChat
|
let chat = jsonChat.toChat
|
||||||
self.channels[chat.id] = chat
|
self.channels[chat.id] = chat
|
||||||
|
|
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.13
|
||||||
import QtQuick.Layouts 1.13
|
import QtQuick.Layouts 1.13
|
||||||
import QtQml.Models 2.13
|
import QtQml.Models 2.13
|
||||||
import QtGraphicalEffects 1.13
|
import QtGraphicalEffects 1.13
|
||||||
|
import QtQuick.Dialogs 1.3
|
||||||
import "../../../../shared"
|
import "../../../../shared"
|
||||||
import "../../../../imports"
|
import "../../../../imports"
|
||||||
import "../components"
|
import "../components"
|
||||||
|
@ -132,6 +133,10 @@ ScrollView {
|
||||||
chatLogView.scrollToBottom(true)
|
chatLogView.scrollToBottom(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onSendingMessageFailed: {
|
||||||
|
sendingMsgFailedPopup.open();
|
||||||
|
}
|
||||||
|
|
||||||
onNewMessagePushed: {
|
onNewMessagePushed: {
|
||||||
if (!chatLogView.scrollToBottom()) {
|
if (!chatLogView.scrollToBottom()) {
|
||||||
root.newMessages++
|
root.newMessages++
|
||||||
|
@ -172,6 +177,13 @@ ScrollView {
|
||||||
section.criteria: ViewSection.FullString
|
section.criteria: ViewSection.FullString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessageDialog {
|
||||||
|
id: sendingMsgFailedPopup
|
||||||
|
standardButtons: StandardButton.Ok
|
||||||
|
text: qsTr("Failed to send message.")
|
||||||
|
icon: StandardIcon.Critical
|
||||||
|
}
|
||||||
|
|
||||||
DelegateModel {
|
DelegateModel {
|
||||||
id: messageListDelegate
|
id: messageListDelegate
|
||||||
property var lessThan: [
|
property var lessThan: [
|
||||||
|
|
Loading…
Reference in New Issue