2017-11-21 14:55:50 +00:00
|
|
|
import React from 'react';
|
2022-01-17 16:10:39 +00:00
|
|
|
import { Keyboard, ViewStyle } from 'react-native';
|
2017-11-21 14:55:50 +00:00
|
|
|
|
2018-09-11 16:32:52 +00:00
|
|
|
import Message from './Message';
|
2020-04-30 20:05:59 +00:00
|
|
|
import MessageContext from './Context';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { debounce } from '../../lib/methods/helpers';
|
2022-05-03 14:27:20 +00:00
|
|
|
import { getMessageTranslation } from './utils';
|
2022-04-12 16:27:05 +00:00
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
2022-06-06 14:17:51 +00:00
|
|
|
import openLink from '../../lib/methods/helpers/openLink';
|
2022-05-07 01:06:08 +00:00
|
|
|
import { IAttachment, TAnyMessageModel, TGetCustomEmoji } from '../../definitions';
|
2022-04-01 21:52:38 +00:00
|
|
|
import { IRoomInfoParam } from '../../views/SearchMessagesView';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { E2E_MESSAGE_TYPE, E2E_STATUS, messagesStatus } from '../../lib/constants';
|
2018-01-09 17:12:55 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IMessageContainerProps {
|
2022-03-02 14:18:01 +00:00
|
|
|
item: TAnyMessageModel;
|
2021-09-13 20:41:05 +00:00
|
|
|
user: {
|
|
|
|
id: string;
|
|
|
|
username: string;
|
|
|
|
token: string;
|
|
|
|
};
|
2022-01-17 16:10:39 +00:00
|
|
|
msg?: string;
|
2022-04-01 21:52:38 +00:00
|
|
|
rid: string;
|
2022-03-02 14:18:01 +00:00
|
|
|
timeFormat?: string;
|
2022-01-17 16:10:39 +00:00
|
|
|
style?: ViewStyle;
|
|
|
|
archived?: boolean;
|
|
|
|
broadcast?: boolean;
|
2022-03-02 14:18:01 +00:00
|
|
|
previousItem?: TAnyMessageModel;
|
2021-09-13 20:41:05 +00:00
|
|
|
baseUrl: string;
|
2022-01-17 16:10:39 +00:00
|
|
|
Message_GroupingPeriod?: number;
|
|
|
|
isReadReceiptEnabled?: boolean;
|
2023-08-04 14:09:36 +00:00
|
|
|
isThreadRoom?: boolean;
|
2022-05-03 14:27:20 +00:00
|
|
|
isSystemMessage?: boolean;
|
2022-03-02 14:18:01 +00:00
|
|
|
useRealName?: boolean;
|
2022-01-17 16:10:39 +00:00
|
|
|
autoTranslateRoom?: boolean;
|
|
|
|
autoTranslateLanguage?: string;
|
|
|
|
status?: number;
|
|
|
|
isIgnored?: boolean;
|
|
|
|
highlighted?: boolean;
|
2022-02-17 15:27:01 +00:00
|
|
|
getCustomEmoji: TGetCustomEmoji;
|
2022-04-01 21:52:38 +00:00
|
|
|
onLongPress?: (item: TAnyMessageModel) => void;
|
|
|
|
onReactionPress?: (emoji: string, id: string) => void;
|
|
|
|
onEncryptedPress?: () => void;
|
|
|
|
onDiscussionPress?: (item: TAnyMessageModel) => void;
|
|
|
|
onThreadPress?: (item: TAnyMessageModel) => void;
|
|
|
|
errorActionsShow?: (item: TAnyMessageModel) => void;
|
|
|
|
replyBroadcast?: (item: TAnyMessageModel) => void;
|
2024-01-25 14:11:07 +00:00
|
|
|
reactionInit?: (messageId: string) => void;
|
2022-04-01 21:52:38 +00:00
|
|
|
fetchThreadName?: (tmid: string, id: string) => Promise<string | undefined>;
|
2023-08-04 14:09:36 +00:00
|
|
|
showAttachment?: (file: IAttachment) => void;
|
2022-04-01 21:52:38 +00:00
|
|
|
onReactionLongPress?: (item: TAnyMessageModel) => void;
|
2023-08-04 14:09:36 +00:00
|
|
|
navToRoomInfo?: (navParam: IRoomInfoParam) => void;
|
2023-03-01 18:26:56 +00:00
|
|
|
handleEnterCall?: () => void;
|
2022-04-01 21:52:38 +00:00
|
|
|
blockAction?: (params: { actionId: string; appId: string; value: string; blockId: string; rid: string; mid: string }) => void;
|
2024-01-25 14:11:07 +00:00
|
|
|
onAnswerButtonPress?: Function;
|
2022-01-17 16:10:39 +00:00
|
|
|
threadBadgeColor?: string;
|
2022-04-01 21:52:38 +00:00
|
|
|
toggleFollowThread?: (isFollowingThread: boolean, tmid?: string) => Promise<void>;
|
|
|
|
jumpToMessage?: (link: string) => void;
|
|
|
|
onPress?: () => void;
|
2023-08-04 14:09:36 +00:00
|
|
|
theme?: TSupportedThemes;
|
2022-08-08 18:38:01 +00:00
|
|
|
closeEmojiAndAction?: (action?: Function, params?: any) => void;
|
2024-01-25 14:11:07 +00:00
|
|
|
isBeingEdited?: boolean;
|
2023-08-04 14:09:36 +00:00
|
|
|
isPreview?: boolean;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
interface IMessageContainerState {
|
|
|
|
isManualUnignored: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
class MessageContainer extends React.Component<IMessageContainerProps, IMessageContainerState> {
|
2018-03-23 16:49:51 +00:00
|
|
|
static defaultProps = {
|
2022-02-17 15:27:01 +00:00
|
|
|
getCustomEmoji: () => null,
|
2018-03-23 16:49:51 +00:00
|
|
|
onLongPress: () => {},
|
2020-02-17 16:06:46 +00:00
|
|
|
blockAction: () => {},
|
2018-05-24 20:17:45 +00:00
|
|
|
archived: false,
|
2019-12-04 16:39:53 +00:00
|
|
|
broadcast: false,
|
2020-11-30 20:00:31 +00:00
|
|
|
isIgnored: false,
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: 'light' as TSupportedThemes
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-03-23 16:49:51 +00:00
|
|
|
|
2020-11-30 20:00:31 +00:00
|
|
|
state = { isManualUnignored: false };
|
|
|
|
|
2023-05-10 18:44:05 +00:00
|
|
|
private subscription?: Function;
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2020-11-04 16:53:44 +00:00
|
|
|
componentDidMount() {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { item } = this.props;
|
2023-05-10 18:44:05 +00:00
|
|
|
// @ts-ignore
|
|
|
|
if (item && item.experimentalSubscribe) {
|
|
|
|
// TODO: Update watermelonDB to recognize experimentalSubscribe at types
|
|
|
|
// experimentalSubscribe(subscriber: (isDeleted: boolean) => void, debugInfo?: any): Unsubscribe
|
|
|
|
// @ts-ignore
|
|
|
|
this.subscription = item.experimentalSubscribe(() => {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.forceUpdate();
|
|
|
|
});
|
2019-06-10 18:36:31 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
shouldComponentUpdate(nextProps: IMessageContainerProps, nextState: IMessageContainerState) {
|
2020-11-30 20:00:31 +00:00
|
|
|
const { isManualUnignored } = this.state;
|
2024-01-25 14:11:07 +00:00
|
|
|
const { threadBadgeColor, isIgnored, highlighted, previousItem, autoTranslateRoom, autoTranslateLanguage, isBeingEdited } =
|
|
|
|
this.props;
|
2023-08-14 20:22:46 +00:00
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
if (nextProps.highlighted !== highlighted) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-12 14:17:32 +00:00
|
|
|
if (nextProps.threadBadgeColor !== threadBadgeColor) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-11-30 20:00:31 +00:00
|
|
|
if (nextProps.isIgnored !== isIgnored) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.isManualUnignored !== isManualUnignored) {
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-31 17:02:35 +00:00
|
|
|
if (nextProps.previousItem?._id !== previousItem?._id) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-01-25 14:11:07 +00:00
|
|
|
if (isBeingEdited !== nextProps.isBeingEdited) {
|
|
|
|
return true;
|
|
|
|
}
|
2023-08-14 20:22:46 +00:00
|
|
|
if (nextProps.autoTranslateRoom !== autoTranslateRoom) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.autoTranslateRoom !== autoTranslateRoom || nextProps.autoTranslateLanguage !== autoTranslateLanguage) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2023-05-10 18:44:05 +00:00
|
|
|
if (this.subscription) {
|
|
|
|
this.subscription();
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
2018-03-02 21:31:44 +00:00
|
|
|
}
|
2017-11-21 14:55:50 +00:00
|
|
|
|
2022-08-30 20:59:10 +00:00
|
|
|
onPressAction = () => {
|
2022-08-08 18:38:01 +00:00
|
|
|
const { closeEmojiAndAction } = this.props;
|
|
|
|
|
|
|
|
if (closeEmojiAndAction) {
|
2022-08-30 20:59:10 +00:00
|
|
|
return closeEmojiAndAction(this.onPress);
|
2022-08-08 18:38:01 +00:00
|
|
|
}
|
2022-08-30 20:59:10 +00:00
|
|
|
|
|
|
|
return this.onPress();
|
2022-08-08 18:38:01 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onPress = debounce(
|
|
|
|
() => {
|
|
|
|
const { onPress } = this.props;
|
|
|
|
if (this.isIgnored) {
|
|
|
|
return this.onIgnoredMessagePress();
|
|
|
|
}
|
2020-11-30 20:00:31 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if (onPress) {
|
|
|
|
return onPress();
|
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
const { item, isThreadRoom } = this.props;
|
|
|
|
Keyboard.dismiss();
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
if ((item.tlm || item.tmid) && !isThreadRoom) {
|
|
|
|
this.onThreadPress();
|
|
|
|
}
|
2022-01-24 15:51:31 +00:00
|
|
|
|
|
|
|
const { onDiscussionPress } = this.props;
|
|
|
|
|
2022-02-07 15:41:29 +00:00
|
|
|
if (item.dlm && onDiscussionPress) {
|
2022-01-24 15:51:31 +00:00
|
|
|
onDiscussionPress(item);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
},
|
|
|
|
300,
|
|
|
|
true
|
|
|
|
);
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
onLongPress = () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { archived, onLongPress, item } = this.props;
|
2020-09-11 14:31:38 +00:00
|
|
|
if (this.isInfo || this.hasError || this.isEncrypted || archived) {
|
2019-05-20 20:43:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (onLongPress) {
|
2019-09-16 20:26:32 +00:00
|
|
|
onLongPress(item);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-11-21 14:55:50 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
onErrorPress = () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { errorActionsShow, item } = this.props;
|
2019-05-20 20:43:50 +00:00
|
|
|
if (errorActionsShow) {
|
2019-09-16 20:26:32 +00:00
|
|
|
errorActionsShow(item);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2022-04-01 21:52:38 +00:00
|
|
|
onReactionPress = (emoji: string) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { onReactionPress, item } = this.props;
|
2019-05-20 20:43:50 +00:00
|
|
|
if (onReactionPress) {
|
2019-10-01 12:54:59 +00:00
|
|
|
onReactionPress(emoji, item.id);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-09-11 16:32:52 +00:00
|
|
|
|
|
|
|
onReactionLongPress = () => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const { onReactionLongPress, item } = this.props;
|
|
|
|
if (onReactionLongPress) {
|
|
|
|
onReactionLongPress(item);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-12-13 15:00:26 +00:00
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
onEncryptedPress = () => {
|
|
|
|
const { onEncryptedPress } = this.props;
|
|
|
|
if (onEncryptedPress) {
|
|
|
|
onEncryptedPress();
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 14:31:38 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
onDiscussionPress = () => {
|
|
|
|
const { onDiscussionPress, item } = this.props;
|
2019-05-20 20:43:50 +00:00
|
|
|
if (onDiscussionPress) {
|
|
|
|
onDiscussionPress(item);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-12-02 13:19:58 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
onThreadPress = () => {
|
|
|
|
const { onThreadPress, item } = this.props;
|
|
|
|
if (onThreadPress) {
|
|
|
|
onThreadPress(item);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-12-13 15:00:26 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onAnswerButtonPress = (msg: string) => {
|
2021-08-27 16:29:34 +00:00
|
|
|
const { onAnswerButtonPress } = this.props;
|
|
|
|
if (onAnswerButtonPress) {
|
2024-01-25 14:11:07 +00:00
|
|
|
onAnswerButtonPress(msg, false);
|
2021-08-27 16:29:34 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-08-27 16:29:34 +00:00
|
|
|
|
2020-11-30 20:00:31 +00:00
|
|
|
onIgnoredMessagePress = () => {
|
|
|
|
this.setState({ isManualUnignored: true });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-11-30 20:00:31 +00:00
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
get isHeader(): boolean {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { item, previousItem, broadcast, Message_GroupingPeriod } = this.props;
|
2019-07-17 14:06:39 +00:00
|
|
|
if (this.hasError || (previousItem && previousItem.status === messagesStatus.ERROR)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
2021-09-13 20:41:05 +00:00
|
|
|
if (
|
|
|
|
previousItem &&
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore TODO: IMessage vs IMessageFromServer non-sense
|
2021-09-13 20:41:05 +00:00
|
|
|
previousItem.ts.toDateString() === item.ts.toDateString() &&
|
|
|
|
previousItem.u.username === item.u.username &&
|
|
|
|
!(previousItem.groupable === false || item.groupable === false || broadcast === true) &&
|
2022-03-02 14:18:01 +00:00
|
|
|
// @ts-ignore TODO: IMessage vs IMessageFromServer non-sense
|
2022-04-01 21:52:38 +00:00
|
|
|
item.ts - previousItem.ts < Message_GroupingPeriod * 1000 &&
|
2022-11-29 15:12:35 +00:00
|
|
|
previousItem.tmid === item.tmid &&
|
|
|
|
item.t !== 'rm' &&
|
|
|
|
previousItem.t !== 'rm'
|
2021-09-13 20:41:05 +00:00
|
|
|
) {
|
2019-09-16 20:26:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
return true;
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
get isThreadReply(): boolean {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { item, previousItem, isThreadRoom } = this.props;
|
2019-09-16 20:26:32 +00:00
|
|
|
if (isThreadRoom) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
if (previousItem && item.tmid && previousItem.tmid !== item.tmid && previousItem.id !== item.tmid) {
|
2019-05-03 13:33:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
get isThreadSequential(): boolean {
|
2020-12-01 12:59:59 +00:00
|
|
|
const { item, isThreadRoom } = this.props;
|
2019-09-16 20:26:32 +00:00
|
|
|
if (isThreadRoom) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-03-02 14:18:01 +00:00
|
|
|
return !!item.tmid;
|
2019-05-03 13:33:38 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
get isEncrypted(): boolean {
|
2020-09-11 14:31:38 +00:00
|
|
|
const { item } = this.props;
|
|
|
|
const { t, e2e } = item;
|
|
|
|
return t === E2E_MESSAGE_TYPE && e2e !== E2E_STATUS.DONE;
|
|
|
|
}
|
|
|
|
|
2022-05-03 14:27:20 +00:00
|
|
|
get isInfo(): string | boolean {
|
2019-05-20 20:43:50 +00:00
|
|
|
const { item } = this.props;
|
2022-11-24 17:24:20 +00:00
|
|
|
if (['e2e', 'discussion-created', 'jitsi_call_started', 'videoconf'].includes(item.t)) {
|
2022-05-03 14:27:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return item.t;
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
get isTemp(): boolean {
|
2019-05-20 20:43:50 +00:00
|
|
|
const { item } = this.props;
|
|
|
|
return item.status === messagesStatus.TEMP || item.status === messagesStatus.ERROR;
|
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
get isIgnored(): boolean {
|
2020-11-30 20:00:31 +00:00
|
|
|
const { isManualUnignored } = this.state;
|
|
|
|
const { isIgnored } = this.props;
|
2022-03-02 14:18:01 +00:00
|
|
|
if (isManualUnignored) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return isIgnored ?? false;
|
2020-11-30 20:00:31 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 14:18:01 +00:00
|
|
|
get hasError(): boolean {
|
2019-05-20 20:43:50 +00:00
|
|
|
const { item } = this.props;
|
|
|
|
return item.status === messagesStatus.ERROR;
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
reactionInit = () => {
|
|
|
|
const { reactionInit, item } = this.props;
|
|
|
|
if (reactionInit) {
|
2024-01-25 14:11:07 +00:00
|
|
|
reactionInit(item.id);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-01-30 19:48:26 +00:00
|
|
|
|
2018-09-11 16:32:52 +00:00
|
|
|
replyBroadcast = () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { replyBroadcast, item } = this.props;
|
2019-05-20 20:43:50 +00:00
|
|
|
if (replyBroadcast) {
|
2019-09-16 20:26:32 +00:00
|
|
|
replyBroadcast(item);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-05-24 20:17:45 +00:00
|
|
|
|
2022-02-17 15:27:01 +00:00
|
|
|
onLinkPress = (link: string): void => {
|
2022-04-11 18:01:43 +00:00
|
|
|
const { item, jumpToMessage, theme } = this.props;
|
2022-04-01 21:52:38 +00:00
|
|
|
const isMessageLink = item?.attachments?.findIndex((att: IAttachment) => att?.message_link === link) !== -1;
|
|
|
|
if (isMessageLink && jumpToMessage) {
|
|
|
|
return jumpToMessage(link);
|
2021-05-26 17:24:54 +00:00
|
|
|
}
|
|
|
|
openLink(link, theme);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2017-11-21 14:55:50 +00:00
|
|
|
render() {
|
2017-11-24 20:44:52 +00:00
|
|
|
const {
|
2021-05-26 17:24:54 +00:00
|
|
|
item,
|
|
|
|
user,
|
|
|
|
style,
|
|
|
|
archived,
|
|
|
|
baseUrl,
|
|
|
|
useRealName,
|
|
|
|
broadcast,
|
|
|
|
fetchThreadName,
|
|
|
|
showAttachment,
|
|
|
|
timeFormat,
|
|
|
|
isReadReceiptEnabled,
|
|
|
|
autoTranslateRoom,
|
|
|
|
autoTranslateLanguage,
|
2023-08-04 14:09:36 +00:00
|
|
|
navToRoomInfo = () => {},
|
2021-05-26 17:24:54 +00:00
|
|
|
getCustomEmoji,
|
|
|
|
isThreadRoom,
|
2023-03-01 18:26:56 +00:00
|
|
|
handleEnterCall,
|
2021-05-26 17:24:54 +00:00
|
|
|
blockAction,
|
|
|
|
rid,
|
|
|
|
threadBadgeColor,
|
|
|
|
toggleFollowThread,
|
|
|
|
jumpToMessage,
|
2023-08-04 14:09:36 +00:00
|
|
|
highlighted,
|
2024-01-25 14:11:07 +00:00
|
|
|
isBeingEdited,
|
2023-08-04 14:09:36 +00:00
|
|
|
isPreview
|
2017-11-24 20:44:52 +00:00
|
|
|
} = this.props;
|
2018-09-11 16:32:52 +00:00
|
|
|
const {
|
2021-05-26 17:24:54 +00:00
|
|
|
id,
|
|
|
|
msg,
|
|
|
|
ts,
|
|
|
|
attachments,
|
|
|
|
urls,
|
|
|
|
reactions,
|
|
|
|
t,
|
|
|
|
avatar,
|
|
|
|
emoji,
|
|
|
|
u,
|
|
|
|
alias,
|
|
|
|
editedBy,
|
|
|
|
role,
|
|
|
|
drid,
|
|
|
|
dcount,
|
|
|
|
dlm,
|
|
|
|
tmid,
|
|
|
|
tcount,
|
|
|
|
tlm,
|
|
|
|
tmsg,
|
|
|
|
mentions,
|
|
|
|
channels,
|
|
|
|
unread,
|
|
|
|
blocks,
|
|
|
|
autoTranslate: autoTranslateMessage,
|
2021-10-20 16:32:58 +00:00
|
|
|
replies,
|
2022-04-20 20:53:11 +00:00
|
|
|
md,
|
|
|
|
comment
|
2018-09-11 16:32:52 +00:00
|
|
|
} = item;
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2019-06-28 17:02:30 +00:00
|
|
|
let message = msg;
|
2022-11-11 19:51:57 +00:00
|
|
|
let isTranslated = false;
|
2023-11-29 18:30:15 +00:00
|
|
|
const otherUserMessage = u?.username !== user?.username;
|
2019-06-28 17:02:30 +00:00
|
|
|
// "autoTranslateRoom" and "autoTranslateLanguage" are properties from the subscription
|
|
|
|
// "autoTranslateMessage" is a toggle between "View Original" and "Translate" state
|
2023-08-14 20:22:46 +00:00
|
|
|
if (autoTranslateRoom && autoTranslateMessage && autoTranslateLanguage && otherUserMessage) {
|
2022-11-11 19:51:57 +00:00
|
|
|
const messageTranslated = getMessageTranslation(item, autoTranslateLanguage);
|
|
|
|
isTranslated = !!messageTranslated;
|
|
|
|
message = messageTranslated || message;
|
2019-06-28 17:02:30 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:22:46 +00:00
|
|
|
const canTranslateMessage = autoTranslateRoom && autoTranslateLanguage && autoTranslateMessage !== false && otherUserMessage;
|
|
|
|
|
2017-11-21 14:55:50 +00:00
|
|
|
return (
|
2020-04-30 20:05:59 +00:00
|
|
|
<MessageContext.Provider
|
|
|
|
value={{
|
feat: new audio player (#5160)
* feat: media auto-download view
* media auto download view completed and saving the settings in mmkv
* audio download preference
* audio auto download when the user who sent the audio is the same logged on mobile
* creation of isAutoDownloadEnabled, evaluate hist hook, Image Full Size preload done
* minor tweak audio show play button after download
* refactor audioFile to handleMediaDownload and fixed the audio download
* desestructured params to download too
* image download and autoDownload, algo fix the formatAttachmentUrl to show the image from local
* add the possibility to cancel image download and clear local images
* refactor blur component
* video download and auto download, also keeped the behavior to download unsuportted videos to the gallery
* add the possibility to start downloading a video, then exit the room, back again to room and cancel the video previously downloading
* remove the custom hook for autoDownload
* remove blurcomponent, fix the blur style in image.tsx, minor tweak video function name
* send messageId to video
* introducing the reducer to keep the downloads in progress
* create a media download selector
* remove all the redux stuff and do the same as file upload
* video download behavior
* done for image and audio
* fix the try catch download media
* clean up
* image container uiKit
* fix lint
* change rn-fetch-blob to expo-filesystem
* add pt-br
* pass the correct message id when there is an attachment on reply
* refactor some changes requested
* fix audio and move the netInfo from autoDownloadPreference to redux
* variable isAutoDownloadEnable name and handleMediaDownload getExtension
* message/Image refactored, change the component to show the image from FastImage to Image
* refactor handleMediaDownload and deleteMedia
* minor tweak
* refactor audio
* refactor video
* fix the type on the messagesView(the view of files)
* minor tweak
* fix the name of searchMediaFIleAsync's result
* minor tweak, add the default behavior, add the OFF as label
* minor tweaks
* verify if the media auto download exists on settings view
* fix media auto download view layout and minor tweak wifi
* avoid auto download from reply
* minor tweak at comment
* tweak list.section
* change the name to netInfoState and Local_document_directory
* remove mediaType and refactor audio and image
* separate blurview
* thumbnail video and video behavior
* add Audio to i18n and minor tweak
* set the blur as always dark and add the possibility to overlay
* don't need to controle the filepath in the view
* fix the loading in image and video at begin
* save the file with a similar filename as expected
* removed the necessity of messageId or id
* minor tweak
* switch useLayoutEffect to useEffect
* avoid onpress do some edge case because of cached at video
* minor tweak
* tweak at audio comment extension
* minor tweak type userpreferences
* remove test id from mediaAutoDownloadView
* change action's name to SET_NET_INFO_STATE
* caching and deleting video's thumbnails
* remove generate thumbnail
* minor tweak in image
* update camera-roll and save the file from local url
* remove local_cache_directory and deleteThumbnail
* update blur to fix error on android
* first commit
* fix togglePlayPause
* separate audio to a folder inside components and minor tweak attachment
* created the slider with text
* play/pause button, currentTime equal the sound, can change the slider and reflect to the sound
* play/pause, track is working and onEnd
* update the icons with play-shaped-filled, pause-shape-filled, loading
* start the tweaks on layout
* can play multiple audios, pausing the previous to execute the new one
* loading animated
* added the audio rate
* layout fixed
* removed the sound manipulation from Slider to manipulate only in the index
* fix time margin horizontal
* fix play 2 audios and play/pause properly
* change the way we treat the audio
* remove audio copy
* minor tweak
* fix rate state
* remove the PAUSE_AUDIO
* fix unloadAll, add hit slop to slider, show the duration on the first render
* refactor colors to be the same as figmas name
* change the class' name and add the method pauseCurrentAudio
* pause audio when unmount a RoomView and unloadAll when focusing at RoomsListView
* pause audio when entering a thread
* fix where call the pauseCurrentAudio
* moved the player from messageAudio to audioPlayer
* refactor audio component
* remove loading
* update snapshot
* fix colors name
* pauseAudio when roomview is blur
* moved audio from message/component/audio to message/Audio
* add navigation focus to AudioPlayer component and fix the jest
* add the { androidImplementation: 'MediaPlayer' }
* fix action sheet swipe 02-room
* fix action sheet swipe 05-threads
* tweak touchable
* remove react.memo from playbutton
* hitSlop
* speed playback from array
* textinputprops
* tweak at names
* minor tweak at onEnd
* minor tweak at names
* update styles
* thumb seek size
* change marginBottom
* add the clamp, adjust the thumb position, remove the necessity of OnEndGestureHandler
* change the utils to constants
* change to audioState
* fix the seek for android
* TDownloadState
* speed array
* pause audio from messagesView when open the files
* update test
* minor tweak
* change the time after ony one click, fixes the thumb to move sync with the click
* Fix seek
* minor tweak Sound to Audio.Sound
* name of Icon
* enable PlaybackSpeed only when playing the audio
* playbackSpeed to mmkv
* mock implementation
* create native button
* minor tweak
* minor tweaks
* playbackSpeed after loadAudio
* avoid show the error when try to setRate without audio
* add messageID to differ audios inside a quote/forward from original one
* unloadRoomAudios instead of unloadAllAudios inside the roomsListView
* minor tweak
---------
Co-authored-by: Diego Mello <diegolmello@gmail.com>
Co-authored-by: Gleidson Daniel Silva <gleidson10daniel@hotmail.com>
2023-11-20 14:13:15 +00:00
|
|
|
id,
|
|
|
|
rid,
|
2020-04-30 20:05:59 +00:00
|
|
|
user,
|
|
|
|
baseUrl,
|
2022-08-30 20:59:10 +00:00
|
|
|
onPress: this.onPressAction,
|
2020-04-30 20:05:59 +00:00
|
|
|
onLongPress: this.onLongPress,
|
|
|
|
reactionInit: this.reactionInit,
|
|
|
|
onErrorPress: this.onErrorPress,
|
|
|
|
replyBroadcast: this.replyBroadcast,
|
|
|
|
onReactionPress: this.onReactionPress,
|
2020-09-11 14:31:38 +00:00
|
|
|
onEncryptedPress: this.onEncryptedPress,
|
2020-04-30 20:05:59 +00:00
|
|
|
onDiscussionPress: this.onDiscussionPress,
|
2020-10-30 17:35:07 +00:00
|
|
|
onReactionLongPress: this.onReactionLongPress,
|
2021-05-26 17:24:54 +00:00
|
|
|
onLinkPress: this.onLinkPress,
|
2021-08-27 16:29:34 +00:00
|
|
|
onAnswerButtonPress: this.onAnswerButtonPress,
|
2021-05-26 17:24:54 +00:00
|
|
|
jumpToMessage,
|
2020-11-12 14:17:32 +00:00
|
|
|
threadBadgeColor,
|
2020-10-30 17:35:07 +00:00
|
|
|
toggleFollowThread,
|
2023-08-14 20:22:46 +00:00
|
|
|
replies,
|
|
|
|
translateLanguage: canTranslateMessage ? autoTranslateLanguage : undefined
|
2023-01-13 19:32:52 +00:00
|
|
|
}}
|
|
|
|
>
|
2022-04-01 21:52:38 +00:00
|
|
|
{/* @ts-ignore*/}
|
2020-04-30 20:05:59 +00:00
|
|
|
<Message
|
|
|
|
id={id}
|
|
|
|
msg={message}
|
2021-10-20 16:32:58 +00:00
|
|
|
md={md}
|
2022-04-01 21:52:38 +00:00
|
|
|
rid={rid}
|
2020-11-04 16:53:44 +00:00
|
|
|
author={u}
|
2020-04-30 20:05:59 +00:00
|
|
|
ts={ts}
|
2022-04-01 21:52:38 +00:00
|
|
|
type={t}
|
2020-04-30 20:05:59 +00:00
|
|
|
attachments={attachments}
|
|
|
|
blocks={blocks}
|
|
|
|
urls={urls}
|
|
|
|
reactions={reactions}
|
|
|
|
alias={alias}
|
|
|
|
avatar={avatar}
|
2020-05-08 17:16:22 +00:00
|
|
|
emoji={emoji}
|
2020-04-30 20:05:59 +00:00
|
|
|
timeFormat={timeFormat}
|
|
|
|
style={style}
|
2022-04-01 21:52:38 +00:00
|
|
|
archived={archived}
|
|
|
|
broadcast={broadcast}
|
2020-04-30 20:05:59 +00:00
|
|
|
useRealName={useRealName}
|
2022-04-01 21:52:38 +00:00
|
|
|
isReadReceiptEnabled={isReadReceiptEnabled}
|
2020-04-30 20:05:59 +00:00
|
|
|
unread={unread}
|
|
|
|
role={role}
|
|
|
|
drid={drid}
|
|
|
|
dcount={dcount}
|
|
|
|
dlm={dlm}
|
|
|
|
tmid={tmid}
|
|
|
|
tcount={tcount}
|
|
|
|
tlm={tlm}
|
|
|
|
tmsg={tmsg}
|
2022-04-01 21:52:38 +00:00
|
|
|
fetchThreadName={fetchThreadName}
|
2020-04-30 20:05:59 +00:00
|
|
|
mentions={mentions}
|
|
|
|
channels={channels}
|
2022-03-02 14:18:01 +00:00
|
|
|
isIgnored={this.isIgnored}
|
|
|
|
isEdited={(editedBy && !!editedBy.username) ?? false}
|
2020-04-30 20:05:59 +00:00
|
|
|
isHeader={this.isHeader}
|
|
|
|
isThreadReply={this.isThreadReply}
|
|
|
|
isThreadSequential={this.isThreadSequential}
|
2023-08-04 14:09:36 +00:00
|
|
|
isThreadRoom={!!isThreadRoom}
|
2020-04-30 20:05:59 +00:00
|
|
|
isInfo={this.isInfo}
|
|
|
|
isTemp={this.isTemp}
|
2020-09-11 14:31:38 +00:00
|
|
|
isEncrypted={this.isEncrypted}
|
2020-04-30 20:05:59 +00:00
|
|
|
hasError={this.hasError}
|
2022-04-01 21:52:38 +00:00
|
|
|
showAttachment={showAttachment}
|
2020-04-30 20:05:59 +00:00
|
|
|
getCustomEmoji={getCustomEmoji}
|
2022-04-01 21:52:38 +00:00
|
|
|
navToRoomInfo={navToRoomInfo}
|
2023-03-01 18:26:56 +00:00
|
|
|
handleEnterCall={handleEnterCall}
|
2022-04-01 21:52:38 +00:00
|
|
|
blockAction={blockAction}
|
|
|
|
highlighted={highlighted}
|
2022-04-20 20:53:11 +00:00
|
|
|
comment={comment}
|
2022-11-11 19:51:57 +00:00
|
|
|
isTranslated={isTranslated}
|
2024-01-25 14:11:07 +00:00
|
|
|
isBeingEdited={isBeingEdited}
|
2023-08-04 14:09:36 +00:00
|
|
|
isPreview={isPreview}
|
2020-04-30 20:05:59 +00:00
|
|
|
/>
|
|
|
|
</MessageContext.Provider>
|
2017-11-21 14:55:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-12-04 16:39:53 +00:00
|
|
|
|
|
|
|
export default withTheme(MessageContainer);
|