fix: code review + error handling

This commit is contained in:
Richard Ramos 2020-05-29 11:09:10 -04:00 committed by Iuri Matias
parent 02c9f1cc6a
commit a244e236e8
5 changed files with 7 additions and 3 deletions

View File

@ -75,7 +75,7 @@ proc load*(self: ChatModel) =
proc leave*(self: ChatModel, chatId: string) =
status_chat.removeFilters(chatId, self.filters[chatId])
status_chat.inactivateChat(chatId)
status_chat.deactivateChat(chatId)
# TODO: REMOVE MAILSERVER TOPIC
# TODO: REMOVE HISTORY

View File

@ -18,6 +18,7 @@ proc newChatItem*(id: string, chatType: ChatType, lastMessage: string = "", time
of ChatType.Public: id
of ChatType.OneToOne: generateAlias(id)
of ChatType.PrivateGroupChat: "TODO: Private Group Name"
of ChatType.Unknown: "Unknown: " & id
result.chatType = chatType
result.lastMessage = lastMessage
result.timestamp = timestamp
@ -42,6 +43,7 @@ proc chatName(chat: Chat): string =
of ChatType.OneToOne: result = chat.lastMessage.alias
of ChatType.Public: result = chat.name
of ChatType.PrivateGroupChat: result = "TODO: determine private group name"
of ChatType.Unknown: result = "Unknown"
proc toChatItem*(chat: Chat): ChatItem =
result = ChatItem(

View File

@ -29,8 +29,9 @@ proc toChat*(jsonChat: JsonNode): Chat =
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,
unviewedMessagesCount: jsonChat{"unviewedMessagesCount"}.getInt,
lastMessage: jsonChat{"lastMessage"}.toMessage
)
if jsonChat["lastMessage"].kind != JNull:
result.lastMessage = jsonChat{"lastMessage"}.toMessage
proc toMessage*(jsonMsg: JsonNode): Message =
result = Message(

View File

@ -48,6 +48,7 @@ method onSignal*(self: SignalSubscriber, data: Signal) {.base.} =
error "onSignal must be overriden in controller. Signal is unhandled"
type ChatType* = enum
Unknown = 0,
OneToOne = 1,
Public = 2,
PrivateGroupChat = 3

View File

@ -47,7 +47,7 @@ proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true) =
}
])
proc inactivateChat*(chatId: string) =
proc deactivateChat*(chatId: string) =
discard callPrivateRPC("saveChat".prefix, %* [
{
"lastClockValue": 0,