2021-09-13 20:41:05 +00:00
|
|
|
import React, { forwardRef, useImperativeHandle } from 'react';
|
2022-03-29 16:09:44 +00:00
|
|
|
import { Alert, Share } from 'react-native';
|
|
|
|
import Clipboard from '@react-native-clipboard/clipboard';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import moment from 'moment';
|
|
|
|
|
|
|
|
import database from '../../lib/database';
|
|
|
|
import I18n from '../../i18n';
|
2022-06-06 14:17:51 +00:00
|
|
|
import log, { logEvent } from '../../lib/methods/helpers/log';
|
2022-04-07 13:22:19 +00:00
|
|
|
import Navigation from '../../lib/navigation/appNavigation';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { getMessageTranslation } from '../message/utils';
|
|
|
|
import { LISTENER } from '../Toast';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
|
|
|
import { showConfirmationAlert } from '../../lib/methods/helpers/info';
|
2022-10-21 18:27:55 +00:00
|
|
|
import { TActionSheetOptionsItem, useActionSheet, ACTION_SHEET_ANIMATION_DURATION } from '../ActionSheet';
|
2023-10-03 12:57:49 +00:00
|
|
|
import Header, { HEADER_HEIGHT, IHeader } from './Header';
|
2022-06-06 14:17:51 +00:00
|
|
|
import events from '../../lib/methods/helpers/log/events';
|
2022-10-21 18:27:55 +00:00
|
|
|
import { IApplicationState, IEmoji, ILoggedUser, TAnyMessageModel, TSubscriptionModel } from '../../definitions';
|
2023-11-30 15:03:03 +00:00
|
|
|
import { getPermalinkMessage, getQuoteMessageLink } from '../../lib/methods';
|
2023-08-04 14:09:36 +00:00
|
|
|
import { compareServerVersion, getRoomTitle, getUidDirectMessage, hasPermission } from '../../lib/methods/helpers';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2022-03-02 14:18:01 +00:00
|
|
|
|
2022-05-02 22:58:23 +00:00
|
|
|
export interface IMessageActionsProps {
|
2022-03-02 14:18:01 +00:00
|
|
|
room: TSubscriptionModel;
|
|
|
|
tmid?: string;
|
|
|
|
user: Pick<ILoggedUser, 'id'>;
|
2022-03-31 12:38:20 +00:00
|
|
|
editInit: (message: TAnyMessageModel) => void;
|
|
|
|
reactionInit: (message: TAnyMessageModel) => void;
|
2022-10-21 18:27:55 +00:00
|
|
|
onReactionPress: (shortname: IEmoji, messageId: string) => void;
|
2022-03-31 12:38:20 +00:00
|
|
|
replyInit: (message: TAnyMessageModel, mention: boolean) => void;
|
2023-11-30 15:03:03 +00:00
|
|
|
jumpToMessage?: (messageUrl?: string, isFromReply?: boolean) => Promise<void>;
|
2021-09-13 20:41:05 +00:00
|
|
|
isMasterDetail: boolean;
|
|
|
|
isReadOnly: boolean;
|
2023-08-04 14:09:36 +00:00
|
|
|
serverVersion?: string | null;
|
2022-03-31 12:38:20 +00:00
|
|
|
Message_AllowDeleting?: boolean;
|
|
|
|
Message_AllowDeleting_BlockDeleteInMinutes?: number;
|
|
|
|
Message_AllowEditing?: boolean;
|
|
|
|
Message_AllowEditing_BlockEditInMinutes?: number;
|
|
|
|
Message_AllowPinning?: boolean;
|
|
|
|
Message_AllowStarring?: boolean;
|
|
|
|
Message_Read_Receipt_Store_Users?: boolean;
|
|
|
|
editMessagePermission?: string[];
|
|
|
|
deleteMessagePermission?: string[];
|
|
|
|
forceDeleteMessagePermission?: string[];
|
2022-11-11 17:28:41 +00:00
|
|
|
deleteOwnMessagePermission?: string[];
|
2022-03-31 12:38:20 +00:00
|
|
|
pinMessagePermission?: string[];
|
2022-11-04 17:09:58 +00:00
|
|
|
createDirectMessagePermission?: string[];
|
2023-10-16 20:55:38 +00:00
|
|
|
createDiscussionOtherUserPermission?: string[];
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-05-02 22:58:23 +00:00
|
|
|
export interface IMessageActions {
|
|
|
|
showMessageActions: (message: TAnyMessageModel) => Promise<void>;
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const MessageActions = React.memo(
|
2022-05-02 22:58:23 +00:00
|
|
|
forwardRef<IMessageActions, IMessageActionsProps>(
|
2021-09-13 20:41:05 +00:00
|
|
|
(
|
|
|
|
{
|
|
|
|
room,
|
|
|
|
tmid,
|
|
|
|
user,
|
|
|
|
editInit,
|
|
|
|
reactionInit,
|
|
|
|
onReactionPress,
|
|
|
|
replyInit,
|
2023-11-30 15:03:03 +00:00
|
|
|
jumpToMessage,
|
2021-09-13 20:41:05 +00:00
|
|
|
isReadOnly,
|
|
|
|
Message_AllowDeleting,
|
|
|
|
Message_AllowDeleting_BlockDeleteInMinutes,
|
|
|
|
Message_AllowEditing,
|
|
|
|
Message_AllowEditing_BlockEditInMinutes,
|
|
|
|
Message_AllowPinning,
|
|
|
|
Message_AllowStarring,
|
|
|
|
Message_Read_Receipt_Store_Users,
|
|
|
|
isMasterDetail,
|
|
|
|
editMessagePermission,
|
|
|
|
deleteMessagePermission,
|
|
|
|
forceDeleteMessagePermission,
|
2022-11-11 17:28:41 +00:00
|
|
|
deleteOwnMessagePermission,
|
2022-11-04 17:09:58 +00:00
|
|
|
pinMessagePermission,
|
2023-08-04 14:09:36 +00:00
|
|
|
createDirectMessagePermission,
|
2023-10-16 20:55:38 +00:00
|
|
|
createDiscussionOtherUserPermission,
|
2023-08-04 14:09:36 +00:00
|
|
|
serverVersion
|
2022-05-02 22:58:23 +00:00
|
|
|
},
|
2021-09-13 20:41:05 +00:00
|
|
|
ref
|
2022-03-31 12:38:20 +00:00
|
|
|
) => {
|
|
|
|
let permissions = {
|
|
|
|
hasEditPermission: false,
|
|
|
|
hasDeletePermission: false,
|
|
|
|
hasForceDeletePermission: false,
|
2022-11-11 17:28:41 +00:00
|
|
|
hasPinPermission: false,
|
2023-10-16 20:55:38 +00:00
|
|
|
hasDeleteOwnPermission: false,
|
|
|
|
hasCreateDirectMessagePermission: false,
|
|
|
|
hasCreateDiscussionOtherUserPermission: false
|
2022-03-31 12:38:20 +00:00
|
|
|
};
|
|
|
|
const { showActionSheet, hideActionSheet } = useActionSheet();
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
const getPermissions = async () => {
|
|
|
|
try {
|
2022-11-11 17:28:41 +00:00
|
|
|
const permission = [
|
|
|
|
editMessagePermission,
|
|
|
|
deleteMessagePermission,
|
|
|
|
forceDeleteMessagePermission,
|
|
|
|
pinMessagePermission,
|
2023-10-16 20:55:38 +00:00
|
|
|
deleteOwnMessagePermission,
|
|
|
|
createDirectMessagePermission,
|
|
|
|
createDiscussionOtherUserPermission
|
2022-11-11 17:28:41 +00:00
|
|
|
];
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await hasPermission(permission, room.rid);
|
2021-09-13 20:41:05 +00:00
|
|
|
permissions = {
|
|
|
|
hasEditPermission: result[0],
|
|
|
|
hasDeletePermission: result[1],
|
|
|
|
hasForceDeletePermission: result[2],
|
2022-11-11 17:28:41 +00:00
|
|
|
hasPinPermission: result[3],
|
2023-10-16 20:55:38 +00:00
|
|
|
hasDeleteOwnPermission: result[4],
|
|
|
|
hasCreateDirectMessagePermission: result[5],
|
|
|
|
hasCreateDiscussionOtherUserPermission: result[6]
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
|
|
|
} catch {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const isOwn = (message: TAnyMessageModel) => message.u && message.u._id === user.id;
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const allowEdit = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (isReadOnly) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const editOwn = isOwn(message);
|
|
|
|
|
|
|
|
if (!(permissions.hasEditPermission || (Message_AllowEditing && editOwn))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const blockEditInMinutes = Message_AllowEditing_BlockEditInMinutes;
|
|
|
|
if (blockEditInMinutes) {
|
|
|
|
let msgTs;
|
|
|
|
if (message.ts != null) {
|
|
|
|
msgTs = moment(message.ts);
|
|
|
|
}
|
2022-03-31 12:38:20 +00:00
|
|
|
let currentTsDiff = 0;
|
2021-09-13 20:41:05 +00:00
|
|
|
if (msgTs != null) {
|
|
|
|
currentTsDiff = moment().diff(msgTs, 'minutes');
|
|
|
|
}
|
|
|
|
return currentTsDiff < blockEditInMinutes;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const allowDelete = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (isReadOnly) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prevent from deleting thread start message when positioned inside the thread
|
|
|
|
if (tmid === message.id) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-11-11 17:28:41 +00:00
|
|
|
const deleteOwn = isOwn(message) && permissions.hasDeleteOwnPermission;
|
2021-09-13 20:41:05 +00:00
|
|
|
if (!(permissions.hasDeletePermission || (Message_AllowDeleting && deleteOwn) || permissions.hasForceDeletePermission)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (permissions.hasForceDeletePermission) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const blockDeleteInMinutes = Message_AllowDeleting_BlockDeleteInMinutes;
|
|
|
|
if (blockDeleteInMinutes != null && blockDeleteInMinutes !== 0) {
|
|
|
|
let msgTs;
|
|
|
|
if (message.ts != null) {
|
|
|
|
msgTs = moment(message.ts);
|
|
|
|
}
|
2022-03-31 12:38:20 +00:00
|
|
|
let currentTsDiff = 0;
|
2021-09-13 20:41:05 +00:00
|
|
|
if (msgTs != null) {
|
|
|
|
currentTsDiff = moment().diff(msgTs, 'minutes');
|
|
|
|
}
|
|
|
|
return currentTsDiff < blockDeleteInMinutes;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
const getPermalink = (message: TAnyMessageModel) => getPermalinkMessage(message);
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleReply = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_REPLY);
|
|
|
|
replyInit(message, true);
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleEdit = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_EDIT);
|
|
|
|
editInit(message);
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleCreateDiscussion = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_DISCUSSION);
|
|
|
|
const params = { message, channel: room, showCloseModal: true };
|
|
|
|
if (isMasterDetail) {
|
|
|
|
Navigation.navigate('ModalStackNavigator', { screen: 'CreateDiscussionView', params });
|
|
|
|
} else {
|
|
|
|
Navigation.navigate('NewMessageStackNavigator', { screen: 'CreateDiscussionView', params });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-08-04 14:09:36 +00:00
|
|
|
const handleShareMessage = (message: TAnyMessageModel) => {
|
|
|
|
const params = { message };
|
|
|
|
if (isMasterDetail) {
|
|
|
|
Navigation.navigate('ModalStackNavigator', { screen: 'ForwardMessageView', params });
|
|
|
|
} else {
|
|
|
|
Navigation.navigate('NewMessageStackNavigator', { screen: 'ForwardMessageView', params });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleUnread = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_UNREAD);
|
|
|
|
const { id: messageId, ts } = message;
|
|
|
|
const { rid } = room;
|
|
|
|
try {
|
|
|
|
const db = database.active;
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.markAsUnread({ messageId });
|
2021-09-13 20:41:05 +00:00
|
|
|
if (result.success) {
|
|
|
|
const subCollection = db.get('subscriptions');
|
|
|
|
const subRecord = await subCollection.find(rid);
|
2022-02-01 13:39:09 +00:00
|
|
|
await db.write(async () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
try {
|
2022-03-31 12:38:20 +00:00
|
|
|
await subRecord.update(sub => (sub.lastOpen = ts as Date)); // TODO: reevaluate IMessage
|
2021-09-13 20:41:05 +00:00
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Navigation.navigate('RoomsListView');
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_UNREAD_F);
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handlePermalink = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_PERMALINK);
|
|
|
|
try {
|
2022-03-31 12:38:20 +00:00
|
|
|
const permalink = await getPermalink(message);
|
|
|
|
Clipboard.setString(permalink ?? '');
|
2021-09-13 20:41:05 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Permalink_copied_to_clipboard') });
|
|
|
|
} catch {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_PERMALINK_F);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleCopy = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_COPY);
|
2022-03-31 12:38:20 +00:00
|
|
|
await Clipboard.setString((message?.attachments?.[0]?.description || message.msg) ?? '');
|
2021-09-13 20:41:05 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Copied_to_clipboard') });
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleShare = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_SHARE);
|
|
|
|
try {
|
2022-03-31 12:38:20 +00:00
|
|
|
const permalink = await getPermalink(message);
|
|
|
|
if (permalink) {
|
|
|
|
Share.share({ message: permalink });
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
} catch {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_SHARE_F);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleQuote = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_QUOTE);
|
|
|
|
replyInit(message, false);
|
|
|
|
};
|
|
|
|
|
2022-11-04 17:09:58 +00:00
|
|
|
const handleReplyInDM = async (message: TAnyMessageModel) => {
|
|
|
|
if (message?.u?.username) {
|
|
|
|
const result = await Services.createDirectMessage(message.u.username);
|
|
|
|
if (result.success) {
|
|
|
|
const { room } = result;
|
|
|
|
const params = {
|
|
|
|
rid: room.rid,
|
|
|
|
name: getRoomTitle(room),
|
|
|
|
t: room.t,
|
|
|
|
roomUserId: getUidDirectMessage(room),
|
|
|
|
replyInDM: message
|
|
|
|
};
|
|
|
|
Navigation.replace('RoomView', params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleStar = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(message.starred ? events.ROOM_MSG_ACTION_UNSTAR : events.ROOM_MSG_ACTION_STAR);
|
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.toggleStarMessage(message.id, message.starred as boolean); // TODO: reevaluate `message.starred` type on IMessage
|
2021-09-13 20:41:05 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: message.starred ? I18n.t('Message_unstarred') : I18n.t('Message_starred') });
|
|
|
|
} catch (e) {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_STAR_F);
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handlePin = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_PIN);
|
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.togglePinMessage(message.id, message.pinned as boolean); // TODO: reevaluate `message.pinned` type on IMessage
|
2021-09-13 20:41:05 +00:00
|
|
|
} catch (e) {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_PIN_F);
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-12-08 18:38:16 +00:00
|
|
|
const handleReaction: IHeader['handleReaction'] = (emoji, message) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_REACTION);
|
2022-12-08 18:38:16 +00:00
|
|
|
if (emoji) {
|
|
|
|
onReactionPress(emoji, message.id);
|
2021-09-13 20:41:05 +00:00
|
|
|
} else {
|
2022-10-21 18:27:55 +00:00
|
|
|
setTimeout(() => reactionInit(message), ACTION_SHEET_ANIMATION_DURATION);
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
hideActionSheet();
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleReadReceipt = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (isMasterDetail) {
|
|
|
|
Navigation.navigate('ModalStackNavigator', { screen: 'ReadReceiptsView', params: { messageId: message.id } });
|
|
|
|
} else {
|
|
|
|
Navigation.navigate('ReadReceiptsView', { messageId: message.id });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
const handleToggleTranslation = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
try {
|
2022-03-02 14:18:01 +00:00
|
|
|
if (!room.autoTranslateLanguage) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
const db = database.active;
|
2022-02-01 13:39:09 +00:00
|
|
|
await db.write(async () => {
|
|
|
|
await message.update(m => {
|
2023-08-14 20:22:46 +00:00
|
|
|
m.autoTranslate = m.autoTranslate !== null ? !m.autoTranslate : false;
|
2021-09-13 20:41:05 +00:00
|
|
|
m._updatedAt = new Date();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const translatedMessage = getMessageTranslation(message, room.autoTranslateLanguage);
|
|
|
|
if (!translatedMessage) {
|
2022-05-27 17:33:21 +00:00
|
|
|
await Services.translateMessage(message.id, room.autoTranslateLanguage);
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleReport = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_MSG_ACTION_REPORT);
|
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.reportMessage(message.id);
|
2021-09-13 20:41:05 +00:00
|
|
|
Alert.alert(I18n.t('Message_Reported'));
|
|
|
|
} catch (e) {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_REPORT_F);
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-31 12:38:20 +00:00
|
|
|
const handleDelete = (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('You_will_not_be_able_to_recover_this_message'),
|
|
|
|
confirmationText: I18n.t('Delete'),
|
|
|
|
onPress: async () => {
|
|
|
|
try {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_DELETE);
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.deleteMessage(message.id, message.subscription ? message.subscription.id : '');
|
2021-09-13 20:41:05 +00:00
|
|
|
} catch (e) {
|
|
|
|
logEvent(events.ROOM_MSG_ACTION_DELETE_F);
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
const getOptions = (message: TAnyMessageModel) => {
|
2022-11-10 19:48:52 +00:00
|
|
|
const options: TActionSheetOptionsItem[] = [];
|
2022-11-24 17:24:20 +00:00
|
|
|
const videoConfBlock = message.t === 'videoconf';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2023-11-30 15:03:03 +00:00
|
|
|
// Jump to message
|
|
|
|
const quoteMessageLink = getQuoteMessageLink(message.attachments);
|
|
|
|
if (quoteMessageLink && jumpToMessage) {
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Jump_to_message'),
|
|
|
|
icon: 'jump-to-message',
|
|
|
|
onPress: () => jumpToMessage(quoteMessageLink, true)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
// Quote
|
2022-11-24 11:37:08 +00:00
|
|
|
if (!isReadOnly && !videoConfBlock) {
|
2021-09-13 20:41:05 +00:00
|
|
|
options.push({
|
|
|
|
title: I18n.t('Quote'),
|
|
|
|
icon: 'quote',
|
|
|
|
onPress: () => handleQuote(message)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:48:52 +00:00
|
|
|
// Reply
|
|
|
|
if (!isReadOnly && !tmid) {
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Reply_in_Thread'),
|
|
|
|
icon: 'threads',
|
|
|
|
onPress: () => handleReply(message)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-04 17:09:58 +00:00
|
|
|
// Reply in DM
|
2023-12-11 15:51:44 +00:00
|
|
|
if (room.t !== 'd' && room.t !== 'l' && !videoConfBlock) {
|
2022-11-04 17:09:58 +00:00
|
|
|
options.push({
|
|
|
|
title: I18n.t('Reply_in_direct_message'),
|
|
|
|
icon: 'arrow-back',
|
2023-12-11 15:51:44 +00:00
|
|
|
onPress: () => handleReplyInDM(message),
|
|
|
|
enabled: permissions.hasCreateDirectMessagePermission
|
2022-11-04 17:09:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
// Create Discussion
|
2023-12-11 15:51:44 +00:00
|
|
|
options.push({
|
|
|
|
title: I18n.t('Start_a_Discussion'),
|
|
|
|
icon: 'discussions',
|
|
|
|
onPress: () => handleCreateDiscussion(message),
|
|
|
|
enabled: permissions.hasCreateDiscussionOtherUserPermission
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2023-08-04 14:09:36 +00:00
|
|
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.2.0') && !videoConfBlock) {
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Forward'),
|
|
|
|
icon: 'arrow-forward',
|
|
|
|
onPress: () => handleShareMessage(message)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:48:52 +00:00
|
|
|
// Permalink
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Get_link'),
|
|
|
|
icon: 'link',
|
|
|
|
onPress: () => handlePermalink(message)
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
// Copy
|
2022-11-24 11:37:08 +00:00
|
|
|
if (!videoConfBlock) {
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Copy'),
|
|
|
|
icon: 'copy',
|
|
|
|
onPress: () => handleCopy(message)
|
|
|
|
});
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
// Share
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Share'),
|
|
|
|
icon: 'share',
|
|
|
|
onPress: () => handleShare(message)
|
|
|
|
});
|
|
|
|
|
2022-11-10 19:48:52 +00:00
|
|
|
// Edit
|
2023-12-12 17:58:40 +00:00
|
|
|
const isEditAllowed = allowEdit(message);
|
|
|
|
if (!videoConfBlock && (isOwn(message) || isEditAllowed)) {
|
2021-09-13 20:41:05 +00:00
|
|
|
options.push({
|
2022-11-10 19:48:52 +00:00
|
|
|
title: I18n.t('Edit'),
|
|
|
|
icon: 'edit',
|
2023-12-11 15:51:44 +00:00
|
|
|
onPress: () => handleEdit(message),
|
2023-12-12 17:58:40 +00:00
|
|
|
enabled: isEditAllowed
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pin
|
2023-12-11 15:51:44 +00:00
|
|
|
if (Message_AllowPinning && !videoConfBlock) {
|
2021-09-13 20:41:05 +00:00
|
|
|
options.push({
|
|
|
|
title: I18n.t(message.pinned ? 'Unpin' : 'Pin'),
|
|
|
|
icon: 'pin',
|
2023-12-11 15:51:44 +00:00
|
|
|
onPress: () => handlePin(message),
|
|
|
|
enabled: permissions?.hasPinPermission
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-11-10 19:48:52 +00:00
|
|
|
// Star
|
2022-11-24 11:37:08 +00:00
|
|
|
if (Message_AllowStarring && !videoConfBlock) {
|
2022-11-10 19:48:52 +00:00
|
|
|
options.push({
|
|
|
|
title: I18n.t(message.starred ? 'Unstar' : 'Star'),
|
|
|
|
icon: message.starred ? 'star-filled' : 'star',
|
|
|
|
onPress: () => handleStar(message)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark as unread
|
|
|
|
if (message.u && message.u._id !== user.id) {
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Mark_unread'),
|
|
|
|
icon: 'flag',
|
|
|
|
onPress: () => handleUnread(message)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
// Read Receipts
|
|
|
|
if (Message_Read_Receipt_Store_Users) {
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Read_Receipt'),
|
|
|
|
icon: 'info',
|
|
|
|
onPress: () => handleReadReceipt(message)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle Auto-translate
|
|
|
|
if (room.autoTranslate && message.u && message.u._id !== user.id) {
|
|
|
|
options.push({
|
2023-08-14 20:22:46 +00:00
|
|
|
title: I18n.t(message.autoTranslate !== false ? 'View_Original' : 'Translate'),
|
2021-09-13 20:41:05 +00:00
|
|
|
icon: 'language',
|
|
|
|
onPress: () => handleToggleTranslation(message)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Report
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Report'),
|
|
|
|
icon: 'warning',
|
|
|
|
danger: true,
|
|
|
|
onPress: () => handleReport(message)
|
|
|
|
});
|
|
|
|
|
|
|
|
// Delete
|
2023-12-12 17:58:40 +00:00
|
|
|
const isDeleteAllowed = allowDelete(message);
|
|
|
|
if (isOwn(message) || isDeleteAllowed) {
|
|
|
|
options.push({
|
|
|
|
title: I18n.t('Delete'),
|
|
|
|
icon: 'delete',
|
|
|
|
danger: true,
|
|
|
|
onPress: () => handleDelete(message),
|
|
|
|
enabled: isDeleteAllowed
|
|
|
|
});
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
|
|
|
|
return options;
|
|
|
|
};
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
const showMessageActions = async (message: TAnyMessageModel) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events.ROOM_SHOW_MSG_ACTIONS);
|
|
|
|
await getPermissions();
|
|
|
|
showActionSheet({
|
|
|
|
options: getOptions(message),
|
2023-10-03 12:57:49 +00:00
|
|
|
headerHeight: HEADER_HEIGHT,
|
2023-12-11 15:51:44 +00:00
|
|
|
customHeader: (
|
|
|
|
<>
|
|
|
|
{!isReadOnly || room.reactWhenReadOnly ? (
|
|
|
|
<Header handleReaction={handleReaction} isMasterDetail={isMasterDetail} message={message} />
|
|
|
|
) : null}
|
|
|
|
</>
|
|
|
|
)
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useImperativeHandle(ref, () => ({ showMessageActions }));
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
2022-03-31 12:38:20 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2021-09-13 20:41:05 +00:00
|
|
|
server: state.server.server,
|
2023-08-04 14:09:36 +00:00
|
|
|
serverVersion: state.server.version,
|
2022-03-31 12:38:20 +00:00
|
|
|
Message_AllowDeleting: state.settings.Message_AllowDeleting as boolean,
|
|
|
|
Message_AllowDeleting_BlockDeleteInMinutes: state.settings.Message_AllowDeleting_BlockDeleteInMinutes as number,
|
|
|
|
Message_AllowEditing: state.settings.Message_AllowEditing as boolean,
|
|
|
|
Message_AllowEditing_BlockEditInMinutes: state.settings.Message_AllowEditing_BlockEditInMinutes as number,
|
|
|
|
Message_AllowPinning: state.settings.Message_AllowPinning as boolean,
|
|
|
|
Message_AllowStarring: state.settings.Message_AllowStarring as boolean,
|
|
|
|
Message_Read_Receipt_Store_Users: state.settings.Message_Read_Receipt_Store_Users as boolean,
|
2021-09-13 20:41:05 +00:00
|
|
|
isMasterDetail: state.app.isMasterDetail,
|
|
|
|
editMessagePermission: state.permissions['edit-message'],
|
|
|
|
deleteMessagePermission: state.permissions['delete-message'],
|
2022-11-11 17:28:41 +00:00
|
|
|
deleteOwnMessagePermission: state.permissions['delete-own-message'],
|
2021-09-13 20:41:05 +00:00
|
|
|
forceDeleteMessagePermission: state.permissions['force-delete-message'],
|
2022-11-04 17:09:58 +00:00
|
|
|
pinMessagePermission: state.permissions['pin-message'],
|
2023-10-16 20:55:38 +00:00
|
|
|
createDirectMessagePermission: state.permissions['create-d'],
|
|
|
|
createDiscussionOtherUserPermission: state.permissions['start-discussion-other-user']
|
2021-09-13 20:41:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, null, null, { forwardRef: true })(MessageActions);
|