import { MatrixClient } from "./MatrixClient" ; category export interface SynapseUser { /***
     * The display name of the user, if set.
     */ displayname ? : string ; /**
     * A set of 3PIDs for the user.
     */ threepids ? : { medium : string ; address : string ; } [ ] ; /**
     * The avatar URL (usually MXC URI) for the user, if set.
     */ avatar_url ? : string ; /**
     * Whether or not the user is a Synapse administrator.
     */ admin ? : boolean ; /**
     * Whether or not the user is deactivated.
     */ deactivated ? : boolean ; } category export interface SynapseUserProperties extends SynapseUser { /**
     * The password for the user. Leave undefined to leave unchanged.
     */ password ? : string ; } category export interface SynapseUserListing { /**
     * User ID.
     */ name : string ; /**
     * Whether or not the user is a guest. 1 is true, 0 is false.
     */ is_guest : number ; /**
     * Whether or not the user is an admin. 1 is true, 0 is false.
     */ admin : number ; /**
     * Whether or not the user is deactivated. 1 is true, 0 is false.
     */ deactivated : number ; /**
     * The type of user, if relevant.
     */ user_type : string | null ; /**
     * The hash of the user's password, if relevant.
     */ password_hash : string | null ; /**
     * The display name of the user, if set.
     */ displayname : string | null ; /**
     * The avatar for the user, if set.
     */ avatar_url : string | null ; } category export interface SynapseUserList { /**
     * A set of users matching the criteria.
     */ users : SynapseUserListing [ ] ; /**
     * The token to use to get the next set of users.
     */ next_token : string ; /**
     * The total number of users on the Synapse instance.
     */ total : number ; } category export interface SynapseRoomListing { room_id : string ; name : string ; canonical_alias : string ; joined_members : number ; joined_local_members : number ; version : string ; creator : string ; encryption : string ; federatable : boolean ; public : boolean ; join_rules : string ; guest_access : string ; history_visibility : string ; state_events : number ; } category export interface SynapseRoomList { rooms : SynapseRoomListing [ ] ; offset : string ; total_rooms : number ; next_batch : string ; prev_batch : string ; } category export enum SynapseRoomProperty { Name = "name" , CanonicalAlias = "canonical_alias" , JoinedMembers = "joined_members" , JoinedLocalMembers = "joined_local_members" , Version = "version" , Creator = "creator" , Encryption = "encryption" , CanFederate = "federatable" , IsPublic = "public" , JoinRules = "join_rules" , GuestAccess = "guest_access" , HistoryVisibility = "history_visibility" , NumStateEvents = "state_events" } category export class SynapseAdminApis { constructor ( private client ) { } param { string } userId returns { Promise < SynapseUser > } public async getUser ( userId ) { return this . client . doRequest ( "GET" , "/_synapse/admin/v2/users/" + encodeURIComponent ( userId ) ) ; } param { string } userId param { SynapseUserProperties } opts returns { Promise < SynapseUser > } public async upsertUser ( userId , opts = { } ) { return this . client . doRequest ( "PUT" , "/_synapse/admin/v2/users/" + encodeURIComponent ( userId ) , undefined , opts ) ; } param { string } from param { number } limit param { string } name param { boolean } guests param { boolean } deactivated returns { Promise < SynapseUserList > } public async listUsers ( from ? , limit ? , name ? , guests = true , deactivated = false ) { const qs = { guests , deactivated } ; if ( from ) qs [ 'from' ] = from ; if ( limit ) qs [ 'limit' ] = limit ; if ( name ) qs [ 'name' ] = name ; return this . client . doRequest ( "GET" , "/_synapse/admin/v2/users" , qs ) ; } param { string } userId returns { Promise < boolean > } public async isAdmin ( userId ) { const response = await this . client . doRequest ( "GET" , `/_synapse/admin/v1/users/${ encodeURIComponent ( userId ) }/admin` ) ; return response [ 'admin' ] || false ; } returns { Promise < boolean > } public async isSelfAdmin ( ) { try { return await this . isAdmin ( await this . client . getUserId ( ) ) ; } catch ( e ) { if ( e ?. body ?. errcode === 'M_FORBIDDEN' ) { return false ; } throw e ; } } param { string } searchTerm param { string } from param { number } limit param { SynapseRoomProperty } orderBy param { boolean } reverseOrder returns { Promise < SynapseRoomList > } public async listRooms ( searchTerm ? , from ? , limit ? , orderBy ? , reverseOrder = false ) { const params = { } ; if ( from ) params [ 'from' ] = from ; if ( limit ) params [ 'limit' ] = limit ; if ( searchTerm ) params [ 'search_term' ] = searchTerm ; if ( orderBy ) params [ 'order_by' ] = orderBy ; if ( reverseOrder ) { params [ 'dir' ] = 'b' ; } else { params [ 'dir' ] = 'f' ; } return this . client . doRequest ( "GET" , "/_synapse/admin/v1/rooms" , params ) ; } param { string } roomId returns { Promise < any [ ] > } public async getRoomState ( roomId ) { const r = await this . client . doRequest ( "GET" , `/_synapse/admin/v1/rooms/${ encodeURIComponent ( roomId ) }/state` ) ; return r ?. [ 'state' ] || [ ] ; } param { string } roomId returns { Promise } public async deleteRoom ( roomId ) { return this . client . doRequest ( "POST" , `/_synapse/admin/v1/rooms/${ encodeURIComponent ( roomId ) }/delete` , { } , { purge : true } ) ; } }