Skip to content

Commit 8e7d296

Browse files
committed
Rename fields & methods and update GET type
1 parent 454cc71 commit 8e7d296

File tree

6 files changed

+243
-217
lines changed

6 files changed

+243
-217
lines changed

spec/unit/matrix-client.spec.ts

Lines changed: 92 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
Room,
5858
RuleId,
5959
TweakName,
60-
UpdateFutureAction,
60+
UpdateDelayedEventAction,
6161
} from "../../src";
6262
import { supportsMatrixCall } from "../../src/webrtc/call";
6363
import { makeBeaconEvent } from "../test-utils/beacon";
@@ -705,26 +705,27 @@ describe("MatrixClient", function () {
705705
});
706706
});
707707

708-
describe("_unstable_sendFuture", () => {
708+
describe("_unstable_sendDelayedEvent", () => {
709709
const unstableMSC4140Prefix = `${ClientPrefix.Unstable}/org.matrix.msc4140`;
710710

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 = { "org.matrix.msc4140.future_timeout": 2000 };
714+
const timeoutDelayOpts = { delay: 2000 };
715+
const realTimeoutDelayOpts = { "org.matrix.msc4140.delay": 2000 };
715716

716717
beforeEach(() => {
717718
unstableFeatures["org.matrix.msc4140"] = true;
718719
});
719720

720721
it("throws when unsupported by server", async () => {
721722
unstableFeatures["org.matrix.msc4140"] = false;
722-
const errorMessage = "Server does not support the Futures API";
723+
const errorMessage = "Server does not support";
723724

724725
await expect(
725-
client._unstable_sendFuture(
726+
client._unstable_sendDelayedEvent(
726727
roomId,
727-
timeoutFutureOpts,
728+
timeoutDelayOpts,
728729
null,
729730
EventType.RoomMessage,
730731
{ ...content },
@@ -733,54 +734,55 @@ describe("MatrixClient", function () {
733734
).rejects.toThrow(errorMessage);
734735

735736
await expect(
736-
client._unstable_sendStateFuture(roomId, timeoutFutureOpts, EventType.RoomTopic, { topic: "topic" }),
737+
client._unstable_sendDelayedStateEvent(roomId, timeoutDelayOpts, EventType.RoomTopic, {
738+
topic: "topic",
739+
}),
737740
).rejects.toThrow(errorMessage);
738741

739-
await expect(client._unstable_getFutures()).rejects.toThrow(errorMessage);
742+
await expect(client._unstable_getDelayedEvents()).rejects.toThrow(errorMessage);
740743

741-
await expect(client._unstable_updateFuture("anyFutureId", UpdateFutureAction.Send)).rejects.toThrow(
742-
errorMessage,
743-
);
744+
await expect(
745+
client._unstable_updateDelayedEvent("anyDelayId", UpdateDelayedEventAction.Send),
746+
).rejects.toThrow(errorMessage);
744747
});
745748

746749
it("works with null threadId", async () => {
747750
httpLookups = [];
748751

749-
const timeoutFutureTxnId = client.makeTxnId();
752+
const timeoutDelayTxnId = client.makeTxnId();
750753
httpLookups.push({
751754
method: "PUT",
752-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
753-
expectQueryParams: timeoutFutureOpts,
754-
data: { future_id: "f1" },
755+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
756+
expectQueryParams: realTimeoutDelayOpts,
757+
data: { delay_id: "id1" },
755758
expectBody: content,
756759
});
757760

758-
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
761+
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
759762
roomId,
760-
timeoutFutureOpts,
763+
timeoutDelayOpts,
761764
null,
762765
EventType.RoomMessage,
763766
{ ...content },
764-
timeoutFutureTxnId,
767+
timeoutDelayTxnId,
765768
);
766769

767-
const actionFutureTxnId = client.makeTxnId();
768-
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
770+
const actionDelayTxnId = client.makeTxnId();
769771
httpLookups.push({
770772
method: "PUT",
771-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
772-
expectQueryParams: actionFutureOpts,
773-
data: { future_id: "f2" },
773+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
774+
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
775+
data: { delay_id: "id2" },
774776
expectBody: content,
775777
});
776778

777-
await client._unstable_sendFuture(
779+
await client._unstable_sendDelayedEvent(
778780
roomId,
779-
actionFutureOpts,
781+
{ parent_delay_id: timeoutDelayId },
780782
null,
781783
EventType.RoomMessage,
782784
{ ...content },
783-
actionFutureTxnId,
785+
actionDelayTxnId,
784786
);
785787
});
786788

@@ -796,41 +798,40 @@ describe("MatrixClient", function () {
796798
},
797799
};
798800

799-
const timeoutFutureTxnId = client.makeTxnId();
801+
const timeoutDelayTxnId = client.makeTxnId();
800802
httpLookups.push({
801803
method: "PUT",
802-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
803-
expectQueryParams: timeoutFutureOpts,
804-
data: { future_id: "f1" },
804+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
805+
expectQueryParams: realTimeoutDelayOpts,
806+
data: { delay_id: "id1" },
805807
expectBody,
806808
});
807809

808-
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
810+
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
809811
roomId,
810-
timeoutFutureOpts,
812+
timeoutDelayOpts,
811813
threadId,
812814
EventType.RoomMessage,
813815
{ ...content },
814-
timeoutFutureTxnId,
816+
timeoutDelayTxnId,
815817
);
816818

817-
const actionFutureTxnId = client.makeTxnId();
818-
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
819+
const actionDelayTxnId = client.makeTxnId();
819820
httpLookups.push({
820821
method: "PUT",
821-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
822-
expectQueryParams: actionFutureOpts,
823-
data: { future_id: "f2" },
822+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
823+
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
824+
data: { delay_id: "id2" },
824825
expectBody,
825826
});
826827

827-
await client._unstable_sendFuture(
828+
await client._unstable_sendDelayedEvent(
828829
roomId,
829-
actionFutureOpts,
830+
{ parent_delay_id: timeoutDelayId },
830831
threadId,
831832
EventType.RoomMessage,
832833
{ ...content },
833-
actionFutureTxnId,
834+
actionDelayTxnId,
834835
);
835836
});
836837

@@ -855,41 +856,40 @@ describe("MatrixClient", function () {
855856
const rootEvent = new MatrixEvent({ event_id: threadId });
856857
room.createThread(threadId, rootEvent, [rootEvent], false);
857858

858-
const timeoutFutureTxnId = client.makeTxnId();
859+
const timeoutDelayTxnId = client.makeTxnId();
859860
httpLookups.push({
860861
method: "PUT",
861-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
862-
expectQueryParams: timeoutFutureOpts,
863-
data: { future_id: "f1" },
862+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
863+
expectQueryParams: realTimeoutDelayOpts,
864+
data: { delay_id: "id1" },
864865
expectBody,
865866
});
866867

867-
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
868+
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
868869
roomId,
869-
timeoutFutureOpts,
870+
timeoutDelayOpts,
870871
threadId,
871872
EventType.RoomMessage,
872873
{ ...content },
873-
timeoutFutureTxnId,
874+
timeoutDelayTxnId,
874875
);
875876

876-
const actionFutureTxnId = client.makeTxnId();
877-
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
877+
const actionDelayTxnId = client.makeTxnId();
878878
httpLookups.push({
879879
method: "PUT",
880-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
881-
expectQueryParams: actionFutureOpts,
882-
data: { future_id: "f2" },
880+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
881+
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
882+
data: { delay_id: "id2" },
883883
expectBody,
884884
});
885885

886-
await client._unstable_sendFuture(
886+
await client._unstable_sendDelayedEvent(
887887
roomId,
888-
actionFutureOpts,
888+
{ parent_delay_id: timeoutDelayId },
889889
threadId,
890890
EventType.RoomMessage,
891891
{ ...content },
892-
actionFutureTxnId,
892+
actionDelayTxnId,
893893
);
894894
});
895895

@@ -924,104 +924,106 @@ describe("MatrixClient", function () {
924924
const rootEvent = new MatrixEvent({ event_id: threadId });
925925
room.createThread(threadId, rootEvent, [rootEvent], false);
926926

927-
const timeoutFutureTxnId = client.makeTxnId();
927+
const timeoutDelayTxnId = client.makeTxnId();
928928
httpLookups.push({
929929
method: "PUT",
930-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutFutureTxnId}`,
931-
expectQueryParams: timeoutFutureOpts,
932-
data: { future_id: "f1" },
930+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${timeoutDelayTxnId}`,
931+
expectQueryParams: realTimeoutDelayOpts,
932+
data: { delay_id: "id1" },
933933
expectBody,
934934
});
935935

936-
const { future_id: timeoutFutureId } = await client._unstable_sendFuture(
936+
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedEvent(
937937
roomId,
938-
timeoutFutureOpts,
938+
timeoutDelayOpts,
939939
threadId,
940940
EventType.RoomMessage,
941941
{ ...content },
942-
timeoutFutureTxnId,
942+
timeoutDelayTxnId,
943943
);
944944

945-
const actionFutureTxnId = client.makeTxnId();
946-
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
945+
const actionDelayTxnId = client.makeTxnId();
947946
httpLookups.push({
948947
method: "PUT",
949-
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionFutureTxnId}`,
950-
expectQueryParams: actionFutureOpts,
951-
data: { future_id: "f2" },
948+
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${actionDelayTxnId}`,
949+
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
950+
data: { delay_id: "id2" },
952951
expectBody,
953952
});
954953

955-
await client._unstable_sendFuture(
954+
await client._unstable_sendDelayedEvent(
956955
roomId,
957-
actionFutureOpts,
956+
{ parent_delay_id: timeoutDelayId },
958957
threadId,
959958
EventType.RoomMessage,
960959
{ ...content },
961-
actionFutureTxnId,
960+
actionDelayTxnId,
962961
);
963962
});
964963

965-
it("can send a state future", async () => {
964+
it("can send a delayed state event", async () => {
966965
httpLookups = [];
967966
const content = { topic: "The year 2000" };
968967

969968
httpLookups.push({
970969
method: "PUT",
971970
path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`,
972-
expectQueryParams: timeoutFutureOpts,
973-
data: { future_id: "f1" },
971+
expectQueryParams: realTimeoutDelayOpts,
972+
data: { delay_id: "id1" },
974973
expectBody: content,
975974
});
976975

977-
const { future_id: timeoutFutureId } = await client._unstable_sendStateFuture(
976+
const { delay_id: timeoutDelayId } = await client._unstable_sendDelayedStateEvent(
978977
roomId,
979-
timeoutFutureOpts,
978+
timeoutDelayOpts,
980979
EventType.RoomTopic,
981980
{ ...content },
982981
);
983982

984-
const actionFutureOpts = { "org.matrix.msc4140.parent_future_id": timeoutFutureId };
985983
httpLookups.push({
986984
method: "PUT",
987985
path: `/rooms/${encodeURIComponent(roomId)}/state/m.room.topic/`,
988-
expectQueryParams: actionFutureOpts,
989-
data: { future_id: "f2" },
986+
expectQueryParams: { "org.matrix.msc4140.parent_delay_id": timeoutDelayId },
987+
data: { delay_id: "id2" },
990988
expectBody: content,
991989
});
992990

993-
await client._unstable_sendStateFuture(roomId, actionFutureOpts, EventType.RoomTopic, { ...content });
991+
await client._unstable_sendDelayedStateEvent(
992+
roomId,
993+
{ parent_delay_id: timeoutDelayId },
994+
EventType.RoomTopic,
995+
{ ...content },
996+
);
994997
});
995998

996-
it("can look up futures", async () => {
999+
it("can look up delayed events", async () => {
9971000
httpLookups = [
9981001
{
9991002
method: "GET",
10001003
prefix: unstableMSC4140Prefix,
1001-
path: "/future",
1004+
path: "/delayed_events",
10021005
data: [],
10031006
},
10041007
];
10051008

1006-
await client._unstable_getFutures();
1009+
await client._unstable_getDelayedEvents();
10071010
});
10081011

1009-
it("can update futures with their tokens", async () => {
1010-
const futureToken = "token";
1011-
const futureAction = UpdateFutureAction.Refresh;
1012+
it("can update delayed events", async () => {
1013+
const delayId = "id";
1014+
const action = UpdateDelayedEventAction.Refresh;
10121015
httpLookups = [
10131016
{
10141017
method: "POST",
10151018
prefix: unstableMSC4140Prefix,
1016-
path: "/update_future",
1019+
path: `/delayed_events/${encodeURIComponent(delayId)}`,
10171020
data: {
1018-
future_id: futureToken,
1019-
action: futureAction,
1021+
action,
10201022
},
10211023
},
10221024
];
10231025

1024-
await client._unstable_updateFuture(futureToken, futureAction);
1026+
await client._unstable_updateDelayedEvent(delayId, action);
10251027
});
10261028
});
10271029

0 commit comments

Comments
 (0)