Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Pinned Messages in E2E rooms #25325

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bcc31d0
useDecryptMessage hook on attachments for encrypted messages
yash-rajpal Apr 27, 2022
e59a47c
add roomId to stories
yash-rajpal Apr 27, 2022
716f0b6
fix lint
yash-rajpal Apr 27, 2022
c41aa2e
fix typescript
yash-rajpal Apr 27, 2022
d68b5e8
resolve conflicts
yash-rajpal Aug 17, 2022
e3c2e75
use new hook to decrypt
yash-rajpal Aug 18, 2022
371e790
fix type errors & remove old hook
yash-rajpal Aug 18, 2022
1c963fb
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Aug 18, 2022
c5edc24
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Aug 23, 2022
f1d68c5
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Aug 23, 2022
6a462ce
rename variable to make better sense
yash-rajpal Aug 23, 2022
e604faa
avoid prop drilling for rid, use hook
yash-rajpal Aug 24, 2022
6c2ffc0
remove log
yash-rajpal Aug 24, 2022
b18cc90
Merge branch 'develop' into improve/e2e-pinned-message
gabriellsh Sep 6, 2022
0ff1af1
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Sep 7, 2022
3c218cc
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Sep 13, 2022
fb2de0c
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Sep 14, 2022
a2f26c4
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Sep 14, 2022
945f052
fix CI
yash-rajpal Sep 14, 2022
706a89f
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Sep 20, 2022
d5f98c8
decrypt pinned message on fetch
yash-rajpal Sep 20, 2022
b31a402
revert old implementation
yash-rajpal Sep 20, 2022
1c122d8
revert mocking test dep
yash-rajpal Sep 20, 2022
a89911c
remove logs & fix lint
yash-rajpal Sep 20, 2022
d84af8a
remove redundant guard clause
yash-rajpal Sep 20, 2022
6533c18
Merge branch 'develop' into improve/e2e-pinned-message
yash-rajpal Sep 20, 2022
5b50365
fix conflicts
yash-rajpal May 7, 2024
0327ae9
remove file
yash-rajpal May 7, 2024
832cd64
types
yash-rajpal May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/meteor/app/message-pin/server/pinMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Meteor.methods({
author_icon: getUserAvatarURL(originalMessage.u.username),
ts: originalMessage.ts,
attachments: recursiveRemove(attachments),
t: originalMessage.t,
},
],
});
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/ui-message/client/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
{{/each}}
{{/if}}
{{#if hasAttachments}}
{{> reactAttachments attachments=msg.attachments file=msg.file }}
{{> reactAttachments attachments=msg.attachments file=msg.file rid=msg.rid }}
{{/if}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ const message = {
attachments: [field, image],
};

export const Default: ComponentStory<typeof Attachments> = () => <Attachments attachments={message.attachments} />;
export const Default: ComponentStory<typeof Attachments> = () => <Attachments attachments={message.attachments} rid='GENERAL' />;

export const Fields: ComponentStory<typeof Attachments> = () => <Attachments attachments={[field]} />;
export const Fields: ComponentStory<typeof Attachments> = () => <Attachments attachments={[field]} rid='GENERAL' />;

export const FailingImage: ComponentStory<typeof Attachments> = () => (
<Attachments attachments={[{ ...image, image_url: 'invalid.url' } as FileAttachmentProps]} />
<Attachments attachments={[{ ...image, image_url: 'invalid.url' } as FileAttachmentProps]} rid='GENERAL' />
);

export const Image: ComponentStory<typeof Attachments> = () => <Attachments attachments={[image]} />;
export const Image: ComponentStory<typeof Attachments> = () => <Attachments attachments={[image]} rid='GENERAL' />;

export const Video: ComponentStory<typeof Attachments> = () => <Attachments attachments={[video]} file={{} as FileProp} />;
export const Video: ComponentStory<typeof Attachments> = () => <Attachments attachments={[video]} file={{} as FileProp} rid='GENERAL' />;

export const Audio: ComponentStory<typeof Attachments> = () => <Attachments attachments={[audio]} file={{} as FileProp} />;
export const Audio: ComponentStory<typeof Attachments> = () => <Attachments attachments={[audio]} file={{} as FileProp} rid='GENERAL' />;
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import React, { FC } from 'react';
import { useBlockRendered } from '../hooks/useBlockRendered';
import Item from './Item';

const Attachments: FC<{ attachments: Array<MessageAttachmentBase>; file?: FileProp }> = ({ attachments = null, file }): any => {
const Attachments: FC<{ attachments: Array<MessageAttachmentBase>; file?: FileProp; rid: string }> = ({
attachments = null,
file,
rid,
}): any => {
const { className, ref } = useBlockRendered<HTMLDivElement>();
return (
<>
<div className={className} ref={ref} />
{attachments?.map((attachment, index) => (
<Item key={index} file={file} attachment={attachment} />
<Item key={index} file={file} attachment={attachment} rid={rid} />
))}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isActionAttachment, MarkdownFields, MessageAttachmentDefault } from '@rocket.chat/core-typings';
import { IMessage, isActionAttachment, MarkdownFields, MessageAttachmentDefault } from '@rocket.chat/core-typings';
import React, { FC, ReactNode, ComponentProps } from 'react';

import { useDecryptedMessage } from '../../../hooks/useDecryptedMessage';
import MarkdownText from '../../MarkdownText';
import { ActionAttachment } from './ActionAttachtment';
import AttachmentAuthor from './Attachment/AttachmentAuthor';
Expand All @@ -23,9 +24,11 @@ const applyMarkdownIfRequires = (
variant: ComponentProps<typeof MarkdownText>['variant'] = 'inline',
): ReactNode => (list?.includes(key) ? <MarkdownText parseEmoji variant={variant} content={text} /> : text);

const DefaultAttachment: FC<MessageAttachmentDefault> = (attachment) => {
const DefaultAttachment: FC<MessageAttachmentDefault & { rid: string }> = (attachment) => {
const [collapsed, collapse] = useCollapse(!!attachment.collapsed);

const decryptedAttachmentText = useDecryptedMessage({ ...attachment, msg: attachment.text } as IMessage);

return (
<AttachmentBlock
color={attachment.color}
Expand Down Expand Up @@ -68,8 +71,8 @@ const DefaultAttachment: FC<MessageAttachmentDefault> = (attachment) => {
)}
{!collapsed && (
<>
{attachment.text && (
<AttachmentText>{applyMarkdownIfRequires(attachment.mrkdwn_in, 'text', attachment.text, 'document')}</AttachmentText>
{decryptedAttachmentText && (
<AttachmentText>{applyMarkdownIfRequires(attachment.mrkdwn_in, 'text', decryptedAttachmentText, 'document')}</AttachmentText>
yash-rajpal marked this conversation as resolved.
Show resolved Hide resolved
)}
{/* {attachment.fields && <FieldsAttachment fields={attachment.mrkdwn_in?.includes('fields') ? attachment.fields.map(({ value, ...rest }) => ({ ...rest, value: <MarkdownText withRichContent={null} content={value} /> })) : attachment.fields} />} */}
{attachment.fields && (
Expand Down
6 changes: 3 additions & 3 deletions apps/meteor/client/components/message/Attachments/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import DefaultAttachment from './DefaultAttachment';
import { FileAttachment } from './Files';
import { QuoteAttachment } from './QuoteAttachment';

const Item: FC<{ attachment: MessageAttachmentBase; file?: FileProp | undefined }> = ({ attachment, file }) => {
const Item: FC<{ attachment: MessageAttachmentBase; file?: FileProp | undefined; rid: string }> = ({ attachment, file, rid }) => {
if (isFileAttachment(attachment) && file) {
return <FileAttachment {...attachment} file={file} />;
}

if (isQuoteAttachment(attachment)) {
return <QuoteAttachment {...attachment} />;
return <QuoteAttachment {...attachment} rid={rid} />;
}

return <DefaultAttachment {...(attachment as any)} />;
return <DefaultAttachment {...(attachment as any)} rid={rid} />;
};

export default memo(Item);
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ const hover = css`
}
`;

export const QuoteAttachment: FC<MessageQuoteAttachment> = ({
export const QuoteAttachment: FC<MessageQuoteAttachment & { rid: string }> = ({
author_icon: url,
author_name: name,
author_link: authorLink,
message_link: messageLink,
ts,
text,
attachments,
rid,
}) => {
const format = useTimeAgo();
return (
Expand Down Expand Up @@ -60,7 +61,7 @@ export const QuoteAttachment: FC<MessageQuoteAttachment> = ({
<MarkdownText parseEmoji variant='document' content={text} />
{attachments && (
<AttachmentInner>
<Attachments attachments={attachments} />
<Attachments attachments={attachments} rid={rid} />
</AttachmentInner>
)}
</AttachmentDetails>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const MessageContent: FC<{ message: IMessage; sequential: boolean; subscription?
<MessageBlockUiKit mid={message._id} blocks={message.blocks} appId rid={message.rid} />
</MessageBlock>
)}
{messageAttachments && <Attachments attachments={messageAttachments} file={message.file} />}
{messageAttachments && <Attachments attachments={messageAttachments} file={message.file} rid={message.rid} />}

{oembedIsEnabled && !!message.urls?.length && <PreviewList urls={message.urls} />}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const MessageSystem: FC<{ message: IMessage }> = ({ message }) => {
</MessageSystemBlock>
{message.attachments && (
<MessageSystemBlock>
<Attachments attachments={message.attachments} file={message.file} />
<Attachments attachments={message.attachments} file={message.file} rid={message.rid} />
</MessageSystemBlock>
)}
{message.actionLinks?.length && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { IMessage } from '../IMessage';
import type { FieldProps } from './FieldProps';
import type { Dimensions } from './Files/Dimensions';
import type { MessageAttachmentBase } from './MessageAttachmentBase';
Expand Down Expand Up @@ -25,6 +26,7 @@ export type MessageAttachmentDefault = {

color?: string;

t?: IMessage['t'];
translations?: {
[language: string]: string;
};
Expand Down