add api enpoint for creating rooms
This commit is contained in:
parent
0697c3b9d0
commit
d88c279c34
3 changed files with 33 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ import (
|
|||
"mxclientlib/mxutils"
|
||||
"unsafe"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
|
|
@ -359,6 +360,32 @@ func apiv0_joinedrooms(cid C.int) *C.char {
|
|||
return C.CString(s)
|
||||
}
|
||||
|
||||
//export apiv0_createroom
|
||||
func apiv0_createroom(cid C.int, data *C.char) *C.char {
|
||||
cli, err := getClient(int(cid))
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
|
||||
var req mautrix.ReqCreateRoom
|
||||
err = json.Unmarshal([]byte(C.GoString(data)), &req)
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
|
||||
resp, err := cli.CreateRoom(context.Background(), &req)
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
|
||||
out, err := json.Marshal(resp)
|
||||
if err != nil {
|
||||
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||
}
|
||||
s := string(out)
|
||||
return C.CString(s)
|
||||
}
|
||||
|
||||
//export apiv0_removeclient
|
||||
func apiv0_removeclient(cid C.int) C.int {
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ ffibuilder.cdef(
|
|||
extern char* apiv0_sendmessage(int cid, char* data);
|
||||
extern char* apiv0_leaveroom(int cid, char* roomid);
|
||||
extern char* apiv0_joinedrooms(int cid);
|
||||
extern char* apiv0_createroom(int cid, char* data);
|
||||
extern int apiv0_removeclient(int cid);
|
||||
extern char* apiv0_listclients();
|
||||
extern char* apiv0_getoptions(int cid);
|
||||
|
|
|
|||
|
|
@ -93,6 +93,11 @@ class _MXClient:
|
|||
r = lib.apiv0_joinedrooms(self.client_id)
|
||||
return checkApiError(r)
|
||||
|
||||
def _createroom(self, data_dict):
|
||||
data = json.dumps(data_dict).encode(encoding="utf-8")
|
||||
r = lib.apiv0_createroom(self.client_id, data)
|
||||
return checkApiError(r)
|
||||
|
||||
def process_event(self, evt):
|
||||
if hasattr(self, "on_event") and callable(self.on_event):
|
||||
self.on_event(evt)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue