Skip to content

Commit

Permalink
make them clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRyanChama committed Mar 24, 2023
1 parent 7c50c10 commit 6386631
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/autocomplete/Autocompleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import AutocompleteProvider, { ICommand } from "./AutocompleteProvider";
import SpaceProvider from "./SpaceProvider";
import { TimelineRenderingType } from "../contexts/RoomContext";
import { filterBoolean } from "../utils/arrays";
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 @@ -442,6 +442,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 @@ -468,7 +468,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 @@ -285,12 +285,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 6386631

Please sign in to comment.