1
0
Fork 0
forked from Mirrors/gomuks

hicli/json: add resolve alias command

This commit is contained in:
Tulir Asokan 2024-10-20 14:10:01 +03:00
parent 34346cffec
commit 8cc475e66b
3 changed files with 19 additions and 0 deletions

View file

@ -79,6 +79,10 @@ func (h *HiClient) handleJSONCommand(ctx context.Context, req *JSONCommand) (any
return unmarshalAndCall(req.Data, func(params *ensureGroupSessionSharedParams) (bool, error) { return unmarshalAndCall(req.Data, func(params *ensureGroupSessionSharedParams) (bool, error) {
return true, h.EnsureGroupSessionShared(ctx, params.RoomID) return true, h.EnsureGroupSessionShared(ctx, params.RoomID)
}) })
case "resolve_alias":
return unmarshalAndCall(req.Data, func(params *resolveAliasParams) (*mautrix.RespAliasResolve, error) {
return h.Client.ResolveAlias(ctx, params.Alias)
})
case "login": case "login":
return unmarshalAndCall(req.Data, func(params *loginParams) (bool, error) { return unmarshalAndCall(req.Data, func(params *loginParams) (bool, error) {
return true, h.LoginPassword(ctx, params.HomeserverURL, params.Username, params.Password) return true, h.LoginPassword(ctx, params.HomeserverURL, params.Username, params.Password)
@ -158,6 +162,10 @@ type ensureGroupSessionSharedParams struct {
RoomID id.RoomID `json:"room_id"` RoomID id.RoomID `json:"room_id"`
} }
type resolveAliasParams struct {
Alias id.RoomAlias `json:"alias"`
}
type loginParams struct { type loginParams struct {
HomeserverURL string `json:"homeserver_url"` HomeserverURL string `json:"homeserver_url"`
Username string `json:"username"` Username string `json:"username"`

View file

@ -27,6 +27,8 @@ import type {
RPCEvent, RPCEvent,
RawDBEvent, RawDBEvent,
ReceiptType, ReceiptType,
ResolveAliasResponse,
RoomAlias,
RoomID, RoomID,
TimelineRowID, TimelineRowID,
UserID, UserID,
@ -161,6 +163,10 @@ export default abstract class RPCClient {
return this.request("paginate_server", { room_id, limit }) return this.request("paginate_server", { room_id, limit })
} }
resolveAlias(alias: RoomAlias): Promise<ResolveAliasResponse> {
return this.request("resolve_alias", { alias })
}
discoverHomeserver(user_id: UserID): Promise<ClientWellKnown> { discoverHomeserver(user_id: UserID): Promise<ClientWellKnown> {
return this.request("discover_homeserver", { user_id }) return this.request("discover_homeserver", { user_id })
} }

View file

@ -139,6 +139,11 @@ export interface PaginationResponse {
has_more: boolean has_more: boolean
} }
export interface ResolveAliasResponse {
room_id: RoomID
servers: string[]
}
export interface EventUnsigned { export interface EventUnsigned {
prev_content?: unknown prev_content?: unknown
prev_sender?: UserID prev_sender?: UserID