Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3380450
D5780.id19294.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D5780.id19294.diff
View Options
diff --git a/native/chat/reaction-message-utils.js b/native/chat/reaction-message-utils.js
new file mode 100644
--- /dev/null
+++ b/native/chat/reaction-message-utils.js
@@ -0,0 +1,81 @@
+// @flow
+
+import invariant from 'invariant';
+import Alert from 'react-native/Libraries/Alert/Alert';
+
+import {
+ sendReactionMessage,
+ sendReactionMessageActionTypes,
+} from 'lib/actions/message-actions';
+import type { BindServerCall, DispatchFunctions } from 'lib/utils/action-utils';
+
+import type { TooltipRoute } from '../navigation/tooltip.react';
+
+function onPressReact(
+ route:
+ | TooltipRoute<'TextMessageTooltipModal'>
+ | TooltipRoute<'MultimediaMessageTooltipModal'>
+ | TooltipRoute<'RobotextMessageTooltipModal'>,
+ dispatchFunctions: DispatchFunctions,
+ bindServerCall: BindServerCall,
+) {
+ const messageID = route.params.item.messageInfo.id;
+ invariant(messageID, 'messageID should be set');
+
+ const threadID = route.params.item.threadInfo.id;
+ invariant(threadID, 'threadID should be set');
+
+ sendReaction(
+ messageID,
+ threadID,
+ '👍',
+ 'add_reaction',
+ dispatchFunctions,
+ bindServerCall,
+ );
+}
+
+function sendReaction(
+ messageID: string,
+ threadID: string,
+ reaction: string,
+ action: 'add_reaction' | 'remove_reaction',
+ dispatchFunctions: DispatchFunctions,
+ bindServerCall: BindServerCall,
+) {
+ const callSendReactionMessage = bindServerCall(sendReactionMessage);
+
+ const reactionMessagePromise = (async () => {
+ try {
+ const result = await callSendReactionMessage({
+ threadID,
+ targetMessageID: messageID,
+ reaction,
+ action,
+ });
+ return {
+ serverID: result.id,
+ threadID,
+ time: result.newMessageInfo.time,
+ newMessageInfos: [result.newMessageInfo],
+ };
+ } catch (e) {
+ Alert.alert(
+ 'Couldn’t send the reaction',
+ 'Please try again later',
+ [{ text: 'OK' }],
+ {
+ cancelable: true,
+ },
+ );
+ throw e;
+ }
+ })();
+
+ dispatchFunctions.dispatchActionPromise(
+ sendReactionMessageActionTypes,
+ reactionMessagePromise,
+ );
+}
+
+export { onPressReact };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 11:52 PM (21 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2595191
Default Alt Text
D5780.id19294.diff (2 KB)
Attached To
Mode
D5780: [native] introduce onPressReact to reaction message utils
Attached
Detach File
Event Timeline
Log In to Comment