Skip to content

Commit

Permalink
Transfer history updates (#321)
Browse files Browse the repository at this point in the history
* Bump js-lib;

* Added compatibility for new transfer history while keeping current state support;

* Fix tests;

* Extended DotYouClientProvider;

* Version bump;

* Reload the community webview when the URI changes;

* Another version bump;

* Another version bump; And matching type fixes;

* Fix tests;

---------

Co-authored-by: Bishwajeet Parhi <[email protected]>
  • Loading branch information
stef-coenen and 2002Bishwajeet authored Jan 30, 2025
1 parent 753c54d commit 935c875
Show file tree
Hide file tree
Showing 38 changed files with 502 additions and 338 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint": "npm run lint -workspaces --if-present"
},
"dependencies": {
"@homebase-id/js-lib": "0.0.6-alpha.23",
"@homebase-id/js-lib": "0.0.7-alpha.36",
"axios": "1.7.5",
"patch-package": "8.0.0",
"react": "18.3.1",
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hooks/auth/useDotYouClientContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ApiType, DotYouClient } from '@homebase-id/js-lib/core';
import { DotYouClient } from '@homebase-id/js-lib/core';
import { useContext, createContext } from 'react';

export const DotYouClientContext = createContext<DotYouClient | null>(
new DotYouClient({ api: ApiType.Guest })
);
export const DotYouClientContext = createContext<DotYouClient | null>(null);

export const useDotYouClientContext = () => {
const dotYouClient = useContext(DotYouClientContext);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/hooks/contacts/useAllConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useAllConnections = (enabled: boolean) => {
const fetchConnections = async () => {
// self invoking function that fetches the contacts in blocks of a CHUNKSIZE untill there are no more contacts to fetch
const internalGetConnections = async (
cursor: number | undefined,
cursor: unknown | undefined,
limit: number
): Promise<DotYouProfile[]> => {
const connections = await getConnections(dotYouClient, { cursor, count: limit });
Expand Down
19 changes: 5 additions & 14 deletions packages/mobile/__tests__/ChatProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('ChatProvider', () => {
(getRandom16ByteArray as jest.Mock) = mockGetRandom16Bytes;
beforeEach(() => {
dotYouClient = new DotYouClient({
loggedInIdentity: 'frodobaggins.me',
hostIdentity: 'frodobaggins.me',
api: ApiType.App,
headers: {},
sharedSecret: new Uint8Array(32),
Expand Down Expand Up @@ -179,7 +179,10 @@ describe('ChatProvider', () => {
const files = undefined;
const linkPreviews = undefined;

(uploadFile as jest.Mock).mockResolvedValue({ file: { fileId: 'file-id' } });
(uploadFile as jest.Mock).mockResolvedValue({
file: { fileId: 'file-id' },
recipientStatus: {},
});

const result = await uploadChatMessage(dotYouClient, message, recipients, files, linkPreviews);

Expand Down Expand Up @@ -216,10 +219,6 @@ describe('ChatProvider', () => {
content: {
message: '',
deliveryStatus: 30,
deliveryDetails: {
'samwisegamgee.me': 30,
'frodobaggins.me': 30,
},
},
archivalStatus: 2,
},
Expand Down Expand Up @@ -276,10 +275,6 @@ describe('ChatProvider', () => {
content: {
message: '',
deliveryStatus: 30,
deliveryDetails: {
'samwisegamgee.me': 30,
'frodobaggins.me': 30,
},
},
archivalStatus: 2,
},
Expand Down Expand Up @@ -334,10 +329,6 @@ describe('ChatProvider', () => {
content: {
message: '',
deliveryStatus: 30,
deliveryDetails: {
'samwisegamgee.me': 30,
'frodobaggins.me': 30,
},
},
archivalStatus: 2,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/__tests__/ConversationProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jest.mock('react-native-fs', () => {

describe('ConversationProvider', () => {
const dotYouClientMock = new DotYouClient({
loggedInIdentity: 'frodobaggins.me',
hostIdentity: 'frodobaggins.me',
api: ApiType.App,
headers: {},
sharedSecret: new Uint8Array(16),
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/__tests__/RNPostReactionProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('RNPostReactionProvider', () => {
let context: ReactionContext;
let comment: NewHomebaseFile<RawReactionContent> | HomebaseFile<RawReactionContent>;
const dotYouClient = new DotYouClient({
loggedInIdentity: 'frodobaggins.me',
hostIdentity: 'frodobaggins.me',
api: ApiType.App,
headers: {},
sharedSecret: new Uint8Array(32),
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('RNPostReactionProvider', () => {
});

it('should handle local comments correctly', async () => {
context.odinId = dotYouClient.getLoggedInIdentity();
context.odinId = dotYouClient.getLoggedInIdentity() || '';
const result = await saveComment(dotYouClient, context, comment);
expect(result).toBeDefined();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/__tests__/RNPostUploadProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('RNPostUploadProvider', () => {
let onVersionConflict: jest.Mock;
let onUpdate: jest.Mock;
const dotYouClient = new DotYouClient({
loggedInIdentity: 'frodobaggins.me',
hostIdentity: 'frodobaggins.me',
api: ApiType.App,
headers: {},
sharedSecret: new Uint8Array(32),
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebase-id-app-mobile",
"version": "0.0.30",
"version": "0.0.32",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
6 changes: 4 additions & 2 deletions packages/mobile/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ let App = () => {
<GestureHandlerRootView>
<PushNotificationProvider>
<RouteContextProvider>
<RootStack />
<Toast />
<DotYouClientProvider>
<RootStack />
<Toast />
</DotYouClientProvider>
</RouteContextProvider>
</PushNotificationProvider>
</GestureHandlerRootView>
Expand Down
15 changes: 6 additions & 9 deletions packages/mobile/src/components/Chat/Chat-Delivery-Indicator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HomebaseFile } from '@homebase-id/js-lib/core';
import { HomebaseFile, RecipientTransferHistory } from '@homebase-id/js-lib/core';
import { ChatDeliveryStatus, ChatMessage } from '../../provider/chat/ChatProvider';
import { t, useDotYouClientContext } from 'homebase-id-app-common';
import { Pressable, StyleProp, Text, TextStyle, View, ViewStyle } from 'react-native';
Expand Down Expand Up @@ -32,17 +32,14 @@ export const ChatDeliveryIndicator = ({
};

export const FailedDeliveryDetails = ({
msg,
recipient,
transferHistory,
style,
}: {
msg: HomebaseFile<ChatMessage>;
recipient: string;
transferHistory: RecipientTransferHistory | undefined;
style?: StyleProp<TextStyle>;
}) => {
const deliveryDetails = msg.serverMetadata?.transferHistory?.recipients[recipient];
if (!deliveryDetails) return null;
if (deliveryDetails.latestSuccessfullyDeliveredVersionTag) return null;
if (!transferHistory) return null;
if (transferHistory.latestSuccessfullyDeliveredVersionTag) return null;

return (
<Text
Expand All @@ -53,7 +50,7 @@ export const FailedDeliveryDetails = ({
style,
]}
>
{t(deliveryDetails.latestTransferStatus)}
{t(transferHistory.latestTransferStatus)}
</Text>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ export const ReportModal = forwardRef(
);
};
const identity = useAuth().getIdentity();
const host = new DotYouClient({
api: ApiType.Guest,
loggedInIdentity: identity || undefined,
hostIdentity: identity || undefined,
}).getRoot();
const host =
(identity &&
new DotYouClient({
api: ApiType.Guest,
loggedInIdentity: identity,
hostIdentity: identity,
}).getRoot()) ||
'';

const onBlock = () =>
openURL(`${host}/owner/connections/${message?.fileMetadata.originalAuthor}/block`);
Expand Down
28 changes: 25 additions & 3 deletions packages/mobile/src/components/Chat/Reactions/Modal/RetryModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import { Container } from '../../../ui/Container/Container';
import { StyleSheet } from 'react-native';
import { TouchableHighlight } from 'react-native-gesture-handler';
import { useChatMessage } from '../../../../hooks/chat/useChatMessage';
import { HomebaseFile } from '@homebase-id/js-lib/core';
import { HomebaseFile, RecipientTransferHistory } from '@homebase-id/js-lib/core';
import { ChatMessage } from '../../../../provider/chat/ChatProvider';
import { UnifiedConversation } from '../../../../provider/chat/ConversationProvider';
import { ChatDrive, UnifiedConversation } from '../../../../provider/chat/ConversationProvider';
import { ErrorNotification } from '../../../ui/Alert/ErrorNotification';
import { Backdrop } from '../../../ui/Modal/Backdrop';
import { useTransferHistory } from '../../../../hooks/file/useTransferHistory';

export const RetryModal = forwardRef(
(
{
Expand All @@ -32,7 +34,26 @@ export const RetryModal = forwardRef(
) => {
const { isDarkMode } = useDarkMode();
const { mutate, error } = useChatMessage().update;
const recipients = message?.serverMetadata?.transferHistory?.recipients;
const { data: transferHistory } = useTransferHistory(
message && {
fileId: message?.fileId,
targetDrive: ChatDrive,
}
).fetch;

const recipients =
(message?.serverMetadata?.transferHistory &&
'recipients' in message.serverMetadata.transferHistory &&
(message.serverMetadata.transferHistory as unknown as {
[key: string]: RecipientTransferHistory;
})) ||
transferHistory?.history.results.reduce(
(acc, curr) => {
acc[curr.recipient] = curr;
return acc;
},
{} as Record<string, RecipientTransferHistory>
);

const onRetry = useCallback(() => {
if (!message) return;
Expand Down Expand Up @@ -69,6 +90,7 @@ export const RetryModal = forwardRef(
return recipients[failedRecipient[0]].latestTransferStatus;
}
}, [failedRecipient, recipients]);

return (
<BottomSheetModal
ref={ref}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ const NotificationGroup = ({
const chatNavigator = useNavigation<NavigationProp<ChatStackParamList>>();
const tabNavigator = useNavigation<NavigationProp<TabStackParamList>>();

if (!identity || !chatNavigator || !tabNavigator) return null;

return (
<View
style={{
Expand Down
10 changes: 6 additions & 4 deletions packages/mobile/src/components/Feed/Interacts/PostInteracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const PostInteracts = memo(
}) => {
const postContent = postFile.fileMetadata.appData.content;
const owner = useDotYouClientContext().getLoggedInIdentity();
const odinId = postFile.fileMetadata.senderOdinId || owner;
const odinId = postFile.fileMetadata.senderOdinId ?? owner;
const postDisabledEmoji =
postContent.reactAccess !== undefined &&
(postContent.reactAccess === false || postContent.reactAccess === 'comment');
Expand Down Expand Up @@ -97,9 +97,11 @@ export const PostInteracts = memo(

const permalink = useMemo(
() =>
`${new DotYouClient({ hostIdentity: odinId || undefined, api: ApiType.Guest }).getRoot()}/posts/${postContent.channelId}/${
postContent.slug ?? postContent.id
}`,
odinId
? `${new DotYouClient({ hostIdentity: odinId, api: ApiType.Guest }).getRoot()}/posts/${postContent.channelId}/${
postContent.slug ?? postContent.id
}`
: '',
[odinId, postContent]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const PostDetailMainContent = ({
| undefined
>();
const owner = useDotYouClientContext().getLoggedInIdentity();
const authorOdinId = postFile.fileMetadata.senderOdinId || owner;
const authorOdinId = postFile.fileMetadata.senderOdinId ?? owner;
const postContent = postFile.fileMetadata.appData.content;

const { data: canReact } = useCanReact({
Expand Down
10 changes: 6 additions & 4 deletions packages/mobile/src/components/Feed/Meta/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ export const ExternalActions = memo(
getReportContentUrl,
} = useManageSocialFeed({ odinId });

const host = new DotYouClient({
api: ApiType.Guest,
loggedInIdentity: identity || undefined,
}).getRoot();
const host = identity
? new DotYouClient({
api: ApiType.Guest,
hostIdentity: identity,
}).getRoot()
: '';
const options: ActionGroupProps[] = [
{
icon: <Users />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getAppName } from '../../../utils/utils';
export const NotificationToaster = () => {
const { route } = useRouteContext();
const dotYouClient = useDotYouClientContext();
const identity = useDotYouClientContext().getLoggedInIdentity();
const identity = useDotYouClientContext().getLoggedInIdentity() || '';
const chatNavigator = useNavigation<NavigationProp<ChatStackParamList>>();
const tabNavigator = useNavigation<NavigationProp<TabStackParamList>>();
const isConversationScreen = route?.name === 'Conversation' && !route.params;
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/src/components/ui/DoubleTapHeart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const DoubleTapHeart = memo(
const postContent = postFile.fileMetadata.appData.content;
const reactionContext: ReactionContext = useMemo(() => {
return {
odinId: odinId || identity,
odinId: odinId || identity || '',
channelId: postContent.channelId,
target: {
globalTransitId: postFile.fileMetadata.globalTransitId ?? 'unknown',
Expand Down
Loading

0 comments on commit 935c875

Please sign in to comment.