Add "Assign Admin" button to the rooms (#156)

* wip on make admin button

* Finish assign admin button

* fixes from pr

* update readme; remove unnecessary console.log; add assign admin to room directory and room view; rename user_id label; set own MXID by default; fix room name display when there is no name
This commit is contained in:
Borislav Pantaleev
2024-11-21 07:11:48 +02:00
committed by GitHub
parent dae6872fe8
commit cb1314ab1d
13 changed files with 204 additions and 31 deletions

View File

@@ -52,7 +52,7 @@ interface Action {
body?: Record<string, any>;
}
interface Room {
export interface Room {
room_id: string;
name?: string;
canonical_alias?: string;
@@ -273,6 +273,7 @@ export interface SynapseDataProvider extends DataProvider {
getRateLimits: (id: Identifier) => Promise<RateLimitsModel>;
setRateLimits: (id: Identifier, rateLimits: RateLimitsModel) => Promise<void>;
checkUsernameAvailability: (username: string) => Promise<UsernameAvailabilityResult>;
makeRoomAdmin: (room_id: string, user_id: string) => Promise<{ success: boolean; error?: string; errcode?: string }>;
}
const resourceMap = {
@@ -866,6 +867,20 @@ const baseDataProvider: SynapseDataProvider = {
}
throw error;
}
},
makeRoomAdmin: async (room_id: string, user_id: string) => {
const base_url = storage.getItem("base_url");
const endpoint_url = `${base_url}/_synapse/admin/v1/rooms/${encodeURIComponent(room_id)}/make_room_admin`;
try {
const { json } = await jsonClient(endpoint_url, { method: "POST", body: JSON.stringify({ user_id }) });
return { success: true };
} catch (error) {
if (error instanceof HttpError) {
return { success: false, error: error.body.error, errcode: error.body.errcode };
}
throw error;
}
}
};