add support to leave a chat
add support to leave a chat add support to leave a chat fix add leave chat methods to model
This commit is contained in:
parent
0ee8f5c0fe
commit
dda6b3c76d
|
@ -89,5 +89,14 @@ QtObject:
|
||||||
let randomColorIndex = rand(channelColors.len - 1)
|
let randomColorIndex = rand(channelColors.len - 1)
|
||||||
result = self.chats.addChatItemToList(ChatItem(id: channel, name: channel, color: channelColors[randomColorIndex]))
|
result = self.chats.addChatItemToList(ChatItem(id: channel, name: channel, color: channelColors[randomColorIndex]))
|
||||||
|
|
||||||
|
proc leaveActiveChat*(self: ChatsView) {.slot.} =
|
||||||
|
self.model.leave(self.activeChannel)
|
||||||
|
let channelCount = self.chats.removeChatItemFromList(self.activeChannel)
|
||||||
|
if channelCount == 0:
|
||||||
|
self.setActiveChannel("")
|
||||||
|
else:
|
||||||
|
let nextChannel = self.chats.chats[self.chats.chats.len - 1]
|
||||||
|
self.setActiveChannel(nextChannel.name)
|
||||||
|
|
||||||
proc updateChat*(self: ChatsView, chat: ChatItem) =
|
proc updateChat*(self: ChatsView, chat: ChatItem) =
|
||||||
self.chats.updateChat(chat)
|
self.chats.updateChat(chat)
|
||||||
|
|
|
@ -76,6 +76,14 @@ QtObject:
|
||||||
|
|
||||||
result = self.chats.len - 1
|
result = self.chats.len - 1
|
||||||
|
|
||||||
|
proc removeChatItemFromList*(self: ChannelsList, channel: string): int =
|
||||||
|
let idx = self.chats.findById(channel)
|
||||||
|
self.beginRemoveRows(newQModelIndex(), idx, idx)
|
||||||
|
self.chats.delete(idx)
|
||||||
|
self.endRemoveRows()
|
||||||
|
|
||||||
|
result = self.chats.len
|
||||||
|
|
||||||
proc getChannel*(self: ChannelsList, index: int): ChatItem =
|
proc getChannel*(self: ChannelsList, index: int): ChatItem =
|
||||||
self.chats[index]
|
self.chats[index]
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ proc join*(self: ChatModel, chatId: string) =
|
||||||
status_chat.chatMessages(chatId)
|
status_chat.chatMessages(chatId)
|
||||||
|
|
||||||
let parsedResult = parseJson(filterResult)["result"]
|
let parsedResult = parseJson(filterResult)["result"]
|
||||||
|
echo parsedResult
|
||||||
var topics = newSeq[string](0)
|
var topics = newSeq[string](0)
|
||||||
for topicObj in parsedResult:
|
for topicObj in parsedResult:
|
||||||
if (($topicObj["chatId"]).strip(chars = {'"'}) == chatId):
|
if (($topicObj["chatId"]).strip(chars = {'"'}) == chatId):
|
||||||
|
@ -58,9 +59,8 @@ proc join*(self: ChatModel, chatId: string) =
|
||||||
else:
|
else:
|
||||||
status_chat.requestMessages(topics, generatedSymKey, peer, 20)
|
status_chat.requestMessages(topics, generatedSymKey, peer, 20)
|
||||||
|
|
||||||
|
proc leave*(self: ChatModel, chatId: string) =
|
||||||
proc sendMessage*(self: ChatModel, chatId: string, msg: string): string =
|
let oneToOne = isOneToOneChat(chatId)
|
||||||
var sentMessage = status_chat.sendChatMessage(chatId, msg)
|
discard status_chat.removeFilters(chatId = chatId, oneToOne = oneToOne)
|
||||||
var parsedMessage = parseJson(sentMessage)["result"]["chats"][0]["lastMessage"]
|
# TODO: other calls (if any)
|
||||||
self.events.emit("messageSent", MsgArgs(message: msg, chatId: chatId, payload: parsedMessage))
|
self.channels.excl(chatId)
|
||||||
sentMessage
|
|
||||||
|
|
|
@ -7,6 +7,22 @@ import chronicles
|
||||||
|
|
||||||
proc loadFilters*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true): string =
|
proc loadFilters*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true): string =
|
||||||
result = callPrivateRPC("loadFilters".prefix, %* [
|
result = callPrivateRPC("loadFilters".prefix, %* [
|
||||||
|
[{
|
||||||
|
"ChatID": chatId, # identifier of the chat
|
||||||
|
"FilterID": filterId, # whisper filter id generated
|
||||||
|
"SymKeyID": symKeyId, # symmetric key id used for symmetric filters
|
||||||
|
"OneToOne": oneToOne, # if asymmetric encryption is used for this chat
|
||||||
|
"Identity": identity, # public key of the other recipient for non-public filters.
|
||||||
|
# FIXME: passing empty string to the topic makes it error
|
||||||
|
# "Topic": topic, # whisper topic
|
||||||
|
"Discovery": discovery,
|
||||||
|
"Negotiated": negotiated,
|
||||||
|
"Listen": listen # whether we are actually listening for messages on this chat, or the filter is only created in order to be able to post on the topic
|
||||||
|
}]
|
||||||
|
])
|
||||||
|
|
||||||
|
proc removeFilters*(chatId: string, filterId: string = "", symKeyId: string = "", oneToOne: bool = false, identity: string = "", topic: string = "", discovery: bool = false, negotiated: bool = false, listen: bool = true): string =
|
||||||
|
result = callPrivateRPC("removeFilters".prefix, %* [
|
||||||
[{
|
[{
|
||||||
"ChatID": chatId, # identifier of the chat
|
"ChatID": chatId, # identifier of the chat
|
||||||
"FilterID": filterId, # whisper filter id generated
|
"FilterID": filterId, # whisper filter id generated
|
||||||
|
|
|
@ -109,8 +109,14 @@ StackLayout {
|
||||||
anchors.rightMargin: -15
|
anchors.rightMargin: -15
|
||||||
anchors.leftMargin: -15
|
anchors.leftMargin: -15
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: console.log("Options click. Will do something later...")
|
onClicked: contextMenu.open()
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||||
|
|
||||||
|
Menu {
|
||||||
|
id: contextMenu
|
||||||
|
MenuItem { text: "Leave Chat"; onTriggered: chatsModel.leaveActiveChat() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue