fix: code review + error handling
This commit is contained in:
parent
02c9f1cc6a
commit
a244e236e8
|
@ -75,7 +75,7 @@ proc load*(self: ChatModel) =
|
||||||
|
|
||||||
proc leave*(self: ChatModel, chatId: string) =
|
proc leave*(self: ChatModel, chatId: string) =
|
||||||
status_chat.removeFilters(chatId, self.filters[chatId])
|
status_chat.removeFilters(chatId, self.filters[chatId])
|
||||||
status_chat.inactivateChat(chatId)
|
status_chat.deactivateChat(chatId)
|
||||||
# TODO: REMOVE MAILSERVER TOPIC
|
# TODO: REMOVE MAILSERVER TOPIC
|
||||||
# TODO: REMOVE HISTORY
|
# TODO: REMOVE HISTORY
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ proc newChatItem*(id: string, chatType: ChatType, lastMessage: string = "", time
|
||||||
of ChatType.Public: id
|
of ChatType.Public: id
|
||||||
of ChatType.OneToOne: generateAlias(id)
|
of ChatType.OneToOne: generateAlias(id)
|
||||||
of ChatType.PrivateGroupChat: "TODO: Private Group Name"
|
of ChatType.PrivateGroupChat: "TODO: Private Group Name"
|
||||||
|
of ChatType.Unknown: "Unknown: " & id
|
||||||
result.chatType = chatType
|
result.chatType = chatType
|
||||||
result.lastMessage = lastMessage
|
result.lastMessage = lastMessage
|
||||||
result.timestamp = timestamp
|
result.timestamp = timestamp
|
||||||
|
@ -42,6 +43,7 @@ proc chatName(chat: Chat): string =
|
||||||
of ChatType.OneToOne: result = chat.lastMessage.alias
|
of ChatType.OneToOne: result = chat.lastMessage.alias
|
||||||
of ChatType.Public: result = chat.name
|
of ChatType.Public: result = chat.name
|
||||||
of ChatType.PrivateGroupChat: result = "TODO: determine private group name"
|
of ChatType.PrivateGroupChat: result = "TODO: determine private group name"
|
||||||
|
of ChatType.Unknown: result = "Unknown"
|
||||||
|
|
||||||
proc toChatItem*(chat: Chat): ChatItem =
|
proc toChatItem*(chat: Chat): ChatItem =
|
||||||
result = ChatItem(
|
result = ChatItem(
|
||||||
|
|
|
@ -29,8 +29,9 @@ proc toChat*(jsonChat: JsonNode): Chat =
|
||||||
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
|
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
|
||||||
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,
|
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,
|
||||||
unviewedMessagesCount: jsonChat{"unviewedMessagesCount"}.getInt,
|
unviewedMessagesCount: jsonChat{"unviewedMessagesCount"}.getInt,
|
||||||
lastMessage: jsonChat{"lastMessage"}.toMessage
|
|
||||||
)
|
)
|
||||||
|
if jsonChat["lastMessage"].kind != JNull:
|
||||||
|
result.lastMessage = jsonChat{"lastMessage"}.toMessage
|
||||||
|
|
||||||
proc toMessage*(jsonMsg: JsonNode): Message =
|
proc toMessage*(jsonMsg: JsonNode): Message =
|
||||||
result = Message(
|
result = Message(
|
||||||
|
|
|
@ -48,6 +48,7 @@ method onSignal*(self: SignalSubscriber, data: Signal) {.base.} =
|
||||||
error "onSignal must be overriden in controller. Signal is unhandled"
|
error "onSignal must be overriden in controller. Signal is unhandled"
|
||||||
|
|
||||||
type ChatType* = enum
|
type ChatType* = enum
|
||||||
|
Unknown = 0,
|
||||||
OneToOne = 1,
|
OneToOne = 1,
|
||||||
Public = 2,
|
Public = 2,
|
||||||
PrivateGroupChat = 3
|
PrivateGroupChat = 3
|
||||||
|
|
|
@ -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, %* [
|
discard callPrivateRPC("saveChat".prefix, %* [
|
||||||
{
|
{
|
||||||
"lastClockValue": 0,
|
"lastClockValue": 0,
|
||||||
|
|
Loading…
Reference in New Issue