Skip to content

Commit

Permalink
Community storm day 2 (#469)
Browse files Browse the repository at this point in the history
* TransformFn caller check for empty pages array;

* Nicer `@channel` support;

* Better check for contentIsComplete;

* Cleanup community RTR

* Fix for link previews;
stef-coenen authored Dec 12, 2024
1 parent c2f2444 commit 5eede24
Showing 11 changed files with 78 additions and 53 deletions.
2 changes: 1 addition & 1 deletion packages/apps/chat-app/src/hooks/chat/useChatMessages.ts
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ export const updateCacheChatMessages = (
includeMetadataHeader: boolean;
}>
>(['chat-messages', conversationId]);
if (!currentData) return;
if (!currentData || !currentData?.pages?.length) return;

const newData = transformFn(currentData);
if (!newData) return;
2 changes: 1 addition & 1 deletion packages/apps/chat-app/src/hooks/chat/useConversations.ts
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ export const updateCacheConversations = (
}>
>(['conversations']);

if (!existingConversations) return;
if (!existingConversations || !existingConversations?.pages?.length) return;

const newData = transformFn(existingConversations);
if (!newData) return;
Original file line number Diff line number Diff line change
@@ -281,16 +281,26 @@ const MessageTextRenderer = ({
'value' in attributes &&
typeof attributes.value === 'string'
) {
return (
<a
href={`https://${attributes.value}`}
target="_blank"
rel="noreferrer noopener"
className="break-words text-primary hover:underline"
>
@{attributes.value.replaceAll('@', '')}
</a>
);
const domainRegex =
/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9]{2,25}(?::\d{1,5})?$/i;

if (domainRegex.test(attributes.value))
return (
<a
href={`https://${attributes.value}`}
target="_blank"
rel="noreferrer noopener"
className="break-words text-primary hover:underline"
>
@{attributes.value.replaceAll('@', '')}
</a>
);
else
return (
<span className="break-all text-primary">
@{attributes.value.replaceAll('@', '')}
</span>
);
}

return null;
@@ -312,13 +322,11 @@ const CommunityMediaMessageBody = ({
return (
<div className={`relative w-full max-w-[75vw] rounded-lg md:max-w-[90%]`}>
{hasACaption ? (
<div className="flex min-w-0 flex-col md:flex-row md:justify-between">
<MessageTextRenderer
community={community}
message={content.message}
className={`whitespace-pre-wrap break-words`}
/>
</div>
<MessageTextRenderer
community={community}
message={content.message}
className={`whitespace-pre-wrap break-words`}
/>
) : null}
<CommunityMedia
msg={msg}
@@ -341,7 +349,6 @@ const CommunityMessageThreadSummary = ({

const {
data: messages,
isFetched,
isFetching,
isRefetching,
refetch,
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ export const updateCacheCommunityMessages = (
includeMetadataHeader: boolean;
}>
>(queryKey);
if (!currentData || !currentData.pages) return;
if (!currentData || !currentData.pages?.length) return;

const newData = transformFn(currentData);
if (!newData || !newData.pages) return;
@@ -374,7 +374,7 @@ export const internalInsertNewMessage = (

const newData = {
...extistingMessages,
pages: extistingMessages?.pages?.map((page, index) => {
pages: extistingMessages.pages.map((page, index) => {
if (isNewFile) {
const filteredSearchResults = page.searchResults.filter(
// Remove messages with the same fileId but more importantly uniqueId so we avoid duplicates with the optimistic update
@@ -494,7 +494,7 @@ export const internalRemoveMessage = (
) => {
return {
...extistingMessages,
pages: extistingMessages?.pages?.map((page) => {
pages: extistingMessages.pages.map((page) => {
return {
...page,
searchResults: page.searchResults.filter(
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ export const updateCachePendingConnections = (
const queryData = queryClient.getQueryData<InfiniteData<PagedResult<RedactedConnectionRequest>>>([
'pending-connections',
]);
if (!queryData) return;
if (!queryData || !queryData?.pages?.length) return;

const newQueryData = transformFn(queryData);
if (newQueryData) {
@@ -137,7 +137,7 @@ export const updateCacheSentConnections = (
const queryData = queryClient.getQueryData<InfiniteData<PagedResult<ConnectionRequest>>>([
'sent-requests',
]);
if (!queryData) return;
if (!queryData || !queryData?.pages?.length) return;

const newQueryData = transformFn(queryData);
if (newQueryData) {
@@ -226,7 +226,7 @@ export const updateCacheActiveConnections = (
exact: false,
});
queries.forEach(([queryKey, queryData]) => {
if (!queryData) return;
if (!queryData || !queryData?.pages?.length) return;

const newQueryData = transformFn(queryData);
if (newQueryData) {
38 changes: 26 additions & 12 deletions packages/common/common-app/src/hooks/links/useLinkMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { SystemFileType, TargetDrive, getPayloadAsJson } from '@homebase-id/js-lib/core';
import { LinkPreview } from '@homebase-id/js-lib/media';
import { getPayloadAsJsonOverPeerByGlobalTransitId } from '@homebase-id/js-lib/peer';
import {
getPayloadAsJsonOverPeer,
getPayloadAsJsonOverPeerByGlobalTransitId,
} from '@homebase-id/js-lib/peer';
import { useQuery } from '@tanstack/react-query';
import { useDotYouClientContext } from '../auth/useDotYouClientContext';

@@ -24,17 +27,28 @@ export const useLinkMetadata = ({
return useQuery({
queryKey: ['link-metadata', targetDrive.alias, fileId, payloadKey],
queryFn: async () => {
if (odinId && globalTransitId) {
return getPayloadAsJsonOverPeerByGlobalTransitId<LinkPreview[]>(
dotYouClient,
odinId,
targetDrive,
globalTransitId,
payloadKey,
{
systemFileType,
}
);
if (odinId && dotYouClient.getHostIdentity() !== odinId) {
if (globalTransitId) {
return getPayloadAsJsonOverPeerByGlobalTransitId<LinkPreview[]>(
dotYouClient,
odinId,
targetDrive,
globalTransitId,
payloadKey,
{
systemFileType,
}
);
} else if (fileId) {
return getPayloadAsJsonOverPeer<LinkPreview[]>(
dotYouClient,
odinId,
targetDrive,
fileId,
payloadKey,
{ systemFileType }
);
}
}

if (!fileId) return [];
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ export const updateCacheSocialFeeds = (
const currentData = queryClient.getQueryData<InfiniteData<RecentsFromConnectionsReturn>>([
'social-feeds',
]);
if (!currentData) return;
if (!currentData || !currentData?.pages?.length) return;

const newData = transformFn(currentData);
if (!newData) return;
Original file line number Diff line number Diff line change
@@ -222,16 +222,21 @@ export const RichTextRenderer = ({
);
case 'mention':
if (attributes && 'value' in attributes && typeof attributes.value === 'string') {
return (
<a
href={`https://${attributes.value}`}
target="_blank"
rel="noreferrer noopener"
className="text-primary hover:underline break-words"
>
@<AuthorName odinId={attributes.value} excludeLink={true} />
</a>
);
const domainRegex =
/^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9]{2,25}(?::\d{1,5})?$/i;

if (domainRegex.test(attributes.value))
return (
<a
href={`https://${attributes.value}`}
target="_blank"
rel="noreferrer noopener"
className="text-primary hover:underline break-words"
>
@<AuthorName odinId={attributes.value} excludeLink={true} />
</a>
);
else return <span className="break-all text-primary">@{attributes.value}</span>;
} else return <></>;

default:
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ export const MentionElement = withRef<
>
<React.Fragment>
{prefix || '@'}
{renderLabel ? renderLabel(element) : element.value}
{(renderLabel ? renderLabel(element) : element.value).replaceAll('@', '')}
{children}
</React.Fragment>
</PlateElement>
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ export const MentionInputElement = withRef<typeof PlateElement>(({ className, ..
<InlineComboboxItem
key={item.key}
onClick={() => onSelectItem(editor, item, search)}
value={item.text}
value={item.text.replaceAll('@', '')}
>
{item.text}
</InlineComboboxItem>
Original file line number Diff line number Diff line change
@@ -297,8 +297,7 @@ export const getContentFromHeaderOrPayloadOverPeer = async <T>(
): Promise<T | null> => {
const { fileId, fileMetadata, sharedSecretEncryptedKeyHeader } = dsr;
const contentIsComplete =
fileMetadata.payloads?.filter((payload) => payload.contentType === 'application/json')
.length === 0;
fileMetadata.payloads?.filter((payload) => payload.key === DEFAULT_PAYLOAD_KEY).length === 0;

const keyHeader = fileMetadata.isEncrypted
? await decryptKeyHeader(dotYouClient, sharedSecretEncryptedKeyHeader)

0 comments on commit 5eede24

Please sign in to comment.