Skip to content

Commit

Permalink
GH-29: Fix urls in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
SetZero committed Feb 18, 2024
1 parent 0dff888 commit 21f3489
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const parseMessage = (message: string | undefined) => {
const parseUI = (message: string | undefined, onLoaded: () => void) => {
if (message && message.includes('<')) {
let messageParser = new MessageUIHelper(message, () => onLoaded());
let element = messageParser.build();

return { standalone: true, element: messageParser.build() };
return { standalone: messageParser.containsImages, element: element };
}

return { standalone: false, element: message };
Expand Down
6 changes: 6 additions & 0 deletions src/helper/MessageUIHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ import UrlPreview from '../components/UrlPreview';

export default class MessageUIHelper {
private input: string;
private _containsImages: boolean = false;
private loaded: (() => void) | undefined;

constructor(input: string, loaded?: () => void) {
this.input = input;
this.loaded = loaded;
}

get containsImages() {
return this._containsImages;
}

build() {
const options: HTMLReactParserOptions = {
replace: ({ name, attribs, children }: any) => {
switch (name) {
case 'img':
this._containsImages = true;
return (<Box>
<LightBoxImage src={attribs.src} />
</Box>);
Expand Down

0 comments on commit 21f3489

Please sign in to comment.