Skip to content

Commit d08205b

Browse files
committed
refactor: modify actions in alignment with other sdks
1 parent 7e1f76f commit d08205b

File tree

10 files changed

+515
-384
lines changed

10 files changed

+515
-384
lines changed

examples/SampleApp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@op-engineering/op-sqlite": "^14.0.4",
3333
"@react-native-async-storage/async-storage": "^2.2.0",
3434
"@react-native-camera-roll/camera-roll": "^7.10.0",
35+
"@react-native-clipboard/clipboard": "^1.16.3",
3536
"@react-native-community/geolocation": "^3.4.0",
3637
"@react-native-community/netinfo": "^11.4.1",
3738
"@react-native-documents/picker": "^10.1.3",

examples/SampleApp/src/utils/messageActions.tsx

Lines changed: 95 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function channelMessageActions({
1717
params,
1818
chatClient,
1919
t,
20-
handleMessageInfo,
20+
// handleMessageInfo,
2121
semantics,
2222
}: {
2323
params: MessageActionsParams;
@@ -27,109 +27,111 @@ export function channelMessageActions({
2727
handleMessageInfo: (message: LocalMessage) => void;
2828
semantics: Theme['semantics'];
2929
}) {
30-
const { dismissOverlay, deleteForMeMessage } = params;
30+
const { dismissOverlay, error, /*deleteForMeMessage*/ } = params;
3131
const actions = messageActions(params);
3232

3333
// We cannot use the useMessageReminder hook here because it is a hook.
3434
const reminder = chatClient.reminders.getFromState(params.message.id);
3535

36-
actions.push({
37-
action: async () => {
38-
try {
36+
// actions.push({
37+
// action: async () => {
38+
// try {
39+
// if (reminder) {
40+
// await chatClient.reminders.deleteReminder(reminder.id);
41+
// } else {
42+
// await chatClient.reminders.createReminder({ messageId: params.message.id });
43+
// }
44+
// dismissOverlay();
45+
// } catch (error) {
46+
// console.error('Error creating reminder:', error);
47+
// }
48+
// },
49+
// actionType: reminder ? 'remove-from-later' : 'save-for-later',
50+
// title: reminder ? 'Remove from Later' : 'Save for Later',
51+
// icon: <Time width={20} height={20} stroke={semantics.textSecondary} />,
52+
// type: 'standard',
53+
// });
54+
if (!error) {
55+
actions.push({
56+
action: () => {
3957
if (reminder) {
40-
await chatClient.reminders.deleteReminder(reminder.id);
41-
} else {
42-
await chatClient.reminders.createReminder({ messageId: params.message.id });
43-
}
44-
dismissOverlay();
45-
} catch (error) {
46-
console.error('Error creating reminder:', error);
47-
}
48-
},
49-
actionType: reminder ? 'remove-from-later' : 'save-for-later',
50-
title: reminder ? 'Remove from Later' : 'Save for Later',
51-
icon: <Time width={20} height={20} stroke={semantics.textSecondary} />,
52-
type: 'standard',
53-
});
54-
actions.push({
55-
action: () => {
56-
if (reminder) {
57-
Alert.alert('Remove Reminder', 'Are you sure you want to remove this reminder?', [
58-
{
59-
text: 'Cancel',
60-
style: 'cancel',
61-
},
62-
{
63-
text: 'Remove',
64-
onPress: () => {
65-
chatClient.reminders.deleteReminder(reminder.id).catch((error) => {
66-
console.error('Error deleting reminder:', error);
67-
});
58+
Alert.alert('Remove Reminder', 'Are you sure you want to remove this reminder?', [
59+
{
60+
text: 'Cancel',
61+
style: 'cancel',
6862
},
69-
style: 'destructive',
70-
},
71-
]);
72-
} else {
73-
Alert.alert(
74-
'Select Reminder Time',
75-
'When would you like to be reminded?',
76-
chatClient.reminders.scheduledOffsetsMs.map((offsetMs) => ({
77-
text: t('duration/Remind Me', { milliseconds: offsetMs }),
78-
onPress: () => {
79-
chatClient.reminders
80-
.upsertReminder({
81-
messageId: params.message.id,
82-
remind_at: new Date(new Date().getTime() + offsetMs).toISOString(),
83-
})
84-
.catch((error) => {
85-
console.error('Error creating reminder:', error);
63+
{
64+
text: 'Remove',
65+
onPress: () => {
66+
chatClient.reminders.deleteReminder(reminder.id).catch((error) => {
67+
console.error('Error deleting reminder:', error);
8668
});
69+
},
70+
style: 'destructive',
8771
},
88-
style: 'default',
89-
})),
90-
);
91-
}
72+
]);
73+
} else {
74+
Alert.alert(
75+
'Select Reminder Time',
76+
'When would you like to be reminded?',
77+
chatClient.reminders.scheduledOffsetsMs.map((offsetMs) => ({
78+
text: t('duration/Remind Me', { milliseconds: offsetMs }),
79+
onPress: () => {
80+
chatClient.reminders
81+
.upsertReminder({
82+
messageId: params.message.id,
83+
remind_at: new Date(new Date().getTime() + offsetMs).toISOString(),
84+
})
85+
.catch((error) => {
86+
console.error('Error creating reminder:', error);
87+
});
88+
},
89+
style: 'default',
90+
})),
91+
);
92+
}
9293

93-
dismissOverlay();
94-
},
95-
actionType: reminder ? 'remove-reminder' : 'remind-me',
96-
title: reminder ? 'Remove Reminder' : 'Remind Me',
97-
icon: <Bell height={20} width={20} stroke={semantics.textSecondary} />,
98-
type: 'standard',
99-
});
100-
actions.push({
101-
action: async () => {
102-
Alert.alert('Delete for me', 'Are you sure you want to delete this message for me?', [
103-
{
104-
text: 'Cancel',
105-
style: 'cancel',
106-
},
107-
{
108-
text: 'Delete',
109-
onPress: async () => {
110-
await deleteForMeMessage?.action();
111-
dismissOverlay();
112-
},
113-
style: 'destructive',
114-
},
115-
]);
116-
},
117-
actionType: 'deleteForMe',
118-
icon: <Delete stroke={semantics.accentError} width={20} height={20} />,
119-
title: t('Delete for me'),
120-
type: 'destructive',
121-
});
94+
dismissOverlay();
95+
},
96+
actionType: reminder ? 'remove-reminder' : 'remind-me',
97+
title: reminder ? 'Remove Reminder' : 'Remind Me',
98+
icon: <Bell height={20} width={20} stroke={semantics.textSecondary} />,
99+
type: 'standard',
100+
});
101+
}
102+
// actions.push({
103+
// action: async () => {
104+
// Alert.alert('Delete for me', 'Are you sure you want to delete this message for me?', [
105+
// {
106+
// text: 'Cancel',
107+
// style: 'cancel',
108+
// },
109+
// {
110+
// text: 'Delete',
111+
// onPress: async () => {
112+
// await deleteForMeMessage?.action();
113+
// dismissOverlay();
114+
// },
115+
// style: 'destructive',
116+
// },
117+
// ]);
118+
// },
119+
// actionType: 'deleteForMe',
120+
// icon: <Delete stroke={semantics.accentError} width={20} height={20} />,
121+
// title: t('Delete for me'),
122+
// type: 'destructive',
123+
// });
122124

123-
actions.push({
124-
action: () => {
125-
dismissOverlay();
126-
handleMessageInfo(params.message);
127-
},
128-
actionType: 'messageInfo',
129-
icon: <Eye height={20} width={20} pathFill={semantics.textSecondary} />,
130-
title: 'Message Info',
131-
type: 'standard',
132-
});
125+
// actions.push({
126+
// action: () => {
127+
// dismissOverlay();
128+
// handleMessageInfo(params.message);
129+
// },
130+
// actionType: 'messageInfo',
131+
// icon: <Eye height={20} width={20} pathFill={semantics.textSecondary} />,
132+
// title: 'Message Info',
133+
// type: 'standard',
134+
// });
133135

134136
return actions;
135137
}

examples/SampleApp/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,6 +2194,11 @@
21942194
resolved "https://registry.yarnpkg.com/@react-native-camera-roll/camera-roll/-/camera-roll-7.10.0.tgz#5e9518d78a9cd87ddc8e68d03e31a608df5033ab"
21952195
integrity sha512-Zm1yHxxTQS2APsnnxUFoLnK+DMMTPqmIQ2z2pGtNyHRXAG40Nt4MLVB3tDJTWnuJLAG87BpTCEvpz49+u0YkUw==
21962196

2197+
"@react-native-clipboard/clipboard@^1.16.3":
2198+
version "1.16.3"
2199+
resolved "https://registry.yarnpkg.com/@react-native-clipboard/clipboard/-/clipboard-1.16.3.tgz#7807a90fd9984bf4d3a96faf2eee20457984a9bd"
2200+
integrity sha512-cMIcvoZKIrShzJHEaHbTAp458R9WOv0fB6UyC7Ek4Qk561Ow/DrzmmJmH/rAZg21Z6ixJ4YSdFDC14crqIBmCQ==
2201+
21972202
"@react-native-community/cli-clean@19.1.2":
21982203
version "19.1.2"
21992204
resolved "https://registry.yarnpkg.com/@react-native-community/cli-clean/-/cli-clean-19.1.2.tgz#10be56a6ab966c141090176e54937cb7b7618a9b"

package/src/components/Channel/Channel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
345345
| 'handleQuotedReply'
346346
| 'handleRetry'
347347
| 'handleThreadReply'
348+
| 'handleBlockUser'
348349
| 'InlineDateSeparator'
349350
| 'InlineUnreadIndicator'
350351
| 'isAttachmentEqual'
@@ -634,6 +635,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
634635
handleReaction,
635636
handleRetry,
636637
handleThreadReply,
638+
handleBlockUser,
637639
hasCameraPicker = isImagePickerAvailable(),
638640
hasCommands,
639641
hasCreatePoll,
@@ -1925,6 +1927,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
19251927
handleReaction,
19261928
handleRetry,
19271929
handleThreadReply,
1930+
handleBlockUser,
19281931
hasCreatePoll:
19291932
hasCreatePoll === undefined ? pollCreationEnabled : hasCreatePoll && pollCreationEnabled,
19301933
ImageLoadingFailedIndicator,

package/src/components/Channel/hooks/useCreateMessagesContext.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const useCreateMessagesContext = ({
3838
handleReaction,
3939
handleRetry,
4040
handleThreadReply,
41+
handleBlockUser,
4142
hasCreatePoll,
4243
ImageLoadingFailedIndicator,
4344
ImageLoadingIndicator,
@@ -154,6 +155,7 @@ export const useCreateMessagesContext = ({
154155
handleReaction,
155156
handleRetry,
156157
handleThreadReply,
158+
handleBlockUser,
157159
hasCreatePoll,
158160
ImageLoadingFailedIndicator,
159161
ImageLoadingIndicator,

package/src/components/Message/Message.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export type MessagePropsWithContext = Pick<
197197
| 'handleReaction'
198198
| 'handleRetry'
199199
| 'handleThreadReply'
200+
| 'handleBlockUser'
200201
| 'isAttachmentEqual'
201202
| 'MessageMenu'
202203
| 'messageActions'
@@ -278,6 +279,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
278279
handleReaction: handleReactionProp,
279280
handleRetry,
280281
handleThreadReply,
282+
handleBlockUser,
281283
isTargetedMessage,
282284
members,
283285
message,
@@ -582,6 +584,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
582584
retry,
583585
threadReply,
584586
unpinMessage,
587+
blockUser,
585588
} = useMessageActions({
586589
channel,
587590
client,
@@ -602,6 +605,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
602605
handleReaction: handleReactionProp,
603606
handleRetry,
604607
handleThreadReply,
608+
handleBlockUser,
605609
message,
606610
onThreadSelect,
607611
openThread,
@@ -639,10 +643,10 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
639643
pinMessage,
640644
quotedReply,
641645
retry,
642-
showMessageReactions,
643646
threadReply,
644647
unpinMessage,
645648
updateMessage,
649+
blockUser,
646650
});
647651

648652
const actionHandlers: MessageActionHandlers = {

0 commit comments

Comments
 (0)