-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathmessageActions.tsx
More file actions
135 lines (129 loc) · 3.82 KB
/
messageActions.tsx
File metadata and controls
135 lines (129 loc) · 3.82 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React from 'react';
import { Alert } from 'react-native';
import { LocalMessage, StreamChat } from 'stream-chat';
import {
Colors,
Delete,
Eye,
messageActions,
MessageActionsParams,
Time,
TranslationContextValue,
Bell,
} from 'stream-chat-react-native';
import { Theme } from 'stream-chat-react-native';
export function channelMessageActions({
params,
chatClient,
t,
handleMessageInfo,
semantics,
}: {
params: MessageActionsParams;
chatClient: StreamChat;
t: TranslationContextValue['t'];
colors?: typeof Colors;
handleMessageInfo: (message: LocalMessage) => void;
semantics: Theme['semantics'];
}) {
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 width={20} height={20} stroke={semantics.textSecondary} />,
type: 'standard',
});
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={20} width={20} stroke={semantics.textSecondary} />,
type: 'standard',
});
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 stroke={semantics.accentError} width={20} height={20} />,
title: t('Delete for me'),
type: 'destructive',
});
actions.push({
action: () => {
dismissOverlay();
handleMessageInfo(params.message);
},
actionType: 'messageInfo',
icon: <Eye height={20} width={20} pathFill={semantics.textSecondary} />,
title: 'Message Info',
type: 'standard',
});
return actions;
}