add api call for 'list joined rooms'
This commit is contained in:
parent
4ad25be512
commit
36a58a36d7
3 changed files with 34 additions and 0 deletions
|
|
@ -300,6 +300,35 @@ func apiv0_leaveroom(cid C.int, roomid *C.char) *C.char {
|
||||||
return C.CString("SUCCESS.")
|
return C.CString("SUCCESS.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export apiv0_joinedrooms
|
||||||
|
func apiv0_joinedrooms(cid C.int) *C.char {
|
||||||
|
cli, err := getClient(int(cid))
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
resp, err := cli.JoinedRooms(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
type roomListItem struct {
|
||||||
|
RoomId id.RoomID `json:"roomid"`
|
||||||
|
IsDirect bool `json:"is_direct"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var roomList []roomListItem
|
||||||
|
|
||||||
|
for _, room := range resp.JoinedRooms {
|
||||||
|
roomList = append(roomList, roomListItem{RoomId: room, IsDirect: cli.IsDirectRoom(room)})
|
||||||
|
}
|
||||||
|
out, err := json.Marshal(roomList)
|
||||||
|
if err != nil {
|
||||||
|
return C.CString(fmt.Sprintf("ERR: %v", err))
|
||||||
|
}
|
||||||
|
s := string(out)
|
||||||
|
return C.CString(s)
|
||||||
|
}
|
||||||
|
|
||||||
//export apiv0_removeclient
|
//export apiv0_removeclient
|
||||||
func apiv0_removeclient(cid C.int) C.int {
|
func apiv0_removeclient(cid C.int) C.int {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ ffibuilder.cdef(
|
||||||
extern char* apiv0_stopclient(int cid);
|
extern char* apiv0_stopclient(int cid);
|
||||||
extern char* apiv0_sendmessage(int cid, char* data);
|
extern char* apiv0_sendmessage(int cid, char* data);
|
||||||
extern char* apiv0_leaveroom(int cid, char* roomid);
|
extern char* apiv0_leaveroom(int cid, char* roomid);
|
||||||
|
extern char* apiv0_joinedrooms(int cid);
|
||||||
extern int apiv0_removeclient(int cid);
|
extern int apiv0_removeclient(int cid);
|
||||||
extern char* apiv0_listclients();
|
extern char* apiv0_listclients();
|
||||||
extern char* apiv0_getoptions(int cid);
|
extern char* apiv0_getoptions(int cid);
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,10 @@ class _MXClient:
|
||||||
r = lib.apiv0_leaveroom(self.client_id, roomid.encode(encoding="utf-8"))
|
r = lib.apiv0_leaveroom(self.client_id, roomid.encode(encoding="utf-8"))
|
||||||
checkApiError(r)
|
checkApiError(r)
|
||||||
|
|
||||||
|
def joinedrooms(self):
|
||||||
|
r = lib.apiv0_joinedrooms(self.client_id)
|
||||||
|
return checkApiError(r)
|
||||||
|
|
||||||
def process_event(self, evt):
|
def process_event(self, evt):
|
||||||
if hasattr(self, "on_event") and callable(self.on_event):
|
if hasattr(self, "on_event") and callable(self.on_event):
|
||||||
self.on_event(evt)
|
self.on_event(evt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue