parent
39c494f9d5
commit
286bb14fb2
|
@ -69,8 +69,7 @@ proc init*(self: ChatController) =
|
||||||
|
|
||||||
proc handleMessage(self: ChatController, data: MessageSignal) =
|
proc handleMessage(self: ChatController, data: MessageSignal) =
|
||||||
for chat in data.chats:
|
for chat in data.chats:
|
||||||
var c = chat
|
self.view.updateChat(chat)
|
||||||
self.view.updateChat(c)
|
|
||||||
self.view.pushMessages(data.messages)
|
self.view.pushMessages(data.messages)
|
||||||
|
|
||||||
proc handleDiscoverySummary(self: ChatController, data: DiscoverySummarySignal) =
|
proc handleDiscoverySummary(self: ChatController, data: DiscoverySummarySignal) =
|
||||||
|
|
|
@ -58,7 +58,7 @@ QtObject:
|
||||||
self.activeChannelChanged()
|
self.activeChannelChanged()
|
||||||
|
|
||||||
proc getActiveChannelIdx(self: ChatsView): QVariant {.slot.} =
|
proc getActiveChannelIdx(self: ChatsView): QVariant {.slot.} =
|
||||||
newQVariant(self.chats.chats.findById(self.activeChannel.id))
|
newQVariant(self.chats.chats.findIndexById(self.activeChannel.id))
|
||||||
|
|
||||||
QtProperty[QVariant] activeChannelIndex:
|
QtProperty[QVariant] activeChannelIndex:
|
||||||
read = getActiveChannelIdx
|
read = getActiveChannelIdx
|
||||||
|
@ -67,7 +67,7 @@ QtObject:
|
||||||
|
|
||||||
proc setActiveChannel*(self: ChatsView, channel: string) =
|
proc setActiveChannel*(self: ChatsView, channel: string) =
|
||||||
if(channel == ""): return
|
if(channel == ""): return
|
||||||
self.activeChannel.setChatItem(self.chats.getChannel(self.chats.chats.findById(channel)))
|
self.activeChannel.setChatItem(self.chats.getChannel(self.chats.chats.findIndexById(channel)))
|
||||||
self.activeChannelChanged()
|
self.activeChannelChanged()
|
||||||
|
|
||||||
proc getActiveChannel*(self: ChatsView): QVariant {.slot.} =
|
proc getActiveChannel*(self: ChatsView): QVariant {.slot.} =
|
||||||
|
@ -103,7 +103,7 @@ QtObject:
|
||||||
read = getMessageList
|
read = getMessageList
|
||||||
notify = activeChannelChanged
|
notify = activeChannelChanged
|
||||||
|
|
||||||
proc pushChatItem*(self: ChatsView, chatItem: var Chat) =
|
proc pushChatItem*(self: ChatsView, chatItem: Chat) =
|
||||||
discard self.chats.addChatItemToList(chatItem)
|
discard self.chats.addChatItemToList(chatItem)
|
||||||
self.messagePushed()
|
self.messagePushed()
|
||||||
|
|
||||||
|
@ -123,5 +123,5 @@ QtObject:
|
||||||
proc leaveActiveChat*(self: ChatsView) {.slot.} =
|
proc leaveActiveChat*(self: ChatsView) {.slot.} =
|
||||||
self.status.chat.leave(self.activeChannel.id)
|
self.status.chat.leave(self.activeChannel.id)
|
||||||
|
|
||||||
proc updateChat*(self: ChatsView, chat: var Chat) =
|
proc updateChat*(self: ChatsView, chat: Chat) =
|
||||||
self.chats.updateChat(chat)
|
self.chats.updateChat(chat)
|
||||||
|
|
|
@ -56,14 +56,14 @@ QtObject:
|
||||||
ChannelsRoles.Color.int: "color"
|
ChannelsRoles.Color.int: "color"
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc addChatItemToList*(self: ChannelsList, channel: var Chat): int =
|
proc addChatItemToList*(self: ChannelsList, channel: Chat): int =
|
||||||
self.beginInsertRows(newQModelIndex(), 0, 0)
|
self.beginInsertRows(newQModelIndex(), 0, 0)
|
||||||
self.chats.insert(channel, 0)
|
self.chats.insert(channel, 0)
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
result = 0
|
result = 0
|
||||||
|
|
||||||
proc removeChatItemFromList*(self: ChannelsList, channel: string): int =
|
proc removeChatItemFromList*(self: ChannelsList, channel: string): int =
|
||||||
let idx = self.chats.findById(channel)
|
let idx = self.chats.findIndexById(channel)
|
||||||
self.beginRemoveRows(newQModelIndex(), idx, idx)
|
self.beginRemoveRows(newQModelIndex(), idx, idx)
|
||||||
self.chats.delete(idx)
|
self.chats.delete(idx)
|
||||||
self.endRemoveRows()
|
self.endRemoveRows()
|
||||||
|
@ -72,8 +72,8 @@ QtObject:
|
||||||
|
|
||||||
proc getChannel*(self: ChannelsList, index: int): Chat = self.chats[index]
|
proc getChannel*(self: ChannelsList, index: int): Chat = self.chats[index]
|
||||||
|
|
||||||
proc upsertChannel(self: ChannelsList, channel: var Chat): int =
|
proc upsertChannel(self: ChannelsList, channel: Chat): int =
|
||||||
let idx = self.chats.findById(channel.id)
|
let idx = self.chats.findIndexById(channel.id)
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
result = self.addChatItemToList(channel)
|
result = self.addChatItemToList(channel)
|
||||||
else:
|
else:
|
||||||
|
@ -83,9 +83,8 @@ QtObject:
|
||||||
for chat in self.chats:
|
for chat in self.chats:
|
||||||
if chat.name == name:
|
if chat.name == name:
|
||||||
return chat.color
|
return chat.color
|
||||||
return "#fa6565" # TODO determine if it is possible to have a chat without color
|
|
||||||
|
|
||||||
proc updateChat*(self: ChannelsList, channel: var Chat) =
|
proc updateChat*(self: ChannelsList, channel: Chat) =
|
||||||
let idx = self.upsertChannel(channel)
|
let idx = self.upsertChannel(channel)
|
||||||
let topLeft = self.createIndex(0, 0, nil)
|
let topLeft = self.createIndex(0, 0, nil)
|
||||||
let bottomRight = self.createIndex(self.chats.len, 0, nil)
|
let bottomRight = self.createIndex(self.chats.len, 0, nil)
|
||||||
|
@ -98,7 +97,7 @@ QtObject:
|
||||||
self.dataChanged(topLeft, bottomRight, @[ChannelsRoles.Name.int, ChannelsRoles.LastMessage.int, ChannelsRoles.Timestamp.int, ChannelsRoles.UnreadMessages.int, ChannelsRoles.Identicon.int, ChannelsRoles.ChatType.int, ChannelsRoles.Color.int])
|
self.dataChanged(topLeft, bottomRight, @[ChannelsRoles.Name.int, ChannelsRoles.LastMessage.int, ChannelsRoles.Timestamp.int, ChannelsRoles.UnreadMessages.int, ChannelsRoles.Identicon.int, ChannelsRoles.ChatType.int, ChannelsRoles.Color.int])
|
||||||
|
|
||||||
proc clearUnreadMessagesCount*(self: ChannelsList, channel: var Chat) =
|
proc clearUnreadMessagesCount*(self: ChannelsList, channel: var Chat) =
|
||||||
let idx = self.chats.findById(channel.id)
|
let idx = self.chats.findIndexById(channel.id)
|
||||||
if idx == -1: return
|
if idx == -1: return
|
||||||
|
|
||||||
let topLeft = self.createIndex(0, 0, nil)
|
let topLeft = self.createIndex(0, 0, nil)
|
||||||
|
|
|
@ -93,9 +93,7 @@ type WhisperFilterSignal* = ref object of Signal
|
||||||
type DiscoverySummarySignal* = ref object of Signal
|
type DiscoverySummarySignal* = ref object of Signal
|
||||||
enodes*: seq[string]
|
enodes*: seq[string]
|
||||||
|
|
||||||
|
proc findIndexById*(self: seq[Chat], id: string): int =
|
||||||
|
|
||||||
proc findById*(self: seq[Chat], id: string): int =
|
|
||||||
result = -1
|
result = -1
|
||||||
var idx = -1
|
var idx = -1
|
||||||
for item in self:
|
for item in self:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import eventemitter, sets, json
|
import eventemitter, json
|
||||||
import sequtils
|
import sequtils
|
||||||
import libstatus/chat as status_chat
|
import libstatus/chat as status_chat
|
||||||
import chronicles
|
import chronicles
|
||||||
|
|
|
@ -32,7 +32,7 @@ proc removeFilters*(chatId: string, filterId: string) =
|
||||||
}]
|
}]
|
||||||
])
|
])
|
||||||
|
|
||||||
proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true, color: string = "#51d0f0") =
|
proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true, color: string) =
|
||||||
discard callPrivateRPC("saveChat".prefix, %* [
|
discard callPrivateRPC("saveChat".prefix, %* [
|
||||||
{
|
{
|
||||||
"lastClockValue": 0, # TODO:
|
"lastClockValue": 0, # TODO:
|
||||||
|
|
Loading…
Reference in New Issue