Skip to content

Commit 1a37c2d

Browse files
committed
Merge futures endpoints into /send and /state
Also add unstable prefixes to future-related query parameters
1 parent a891c9a commit 1a37c2d

File tree

4 files changed

+25
-39
lines changed

4 files changed

+25
-39
lines changed

spec/unit/matrix-client.spec.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ describe("MatrixClient", function () {
711711
const roomId = "!room:example.org";
712712
const body = "This is the body";
713713
const content = { body, msgtype: MsgType.Text } satisfies RoomMessageEventContent;
714-
const timeoutFutureOpts = { future_timeout: 2000 };
714+
const timeoutFutureOpts = { "org.matrix.msc4140.future_timeout": 2000 };
715715

716716
beforeEach(() => {
717717
unstableFeatures["org.matrix.msc4140"] = true;
@@ -749,8 +749,7 @@ describe("MatrixClient", function () {
749749
const timeoutFutureTxnId = client.makeTxnId();
750750
httpLookups.push({
751751
method: "PUT",
752-
prefix: unstableMSC4140Prefix,
753-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
752+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
754753
expectQueryParams: timeoutFutureOpts,
755754
data: { future_id: "f1" },
756755
expectBody: content,
@@ -766,11 +765,10 @@ describe("MatrixClient", function () {
766765
);
767766

768767
const actionFutureTxnId = client.makeTxnId();
769-
const actionFutureOpts = { parent_future_id: timeoutFutureId };
768+
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
770769
httpLookups.push({
771770
method: "PUT",
772-
prefix: unstableMSC4140Prefix,
773-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
771+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
774772
expectQueryParams: actionFutureOpts,
775773
data: { future_id: "f2" },
776774
expectBody: content,
@@ -801,8 +799,7 @@ describe("MatrixClient", function () {
801799
const timeoutFutureTxnId = client.makeTxnId();
802800
httpLookups.push({
803801
method: "PUT",
804-
prefix: unstableMSC4140Prefix,
805-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
802+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
806803
expectQueryParams: timeoutFutureOpts,
807804
data: { future_id: "f1" },
808805
expectBody,
@@ -818,11 +815,10 @@ describe("MatrixClient", function () {
818815
);
819816

820817
const actionFutureTxnId = client.makeTxnId();
821-
const actionFutureOpts = { parent_future_id: timeoutFutureId };
818+
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
822819
httpLookups.push({
823820
method: "PUT",
824-
prefix: unstableMSC4140Prefix,
825-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
821+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
826822
expectQueryParams: actionFutureOpts,
827823
data: { future_id: "f2" },
828824
expectBody,
@@ -862,8 +858,7 @@ describe("MatrixClient", function () {
862858
const timeoutFutureTxnId = client.makeTxnId();
863859
httpLookups.push({
864860
method: "PUT",
865-
prefix: unstableMSC4140Prefix,
866-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
861+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
867862
expectQueryParams: timeoutFutureOpts,
868863
data: { future_id: "f1" },
869864
expectBody,
@@ -879,11 +874,10 @@ describe("MatrixClient", function () {
879874
);
880875

881876
const actionFutureTxnId = client.makeTxnId();
882-
const actionFutureOpts = { parent_future_id: timeoutFutureId };
877+
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
883878
httpLookups.push({
884879
method: "PUT",
885-
prefix: unstableMSC4140Prefix,
886-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
880+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
887881
expectQueryParams: actionFutureOpts,
888882
data: { future_id: "f2" },
889883
expectBody,
@@ -933,8 +927,7 @@ describe("MatrixClient", function () {
933927
const timeoutFutureTxnId = client.makeTxnId();
934928
httpLookups.push({
935929
method: "PUT",
936-
prefix: unstableMSC4140Prefix,
937-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
930+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
938931
expectQueryParams: timeoutFutureOpts,
939932
data: { future_id: "f1" },
940933
expectBody,
@@ -950,11 +943,10 @@ describe("MatrixClient", function () {
950943
);
951944

952945
const actionFutureTxnId = client.makeTxnId();
953-
const actionFutureOpts = { parent_future_id: timeoutFutureId };
946+
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
954947
httpLookups.push({
955948
method: "PUT",
956-
prefix: unstableMSC4140Prefix,
957-
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
949+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
958950
expectQueryParams: actionFutureOpts,
959951
data: { future_id: "f2" },
960952
expectBody,
@@ -976,8 +968,7 @@ describe("MatrixClient", function () {
976968

977969
httpLookups.push({
978970
method: "PUT",
979-
prefix: unstableMSC4140Prefix,
980-
path: `/rooms/${encodeURIComponent(roomId)}/state_future/m.room.topic/`,
971+
path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`,
981972
expectQueryParams: timeoutFutureOpts,
982973
data: { future_id: "f1" },
983974
expectBody: content,
@@ -990,11 +981,10 @@ describe("MatrixClient", function () {
990981
{ ...content },
991982
);
992983

993-
const actionFutureOpts = { parent_future_id: timeoutFutureId };
984+
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
994985
httpLookups.push({
995986
method: "PUT",
996-
prefix: unstableMSC4140Prefix,
997-
path: `/rooms/${encodeURIComponent(roomId)}/state_future/m.room.topic/`,
987+
path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`,
998988
expectQueryParams: actionFutureOpts,
999989
data: { future_id: "f2" },
1000990
expectBody: content,

src/@types/requests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ export interface ISendEventResponse {
7777
}
7878

7979
export type ParentFutureId = {
80-
parent_future_id: string;
80+
"org.matrix.msc4140.parent_future_id": string;
8181
};
8282

8383
export type FutureTimeout = {
84-
future_timeout: number;
84+
"org.matrix.msc4140.future_timeout": number;
8585
};
8686

8787
export type SendTimeoutFutureRequestOpts = FutureTimeout & Partial<ParentFutureId>;

src/client.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4909,13 +4909,12 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
49094909
$txnId: txnId,
49104910
};
49114911

4912-
const futurePathPart = futureOpts ? "_future" : "";
49134912
let path: string;
49144913

49154914
if (event.isState()) {
4916-
let pathTemplate = `/rooms/$roomId/state${futurePathPart}/$eventType`;
4915+
let pathTemplate = "/rooms/$roomId/state/$eventType";
49174916
if (event.getStateKey() && event.getStateKey()!.length > 0) {
4918-
pathTemplate = `/rooms/$roomId/state${futurePathPart}/$eventType/$stateKey`;
4917+
pathTemplate = "/rooms/$roomId/state/$eventType/$stateKey";
49194918
}
49204919
path = utils.encodeUri(pathTemplate, pathParams);
49214920
} else if (event.isRedaction() && event.event.redacts) {
@@ -4929,7 +4928,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
49294928
...pathParams,
49304929
});
49314930
} else {
4932-
path = utils.encodeUri(`/rooms/$roomId/send${futurePathPart}/$eventType/$txnId`, pathParams);
4931+
path = utils.encodeUri("/rooms/$roomId/send/$eventType/$txnId", pathParams);
49334932
}
49344933

49354934
const content = event.getWireContent();
@@ -4939,9 +4938,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
49394938
return res;
49404939
});
49414940
} else {
4942-
return this.http.authedRequest<SendFutureResponse>(Method.Put, path, { ...futureOpts }, content, {
4943-
prefix: `${ClientPrefix.Unstable}/${UNSTABLE_MSC4140_FUTURES}`,
4944-
});
4941+
return this.http.authedRequest<SendFutureResponse>(Method.Put, path, { ...futureOpts }, content);
49454942
}
49464943
}
49474944

@@ -5319,12 +5316,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
53195316
$eventType: eventType,
53205317
$stateKey: stateKey,
53215318
};
5322-
let path = utils.encodeUri("/rooms/$roomId/state_future/$eventType", pathParams);
5319+
let path = utils.encodeUri("/rooms/$roomId/state/$eventType", pathParams);
53235320
if (stateKey !== undefined) {
53245321
path = utils.encodeUri(path + "/$stateKey", pathParams);
53255322
}
5326-
return this.http.authedRequest(Method.Put, path, { ...futureOpts }, content as Body, {
5327-
prefix: `${ClientPrefix.Unstable}/${UNSTABLE_MSC4140_FUTURES}`,
5323+
return this.http.authedRequest(Method.Put, path, futureOpts, content as Body, {
53285324
...opts,
53295325
});
53305326
}

src/matrixrtc/MatrixRTCSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
882882
const res = await this.client._unstable_sendStateFuture(
883883
this.room.roomId,
884884
{
885-
future_timeout: 8000,
885+
"org.matrix.msc4140.future_timeout": 8000,
886886
},
887887
EventType.GroupCallMemberPrefix,
888888
{}, // leave event

0 commit comments

Comments
 (0)