Merge pull request #774 from vector-im/add-more-hsApi

Add more homeserver api
This commit is contained in:
Robert Long 2022-07-06 12:23:34 -07:00 committed by GitHub
commit 3959968c29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 4 deletions

View file

@ -271,6 +271,12 @@ export class HomeServerApi {
return this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`, {}, {}, options); return this._post(`/join/${encodeURIComponent(roomIdOrAlias)}`, {}, {}, options);
} }
invite(roomId: string, userId: string, options?: BaseRequestOptions): IHomeServerRequest {
return this._post(`/rooms/${encodeURIComponent(roomId)}/invite`, {}, {
user_id: userId
}, options);
}
leave(roomId: string, options?: BaseRequestOptions): IHomeServerRequest { leave(roomId: string, options?: BaseRequestOptions): IHomeServerRequest {
return this._post(`/rooms/${encodeURIComponent(roomId)}/leave`, {}, {}, options); return this._post(`/rooms/${encodeURIComponent(roomId)}/leave`, {}, {}, options);
} }
@ -298,6 +304,13 @@ export class HomeServerApi {
return this._post(`/dehydrated_device/claim`, {}, {device_id: deviceId}, options); return this._post(`/dehydrated_device/claim`, {}, {device_id: deviceId}, options);
} }
searchProfile(searchTerm: string, limit?: number, options?: BaseRequestOptions): IHomeServerRequest {
return this._post(`/user_directory/search`, {}, {
limit: limit ?? 10,
search_term: searchTerm,
}, options);
}
profile(userId: string, options?: BaseRequestOptions): IHomeServerRequest { profile(userId: string, options?: BaseRequestOptions): IHomeServerRequest {
return this._get(`/profile/${encodeURIComponent(userId)}`); return this._get(`/profile/${encodeURIComponent(userId)}`);
} }

View file

@ -415,7 +415,7 @@ export class BaseRoom extends EventEmitter {
} }
get type() { get type() {
return this._summary.data.type; return this._summary.data.type ?? undefined;
} }
get lastMessageTimestamp() { get lastMessageTimestamp() {

View file

@ -61,6 +61,10 @@ export class Invite extends EventEmitter {
return this._inviteData.avatarColorId || this.id; return this._inviteData.avatarColorId || this.id;
} }
get type() {
return this._inviteData.type ?? undefined;
}
get timestamp() { get timestamp() {
return this._inviteData.timestamp; return this._inviteData.timestamp;
} }
@ -89,7 +93,7 @@ export class Invite extends EventEmitter {
await this._platform.logger.wrapOrRun(log, "acceptInvite", async log => { await this._platform.logger.wrapOrRun(log, "acceptInvite", async log => {
this._accepting = true; this._accepting = true;
this._emitChange("accepting"); this._emitChange("accepting");
await this._hsApi.join(this._roomId, {log}).response(); await this._hsApi.joinIdOrAlias(this.canonicalAlias ?? this._roomId, {log}).response();
}); });
} }
@ -189,7 +193,7 @@ export class Invite extends EventEmitter {
roomId: this.id, roomId: this.id,
isEncrypted: !!summaryData.encryption, isEncrypted: !!summaryData.encryption,
isDirectMessage: summaryData.isDirectMessage, isDirectMessage: summaryData.isDirectMessage,
// type: type: summaryData.type,
name, name,
avatarUrl, avatarUrl,
avatarColorId, avatarColorId,

View file

@ -163,7 +163,7 @@ export class GapWriter {
if (!Array.isArray(chunk)) { if (!Array.isArray(chunk)) {
throw new Error("Invalid chunk in response"); throw new Error("Invalid chunk in response");
} }
if (typeof end !== "string") { if (typeof end !== "string" && typeof end !== "undefined") {
throw new Error("Invalid end token in response"); throw new Error("Invalid end token in response");
} }