Fix: code review

Fixes #257
This commit is contained in:
Richard Ramos 2020-06-10 08:31:51 -04:00 committed by Iuri Matias
parent 39c494f9d5
commit 286bb14fb2
6 changed files with 14 additions and 18 deletions

View File

@ -69,8 +69,7 @@ proc init*(self: ChatController) =
proc handleMessage(self: ChatController, data: MessageSignal) =
for chat in data.chats:
var c = chat
self.view.updateChat(c)
self.view.updateChat(chat)
self.view.pushMessages(data.messages)
proc handleDiscoverySummary(self: ChatController, data: DiscoverySummarySignal) =

View File

@ -58,7 +58,7 @@ QtObject:
self.activeChannelChanged()
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:
read = getActiveChannelIdx
@ -67,7 +67,7 @@ QtObject:
proc setActiveChannel*(self: ChatsView, channel: string) =
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()
proc getActiveChannel*(self: ChatsView): QVariant {.slot.} =
@ -103,7 +103,7 @@ QtObject:
read = getMessageList
notify = activeChannelChanged
proc pushChatItem*(self: ChatsView, chatItem: var Chat) =
proc pushChatItem*(self: ChatsView, chatItem: Chat) =
discard self.chats.addChatItemToList(chatItem)
self.messagePushed()
@ -123,5 +123,5 @@ QtObject:
proc leaveActiveChat*(self: ChatsView) {.slot.} =
self.status.chat.leave(self.activeChannel.id)
proc updateChat*(self: ChatsView, chat: var Chat) =
proc updateChat*(self: ChatsView, chat: Chat) =
self.chats.updateChat(chat)

View File

@ -56,14 +56,14 @@ QtObject:
ChannelsRoles.Color.int: "color"
}.toTable
proc addChatItemToList*(self: ChannelsList, channel: var Chat): int =
proc addChatItemToList*(self: ChannelsList, channel: Chat): int =
self.beginInsertRows(newQModelIndex(), 0, 0)
self.chats.insert(channel, 0)
self.endInsertRows()
result = 0
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.chats.delete(idx)
self.endRemoveRows()
@ -72,8 +72,8 @@ QtObject:
proc getChannel*(self: ChannelsList, index: int): Chat = self.chats[index]
proc upsertChannel(self: ChannelsList, channel: var Chat): int =
let idx = self.chats.findById(channel.id)
proc upsertChannel(self: ChannelsList, channel: Chat): int =
let idx = self.chats.findIndexById(channel.id)
if idx == -1:
result = self.addChatItemToList(channel)
else:
@ -83,9 +83,8 @@ QtObject:
for chat in self.chats:
if chat.name == name:
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 topLeft = self.createIndex(0, 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])
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
let topLeft = self.createIndex(0, 0, nil)

View File

@ -93,9 +93,7 @@ type WhisperFilterSignal* = ref object of Signal
type DiscoverySummarySignal* = ref object of Signal
enodes*: seq[string]
proc findById*(self: seq[Chat], id: string): int =
proc findIndexById*(self: seq[Chat], id: string): int =
result = -1
var idx = -1
for item in self:

View File

@ -1,4 +1,4 @@
import eventemitter, sets, json
import eventemitter, json
import sequtils
import libstatus/chat as status_chat
import chronicles

View File

@ -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, %* [
{
"lastClockValue": 0, # TODO: