You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-06-15 23:01:41 +03:00
task: unify unstable prefix code between client and tests
This commit is contained in:
@ -29,9 +29,10 @@ import {
|
|||||||
Room,
|
Room,
|
||||||
} from "../../src/matrix";
|
} from "../../src/matrix";
|
||||||
import { logger } from "../../src/logger";
|
import { logger } from "../../src/logger";
|
||||||
import { encodeParams, encodeUri, QueryDict, replaceParam } from "../../src/utils";
|
import { encodeParams, encodeUri, prefixUnstableParameters, QueryDict } from "../../src/utils";
|
||||||
import { TestClient } from "../TestClient";
|
import { TestClient } from "../TestClient";
|
||||||
import { FeatureSupport, Thread, THREAD_RELATION_TYPE, ThreadEvent } from "../../src/models/thread";
|
import { FeatureSupport, Thread, THREAD_RELATION_TYPE, ThreadEvent } from "../../src/models/thread";
|
||||||
|
import { Feature, ServerSupport } from "../../src/feature";
|
||||||
import { emitPromise } from "../test-utils/test-utils";
|
import { emitPromise } from "../test-utils/test-utils";
|
||||||
|
|
||||||
const userId = "@alice:localhost";
|
const userId = "@alice:localhost";
|
||||||
@ -49,13 +50,11 @@ const withoutRoomId = (e: Partial<IEvent>): Partial<IEvent> => {
|
|||||||
/**
|
/**
|
||||||
* Our httpBackend only allows matching calls if we have the exact same query, in the exact same order
|
* Our httpBackend only allows matching calls if we have the exact same query, in the exact same order
|
||||||
* This method allows building queries with the exact same parameter order as the fetchRelations method in client
|
* This method allows building queries with the exact same parameter order as the fetchRelations method in client
|
||||||
|
* @param supports features supported by our client
|
||||||
* @param params query parameters
|
* @param params query parameters
|
||||||
*/
|
*/
|
||||||
const buildRelationPaginationQuery = (params: QueryDict): string => {
|
const buildRelationPaginationQuery = (supports: Map<Feature, ServerSupport>, params: QueryDict): string => {
|
||||||
if (Thread.hasServerSideFwdPaginationSupport === FeatureSupport.Experimental) {
|
return "?" + encodeParams(prefixUnstableParameters(supports, params)).toString();
|
||||||
params = replaceParam("dir", "org.matrix.msc3715.dir", params);
|
|
||||||
}
|
|
||||||
return "?" + encodeParams(params).toString();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const USER_MEMBERSHIP_EVENT = utils.mkMembership({
|
const USER_MEMBERSHIP_EVENT = utils.mkMembership({
|
||||||
@ -619,7 +618,7 @@ describe("MatrixClient event timelines", function () {
|
|||||||
encodeURIComponent(THREAD_ROOT.event_id!) +
|
encodeURIComponent(THREAD_ROOT.event_id!) +
|
||||||
"/" +
|
"/" +
|
||||||
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
||||||
buildRelationPaginationQuery({ dir: Direction.Backward, limit: 1 }),
|
buildRelationPaginationQuery(client.canSupport, { dir: Direction.Backward, limit: 1 }),
|
||||||
)
|
)
|
||||||
.respond(200, function () {
|
.respond(200, function () {
|
||||||
return {
|
return {
|
||||||
@ -1789,7 +1788,7 @@ describe("MatrixClient event timelines", function () {
|
|||||||
encodeURIComponent(THREAD_ROOT.event_id!) +
|
encodeURIComponent(THREAD_ROOT.event_id!) +
|
||||||
"/" +
|
"/" +
|
||||||
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
||||||
buildRelationPaginationQuery({ dir: Direction.Backward, limit: 1 }),
|
buildRelationPaginationQuery(client.canSupport, { dir: Direction.Backward, limit: 1 }),
|
||||||
)
|
)
|
||||||
.respond(200, function () {
|
.respond(200, function () {
|
||||||
return {
|
return {
|
||||||
@ -1847,7 +1846,7 @@ describe("MatrixClient event timelines", function () {
|
|||||||
encodeURIComponent(THREAD_ROOT.event_id!) +
|
encodeURIComponent(THREAD_ROOT.event_id!) +
|
||||||
"/" +
|
"/" +
|
||||||
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
||||||
buildRelationPaginationQuery({ dir: Direction.Backward, from: "start_token" }),
|
buildRelationPaginationQuery(client.canSupport, { dir: Direction.Backward, from: "start_token" }),
|
||||||
)
|
)
|
||||||
.respond(200, function () {
|
.respond(200, function () {
|
||||||
return {
|
return {
|
||||||
@ -1861,7 +1860,7 @@ describe("MatrixClient event timelines", function () {
|
|||||||
encodeURIComponent(THREAD_ROOT.event_id!) +
|
encodeURIComponent(THREAD_ROOT.event_id!) +
|
||||||
"/" +
|
"/" +
|
||||||
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
encodeURIComponent(THREAD_RELATION_TYPE.name) +
|
||||||
buildRelationPaginationQuery({ dir: Direction.Forward, from: "end_token" }),
|
buildRelationPaginationQuery(client.canSupport, { dir: Direction.Forward, from: "end_token" }),
|
||||||
)
|
)
|
||||||
.respond(200, function () {
|
.respond(200, function () {
|
||||||
return {
|
return {
|
||||||
|
@ -38,7 +38,7 @@ import { Filter, IFilterDefinition, IRoomEventFilter } from "./filter";
|
|||||||
import { CallEventHandlerEvent, CallEventHandler, CallEventHandlerEventHandlerMap } from "./webrtc/callEventHandler";
|
import { CallEventHandlerEvent, CallEventHandler, CallEventHandlerEventHandlerMap } from "./webrtc/callEventHandler";
|
||||||
import { GroupCallEventHandlerEvent, GroupCallEventHandlerEventHandlerMap } from "./webrtc/groupCallEventHandler";
|
import { GroupCallEventHandlerEvent, GroupCallEventHandlerEventHandlerMap } from "./webrtc/groupCallEventHandler";
|
||||||
import * as utils from "./utils";
|
import * as utils from "./utils";
|
||||||
import { replaceParam, QueryDict, sleep, noUnsafeEventProps, safeSet } from "./utils";
|
import { QueryDict, sleep, noUnsafeEventProps, safeSet } from "./utils";
|
||||||
import { Direction, EventTimeline } from "./models/event-timeline";
|
import { Direction, EventTimeline } from "./models/event-timeline";
|
||||||
import { IActionsObject, PushProcessor } from "./pushprocessor";
|
import { IActionsObject, PushProcessor } from "./pushprocessor";
|
||||||
import { AutoDiscovery, AutoDiscoveryAction } from "./autodiscovery";
|
import { AutoDiscovery, AutoDiscoveryAction } from "./autodiscovery";
|
||||||
@ -7956,13 +7956,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
eventType?: EventType | string | null,
|
eventType?: EventType | string | null,
|
||||||
opts: IRelationsRequestOpts = { dir: Direction.Backward },
|
opts: IRelationsRequestOpts = { dir: Direction.Backward },
|
||||||
): Promise<IRelationsResponse> {
|
): Promise<IRelationsResponse> {
|
||||||
let params = opts as QueryDict;
|
const params = utils.prefixUnstableParameters(this.canSupport, opts as QueryDict);
|
||||||
if (Thread.hasServerSideFwdPaginationSupport === FeatureSupport.Experimental) {
|
|
||||||
params = replaceParam("dir", "org.matrix.msc3715.dir", params);
|
|
||||||
}
|
|
||||||
if (this.canSupport.get(Feature.RelationsRecursion) === ServerSupport.Unstable) {
|
|
||||||
params = replaceParam("recurse", "org.matrix.msc3981.recurse", params);
|
|
||||||
}
|
|
||||||
const queryString = utils.encodeParams(params);
|
const queryString = utils.encodeParams(params);
|
||||||
|
|
||||||
let templatedUrl = "/rooms/$roomId/relations/$eventId";
|
let templatedUrl = "/rooms/$roomId/relations/$eventId";
|
||||||
|
12
src/utils.ts
12
src/utils.ts
@ -25,6 +25,8 @@ import { Optional } from "matrix-events-sdk";
|
|||||||
import { IEvent, MatrixEvent } from "./models/event";
|
import { IEvent, MatrixEvent } from "./models/event";
|
||||||
import { M_TIMESTAMP } from "./@types/location";
|
import { M_TIMESTAMP } from "./@types/location";
|
||||||
import { ReceiptType } from "./@types/read_receipts";
|
import { ReceiptType } from "./@types/read_receipts";
|
||||||
|
import { Feature, ServerSupport } from "./feature";
|
||||||
|
import { FeatureSupport, Thread } from "./models/thread";
|
||||||
|
|
||||||
const interns = new Map<string, string>();
|
const interns = new Map<string, string>();
|
||||||
|
|
||||||
@ -87,6 +89,16 @@ export function replaceParam(stable: string, unstable: string, dict: QueryDict):
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function prefixUnstableParameters(supports: Map<Feature, ServerSupport>, params: QueryDict): QueryDict {
|
||||||
|
if (Thread.hasServerSideFwdPaginationSupport === FeatureSupport.Experimental) {
|
||||||
|
params = replaceParam("dir", "org.matrix.msc3715.dir", params);
|
||||||
|
}
|
||||||
|
if (supports.get(Feature.RelationsRecursion) === ServerSupport.Unstable) {
|
||||||
|
params = replaceParam("recurse", "org.matrix.msc3981.recurse", params);
|
||||||
|
}
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode a query string in `application/x-www-form-urlencoded` format.
|
* Decode a query string in `application/x-www-form-urlencoded` format.
|
||||||
* @param query - A query string to decode e.g.
|
* @param query - A query string to decode e.g.
|
||||||
|
Reference in New Issue
Block a user