add api call for 'list joined rooms'

This commit is contained in:
saces 2026-02-13 23:38:44 +01:00
parent 4ad25be512
commit 36a58a36d7
3 changed files with 34 additions and 0 deletions

View file

@ -300,6 +300,35 @@ func apiv0_leaveroom(cid C.int, roomid *C.char) *C.char {
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
func apiv0_removeclient(cid C.int) C.int {
return 0

View file

@ -46,6 +46,7 @@ ffibuilder.cdef(
extern char* apiv0_stopclient(int cid);
extern char* apiv0_sendmessage(int cid, char* data);
extern char* apiv0_leaveroom(int cid, char* roomid);
extern char* apiv0_joinedrooms(int cid);
extern int apiv0_removeclient(int cid);
extern char* apiv0_listclients();
extern char* apiv0_getoptions(int cid);

View file

@ -81,6 +81,10 @@ class _MXClient:
r = lib.apiv0_leaveroom(self.client_id, roomid.encode(encoding="utf-8"))
checkApiError(r)
def joinedrooms(self):
r = lib.apiv0_joinedrooms(self.client_id)
return checkApiError(r)
def process_event(self, evt):
if hasattr(self, "on_event") and callable(self.on_event):
self.on_event(evt)