Skip to content

Commit a9b950c

Browse files
make them clickable
1 parent 49e8fc1 commit a9b950c

File tree

8 files changed

+32
-10
lines changed

8 files changed

+32
-10
lines changed

src/HtmlUtils.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op
617617

618618
const match = BIGEMOJI_REGEX.exec(contentBodyTrimmed);
619619
const matched = match && match[0] && match[0].length === contentBodyTrimmed.length;
620-
emojiBody = (matched || isAllHtmlEmoji);
620+
emojiBody = matched || isAllHtmlEmoji;
621621
}
622622

623623
const className = classNames({

src/autocomplete/Autocompleter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { timeout } from "../utils/promise";
2727
import AutocompleteProvider, { ICommand } from "./AutocompleteProvider";
2828
import SpaceProvider from "./SpaceProvider";
2929
import { TimelineRenderingType } from "../contexts/RoomContext";
30+
import { ICustomEmoji } from "../emojipicker/customemoji";
3031

3132
export interface ISelectionRange {
3233
beginning?: boolean; // whether the selection is in the first block of the editor or not

src/components/views/messages/TextualBody.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
439439
let target = e.target as HTMLLinkElement;
440440
// links processed by linkifyjs have their own handler so don't handle those here
441441
if (target.classList.contains(linkifyOpts.className as string)) return;
442+
// handle clicking packs
443+
const packUrl = target.getAttribute("data-mx-pack-url");
444+
if (packUrl) {
445+
// it could be converted to a localHref -> therefore handle locally
446+
e.preventDefault();
447+
window.location.hash = tryTransformPermalinkToLocalHref(packUrl);
448+
}
442449
if (target.nodeName !== "A") {
443450
// Jump to parent as the `<a>` may contain children, e.g. an anchor wrapping an inline code section
444451
target = target.closest<HTMLLinkElement>("a");

src/editor/autocomplete.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,14 @@ export default class AutocompleteWrapperModel {
109109
// command needs special handling for auto complete, but also renders as plain texts
110110
return [(this.partCreator as CommandPartCreator).command(text)];
111111
case "customEmoji":
112-
return [this.partCreator.customEmoji(text, completionId, completion.customEmoji?.roomId, completion.customEmoji?.eventId)];
112+
return [
113+
this.partCreator.customEmoji(
114+
text,
115+
completionId,
116+
completion.customEmoji?.roomId,
117+
completion.customEmoji?.eventId,
118+
),
119+
];
113120
default:
114121
// used for emoji and other plain text completion replacement
115122
return this.partCreator.plainWithEmoji(text);

src/editor/parts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ class CustomEmojiPart extends PillPart implements ICustomEmojiPart {
466466
return {
467467
...super.serialize(),
468468
roomId: this.roomId,
469-
eventId: this.eventId
469+
eventId: this.eventId,
470470
};
471471
}
472472
}

src/editor/serialize.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ export function mdSerialize(model: EditorModel): string {
5353
`[${part.text.replace(/[[\\\]]/g, (c) => "\\" + c)}](${makeGenericPermalink(part.resourceId)})`
5454
);
5555
case Type.CustomEmoji:
56-
const customEmojiPart : ICustomEmojiPart = part;
57-
if (customEmojiPart.roomId) {
58-
const permalink = makeRoomPermalink(customEmojiPart.roomId, customEmojiPart.eventId);
56+
if ((part as ICustomEmojiPart).roomId) {
57+
const permalink = makeRoomPermalink(
58+
(part as ICustomEmojiPart).roomId,
59+
(part as ICustomEmojiPart).eventId,
60+
);
5961
return (
6062
html +
6163
`<img data-mx-emoticon height="18" src="${encodeURI(part.resourceId)}"` +

src/emojipicker/customemoji.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { JoinRule, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
1919
export function loadImageSet(imageSetEvent: MatrixEvent, room?: Room): ICustomEmoji[] {
2020
const loadedImages: ICustomEmoji[] = [];
2121
const images = imageSetEvent.getContent().images;
22-
let eventId : string | undefined;
23-
let roomId : string | undefined;
22+
let eventId: string | undefined;
23+
let roomId: string | undefined;
2424
if (!images) {
2525
return [];
2626
}

src/utils/permalinks/Permalinks.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,17 @@ export function makeRoomPermalink(roomId: string, eventId?: string): string {
282282

283283
// If the roomId isn't actually a room ID, don't try to list the servers.
284284
// Aliases are already routable, and don't need extra information.
285-
if (roomId[0] !== "!") return eventId ? getPermalinkConstructor().forRoom(roomId, []) : getPermalinkConstructor().forEvent(roomId, eventId, []);
285+
if (roomId[0] !== "!")
286+
return eventId
287+
? getPermalinkConstructor().forRoom(roomId, [])
288+
: getPermalinkConstructor().forEvent(roomId, eventId, []);
286289

287290
const client = MatrixClientPeg.get();
288291
const room = client.getRoom(roomId);
289292
if (!room) {
290-
return eventId ? getPermalinkConstructor().forRoom(roomId, []) : getPermalinkConstructor().forEvent(roomId, eventId, []);
293+
return eventId
294+
? getPermalinkConstructor().forRoom(roomId, [])
295+
: getPermalinkConstructor().forEvent(roomId, eventId, []);
291296
}
292297
const permalinkCreator = new RoomPermalinkCreator(room);
293298
permalinkCreator.load();

0 commit comments

Comments
 (0)