Skip to content

Commit 117d99e

Browse files
committed
feat: add optional support of delete message for me
1 parent 7d3dd9e commit 117d99e

File tree

25 files changed

+86
-11
lines changed

25 files changed

+86
-11
lines changed

examples/ExpoMessaging/app/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Alert, Image, Pressable, StyleSheet, View } from 'react-native';
2-
import { ChannelList } from 'stream-chat-expo';
2+
import { ChannelList, SqliteClient } from 'stream-chat-expo';
33
import { useCallback, useContext, useMemo } from 'react';
44
import { Stack, useRouter } from 'expo-router';
55
import { ChannelSort } from 'stream-chat';
@@ -19,7 +19,13 @@ const LogoutButton = () => {
1919
const onLogoutHandler = useCallback(() => {
2020
Alert.alert('Logout', 'Are you sure you want to logout?', [
2121
{ text: 'Cancel', style: 'cancel' },
22-
{ text: 'Logout', onPress: logOut },
22+
{
23+
text: 'Logout',
24+
onPress: () => {
25+
SqliteClient.resetDB();
26+
logOut();
27+
},
28+
},
2329
]);
2430
}, [logOut]);
2531

examples/ExpoMessaging/components/ChatWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const ChatWrapper = ({ children }: PropsWithChildren<{}>) => {
4646

4747
return (
4848
<OverlayProvider i18nInstance={streami18n} value={{ style: theme }}>
49-
<Chat client={chatClient} i18nInstance={streami18n}>
49+
<Chat client={chatClient} i18nInstance={streami18n} enableOfflineSupport>
5050
{children}
5151
</Chat>
5252
</OverlayProvider>

package/src/components/Channel/Channel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ export type ChannelPropsWithContext = Pick<ChannelContextValue, 'channel'> &
321321
| 'giphyVersion'
322322
| 'handleBan'
323323
| 'handleCopy'
324+
| 'handleDeleteForMe'
324325
| 'handleDelete'
325326
| 'handleEdit'
326327
| 'handleFlag'
@@ -579,6 +580,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
579580
handleAttachButtonPress,
580581
handleBan,
581582
handleCopy,
583+
handleDeleteForMe,
582584
handleDelete,
583585
handleEdit,
584586
handleFlag,
@@ -1837,6 +1839,7 @@ const ChannelWithContext = (props: PropsWithChildren<ChannelPropsWithContext>) =
18371839
handleBan,
18381840
handleCopy,
18391841
handleDelete,
1842+
handleDeleteForMe,
18401843
handleEdit,
18411844
handleFlag,
18421845
handleMarkUnread,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const useCreateMessagesContext = ({
3333
handleBan,
3434
handleCopy,
3535
handleDelete,
36+
handleDeleteForMe,
3637
handleEdit,
3738
handleFlag,
3839
handleMarkUnread,
@@ -150,6 +151,7 @@ export const useCreateMessagesContext = ({
150151
handleBan,
151152
handleCopy,
152153
handleDelete,
154+
handleDeleteForMe,
153155
handleEdit,
154156
handleFlag,
155157
handleMarkUnread,

package/src/components/Message/Message.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export type MessagePropsWithContext = Pick<
155155
| 'handleBan'
156156
| 'handleCopy'
157157
| 'handleDelete'
158+
| 'handleDeleteForMe'
158159
| 'handleEdit'
159160
| 'handleFlag'
160161
| 'handleMarkUnread'
@@ -228,6 +229,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
228229
groupStyles = ['bottom'],
229230
handleBan,
230231
handleCopy,
232+
handleDeleteForMe,
231233
handleDelete,
232234
handleEdit,
233235
handleFlag,
@@ -508,12 +510,14 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
508510
setEditingState,
509511
setQuotedMessage,
510512
supportedReactions,
513+
updateMessage,
511514
});
512515

513516
const {
514517
banUser,
515518
copyMessage,
516519
deleteMessage,
520+
deleteForMeMessage,
517521
editMessage,
518522
flagMessage,
519523
handleReaction,
@@ -534,6 +538,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
534538
handleBan,
535539
handleCopy,
536540
handleDelete,
541+
handleDeleteForMe,
537542
handleEdit,
538543
handleFlag,
539544
handleMarkUnread,
@@ -565,6 +570,7 @@ const MessageWithContext = (props: MessagePropsWithContext) => {
565570
: messageActionsProp({
566571
banUser,
567572
copyMessage,
573+
deleteForMe: deleteForMeMessage,
568574
deleteMessage,
569575
dismissOverlay,
570576
editMessage,

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ export const useMessageActionHandlers = ({
1919
sendReaction,
2020
setEditingState,
2121
setQuotedMessage,
22+
updateMessage,
2223
}: Pick<
2324
MessagesContextValue,
24-
'sendReaction' | 'deleteMessage' | 'deleteReaction' | 'retrySendMessage' | 'supportedReactions'
25+
| 'sendReaction'
26+
| 'deleteMessage'
27+
| 'updateMessage'
28+
| 'deleteReaction'
29+
| 'retrySendMessage'
30+
| 'supportedReactions'
2531
> &
2632
Pick<ChannelContextValue, 'channel' | 'enforceUniqueReaction'> &
2733
Pick<ChatContextValue, 'client'> &
@@ -66,6 +72,17 @@ export const useMessageActionHandlers = ({
6672
);
6773
};
6874

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+
6986
const handleToggleMuteUser = async () => {
7087
if (!message.user?.id) {
7188
return;
@@ -182,6 +199,7 @@ export const useMessageActionHandlers = ({
182199

183200
return {
184201
handleCopyMessage,
202+
handleDeleteForMeMessage,
185203
handleDeleteMessage,
186204
handleEditMessage,
187205
handleFlagMessage,

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type MessageActionsHookProps = Pick<
3838
| 'sendReaction'
3939
| 'handleBan'
4040
| 'handleCopy'
41+
| 'handleDeleteForMe'
4142
| 'handleDelete'
4243
| 'handleEdit'
4344
| 'handleFlag'
@@ -72,6 +73,7 @@ export const useMessageActions = ({
7273
enforceUniqueReaction,
7374
handleBan,
7475
handleCopy,
76+
handleDeleteForMe,
7577
handleDelete,
7678
handleEdit,
7779
handleFlag,
@@ -92,6 +94,7 @@ export const useMessageActions = ({
9294
supportedReactions,
9395
t,
9496
setQuotedMessage,
97+
updateMessage,
9598
}: MessageActionsHookProps) => {
9699
const {
97100
theme: {
@@ -100,6 +103,7 @@ export const useMessageActions = ({
100103
} = useTheme();
101104
const {
102105
handleCopyMessage,
106+
handleDeleteForMeMessage,
103107
handleDeleteMessage,
104108
handleEditMessage,
105109
handleFlagMessage,
@@ -122,6 +126,7 @@ export const useMessageActions = ({
122126
setEditingState,
123127
setQuotedMessage,
124128
supportedReactions,
129+
updateMessage,
125130
});
126131

127132
const error = message.type === 'error' || message.status === MessageStatusTypes.FAILED;
@@ -182,6 +187,20 @@ export const useMessageActions = ({
182187
titleStyle: { color: accent_red },
183188
};
184189

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+
185204
const editMessage: MessageActionType = {
186205
action: () => {
187206
dismissOverlay();
@@ -319,6 +338,7 @@ export const useMessageActions = ({
319338
return {
320339
banUser,
321340
copyMessage,
341+
deleteForMeMessage,
322342
deleteMessage,
323343
editMessage,
324344
flagMessage,

package/src/contexts/messagesContext/MessagesContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@ 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>;
407409
/** Handler to access when a delete message action is invoked */
408410
handleDelete?: (message: LocalMessage) => Promise<void>;
409411
/** Handler to access when an edit message action is invoked */

package/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Create Poll": "Create Poll",
2424
"Delete": "Delete",
2525
"Delete Message": "Delete Message",
26+
"Delete for me": "Delete for me",
2627
"Device camera is used to take photos or videos.": "Device camera is used to take photos or videos.",
2728
"Device gallery permissions is used to take photos or videos.": "Device gallery permissions is used to take photos or videos.",
2829
"Do you want to send a copy of this message to a moderator for further investigation?": "Do you want to send a copy of this message to a moderator for further investigation?",

package/src/i18n/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Create Poll": "Crear encuesta",
2424
"Delete": "Eliminar",
2525
"Delete Message": "Eliminar mensaje",
26+
"Delete for me": "Eliminar para mí",
2627
"Device camera is used to take photos or videos.": "La cámara del dispositivo se utiliza para tomar fotografías o vídeos.",
2728
"Device gallery permissions is used to take photos or videos.": "Los permisos de la galería del dispositivo se utilizan para tomar fotos o videos.",
2829
"Do you want to send a copy of this message to a moderator for further investigation?": "¿Deseas enviar una copia de este mensaje a un moderador para una investigación adicional?",

0 commit comments

Comments
 (0)