feat: make saveChat API more flexible by taking a ChatType

Previously, this API would take a flag `oneToOne` and would use it to determine
whether the chat type is going to be `1` or `2`. However, there are many more chat
types, so it's important this API supports all of them.

Since we already have an enum in place, I'm changing this function to take it instead.

In addition, it also gets a `profile` parameter which is needed to implement
the status timeline functionality.
This commit is contained in:
Pascal Precht 2020-12-17 10:56:58 +01:00 committed by Iuri Matias
parent d91d41cffa
commit 810ce12a56
2 changed files with 4 additions and 3 deletions

View File

@ -94,7 +94,7 @@ proc join*(self: ChatModel, chatId: string, chatType: ChatType, ensName: string
var chat = newChat(chatId, ChatType(chatType))
self.channels[chat.id] = chat
status_chat.saveChat(chatId, chatType.isOneToOne, true, chat.color, ensName)
status_chat.saveChat(chatId, chatType, true, chat.color, ensName)
if ensName != "":
chat.name = ensName
chat.ensName = ensName

View File

@ -18,7 +18,7 @@ proc removeFilters*(chatId: string, filterId: string) =
[{ "ChatID": chatId, "FilterID": filterId }]
])
proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true, color: string, ensName: string = "") =
proc saveChat*(chatId: string, chatType: ChatType, active: bool = true, color: string, ensName: string = "", profile: string = "") =
# TODO: ideally status-go/stimbus should handle some of these fields instead of having the client
# send them: lastMessage, unviewedMEssagesCount, timestamp, lastClockValue, name?
discard callPrivateRPC("saveChat".prefix, %* [
@ -28,9 +28,10 @@ proc saveChat*(chatId: string, oneToOne: bool = false, active: bool = true, colo
"name": (if ensName != "": ensName else: chatId),
"lastMessage": nil, # TODO:
"active": active,
"profile": profile,
"id": chatId,
"unviewedMessagesCount": 0, # TODO:
"chatType": if oneToOne: 1 else: 2, # TODO: use constants
"chatType": chatType.int,
"timestamp": 1588940692659 # TODO:
}
])