types global,4 procs now work,add start proc arg

This commit is contained in:
array-in-a-matrix 2023-12-09 14:57:28 -05:00
parent c0d3c02ba0
commit 281c6e987e
2 changed files with 13 additions and 13 deletions

View file

@ -2,6 +2,6 @@ import src/MatrixAuth
export newMatrixAuth, passwordLogin, accessToken
import src/MatrixClient
export Event
export Client, Content, Unsigned, Event, Filter
export newMatrixClient, start, onRoomMessage
export sendReadReceipt, setTyping, replyText, replyHtmlText, replyNotice, replyHtmlNotice, sendNotice, sendHtmlNotice, sendText, sendHtmlText, redactEvent # {sendMessage, sendEvent, sendRawEvent, sendStateEvent} do not work yet
export sendReadReceipt, setTyping, replyText, replyHtmlText, replyNotice, replyHtmlNotice, sendNotice, sendHtmlNotice, sendText, sendHtmlText, sendMessage, sendEvent, sendRawEvent, sendStateEvent, redactEvent

View file

@ -6,35 +6,35 @@ type storage = ref object
type cryptoStore = ref object
type Client = ref object
type Client* = ref object
homeserverUrl*: cstring
accessToken*: cstring
cryptoStore*: ICryptoStorageProvider
type Content = ref object
type Content* = ref object
body*, msgtype*: cstring
type Unsigned = ref object
type Unsigned* = ref object
transaction_id*: cstring
type Event* = ref object
content*: Content
unsigned*: Unsigned
event_id*, sender*, `type`*, room_id*: string
event_id*, sender*, `type`*, room_id*: cstring
origin_server_ts*: int
type Filter* = ref object
proc newMatrixClient*(homeserver, token: cstring): Client {.importjs: "new MatrixClient(#, #)".}
proc newMatrixClient*(homeserver, token: cstring, storage: storage): Client {.importjs: "new MatrixClient(#, #, #)".}
proc newMatrixClient*(homeserver, token: cstring, storage: storage, cryptoStore: cryptoStore): Client {.importjs: "new MatrixClient(#, #, #, #)".}
proc start*(client: Client) {.importjs: "#.start()".} #? returns a promise
# TODO: proc start*(client: Client, filter) {.importjs: "#.start(#)".}
proc start*(client: Client, filter: Filter = nil) {.importjs: "#.start(#)".} #? returns a promise
proc onRoomMessage*(client: Client, callback: proc(roomId: cstring, event: Event)) {.importjs: "#.on('room.message', #)".}
# TODO: add more for each event name
#? below returns promises
#? several comment says 'content' is of type 'string' but is given the 'any' type
proc sendReadReceipt*(client: Client, roomId: cstring, eventId: cstring) {.importjs: "#.sendReadReceipt(#, #)".}
proc setTyping*(client: Client, roomId: cstring, typing: bool) {.importjs: "#.setTyping(#, #)".}
@ -58,12 +58,12 @@ proc sendText*(client: Client, roomId: cstring, text: cstring) {.importjs: "#.se
proc sendHtmlText*(client: Client, roomId: cstring, html: cstring) {.importjs: "#.sendHtmlText(#, #)".}
# proc sendMessage*(client: Client, roomId: cstring, content: any) {.importjs: "#.sendMessage(#, #)".}
proc sendMessage*(client: Client, roomId: cstring, content: Event) {.importjs: "#.sendMessage(#, #)".}
# proc sendEvent*(client: Client, roomId: cstring, eventType: cstring, content: any) {.importjs: "#.sendEvent(#, #, #)".}
proc sendEvent*(client: Client, roomId: cstring, eventType: cstring, content: Event) {.importjs: "#.sendEvent(#, #, #)".}
# proc sendRawEvent*(client: Client, roomId: cstring, eventType: cstring, content: any) {.importjs: "#.sendRawEvent(#, #, #)".}
proc sendRawEvent*(client: Client, roomId: cstring, eventType: cstring, content: Event) {.importjs: "#.sendRawEvent(#, #, #)".}
# proc sendStateEvent*(client: Client, roomId: cstring, `type`: cstring, content: any) {.importjs: "#.sendStateEvent(#, #, #, #)".}
proc sendStateEvent*(client: Client, roomId: cstring, `type`: cstring, content: Event) {.importjs: "#.sendStateEvent(#, #, #, #)".}
proc redactEvent*(client: Client, roomId: cstring, eventId: cstring, reason: cstring = nil) {.importjs: "#.redactEvent(#, #, #)".}