use chats() instead of callPrivateRPC()

This commit is contained in:
Richard Ramos 2021-10-08 08:37:42 -04:00
parent b60faf9644
commit b82f8b35e3
No known key found for this signature in database
GPG Key ID: 80D4B01265FDFE8F
1 changed files with 85 additions and 0 deletions

85
status_go/chat.nim Normal file
View File

@ -0,0 +1,85 @@
import segfaults
type
StatusGoChat* = object
active: cint
id: cstring
name: cstring
chatType*: cint
color: cstring
deletedAtClockValue: culonglong
description: cstring
emoji: cstring
identicon: cstring
lastClockValue: culonglong
muted: cint
timestamp: clonglong
unviewedMentionsCount: cint
unviewedMessagesCount: cint
StatusGoChatArray* = object
len*: cint
data*: ptr UncheckedArray[StatusGoChat]
ChatType* {.pure.}= enum
Unknown = 0,
OneToOne = 1,
Public = 2,
PrivateGroupChat = 3,
Profile = 4,
Timeline = 5
CommunityChat = 6
Chat* = object
active*: bool
id*: string
name*: string
chatType*: ChatType
color*: string
deletedAtClockValue*: uint64
description*: string
emoji*: string
identicon*: string
lastClockValue*: uint64
muted*: bool
timestamp*: int64
unviewedMentionsCount*: int
unviewedMessagesCount*: int
proc statusgo_chats(): StatusGoChatArray {.importc: "Chats".}
proc c_free*(p: pointer) {.importc: "free", header: "<stdlib.h>".}
proc newChat*(goChat: StatusGoChat): Chat =
result.active = goChat.active.bool
result.id = $goChat.id
result.name = $goChat.name
result.chatType = ChatType(goChat.chatType)
result.color = $goChat.color
result.deletedAtClockValue = goChat.deletedAtClockValue
result.description = $goChat.description
result.emoji = $goChat.emoji
result.identicon = $goChat.identicon
result.lastClockValue = goChat.lastClockValue
result.muted = goChat.muted.bool
result.timestamp = goChat.timestamp
result.unviewedMentionsCount = goChat.unviewedMentionsCount
result.unviewedMessagesCount = goChat.unviewedMessagesCount
c_free(goChat.id)
c_free(goChat.name)
c_free(goChat.color)
c_free(goChat.description)
c_free(goChat.emoji)
c_free(goChat.identicon)
proc chats*(): seq[Chat] =
let chatArr = statusgo_chats()
if chatArr.len == 0:
return
for i in 0 .. chatArr.len - 1:
result.add newChat(StatusGoChat(chatArr.data[i]))
c_free(chatArr.data)