You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Add tests for sendEvent threadId handling (#2435)
* Add tests for sendEvent threadId handling * Fix sendEvent threadId relation support not adding `is_falling_back` field
This commit is contained in:
committed by
GitHub
parent
aa94d5d95c
commit
07189f0637
@ -87,7 +87,7 @@ describe("MatrixClient", function() {
|
|||||||
// }
|
// }
|
||||||
// items are popped off when processed and block if no items left.
|
// items are popped off when processed and block if no items left.
|
||||||
];
|
];
|
||||||
let acceptKeepalives;
|
let acceptKeepalives: boolean;
|
||||||
let pendingLookup = null;
|
let pendingLookup = null;
|
||||||
function httpReq(cb, method, path, qp, data, prefix) {
|
function httpReq(cb, method, path, qp, data, prefix) {
|
||||||
if (path === KEEP_ALIVE_PATH && acceptKeepalives) {
|
if (path === KEEP_ALIVE_PATH && acceptKeepalives) {
|
||||||
@ -127,7 +127,7 @@ describe("MatrixClient", function() {
|
|||||||
(next.error ? "BAD" : "GOOD") + " response",
|
(next.error ? "BAD" : "GOOD") + " response",
|
||||||
);
|
);
|
||||||
if (next.expectBody) {
|
if (next.expectBody) {
|
||||||
expect(next.expectBody).toEqual(data);
|
expect(data).toEqual(next.expectBody);
|
||||||
}
|
}
|
||||||
if (next.expectQueryParams) {
|
if (next.expectQueryParams) {
|
||||||
Object.keys(next.expectQueryParams).forEach(function(k) {
|
Object.keys(next.expectQueryParams).forEach(function(k) {
|
||||||
@ -777,7 +777,7 @@ describe("MatrixClient", function() {
|
|||||||
expectBody: content,
|
expectBody: content,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
await client.sendEvent(roomId, EventType.RoomMessage, content, txnId);
|
await client.sendEvent(roomId, EventType.RoomMessage, { ...content }, txnId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("overload with null threadId works", async () => {
|
it("overload with null threadId works", async () => {
|
||||||
@ -790,20 +790,99 @@ describe("MatrixClient", function() {
|
|||||||
expectBody: content,
|
expectBody: content,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
await client.sendEvent(roomId, null, EventType.RoomMessage, content, txnId);
|
await client.sendEvent(roomId, null, EventType.RoomMessage, { ...content }, txnId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("overload with threadId works", async () => {
|
it("overload with threadId works", async () => {
|
||||||
const eventId = "$eventId:example.org";
|
const eventId = "$eventId:example.org";
|
||||||
const txnId = client.makeTxnId();
|
const txnId = client.makeTxnId();
|
||||||
|
const threadId = "$threadId:server";
|
||||||
httpLookups = [{
|
httpLookups = [{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`,
|
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`,
|
||||||
data: { event_id: eventId },
|
data: { event_id: eventId },
|
||||||
expectBody: content,
|
expectBody: {
|
||||||
|
...content,
|
||||||
|
"m.relates_to": {
|
||||||
|
"event_id": threadId,
|
||||||
|
"is_falling_back": true,
|
||||||
|
"rel_type": "m.thread",
|
||||||
|
},
|
||||||
|
},
|
||||||
}];
|
}];
|
||||||
|
|
||||||
await client.sendEvent(roomId, "$threadId:server", EventType.RoomMessage, content, txnId);
|
await client.sendEvent(roomId, threadId, EventType.RoomMessage, { ...content }, txnId);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add thread relation if threadId is passed and the relation is missing", async () => {
|
||||||
|
const eventId = "$eventId:example.org";
|
||||||
|
const threadId = "$threadId:server";
|
||||||
|
const txnId = client.makeTxnId();
|
||||||
|
|
||||||
|
const room = new Room(roomId, client, userId);
|
||||||
|
store.getRoom.mockReturnValue(room);
|
||||||
|
|
||||||
|
const rootEvent = new MatrixEvent({ event_id: threadId });
|
||||||
|
room.createThread(threadId, rootEvent, [rootEvent], false);
|
||||||
|
|
||||||
|
httpLookups = [{
|
||||||
|
method: "PUT",
|
||||||
|
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`,
|
||||||
|
data: { event_id: eventId },
|
||||||
|
expectBody: {
|
||||||
|
...content,
|
||||||
|
"m.relates_to": {
|
||||||
|
"m.in_reply_to": {
|
||||||
|
event_id: threadId,
|
||||||
|
},
|
||||||
|
"event_id": threadId,
|
||||||
|
"is_falling_back": true,
|
||||||
|
"rel_type": "m.thread",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
|
||||||
|
await client.sendEvent(roomId, threadId, EventType.RoomMessage, { ...content }, txnId);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should add thread relation if threadId is passed and the relation is missing with reply", async () => {
|
||||||
|
const eventId = "$eventId:example.org";
|
||||||
|
const threadId = "$threadId:server";
|
||||||
|
const txnId = client.makeTxnId();
|
||||||
|
|
||||||
|
const content = {
|
||||||
|
body,
|
||||||
|
"m.relates_to": {
|
||||||
|
"m.in_reply_to": {
|
||||||
|
event_id: "$other:event",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const room = new Room(roomId, client, userId);
|
||||||
|
store.getRoom.mockReturnValue(room);
|
||||||
|
|
||||||
|
const rootEvent = new MatrixEvent({ event_id: threadId });
|
||||||
|
room.createThread(threadId, rootEvent, [rootEvent], false);
|
||||||
|
|
||||||
|
httpLookups = [{
|
||||||
|
method: "PUT",
|
||||||
|
path: `/rooms/${encodeURIComponent(roomId)}/send/m.room.message/${txnId}`,
|
||||||
|
data: { event_id: eventId },
|
||||||
|
expectBody: {
|
||||||
|
...content,
|
||||||
|
"m.relates_to": {
|
||||||
|
"m.in_reply_to": {
|
||||||
|
event_id: "$other:event",
|
||||||
|
},
|
||||||
|
"event_id": threadId,
|
||||||
|
"is_falling_back": false,
|
||||||
|
"rel_type": "m.thread",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}];
|
||||||
|
|
||||||
|
await client.sendEvent(roomId, threadId, EventType.RoomMessage, { ...content }, txnId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3772,17 +3772,20 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
// If we expect that an event is part of a thread but is missing the relation
|
// If we expect that an event is part of a thread but is missing the relation
|
||||||
// we need to add it manually, as well as the reply fallback
|
// we need to add it manually, as well as the reply fallback
|
||||||
if (threadId && !content["m.relates_to"]?.rel_type) {
|
if (threadId && !content["m.relates_to"]?.rel_type) {
|
||||||
|
const isReply = !!content["m.relates_to"]?.["m.in_reply_to"];
|
||||||
content["m.relates_to"] = {
|
content["m.relates_to"] = {
|
||||||
...content["m.relates_to"],
|
...content["m.relates_to"],
|
||||||
"rel_type": THREAD_RELATION_TYPE.name,
|
"rel_type": THREAD_RELATION_TYPE.name,
|
||||||
"event_id": threadId,
|
"event_id": threadId,
|
||||||
|
// Set is_falling_back to true unless this is actually intended to be a reply
|
||||||
|
"is_falling_back": !isReply,
|
||||||
};
|
};
|
||||||
const thread = this.getRoom(roomId)?.getThread(threadId);
|
const thread = this.getRoom(roomId)?.getThread(threadId);
|
||||||
if (thread) {
|
if (thread && !isReply) {
|
||||||
content["m.relates_to"]["m.in_reply_to"] = {
|
content["m.relates_to"]["m.in_reply_to"] = {
|
||||||
"event_id": thread.lastReply((ev: MatrixEvent) => {
|
"event_id": thread.lastReply((ev: MatrixEvent) => {
|
||||||
return ev.isRelation(THREAD_RELATION_TYPE.name) && !ev.status;
|
return ev.isRelation(THREAD_RELATION_TYPE.name) && !ev.status;
|
||||||
})?.getId(),
|
})?.getId() ?? threadId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4031,7 +4034,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
$txnId: txnId,
|
$txnId: txnId,
|
||||||
};
|
};
|
||||||
|
|
||||||
let path;
|
let path: string;
|
||||||
|
|
||||||
if (event.isState()) {
|
if (event.isState()) {
|
||||||
let pathTemplate = "/rooms/$roomId/state/$eventType";
|
let pathTemplate = "/rooms/$roomId/state/$eventType";
|
||||||
|
@ -139,10 +139,10 @@ export const getTextForLocationEvent = (
|
|||||||
/**
|
/**
|
||||||
* Generates the content for a Location event
|
* Generates the content for a Location event
|
||||||
* @param uri a geo:// uri for the location
|
* @param uri a geo:// uri for the location
|
||||||
* @param ts the timestamp when the location was correct (milliseconds since
|
* @param timestamp the timestamp when the location was correct (milliseconds since
|
||||||
* the UNIX epoch)
|
* the UNIX epoch)
|
||||||
* @param description the (optional) label for this location on the map
|
* @param description the (optional) label for this location on the map
|
||||||
* @param asset_type the (optional) asset type of this location e.g. "m.self"
|
* @param assetType the (optional) asset type of this location e.g. "m.self"
|
||||||
* @param text optional. A text for the location
|
* @param text optional. A text for the location
|
||||||
*/
|
*/
|
||||||
export const makeLocationContent = (
|
export const makeLocationContent = (
|
||||||
|
Reference in New Issue
Block a user