Skip to content

Commit

Permalink
"TODO" cleanup; And remove full mail cache invalidation in quick win …
Browse files Browse the repository at this point in the history
…scenario's (#220)

* "TODO" cleanup; And remove full mail cache invalidation in quick win scenario's;

* Extended debug flag for RN;

* Added refIds;
  • Loading branch information
stef-coenen authored Aug 29, 2024
1 parent 709b7fa commit 50f3afa
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export const ChatMediaGallery = ({ msg }: { msg: HomebaseFile<ChatMessage> }) =>
return () => window.removeEventListener('keydown', handleKeyDown);
}, [msg, mediaKey]);

// TODO: Added previewThumbnail of the grid

const payload = msg.fileMetadata.payloads.find((p) => p.key === mediaKey);
const contentType = payload?.contentType;
const dialog = (
Expand Down
5 changes: 1 addition & 4 deletions packages/chat-app/src/hooks/chat/useChatMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export const useChatMessages = (props?: { conversationId: string | undefined })
!recipientStatus.status ||
recipientStatus.status?.toLowerCase() !== SendReadReceiptResponseRecipientStatus.Enqueued
);
if (someFailed) {
// TODO: Should we throw an error?
console.error('Error marking chat as read', { response });
}
if (someFailed) console.error('Error marking chat as read', { response });
});

return response;
Expand Down
2 changes: 1 addition & 1 deletion packages/chat-app/src/providers/ChatProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export const softDeleteChatMessage = async (

for (let i = 0; i < message.fileMetadata.payloads.length; i++) {
const payload = message.fileMetadata.payloads[i];
// TODO: Should the payload be deleted for everyone? With "TransitOptions"
// TODO: Should the payload be deleted for everyone? With "TransitOptions"; Needs server side support for it;
const deleteResult = await deletePayload(
dotYouClient,
ChatDrive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export const useWebsocketSubscriber = (
() => {
setIsConected(true);
onReconnect && onReconnect();
}
},
undefined,
refId
);
setIsConected(true);
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export const CommunityMediaGallery = ({
return () => window.removeEventListener('keydown', handleKeyDown);
}, [msg, mediaKey]);

// TODO: Added previewThumbnail of the grid

const payload = msg.fileMetadata.payloads.find((p) => p.key === mediaKey);
const contentType = payload?.contentType;
const dialog = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ const useCommunityWebsocket = (communityId: string | undefined, isEnabled: boole
[targetDrive],
() => {
queryClient.invalidateQueries({ queryKey: ['process-inbox'] });
}
},
undefined,
'useLiveCommunityProcessor'
);
};

Expand Down
5 changes: 4 additions & 1 deletion packages/feed-app/src/hooks/useLiveFeedProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ const useFeedWebSocket = (isEnabled: boolean) => {
useWebsocketSubscriber(
isEnabled ? handler : undefined,
['fileAdded', 'fileModified'],
websocketDrives
websocketDrives,
undefined,
undefined,
'useLiveFeedProcessor'
);
};
6 changes: 4 additions & 2 deletions packages/js-lib/src/core/WebsocketData/WebsocketProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ export const Subscribe = async (
handler: (data: TypedConnectionNotification) => void,
onDisconnect?: () => void,
onReconnect?: () => void,
args?: unknown // Extra parameters to pass to WebSocket constructor; Only applicable for React Native...; TODO: Remove this
args?: unknown, // Extra parameters to pass to WebSocket constructor; Only applicable for React Native...; TODO: Remove this,
refId?: string
): Promise<void> => {
const apiType = dotYouClient.getType();
const sharedSecret = dotYouClient.getSharedSecret();
Expand All @@ -287,7 +288,8 @@ export const Subscribe = async (
activeSs = sharedSecret;
subscribers.push({ handler, onDisconnect, onReconnect });

if (isDebug) console.debug(`[NotificationProvider] New subscriber (${subscribers.length})`);
if (isDebug)
console.debug(`[NotificationProvider] New subscriber (${subscribers.length})`, refId);

// Already connected, no need to initiate a new connection
if (webSocketClient) return Promise.resolve();
Expand Down
6 changes: 5 additions & 1 deletion packages/js-lib/src/helpers/BrowserUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ export const isLocalStorageAvailable = () => {
export const isTouchDevice = () => 'ontouchstart' in window || navigator.maxTouchPoints > 0;

export const hasDebugFlag = () =>
isLocalStorageAvailable() ? localStorage.getItem('debug') === '1' : false;
isLocalStorageAvailable()
? localStorage.getItem('debug') === '1'
: typeof navigator !== 'undefined' &&
navigator.product === 'ReactNative' &&
(global as any).debug;
4 changes: 2 additions & 2 deletions packages/js-lib/src/media/Link/LinkPreviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const getLinkPreview = async (
title: response.data.title || '',
description: response.data.description || '',
imageUrl: response.data.imageUrl || undefined,
imageWidth: response.data.imageWidth || undefined, // TODO: Should we find a way to always get one from the dataUri?
imageHeight: response.data.imageHeight || undefined, // TODO: Should we find a way to always get one from the dataUri?
imageWidth: response.data.imageWidth || undefined,
imageHeight: response.data.imageHeight || undefined,
url: response.data.url,
};
})
Expand Down
3 changes: 1 addition & 2 deletions packages/js-lib/src/public/posts/PostProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ export const removePost = async (
const targetDrive = GetTargetDriveFromChannelId(channelId);

if (postFile.fileMetadata.globalTransitId) {
// Fetch the first 1000 comments and delete them with the post;
// TODO: this should support a larger numbers of comments; Or a delete of a tree of groupIds
// Fetch the first 1000 comments and delete their level 2 replies by groupId;
const comments = (
await queryBatch(
dotYouClient,
Expand Down
4 changes: 2 additions & 2 deletions packages/js-lib/src/public/posts/PostUploadProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const uploadPost = async <T extends PostContent>(
recipients: [],
schedule: ScheduleOptions.SendLater,
priority: PriorityOptions.Medium,
sendContents: SendContents.All, // TODO: Should this be header only?
sendContents: SendContents.All,
},
};

Expand Down Expand Up @@ -346,7 +346,7 @@ const uploadPostHeader = async <T extends PostContent>(
recipients: [],
schedule: ScheduleOptions.SendLater,
priority: PriorityOptions.Medium,
sendContents: SendContents.All, // TODO: Should this be header only?
sendContents: SendContents.All,
},
};

Expand Down
13 changes: 3 additions & 10 deletions packages/mail-app/src/hooks/mail/useLiveMailProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ const useMailWebsocket = (isEnabled: boolean) => {
);
if (!updatedChatMessage) return;

const sender =
notification.header.fileMetadata.senderOdinId ||
updatedChatMessage.fileMetadata.appData.content.sender;

if (!sender || sender === identity) {
// Ignore messages sent by the current user
return;
}

const existingConversations = queryClient.getQueryData<
InfiniteData<MailConversationsReturn>
>(['mail-conversations']);
Expand Down Expand Up @@ -127,6 +118,8 @@ const useMailWebsocket = (isEnabled: boolean) => {
websocketDrives,
() => {
queryClient.invalidateQueries({ queryKey: ['process-inbox'] });
}
},
undefined,
'useLiveMailProcessor'
);
};
8 changes: 0 additions & 8 deletions packages/mail-app/src/hooks/mail/useMailConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,6 @@ export const useMailConversation = (props?: { messageFileId: string }) => {
queryClient.setQueryData(['mail-conversations'], context?.existingConversations);
console.error('Error sending mail message', _error);
},
onSettled: async () => {
// TODO: Should we really fully refetch the mail conversations and mail thread? Might be a lot of data...
queryClient.invalidateQueries({ queryKey: ['mail-conversations'] });
},
}),
markAsRead: useMutation({
mutationFn: markAsRead,
Expand Down Expand Up @@ -528,10 +524,6 @@ export const useMailDraft = (props?: { draftFileId: string }) => {

console.error('Error removing draft mail message', _error);
},
onSettled: async () => {
queryClient.invalidateQueries({ queryKey: ['mail-conversations'] });
// Should we fully refetch the mail conversations and mail thread? Might be a lot of data...
},
}),
};
};
Expand Down
5 changes: 0 additions & 5 deletions packages/mail-app/src/hooks/mail/useMailThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ export const useMailThread = (props?: { threadId: string | undefined }) => {

console.error('Error removing messages', error);
},
onSettled: () => {
// TODO: This can be optimized to use the uploadResults to update the versionTag;
// Just not sure if it should live here, or be part fo the websocket connection?
queryClient.invalidateQueries({ queryKey: ['mail-conversations'] });
},
}),
archive: useMutation({
mutationFn: archiveMailThread,
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/owner-app/src/hooks/configure/useInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const useInit = () => {
}

// Do a first publish of the static files
// This is normally a side effect from the useAttribute hook.. TODO: Move to providers instead of the hook
// This is normally a side effect from the useAttribute hook.. but we need to do it here after the first setup
await publishStaticFiles(undefined);

const defaultServerSettings = getSettings(dotYouClient);
Expand Down
1 change: 0 additions & 1 deletion packages/owner-app/src/hooks/contacts/useContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const useContact = ({

// Direct fetch with odinId:
// Use the data from the contact book, if it exists and if it's a contact level source or we are not allowed to save anyway
// TODO: Not sure if this is the best way yet... But it works for now
const contactBookContact = await getContactByOdinId(dotYouClient, odinId);
if (
!hasCache && // If we have a contact on drive, and we don't have cache, we need a fast return; Otherwise we trigger a refresh
Expand Down
2 changes: 1 addition & 1 deletion packages/owner-app/src/hooks/profiles/useAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useAttributes = ({
profileId,
sectionId,
undefined,
100 // TODO: Should we page this properly, or how many profile attributes do we expect as normal?
200 // TODO: Should we page this properly, or how many profile attributes do we expect being "normal"?
);

return foundAttributes.map((attr) => {
Expand Down
18 changes: 7 additions & 11 deletions packages/owner-app/src/templates/DemoData/DemoData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ const DemoDataProfile = ({ client, realmData }: { client: DotYouClient; realmDat
<h1>Profile:</h1>
<button
onClick={addName}
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
isNameSet ? 'pointer-events-none bg-gray-300' : 'bg-green-500'
}`}
disabled={isNameSet}
Expand All @@ -417,7 +417,7 @@ const DemoDataProfile = ({ client, realmData }: { client: DotYouClient; realmDat
</button>
<button
onClick={addPhoto}
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
attrHasData(photoAttr) && isPhotoFetched
? 'pointer-events-none bg-gray-300'
: 'bg-green-500'
Expand All @@ -428,7 +428,7 @@ const DemoDataProfile = ({ client, realmData }: { client: DotYouClient; realmDat
</button>
<button
onClick={addSocials}
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
attrHasData(socialAttr) && isSocialFetched
? 'pointer-events-none bg-gray-300'
: 'bg-green-500'
Expand All @@ -439,7 +439,7 @@ const DemoDataProfile = ({ client, realmData }: { client: DotYouClient; realmDat
</button>
<button
onClick={addBiography}
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
bioAttr && isBioFetched ? 'pointer-events-none bg-gray-300' : 'bg-green-500'
}`}
disabled={(bioAttr && isBioFetched) || false}
Expand Down Expand Up @@ -513,10 +513,6 @@ const DemoDataHomeAndTheme = ({ realmData }: { client: DotYouClient; realmData:
{ type: 'image/webp' }
);

// TODO: Save tag and leadText into status and shortBio attributes
// StatusAttr.data[HomePageThemeFields.TagLineId] = realmData.home.tagLine;
// ShortBioAttr.data[HomePageThemeFields.LeadTextId] = realmData.home.lead;

saveRoot({
fileMetadata: {
appData: {
Expand All @@ -536,7 +532,7 @@ const DemoDataHomeAndTheme = ({ realmData }: { client: DotYouClient; realmData:
<h1>Theme:</h1>
<button
onClick={addTheme}
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
hasThemeData ? 'pointer-events-none bg-gray-300' : 'bg-green-500'
}`}
disabled={!!hasThemeData}
Expand Down Expand Up @@ -683,7 +679,7 @@ const DemoDataBlog = ({
<h1>Blog:</h1>
<button
onClick={addChannels}
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
channelAttr && isChannelFetched ? 'pointer-events-none bg-gray-300' : 'bg-green-500'
}`}
disabled={(channelAttr && isChannelFetched) || false}
Expand Down Expand Up @@ -746,7 +742,7 @@ const CirclesAndConnections = ({ realmData }: { realmData: RealmData }) => {
<h1>Circles and Connections:</h1>
<button
onClick={createCircles}
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
className={`my-2 block w-1/3 rounded border-0 px-4 py-2 text-white hover:bg-green-600 focus:outline-none ${
hasDemoCircles ? 'pointer-events-none bg-gray-300' : 'bg-green-500'
}`}
disabled={hasDemoCircles || false}
Expand Down
Loading

0 comments on commit 50f3afa

Please sign in to comment.