Skip to content

Commit

Permalink
Added empty chat placeholder; Cleanup channel creation over peer; Fix…
Browse files Browse the repository at this point in the history
…ed broken upload message for community owner;
  • Loading branch information
stef-coenen committed Oct 24, 2024
1 parent c7cde00 commit e9de31a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ const CommunityTextMessageBody = ({
>
<div className="flex flex-col md:flex-row md:flex-wrap md:gap-2">
<div className="flex w-full min-w-0 flex-col gap-1">
{/* {content.replyId ? <EmbeddedMessageWithId msgId={content.replyId} /> : null} */}

<MessageTextRenderer
community={community}
message={content.message}
Expand Down Expand Up @@ -190,7 +188,6 @@ const MessageTextRenderer = ({
}).fetch;

if (!message) return null;

return (
<RichTextRenderer
body={message}
Expand All @@ -204,11 +201,7 @@ const MessageTextRenderer = ({
'value' in attributes &&
typeof attributes.value === 'string'
) {
const tagGuid =
('uniqueId' in attributes &&
typeof attributes.uniqueId === 'string' &&
attributes.uniqueId) ||
formatGuidId(toGuidId(attributes.value));
const tagGuid = formatGuidId(toGuidId(attributes.value));

const hasChannel = !!channels?.find((channel) =>
stringGuidsEqual(channel.fileMetadata.appData.uniqueId, tagGuid)
Expand All @@ -217,7 +210,7 @@ const MessageTextRenderer = ({
if (hasChannel) {
return (
<Link
to={`${COMMUNITY_ROOT}/${community?.fileMetadata.appData.uniqueId}/${tagGuid}`}
to={`${COMMUNITY_ROOT}/${community?.fileMetadata.senderOdinId}/${community?.fileMetadata.appData.uniqueId}/${tagGuid}`}
className="break-all text-primary hover:underline"
>
#{attributes.value.trim()}{' '}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ export const CommunityHistory = ({
}, [messages, origin]) || [];

useEffect(() => {
if (
setIsEmptyChat &&
isFetched &&
(!flattenedMsgs || flattenedMsgs?.filter((msg) => msg.fileId).length === 0)
)
if (setIsEmptyChat && isFetched && (!flattenedMsgs || flattenedMsgs.length === 0))
setIsEmptyChat(true);
}, [isFetched, flattenedMsgs]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ export const useCommunityMessage = (props?: {
);
}
},
onError: (err, messageParams) => {

Check warning on line 229 in packages/community-app/src/hooks/community/messages/useCommunityMessage.ts

View workflow job for this annotation

GitHub Actions / build

'messageParams' is defined but never used
console.error('Failed to update the chat message', err);
},
}),
update: useMutation({
mutationFn: updateMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const uploadCommunityMessage = async (

const recipientStatus = uploadResult.recipientStatus;
if (
recipientStatus &&
Object.values(recipientStatus).some(
(status) => status.toString().toLowerCase() === TransferUploadStatus.EnqueuedFailed
)
Expand Down
2 changes: 1 addition & 1 deletion packages/community-app/src/providers/CommunityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export const saveCommunityChannel = async (
description: '',
});
const uploadMetadata: UploadFileMetadata = {
allowDistribution: false,
allowDistribution: true,
appData: {
uniqueId: uniqueId,
groupId: communityId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useMarkCommunityAsRead } from '../../hooks/community/useMarkCommunityAs
import { CommunityCatchup } from '../../components/Community/CommunityCatchup';

export const CommunityChannelDetail = () => {
const [isEmtpyChannel, setIsEmptyChannel] = useState<boolean>(false);
const { odinKey, communityKey: communityId, channelKey: channelId, threadKey } = useParams();
const { data: community, isFetched } = useCommunity({ odinId: odinKey, communityId }).fetch;
const navigate = useNavigate();
Expand Down Expand Up @@ -73,21 +74,27 @@ export const CommunityChannelDetail = () => {
<div className="flex h-full flex-grow flex-col overflow-hidden">
<CommunityChannelHeader community={community || undefined} channel={channelDsr} />
<ErrorBoundary>
<CommunityHistory
community={community || undefined}
channel={channelDsr || undefined}
doOpenThread={(thread) =>
navigate(
`${COMMUNITY_ROOT}/${odinKey}/${communityId}/${channelId}/${thread.fileMetadata.appData.uniqueId}/thread`
)
}
/>
{isEmtpyChannel ? (
<EmptyChannel channel={channelDsr} />
) : (
<CommunityHistory
community={community || undefined}
channel={channelDsr || undefined}
doOpenThread={(thread) =>
navigate(
`${COMMUNITY_ROOT}/${odinKey}/${communityId}/${channelId}/${thread.fileMetadata.appData.uniqueId}/thread`
)
}
setIsEmptyChat={setIsEmptyChannel}
/>
)}
</ErrorBoundary>
<ErrorBoundary>
<MessageComposer
community={community || undefined}
channel={channelDsr || undefined}
key={channelId}
onSend={() => setIsEmptyChannel(false)}
/>
</ErrorBoundary>
</div>
Expand Down Expand Up @@ -298,3 +305,25 @@ const CommunityThread = ({
</div>
);
};

const EmptyChannel = ({ channel }: { channel: HomebaseFile<CommunityChannel> | undefined }) => {
const { odinKey, communityKey } = useParams();

if (!channel) return null;
return (
<div className="flex h-full flex-grow flex-col-reverse">
<div className="p-5">
<p className="mb-2 text-2xl"># {channel.fileMetadata.appData.content?.title}</p>
<Link
className="text-primary hover:underline"
to={`${COMMUNITY_ROOT}/${odinKey}/${communityKey}/direct/${channel.fileMetadata.senderOdinId}`}
>
@<AuthorName odinId={channel.fileMetadata.senderOdinId} excludeLink={true} />
</Link>{' '}
{t('created this channel on')}{' '}
{formatDateExludingYearIfCurrent(new Date(channel.fileMetadata.created))}
<p>{channel.fileMetadata.appData.content?.description}</p>
</div>
</div>
);
};

0 comments on commit e9de31a

Please sign in to comment.