-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathmessageActions.tsx
More file actions
115 lines (110 loc) · 3.23 KB
/
messageActions.tsx
File metadata and controls
115 lines (110 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { Alert } from 'react-native';
import { StreamChat } from 'stream-chat';
import {
Colors,
Delete,
messageActions,
MessageActionsParams,
Time,
TranslationContextValue,
} from 'stream-chat-react-native';
import { Bell } from '../icons/Bell';
export function channelMessageActions({
params,
chatClient,
colors,
t,
}: {
params: MessageActionsParams;
chatClient: StreamChat;
t: TranslationContextValue['t'];
colors?: typeof Colors;
}) {
const { dismissOverlay, deleteForMeMessage } = params;
const actions = messageActions(params);
// We cannot use the useMessageReminder hook here because it is a hook.
const reminder = chatClient.reminders.getFromState(params.message.id);
actions.push({
action: async () => {
try {
if (reminder) {
await chatClient.reminders.deleteReminder(reminder.id);
} else {
await chatClient.reminders.createReminder({ messageId: params.message.id });
}
dismissOverlay();
} catch (error) {
console.error('Error creating reminder:', error);
}
},
actionType: reminder ? 'remove-from-later' : 'save-for-later',
title: reminder ? 'Remove from Later' : 'Save for Later',
icon: <Time pathFill={colors?.grey} />,
});
actions.push({
action: () => {
if (reminder) {
Alert.alert('Remove Reminder', 'Are you sure you want to remove this reminder?', [
{
text: 'Cancel',
style: 'cancel',
},
{
text: 'Remove',
onPress: () => {
chatClient.reminders.deleteReminder(reminder.id).catch((error) => {
console.error('Error deleting reminder:', error);
});
},
style: 'destructive',
},
]);
} else {
Alert.alert(
'Select Reminder Time',
'When would you like to be reminded?',
chatClient.reminders.scheduledOffsetsMs.map((offsetMs) => ({
text: t('duration/Remind Me', { milliseconds: offsetMs }),
onPress: () => {
chatClient.reminders
.upsertReminder({
messageId: params.message.id,
remind_at: new Date(new Date().getTime() + offsetMs).toISOString(),
})
.catch((error) => {
console.error('Error creating reminder:', error);
});
},
style: 'default',
})),
);
}
dismissOverlay();
},
actionType: reminder ? 'remove-reminder' : 'remind-me',
title: reminder ? 'Remove Reminder' : 'Remind Me',
icon: <Bell height={24} width={24} />,
});
actions.push({
action: async () => {
Alert.alert('Delete for me', 'Are you sure you want to delete this message for me?', [
{
text: 'Cancel',
style: 'cancel',
},
{
text: 'Delete',
onPress: async () => {
await deleteForMeMessage?.action();
dismissOverlay();
},
style: 'destructive',
},
]);
},
actionType: 'deleteForMe',
icon: <Delete fill={colors?.accent_red} size={24} />,
title: t('Delete for me'),
});
return actions;
}