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, Unknown = 0,
OneToOne = 1, OneToOne = 1,
Public = 2, Public = 2,
PrivateGroupChat = 3 PrivateGroupChat = 3,
Profile = 4,
Timeline = 5
proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne proc isOneToOne*(self: ChatType): bool = self == ChatType.OneToOne

View File

@ -109,13 +109,17 @@ proc newChat*(id: string, chatType: ChatType): Chat =
result.name = id result.name = id
proc toChat*(jsonChat: JsonNode): Chat = 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( result = Chat(
id: jsonChat{"id"}.getStr, id: jsonChat{"id"}.getStr,
name: jsonChat{"name"}.getStr, name: jsonChat{"name"}.getStr,
identicon: "", identicon: "",
color: jsonChat{"color"}.getStr, color: jsonChat{"color"}.getStr,
isActive: jsonChat{"active"}.getBool, isActive: jsonChat{"active"}.getBool,
chatType: ChatType(jsonChat{"chatType"}.getInt), chatType: chatType,
timestamp: jsonChat{"timestamp"}.getBiggestInt, timestamp: jsonChat{"timestamp"}.getBiggestInt,
lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt, lastClockValue: jsonChat{"lastClockValue"}.getBiggestInt,
deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt, deletedAtClockValue: jsonChat{"deletedAtClockValue"}.getBiggestInt,