You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Allow to omit optional params for /relations calls (#2053)
This commit is contained in:
@@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Callback } from "../client";
|
import { Callback } from "../client";
|
||||||
import { IContent } from "../models/event";
|
import { IContent, IEvent } from "../models/event";
|
||||||
import { Preset, Visibility } from "./partials";
|
import { Preset, Visibility } from "./partials";
|
||||||
import { SearchKey } from "./search";
|
import { SearchKey } from "./search";
|
||||||
import { IRoomEventFilter } from "../filter";
|
import { IRoomEventFilter } from "../filter";
|
||||||
@@ -139,4 +139,18 @@ export interface IBindThreePidBody {
|
|||||||
id_access_token: string;
|
id_access_token: string;
|
||||||
sid: string;
|
sid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IRelationsRequestOpts {
|
||||||
|
from?: string;
|
||||||
|
to?: string;
|
||||||
|
limit?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IRelationsResponse {
|
||||||
|
original_event: IEvent;
|
||||||
|
chunk: IEvent[];
|
||||||
|
next_batch?: string;
|
||||||
|
prev_batch?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/* eslint-enable camelcase */
|
/* eslint-enable camelcase */
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ import {
|
|||||||
IPaginateOpts,
|
IPaginateOpts,
|
||||||
IPresenceOpts,
|
IPresenceOpts,
|
||||||
IRedactOpts,
|
IRedactOpts,
|
||||||
|
IRelationsRequestOpts,
|
||||||
|
IRelationsResponse,
|
||||||
IRoomDirectoryOptions,
|
IRoomDirectoryOptions,
|
||||||
ISearchOpts,
|
ISearchOpts,
|
||||||
ISendEventResponse,
|
ISendEventResponse,
|
||||||
@@ -6257,16 +6259,20 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* @param {string} relationType the rel_type of the relations requested
|
* @param {string} relationType the rel_type of the relations requested
|
||||||
* @param {string} eventType the event type of the relations requested
|
* @param {string} eventType the event type of the relations requested
|
||||||
* @param {Object} opts options with optional values for the request.
|
* @param {Object} opts options with optional values for the request.
|
||||||
* @param {Object} opts.from the pagination token returned from a previous request as `nextBatch` to return following relations.
|
|
||||||
* @return {Object} an object with `events` as `MatrixEvent[]` and optionally `nextBatch` if more relations are available.
|
* @return {Object} an object with `events` as `MatrixEvent[]` and optionally `nextBatch` if more relations are available.
|
||||||
*/
|
*/
|
||||||
public async relations(
|
public async relations(
|
||||||
roomId: string,
|
roomId: string,
|
||||||
eventId: string,
|
eventId: string,
|
||||||
relationType: string,
|
relationType: RelationType | string | null,
|
||||||
eventType: string,
|
eventType: EventType | string | null,
|
||||||
opts: { from: string },
|
opts: IRelationsRequestOpts = {},
|
||||||
): Promise<{ originalEvent: MatrixEvent, events: MatrixEvent[], nextBatch?: string }> {
|
): Promise<{
|
||||||
|
originalEvent: MatrixEvent;
|
||||||
|
events: MatrixEvent[];
|
||||||
|
nextBatch?: string;
|
||||||
|
prevBatch?: string;
|
||||||
|
}> {
|
||||||
const fetchedEventType = this.getEncryptedIfNeededEventType(roomId, eventType);
|
const fetchedEventType = this.getEncryptedIfNeededEventType(roomId, eventType);
|
||||||
const result = await this.fetchRelations(
|
const result = await this.fetchRelations(
|
||||||
roomId,
|
roomId,
|
||||||
@@ -6296,6 +6302,7 @@ export class MatrixClient extends EventEmitter {
|
|||||||
originalEvent,
|
originalEvent,
|
||||||
events,
|
events,
|
||||||
nextBatch: result.next_batch,
|
nextBatch: result.next_batch,
|
||||||
|
prevBatch: result.prev_batch,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6743,26 +6750,30 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* Fetches relations for a given event
|
* Fetches relations for a given event
|
||||||
* @param {string} roomId the room of the event
|
* @param {string} roomId the room of the event
|
||||||
* @param {string} eventId the id of the event
|
* @param {string} eventId the id of the event
|
||||||
* @param {string} relationType the rel_type of the relations requested
|
* @param {string} [relationType] the rel_type of the relations requested
|
||||||
* @param {string} eventType the event type of the relations requested
|
* @param {string} [eventType] the event type of the relations requested
|
||||||
* @param {Object} opts options with optional values for the request.
|
* @param {Object} [opts] options with optional values for the request.
|
||||||
* @param {Object} opts.from the pagination token returned from a previous request as `next_batch` to return following relations.
|
* @return {Object} the response, with chunk, prev_batch and, next_batch.
|
||||||
* @return {Object} the response, with chunk and next_batch.
|
|
||||||
*/
|
*/
|
||||||
public async fetchRelations(
|
public async fetchRelations(
|
||||||
roomId: string,
|
roomId: string,
|
||||||
eventId: string,
|
eventId: string,
|
||||||
relationType: string,
|
relationType?: RelationType | string | null,
|
||||||
eventType: string,
|
eventType?: EventType | string | null,
|
||||||
opts: { from: string },
|
opts: IRelationsRequestOpts = {},
|
||||||
): Promise<any> { // TODO: Types
|
): Promise<IRelationsResponse> {
|
||||||
const queryParams: any = {};
|
const params = new URLSearchParams();
|
||||||
if (opts.from) {
|
for (const [key, val] of Object.entries(opts)) {
|
||||||
queryParams.from = opts.from;
|
params.set(key, val);
|
||||||
}
|
}
|
||||||
const queryString = utils.encodeParams(queryParams);
|
const queryString = params.toString();
|
||||||
|
|
||||||
|
let templatedUrl = "/rooms/$roomId/relations/$eventId";
|
||||||
|
if (relationType !== null) templatedUrl += "/$relationType";
|
||||||
|
if (eventType !== null) templatedUrl += "/$eventType";
|
||||||
|
|
||||||
const path = utils.encodeUri(
|
const path = utils.encodeUri(
|
||||||
"/rooms/$roomId/relations/$eventId/$relationType/$eventType?" + queryString, {
|
templatedUrl + "?" + queryString, {
|
||||||
$roomId: roomId,
|
$roomId: roomId,
|
||||||
$eventId: eventId,
|
$eventId: eventId,
|
||||||
$relationType: relationType,
|
$relationType: relationType,
|
||||||
|
|||||||
Reference in New Issue
Block a user