Skip to content

Commit

Permalink
make them clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
tenpura-shrimp committed Mar 13, 2023
1 parent 7619fec commit 00cc499
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/HtmlUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ export function bodyToHtml(content: IContent, highlights: Optional<string[]>, op

const match = BIGEMOJI_REGEX.exec(contentBodyTrimmed);
const matched = match && match[0] && match[0].length === contentBodyTrimmed.length;
emojiBody = (matched || isAllHtmlEmoji);
emojiBody = matched || isAllHtmlEmoji;
}

const className = classNames({
Expand Down
1 change: 1 addition & 0 deletions src/autocomplete/Autocompleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { timeout } from "../utils/promise";
import AutocompleteProvider, { ICommand } from "./AutocompleteProvider";
import SpaceProvider from "./SpaceProvider";
import { TimelineRenderingType } from "../contexts/RoomContext";
import { ICustomEmoji } from "../emojipicker/customemoji";

export interface ISelectionRange {
beginning?: boolean; // whether the selection is in the first block of the editor or not
Expand Down
7 changes: 7 additions & 0 deletions src/components/views/messages/TextualBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,13 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
let target = e.target as HTMLLinkElement;
// links processed by linkifyjs have their own handler so don't handle those here
if (target.classList.contains(linkifyOpts.className as string)) return;
// handle clicking packs
const packUrl = target.getAttribute("data-mx-pack-url");
if (packUrl) {
// it could be converted to a localHref -> therefore handle locally
e.preventDefault();
window.location.hash = tryTransformPermalinkToLocalHref(packUrl);
}
if (target.nodeName !== "A") {
// Jump to parent as the `<a>` may contain children, e.g. an anchor wrapping an inline code section
target = target.closest<HTMLLinkElement>("a");
Expand Down
9 changes: 8 additions & 1 deletion src/editor/autocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ export default class AutocompleteWrapperModel {
// command needs special handling for auto complete, but also renders as plain texts
return [(this.partCreator as CommandPartCreator).command(text)];
case "customEmoji":
return [this.partCreator.customEmoji(text, completionId, completion.customEmoji?.roomId, completion.customEmoji?.eventId)];
return [
this.partCreator.customEmoji(
text,
completionId,
completion.customEmoji?.roomId,
completion.customEmoji?.eventId,
),
];
default:
// used for emoji and other plain text completion replacement
return this.partCreator.plainWithEmoji(text);
Expand Down
2 changes: 1 addition & 1 deletion src/editor/parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class CustomEmojiPart extends PillPart implements ICustomEmojiPart {
return {
...super.serialize(),
roomId: this.roomId,
eventId: this.eventId
eventId: this.eventId,
};
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/editor/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export function mdSerialize(model: EditorModel): string {
`[${part.text.replace(/[[\\\]]/g, (c) => "\\" + c)}](${makeGenericPermalink(part.resourceId)})`
);
case Type.CustomEmoji:
const customEmojiPart : ICustomEmojiPart = part;
if (customEmojiPart.roomId) {
const permalink = makeRoomPermalink(customEmojiPart.roomId, customEmojiPart.eventId);
if ((part as ICustomEmojiPart).roomId) {
const permalink = makeRoomPermalink(
(part as ICustomEmojiPart).roomId,
(part as ICustomEmojiPart).eventId,
);
return (
html +
`<img data-mx-emoticon height="18" src="${encodeURI(part.resourceId)}"` +
Expand Down
4 changes: 2 additions & 2 deletions src/emojipicker/customemoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { JoinRule, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
export function loadImageSet(imageSetEvent: MatrixEvent, room?: Room): ICustomEmoji[] {
const loadedImages: ICustomEmoji[] = [];
const images = imageSetEvent.getContent().images;
let eventId : string | undefined;
let roomId : string | undefined;
let eventId: string | undefined;
let roomId: string | undefined;
if (!images) {
return [];
}
Expand Down
9 changes: 7 additions & 2 deletions src/utils/permalinks/Permalinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,17 @@ export function makeRoomPermalink(roomId: string, eventId?: string): string {

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

const client = MatrixClientPeg.get();
const room = client.getRoom(roomId);
if (!room) {
return eventId ? getPermalinkConstructor().forRoom(roomId, []) : getPermalinkConstructor().forEvent(roomId, eventId, []);
return eventId
? getPermalinkConstructor().forRoom(roomId, [])
: getPermalinkConstructor().forEvent(roomId, eventId, []);
}
const permalinkCreator = new RoomPermalinkCreator(room);
permalinkCreator.load();
Expand Down

0 comments on commit 00cc499

Please sign in to comment.