wrapped various text-sending related methods

This commit is contained in:
array-in-a-matrix 2023-12-09 00:15:01 -05:00
parent 4cd2790279
commit c0d3c02ba0
2 changed files with 37 additions and 5 deletions

View file

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

View file

@ -23,7 +23,6 @@ type Event* = ref object
event_id*, sender*, `type`*, room_id*: string
origin_server_ts*: int
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(#, #, #, #)".}
@ -34,6 +33,37 @@ proc start*(client: Client) {.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
proc replyNotice*(client: Client, roomId: cstring, event: Event, text: cstring) {.importjs: "#.replyNotice(#, #, #)".} #? returns a promise
proc replyNotice*(client: Client, roomId: cstring, event: Event, text: cstring, html: cstring) {.importjs: "#.replyNotice(#, #, #, #)".} #? returns a promise
# TODO: add more reply js methods/nim procs
#? 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(#, #)".}
proc setTyping*(client: Client, roomId: cstring, typing: bool, timeout: float) {.importjs: "#.setTyping(#, #, #)".}
proc replyText*(client: Client, roomId: cstring, event: Event, text: cstring) {.importjs: "#.replyText(#, #, #)".}
proc replyText*(client: Client, roomId: cstring, event: Event, text: cstring, html: cstring) {.importjs: "#.replyText(#, #, #, #)".}
proc replyHtmlText*(client: Client, roomId: cstring, event: Event, html: cstring) {.importjs: "#.replyHtmlText(#, #, #)".}
proc replyNotice*(client: Client, roomId: cstring, event: Event, text: cstring) {.importjs: "#.replyNotice(#, #, #)".}
proc replyNotice*(client: Client, roomId: cstring, event: Event, text: cstring, html: cstring) {.importjs: "#.replyNotice(#, #, #, #)".}
proc replyHtmlNotice*(client: Client, roomId: cstring, event: Event, html: cstring) {.importjs: "#.replyHtmlNotice(#, #, #)".}
proc sendNotice*(client: Client, roomId: cstring, text: cstring) {.importjs: "#.sendNotice(#, #)".}
proc sendHtmlNotice*(client: Client, roomId: cstring, html: cstring) {.importjs: "#.sendHtmlNotice(#, #)".}
proc sendText*(client: Client, roomId: cstring, text: cstring) {.importjs: "#.sendText(#, #)".}
proc sendHtmlText*(client: Client, roomId: cstring, html: cstring) {.importjs: "#.sendHtmlText(#, #)".}
# proc sendMessage*(client: Client, roomId: cstring, content: any) {.importjs: "#.sendMessage(#, #)".}
# proc sendEvent*(client: Client, roomId: cstring, eventType: cstring, content: any) {.importjs: "#.sendEvent(#, #, #)".}
# proc sendRawEvent*(client: Client, roomId: cstring, eventType: cstring, content: any) {.importjs: "#.sendRawEvent(#, #, #)".}
# proc sendStateEvent*(client: Client, roomId: cstring, `type`: cstring, content: any) {.importjs: "#.sendStateEvent(#, #, #, #)".}
proc redactEvent*(client: Client, roomId: cstring, eventId: cstring, reason: cstring = nil) {.importjs: "#.redactEvent(#, #, #)".}