fix: introduce chat types for Timeline and Profile

When dealing with Timeline and Profile chat data, the `HEAD~1` would break
because we're trying to access `ChatType(4)` inside our `toChat` API.

To fix this issue, we have to make `ChatType` aware of `4` and `5` which are
`Profile` and `Timeline` respectively.
This commit is contained in:
Pascal Precht 2020-12-18 14:48:45 +01:00 committed by Iuri Matias
parent 3258ac8f9c
commit 4354ee15ed
2 changed files with 8 additions and 2 deletions

View File

@ -5,7 +5,9 @@ type ChatType* {.pure.}= enum
Unknown = 0,
OneToOne = 1,
Public = 2,
PrivateGroupChat = 3
PrivateGroupChat = 3,
Profile = 4,
Timeline = 5
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne

View File

@ -109,13 +109,17 @@ proc newChat*(id: string, chatType: ChatType): Chat =
result.name = id
proc toChat*(jsonChat: JsonNode): Chat =
let chatTypeInt = jsonChat{"chatType"}.getInt
let chatType: ChatType = if chatTypeInt >= ord(low(ChatType)) or chatTypeInt <= ord(high(ChatType)): ChatType(chatTypeInt) else: ChatType.Unknown
result = Chat(
id: jsonChat{"id"}.getStr,
name: jsonChat{"name"}.getStr,
identicon: "",
color: jsonChat{"color"}.getStr,
isActive: jsonChat{"active"}.getBool,
chatType: ChatType(jsonChat{"chatType"}.getInt),
chatType: chatType,
timestamp: jsonChat{"timestamp"}.getBiggestInt,
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,