mirror of https://github.com/vector-im/riot-web
Location (live) share replies now provide a fallback content (#8949)
* Implement location share reply fallback content * Replace single condition switch with ifpull/28217/head
parent
924865b315
commit
a2f31fdfb4
|
@ -19,10 +19,12 @@ import sanitizeHtml from "sanitize-html";
|
|||
import escapeHtml from "escape-html";
|
||||
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread";
|
||||
import { MsgType } from "matrix-js-sdk/src/@types/event";
|
||||
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
||||
|
||||
import { PERMITTED_URL_SCHEMES } from "../HtmlUtils";
|
||||
import { makeUserPermalink, RoomPermalinkCreator } from "./permalinks/Permalinks";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import { isSelfLocation } from "./location";
|
||||
|
||||
export function getParentEventId(ev?: MatrixEvent): string | undefined {
|
||||
if (!ev || ev.isRedacted()) return;
|
||||
|
@ -93,6 +95,15 @@ export function getNestedReplyText(
|
|||
const userLink = makeUserPermalink(ev.getSender());
|
||||
const mxid = ev.getSender();
|
||||
|
||||
if (M_BEACON_INFO.matches(ev.getType())) {
|
||||
const aTheir = isSelfLocation(ev.getContent()) ? "their" : "a";
|
||||
return {
|
||||
html: `<mx-reply><blockquote><a href="${evLink}">In reply to</a> <a href="${userLink}">${mxid}</a>`
|
||||
+ `<br>shared ${aTheir} live location.</blockquote></mx-reply>`,
|
||||
body: `> <${mxid}> shared ${aTheir} live location.\n\n`,
|
||||
};
|
||||
}
|
||||
|
||||
// This fallback contains text that is explicitly EN.
|
||||
switch (msgtype) {
|
||||
case MsgType.Text:
|
||||
|
@ -126,6 +137,13 @@ export function getNestedReplyText(
|
|||
+ `<br>sent a file.</blockquote></mx-reply>`;
|
||||
body = `> <${mxid}> sent a file.\n\n`;
|
||||
break;
|
||||
case MsgType.Location: {
|
||||
const aTheir = isSelfLocation(ev.getContent()) ? "their" : "a";
|
||||
html = `<mx-reply><blockquote><a href="${evLink}">In reply to</a> <a href="${userLink}">${mxid}</a>`
|
||||
+ `<br>shared ${aTheir} location.</blockquote></mx-reply>`;
|
||||
body = `> <${mxid}> shared ${aTheir} location.\n\n`;
|
||||
break;
|
||||
}
|
||||
case MsgType.Emote: {
|
||||
html = `<mx-reply><blockquote><a href="${evLink}">In reply to</a> * `
|
||||
+ `<a href="${userLink}">${mxid}</a><br>${html}</blockquote></mx-reply>`;
|
||||
|
|
|
@ -14,6 +14,10 @@ See the License for the specific language governing permissions and
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { IContent, MatrixEvent, MsgType } from "matrix-js-sdk/src/matrix";
|
||||
import { M_BEACON_INFO } from "matrix-js-sdk/src/@types/beacon";
|
||||
import { LocationAssetType, M_ASSET } from "matrix-js-sdk/src/@types/location";
|
||||
|
||||
import {
|
||||
getNestedReplyText,
|
||||
getParentEventId,
|
||||
|
@ -24,6 +28,22 @@ import {
|
|||
import { mkEvent } from "./test-utils";
|
||||
import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks";
|
||||
|
||||
function makeTestEvent(type: string, content: IContent): MatrixEvent {
|
||||
return mkEvent({
|
||||
event: true,
|
||||
type: type,
|
||||
user: "@user1:server",
|
||||
room: "!room1:server",
|
||||
content,
|
||||
});
|
||||
}
|
||||
|
||||
const mockPermalinkGenerator = {
|
||||
forEvent(eventId: string): string {
|
||||
return "$$permalink$$";
|
||||
},
|
||||
} as RoomPermalinkCreator;
|
||||
|
||||
// don't litter test console with logs
|
||||
jest.mock("matrix-js-sdk/src/logger");
|
||||
|
||||
|
@ -99,22 +119,29 @@ But this is not
|
|||
|
||||
describe("getNestedReplyText", () => {
|
||||
it("Returns valid reply fallback text for m.text msgtypes", () => {
|
||||
const event = mkEvent({
|
||||
event: true,
|
||||
type: "m.room.message",
|
||||
user: "@user1:server",
|
||||
room: "!room1:server",
|
||||
content: {
|
||||
body: "body",
|
||||
msgtype: "m.text",
|
||||
},
|
||||
const event = makeTestEvent(MsgType.Text, {
|
||||
body: "body",
|
||||
msgtype: "m.text",
|
||||
});
|
||||
|
||||
expect(getNestedReplyText(event, {
|
||||
forEvent(eventId: string): string {
|
||||
return "$$permalink$$";
|
||||
},
|
||||
} as RoomPermalinkCreator)).toMatchSnapshot();
|
||||
expect(getNestedReplyText(event, mockPermalinkGenerator)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
[
|
||||
["m.room.message", MsgType.Location, LocationAssetType.Pin],
|
||||
["m.room.message", MsgType.Location, LocationAssetType.Self],
|
||||
[M_BEACON_INFO.name, undefined, LocationAssetType.Pin],
|
||||
[M_BEACON_INFO.name, undefined, LocationAssetType.Self],
|
||||
].forEach(([type, msgType, assetType]) => {
|
||||
it(`should create the expected fallback text for ${assetType} ${type}/${msgType}`, () => {
|
||||
const event = makeTestEvent(type, {
|
||||
body: "body",
|
||||
msgtype: msgType,
|
||||
[M_ASSET.name]: { type: assetType },
|
||||
});
|
||||
|
||||
expect(getNestedReplyText(event, mockPermalinkGenerator)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -8,3 +8,39 @@ Object {
|
|||
"html": "<mx-reply><blockquote><a href=\\"$$permalink$$\\">In reply to</a> <a href=\\"https://matrix.to/#/@user1:server\\">@user1:server</a><br>body</blockquote></mx-reply>",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Reply getNestedReplyText should create the expected fallback text for m.pin m.room.message/m.location 1`] = `
|
||||
Object {
|
||||
"body": "> <@user1:server> shared a location.
|
||||
|
||||
",
|
||||
"html": "<mx-reply><blockquote><a href=\\"$$permalink$$\\">In reply to</a> <a href=\\"https://matrix.to/#/@user1:server\\">@user1:server</a><br>shared a location.</blockquote></mx-reply>",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Reply getNestedReplyText should create the expected fallback text for m.pin org.matrix.msc3672.beacon_info/undefined 1`] = `
|
||||
Object {
|
||||
"body": "> <@user1:server> shared a live location.
|
||||
|
||||
",
|
||||
"html": "<mx-reply><blockquote><a href=\\"$$permalink$$\\">In reply to</a> <a href=\\"https://matrix.to/#/@user1:server\\">@user1:server</a><br>shared a live location.</blockquote></mx-reply>",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Reply getNestedReplyText should create the expected fallback text for m.self m.room.message/m.location 1`] = `
|
||||
Object {
|
||||
"body": "> <@user1:server> shared their location.
|
||||
|
||||
",
|
||||
"html": "<mx-reply><blockquote><a href=\\"$$permalink$$\\">In reply to</a> <a href=\\"https://matrix.to/#/@user1:server\\">@user1:server</a><br>shared their location.</blockquote></mx-reply>",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Reply getNestedReplyText should create the expected fallback text for m.self org.matrix.msc3672.beacon_info/undefined 1`] = `
|
||||
Object {
|
||||
"body": "> <@user1:server> shared their live location.
|
||||
|
||||
",
|
||||
"html": "<mx-reply><blockquote><a href=\\"$$permalink$$\\">In reply to</a> <a href=\\"https://matrix.to/#/@user1:server\\">@user1:server</a><br>shared their live location.</blockquote></mx-reply>",
|
||||
}
|
||||
`;
|
||||
|
|
Loading…
Reference in New Issue