Skip to content

Commit 5d4e05b

Browse files
committed
Satisfy revised MSC4140
Replace future tokens with future IDs and actions for updating futures
1 parent 5cc00ad commit 5d4e05b

File tree

5 files changed

+89
-98
lines changed

5 files changed

+89
-98
lines changed

spec/unit/matrix-client.spec.ts

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
Room,
5858
RuleId,
5959
TweakName,
60+
UpdateFutureAction,
6061
} from "../../src";
6162
import { supportsMatrixCall } from "../../src/webrtc/call";
6263
import { makeBeaconEvent } from "../test-utils/beacon";
@@ -711,17 +712,6 @@ describe("MatrixClient", function () {
711712
const body = "This is the body";
712713
const content = { body, msgtype: MsgType.Text } satisfies RoomMessageEventContent;
713714
const timeoutFutureOpts = { future_timeout: 2000 };
714-
const timeoutFutureResponse = {
715-
future_group_id: "fg",
716-
send_token: "st",
717-
cancel_token: "ct",
718-
refresh_token: "rt",
719-
};
720-
const actionFutureResponse = {
721-
future_group_id: "fg",
722-
send_token: "sa",
723-
cancel_token: "ca",
724-
};
725715

726716
beforeEach(() => {
727717
unstableFeatures["org.matrix.msc4140"] = true;
@@ -748,7 +738,9 @@ describe("MatrixClient", function () {
748738

749739
await expect(client._unstable_getFutures()).rejects.toThrow(errorMessage);
750740

751-
await expect(client._unstable_updateFutureWithToken("token")).rejects.toThrow(errorMessage);
741+
await expect(client._unstable_updateFuture("anyFutureId", UpdateFutureAction.Send)).rejects.toThrow(
742+
errorMessage,
743+
);
752744
});
753745

754746
it("works with null threadId", async () => {
@@ -760,11 +752,11 @@ describe("MatrixClient", function () {
760752
prefix: unstableMSC4140Prefix,
761753
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
762754
expectQueryParams: timeoutFutureOpts,
763-
data: timeoutFutureResponse,
755+
data: { future_id: "f1" },
764756
expectBody: content,
765757
});
766758

767-
const { future_group_id: futureGroupId } = await client._unstable_sendFuture(
759+
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
768760
roomId,
769761
timeoutFutureOpts,
770762
null,
@@ -774,13 +766,13 @@ describe("MatrixClient", function () {
774766
);
775767

776768
const actionFutureTxnId = client.makeTxnId();
777-
const actionFutureOpts = { future_group_id: futureGroupId };
769+
const actionFutureOpts = { parent_future_id: timeoutFutureId };
778770
httpLookups.push({
779771
method: "PUT",
780772
prefix: unstableMSC4140Prefix,
781773
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
782774
expectQueryParams: actionFutureOpts,
783-
data: actionFutureResponse,
775+
data: { future_id: "f2" },
784776
expectBody: content,
785777
});
786778

@@ -812,11 +804,11 @@ describe("MatrixClient", function () {
812804
prefix: unstableMSC4140Prefix,
813805
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
814806
expectQueryParams: timeoutFutureOpts,
815-
data: timeoutFutureResponse,
807+
data: { future_id: "f1" },
816808
expectBody,
817809
});
818810

819-
const { future_group_id: futureGroupId } = await client._unstable_sendFuture(
811+
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
820812
roomId,
821813
timeoutFutureOpts,
822814
threadId,
@@ -826,13 +818,13 @@ describe("MatrixClient", function () {
826818
);
827819

828820
const actionFutureTxnId = client.makeTxnId();
829-
const actionFutureOpts = { future_group_id: futureGroupId };
821+
const actionFutureOpts = { parent_future_id: timeoutFutureId };
830822
httpLookups.push({
831823
method: "PUT",
832824
prefix: unstableMSC4140Prefix,
833825
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
834826
expectQueryParams: actionFutureOpts,
835-
data: actionFutureResponse,
827+
data: { future_id: "f2" },
836828
expectBody,
837829
});
838830

@@ -873,11 +865,11 @@ describe("MatrixClient", function () {
873865
prefix: unstableMSC4140Prefix,
874866
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
875867
expectQueryParams: timeoutFutureOpts,
876-
data: timeoutFutureResponse,
868+
data: { future_id: "f1" },
877869
expectBody,
878870
});
879871

880-
const { future_group_id: futureGroupId } = await client._unstable_sendFuture(
872+
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
881873
roomId,
882874
timeoutFutureOpts,
883875
threadId,
@@ -887,13 +879,13 @@ describe("MatrixClient", function () {
887879
);
888880

889881
const actionFutureTxnId = client.makeTxnId();
890-
const actionFutureOpts = { future_group_id: futureGroupId };
882+
const actionFutureOpts = { parent_future_id: timeoutFutureId };
891883
httpLookups.push({
892884
method: "PUT",
893885
prefix: unstableMSC4140Prefix,
894886
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
895887
expectQueryParams: actionFutureOpts,
896-
data: actionFutureResponse,
888+
data: { future_id: "f2" },
897889
expectBody,
898890
});
899891

@@ -944,11 +936,11 @@ describe("MatrixClient", function () {
944936
prefix: unstableMSC4140Prefix,
945937
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${timeoutFutureTxnId}`,
946938
expectQueryParams: timeoutFutureOpts,
947-
data: timeoutFutureResponse,
939+
data: { future_id: "f1" },
948940
expectBody,
949941
});
950942

951-
const { future_group_id: futureGroupId } = await client._unstable_sendFuture(
943+
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
952944
roomId,
953945
timeoutFutureOpts,
954946
threadId,
@@ -958,13 +950,13 @@ describe("MatrixClient", function () {
958950
);
959951

960952
const actionFutureTxnId = client.makeTxnId();
961-
const actionFutureOpts = { future_group_id: futureGroupId };
953+
const actionFutureOpts = { parent_future_id: timeoutFutureId };
962954
httpLookups.push({
963955
method: "PUT",
964956
prefix: unstableMSC4140Prefix,
965957
path: `/rooms/${encodeURIComponent(roomId)}/send_future/m.room.message/${actionFutureTxnId}`,
966958
expectQueryParams: actionFutureOpts,
967-
data: actionFutureResponse,
959+
data: { future_id: "f2" },
968960
expectBody,
969961
});
970962

@@ -987,24 +979,24 @@ describe("MatrixClient", function () {
987979
prefix: unstableMSC4140Prefix,
988980
path: `/rooms/${encodeURIComponent(roomId)}/state_future/m.room.topic/`,
989981
expectQueryParams: timeoutFutureOpts,
990-
data: timeoutFutureResponse,
982+
data: { future_id: "f1" },
991983
expectBody: content,
992984
});
993985

994-
const { future_group_id: futureGroupId } = await client._unstable_sendStateFuture(
986+
const { future_id: timeoutFutureId } = await client._unstable_sendStateFuture(
995987
roomId,
996988
timeoutFutureOpts,
997989
EventType.RoomTopic,
998990
{ ...content },
999991
);
1000992

1001-
const actionFutureOpts = { future_group_id: futureGroupId };
993+
const actionFutureOpts = { parent_future_id: timeoutFutureId };
1002994
httpLookups.push({
1003995
method: "PUT",
1004996
prefix: unstableMSC4140Prefix,
1005997
path: `/rooms/${encodeURIComponent(roomId)}/state_future/m.room.topic/`,
1006998
expectQueryParams: actionFutureOpts,
1007-
data: actionFutureResponse,
999+
data: { future_id: "f2" },
10081000
expectBody: content,
10091001
});
10101002

@@ -1026,16 +1018,20 @@ describe("MatrixClient", function () {
10261018

10271019
it("can update futures with their tokens", async () => {
10281020
const futureToken = "token";
1021+
const futureAction = UpdateFutureAction.Refresh;
10291022
httpLookups = [
10301023
{
10311024
method: "POST",
10321025
prefix: unstableMSC4140Prefix,
1033-
path: `/future/${futureToken}`,
1034-
data: {},
1026+
path: "/update_future",
1027+
data: {
1028+
future_id: futureToken,
1029+
action: futureAction,
1030+
},
10351031
},
10361032
];
10371033

1038-
await client._unstable_updateFutureWithToken(futureToken);
1034+
await client._unstable_updateFuture(futureToken, futureAction);
10391035
});
10401036
});
10411037

src/@types/requests.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,34 +76,32 @@ export interface ISendEventResponse {
7676
event_id: string;
7777
}
7878

79-
export type FutureGroupId = {
80-
future_group_id: string;
79+
export type ParentFutureId = {
80+
parent_future_id: string;
8181
};
8282

8383
export type FutureTimeout = {
8484
future_timeout: number;
8585
};
8686

87-
export type SendTimeoutFutureRequestOpts = FutureTimeout & Partial<FutureGroupId>;
88-
export type SendActionFutureRequestOpts = FutureGroupId;
87+
export type SendTimeoutFutureRequestOpts = FutureTimeout & Partial<ParentFutureId>;
88+
export type SendActionFutureRequestOpts = ParentFutureId;
8989

9090
export type SendFutureRequestOpts = SendTimeoutFutureRequestOpts | SendActionFutureRequestOpts;
9191

92-
export type ActionFutureTokens = {
93-
send_token: string;
94-
cancel_token: string;
92+
export type SendFutureResponse = {
93+
future_id: string;
9594
};
9695

97-
export type TimeoutFutureTokens = ActionFutureTokens & {
98-
refresh_token: string;
99-
};
100-
101-
export type SendActionFutureResponse = FutureGroupId & ActionFutureTokens;
102-
export type SendTimeoutFutureResponse = FutureGroupId & TimeoutFutureTokens;
96+
export enum UpdateFutureAction {
97+
Send = "send",
98+
Cancel = "cancel",
99+
Refresh = "refresh",
100+
}
103101

104-
export type SendFutureResponse<F extends SendFutureRequestOpts> = F extends SendTimeoutFutureRequestOpts
105-
? SendTimeoutFutureResponse
106-
: SendActionFutureResponse;
102+
export type UpdateFutureRequestOpts = SendFutureResponse & {
103+
action: UpdateFutureAction;
104+
};
107105

108106
interface FuturePartialEvent {
109107
room_id: string;
@@ -112,8 +110,8 @@ interface FuturePartialEvent {
112110
content: IContent;
113111
}
114112

115-
export type ActionFutureInfo = FutureGroupId & FuturePartialEvent & ActionFutureTokens;
116-
export type TimeoutFutureInfo = FutureGroupId & FutureTimeout & FuturePartialEvent & TimeoutFutureTokens;
113+
export type ActionFutureInfo = SendFutureResponse & FuturePartialEvent;
114+
export type TimeoutFutureInfo = SendFutureResponse & FutureTimeout & FuturePartialEvent;
117115

118116
export type FutureInfo = ActionFutureInfo | TimeoutFutureInfo;
119117

0 commit comments

Comments
 (0)