Skip to content

Commit 089577b

Browse files
committed
fix: add action to sample app only
1 parent b1d412b commit 089577b

File tree

8 files changed

+30
-47
lines changed

8 files changed

+30
-47
lines changed

examples/SampleApp/src/utils/messageActions.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Alert } from 'react-native';
22
import { StreamChat } from 'stream-chat';
33
import {
44
Colors,
5+
Delete,
56
messageActions,
67
MessageActionsParams,
78
Time,
@@ -20,7 +21,7 @@ export function channelMessageActions({
2021
t: TranslationContextValue['t'];
2122
colors?: typeof Colors;
2223
}) {
23-
const { dismissOverlay } = params;
24+
const { dismissOverlay, updateMessage } = params;
2425
const actions = messageActions(params);
2526

2627
// We cannot use the useMessageReminder hook here because it is a hook.
@@ -88,6 +89,30 @@ export function channelMessageActions({
8889
title: reminder ? 'Remove Reminder' : 'Remind Me',
8990
icon: <Bell height={24} width={24} />,
9091
});
92+
actions.push({
93+
action: async () => {
94+
Alert.alert('Delete for me', 'Are you sure you want to delete this message for me?', [
95+
{
96+
text: 'Cancel',
97+
style: 'cancel',
98+
},
99+
{
100+
text: 'Delete',
101+
onPress: async () => {
102+
const { message: deletedMessage } = await chatClient.deleteMessage(params.message.id, {
103+
deleteForMe: true,
104+
});
105+
updateMessage(deletedMessage);
106+
dismissOverlay();
107+
},
108+
style: 'destructive',
109+
},
110+
]);
111+
},
112+
actionType: 'deleteForMe',
113+
icon: <Delete fill={colors?.accent_red} size={24} />,
114+
title: t('Delete for me'),
115+
});
91116

92117
return actions;
93118
}

package/src/components/Channel/Channel.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
321321
| 'giphyVersion'
322322
| 'handleBan'
323323
| 'handleCopy'
324-
| 'handleDeleteForMe'
325324
| 'handleDelete'
326325
| 'handleEdit'
327326
| 'handleFlag'
@@ -580,7 +579,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
580579
handleAttachButtonPress,
581580
handleBan,
582581
handleCopy,
583-
handleDeleteForMe,
584582
handleDelete,
585583
handleEdit,
586584
handleFlag,
@@ -1839,7 +1837,6 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
18391837
handleBan,
18401838
handleCopy,
18411839
handleDelete,
1842-
handleDeleteForMe,
18431840
handleEdit,
18441841
handleFlag,
18451842
handleMarkUnread,

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const useCreateMessagesContext = ({
3333
handleBan,
3434
handleCopy,
3535
handleDelete,
36-
handleDeleteForMe,
3736
handleEdit,
3837
handleFlag,
3938
handleMarkUnread,
@@ -151,7 +150,6 @@ export const useCreateMessagesContext = ({
151150
handleBan,
152151
handleCopy,
153152
handleDelete,
154-
handleDeleteForMe,
155153
handleEdit,
156154
handleFlag,
157155
handleMarkUnread,

package/src/components/Message/Message.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ export type MessagePropsWithContext = Pick<
155155
| 'handleBan'
156156
| 'handleCopy'
157157
| 'handleDelete'
158-
| 'handleDeleteForMe'
159158
| 'handleEdit'
160159
| 'handleFlag'
161160
| 'handleMarkUnread'
@@ -229,7 +228,6 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
229228
groupStyles = ['bottom'],
230229
handleBan,
231230
handleCopy,
232-
handleDeleteForMe,
233231
handleDelete,
234232
handleEdit,
235233
handleFlag,
@@ -517,7 +515,6 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
517515
banUser,
518516
copyMessage,
519517
deleteMessage,
520-
deleteForMeMessage,
521518
editMessage,
522519
flagMessage,
523520
handleReaction,
@@ -538,7 +535,6 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
538535
handleBan,
539536
handleCopy,
540537
handleDelete,
541-
handleDeleteForMe,
542538
handleEdit,
543539
handleFlag,
544540
handleMarkUnread,
@@ -570,7 +566,6 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
570566
: messageActionsProp({
571567
banUser,
572568
copyMessage,
573-
deleteForMe: deleteForMeMessage,
574569
deleteMessage,
575570
dismissOverlay,
576571
editMessage,
@@ -588,6 +583,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
588583
showMessageReactions,
589584
threadReply,
590585
unpinMessage,
586+
updateMessage,
591587
});
592588

593589
const actionHandlers: MessageActionHandlers = {

package/src/components/Message/hooks/useMessageActionHandlers.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export const useMessageActionHandlers = ({
1919
sendReaction,
2020
setEditingState,
2121
setQuotedMessage,
22-
updateMessage,
2322
}: Pick<
2423
MessagesContextValue,
2524
| 'sendReaction'
@@ -72,17 +71,6 @@ export const useMessageActionHandlers = ({
7271
);
7372
};
7473

75-
const handleDeleteForMeMessage = async () => {
76-
try {
77-
const { message: deletedMessage } = await client.deleteMessage(message.id, {
78-
deleteForMe: true,
79-
});
80-
updateMessage(deletedMessage);
81-
} catch (error) {
82-
console.log('Error deleting message for me:', error);
83-
}
84-
};
85-
8674
const handleToggleMuteUser = async () => {
8775
if (!message.user?.id) {
8876
return;
@@ -199,7 +187,6 @@ export const useMessageActionHandlers = ({
199187

200188
return {
201189
handleCopyMessage,
202-
handleDeleteForMeMessage,
203190
handleDeleteMessage,
204191
handleEditMessage,
205192
handleFlagMessage,

package/src/components/Message/hooks/useMessageActions.tsx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export type MessageActionsHookProps = Pick<
3838
| 'sendReaction'
3939
| 'handleBan'
4040
| 'handleCopy'
41-
| 'handleDeleteForMe'
4241
| 'handleDelete'
4342
| 'handleEdit'
4443
| 'handleFlag'
@@ -73,7 +72,6 @@ export const useMessageActions = ({
7372
enforceUniqueReaction,
7473
handleBan,
7574
handleCopy,
76-
handleDeleteForMe,
7775
handleDelete,
7876
handleEdit,
7977
handleFlag,
@@ -103,7 +101,6 @@ export const useMessageActions = ({
103101
} = useTheme();
104102
const {
105103
handleCopyMessage,
106-
handleDeleteForMeMessage,
107104
handleDeleteMessage,
108105
handleEditMessage,
109106
handleFlagMessage,
@@ -187,20 +184,6 @@ export const useMessageActions = ({
187184
titleStyle: { color: accent_red },
188185
};
189186

190-
const deleteForMeMessage: MessageActionType = {
191-
action: () => {
192-
dismissOverlay();
193-
if (handleDeleteForMe) {
194-
handleDeleteForMe(message);
195-
}
196-
handleDeleteForMeMessage();
197-
},
198-
actionType: 'deleteForMe',
199-
icon: <Delete fill={accent_red} size={24} />,
200-
title: t('Delete for me'),
201-
titleStyle: { color: accent_red },
202-
};
203-
204187
const editMessage: MessageActionType = {
205188
action: () => {
206189
dismissOverlay();
@@ -338,7 +321,6 @@ export const useMessageActions = ({
338321
return {
339322
banUser,
340323
copyMessage,
341-
deleteForMeMessage,
342324
deleteMessage,
343325
editMessage,
344326
flagMessage,

package/src/components/Message/utils/messageActions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { MessageContextValue } from '../../../contexts/messageContext/MessageContext';
2+
import type { MessagesContextValue } from '../../../contexts/messagesContext/MessagesContext';
23
import type { OwnCapabilitiesContextValue } from '../../../contexts/ownCapabilitiesContext/OwnCapabilitiesContext';
34
import { isClipboardAvailable } from '../../../native';
45

@@ -25,9 +26,8 @@ export type MessageActionsParams = {
2526
showMessageReactions: boolean;
2627
threadReply: MessageActionType;
2728
unpinMessage: MessageActionType;
28-
// Optional Actions
29-
deleteForMe?: MessageActionType;
30-
} & Pick<MessageContextValue, 'message' | 'isMyMessage'>;
29+
} & Pick<MessageContextValue, 'message' | 'isMyMessage'> &
30+
Pick<MessagesContextValue, 'updateMessage'>;
3131

3232
export type MessageActionsProp = (param: MessageActionsParams) => MessageActionType[];
3333

package/src/contexts/messagesContext/MessagesContext.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@ export type MessagesContextValue = Pick<MessageContextValue, 'isMessageAIGenerat
404404
handleBan?: (message: LocalMessage) => Promise<void>;
405405
/** Handler to access when a copy message action is invoked */
406406
handleCopy?: (message: LocalMessage) => Promise<void>;
407-
/** Handler to access when a delete for me message action is invoked */
408-
handleDeleteForMe?: (message: LocalMessage) => Promise<void>;
409407
/** Handler to access when a delete message action is invoked */
410408
handleDelete?: (message: LocalMessage) => Promise<void>;
411409
/** Handler to access when an edit message action is invoked */

0 commit comments

Comments
 (0)