Add asPlain to messages
This commit is contained in:
parent
7beaa62003
commit
fad04765d4
|
@ -8,12 +8,12 @@ import { debounce } from '../../lib/methods/helpers';
|
||||||
import { getMessageTranslation } from './utils';
|
import { getMessageTranslation } from './utils';
|
||||||
import { TSupportedThemes, withTheme } from '../../theme';
|
import { TSupportedThemes, withTheme } from '../../theme';
|
||||||
import openLink from '../../lib/methods/helpers/openLink';
|
import openLink from '../../lib/methods/helpers/openLink';
|
||||||
import { IAttachment, TAnyMessageModel, TGetCustomEmoji } from '../../definitions';
|
import { IAttachment, TAnyMessage, TGetCustomEmoji } from '../../definitions';
|
||||||
import { IRoomInfoParam } from '../../views/SearchMessagesView';
|
import { IRoomInfoParam } from '../../views/SearchMessagesView';
|
||||||
import { E2E_MESSAGE_TYPE, E2E_STATUS, messagesStatus } from '../../lib/constants';
|
import { E2E_MESSAGE_TYPE, E2E_STATUS, messagesStatus } from '../../lib/constants';
|
||||||
|
|
||||||
interface IMessageContainerProps {
|
interface TAnyMessageContainerProps {
|
||||||
item: TAnyMessageModel;
|
item: TAnyMessage;
|
||||||
user: {
|
user: {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
@ -25,7 +25,7 @@ interface IMessageContainerProps {
|
||||||
style?: ViewStyle;
|
style?: ViewStyle;
|
||||||
archived?: boolean;
|
archived?: boolean;
|
||||||
broadcast?: boolean;
|
broadcast?: boolean;
|
||||||
previousItem?: TAnyMessageModel;
|
previousItem?: TAnyMessage;
|
||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
Message_GroupingPeriod?: number;
|
Message_GroupingPeriod?: number;
|
||||||
isReadReceiptEnabled?: boolean;
|
isReadReceiptEnabled?: boolean;
|
||||||
|
@ -38,17 +38,17 @@ interface IMessageContainerProps {
|
||||||
isIgnored?: boolean;
|
isIgnored?: boolean;
|
||||||
highlighted?: boolean;
|
highlighted?: boolean;
|
||||||
getCustomEmoji: TGetCustomEmoji;
|
getCustomEmoji: TGetCustomEmoji;
|
||||||
onLongPress?: (item: TAnyMessageModel) => void;
|
onLongPress?: (item: TAnyMessage) => void;
|
||||||
onReactionPress?: (emoji: string, id: string) => void;
|
onReactionPress?: (emoji: string, id: string) => void;
|
||||||
onEncryptedPress?: () => void;
|
onEncryptedPress?: () => void;
|
||||||
onDiscussionPress?: (item: TAnyMessageModel) => void;
|
onDiscussionPress?: (item: TAnyMessage) => void;
|
||||||
onThreadPress?: (item: TAnyMessageModel) => void;
|
onThreadPress?: (item: TAnyMessage) => void;
|
||||||
errorActionsShow?: (item: TAnyMessageModel) => void;
|
errorActionsShow?: (item: TAnyMessage) => void;
|
||||||
replyBroadcast?: (item: TAnyMessageModel) => void;
|
replyBroadcast?: (item: TAnyMessage) => void;
|
||||||
reactionInit?: (item: TAnyMessageModel) => void;
|
reactionInit?: (item: TAnyMessage) => void;
|
||||||
fetchThreadName?: (tmid: string, id: string) => Promise<string | undefined>;
|
fetchThreadName?: (tmid: string, id: string) => Promise<string | undefined>;
|
||||||
showAttachment: (file: IAttachment) => void;
|
showAttachment: (file: IAttachment) => void;
|
||||||
onReactionLongPress?: (item: TAnyMessageModel) => void;
|
onReactionLongPress?: (item: TAnyMessage) => void;
|
||||||
navToRoomInfo: (navParam: IRoomInfoParam) => void;
|
navToRoomInfo: (navParam: IRoomInfoParam) => void;
|
||||||
callJitsi?: () => void;
|
callJitsi?: () => void;
|
||||||
blockAction?: (params: { actionId: string; appId: string; value: string; blockId: string; rid: string; mid: string }) => void;
|
blockAction?: (params: { actionId: string; appId: string; value: string; blockId: string; rid: string; mid: string }) => void;
|
||||||
|
@ -61,11 +61,11 @@ interface IMessageContainerProps {
|
||||||
closeEmojiAndAction?: (action?: Function, params?: any) => void;
|
closeEmojiAndAction?: (action?: Function, params?: any) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IMessageContainerState {
|
interface TAnyMessageContainerState {
|
||||||
isManualUnignored: boolean;
|
isManualUnignored: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MessageContainer extends React.Component<IMessageContainerProps, IMessageContainerState> {
|
class MessageContainer extends React.Component<TAnyMessageContainerProps, TAnyMessageContainerState> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
getCustomEmoji: () => null,
|
getCustomEmoji: () => null,
|
||||||
onLongPress: () => {},
|
onLongPress: () => {},
|
||||||
|
@ -97,7 +97,7 @@ class MessageContainer extends React.Component<IMessageContainerProps, IMessageC
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// shouldComponentUpdate(nextProps: IMessageContainerProps, nextState: IMessageContainerState) {
|
// shouldComponentUpdate(nextProps: TAnyMessageContainerProps, nextState: TAnyMessageContainerState) {
|
||||||
// const { isManualUnignored } = this.state;
|
// const { isManualUnignored } = this.state;
|
||||||
// const { threadBadgeColor, isIgnored, highlighted, previousItem } = this.props;
|
// const { threadBadgeColor, isIgnored, highlighted, previousItem } = this.props;
|
||||||
// if (nextProps.highlighted !== highlighted) {
|
// if (nextProps.highlighted !== highlighted) {
|
||||||
|
@ -233,11 +233,11 @@ class MessageContainer extends React.Component<IMessageContainerProps, IMessageC
|
||||||
try {
|
try {
|
||||||
if (
|
if (
|
||||||
previousItem &&
|
previousItem &&
|
||||||
// @ts-ignore TODO: IMessage vs IMessageFromServer non-sense
|
// @ts-ignore TODO: TAnyMessage vs TAnyMessageFromServer non-sense
|
||||||
previousItem.ts.toDateString() === item.ts.toDateString() &&
|
previousItem.ts.toDateString() === item.ts.toDateString() &&
|
||||||
previousItem.u.username === item.u.username &&
|
previousItem.u.username === item.u.username &&
|
||||||
!(previousItem.groupable === false || item.groupable === false || broadcast === true) &&
|
!(previousItem.groupable === false || item.groupable === false || broadcast === true) &&
|
||||||
// @ts-ignore TODO: IMessage vs IMessageFromServer non-sense
|
// @ts-ignore TODO: TAnyMessage vs TAnyMessageFromServer non-sense
|
||||||
item.ts - previousItem.ts < Message_GroupingPeriod * 1000 &&
|
item.ts - previousItem.ts < Message_GroupingPeriod * 1000 &&
|
||||||
previousItem.tmid === item.tmid
|
previousItem.tmid === item.tmid
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* eslint-disable complexity */
|
/* eslint-disable complexity */
|
||||||
import { MessageTypesValues, TMessageModel } from '../../definitions/IMessage';
|
import { MessageTypesValues, TAnyMessage } from '../../definitions/IMessage';
|
||||||
import I18n from '../../i18n';
|
import I18n from '../../i18n';
|
||||||
import { DISCUSSION } from './constants';
|
import { DISCUSSION } from './constants';
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ export const getInfoMessage = ({ type, role, msg, author, comment }: TInfoMessag
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMessageTranslation = (message: TMessageModel, autoTranslateLanguage: string): string | null => {
|
export const getMessageTranslation = (message: TAnyMessage, autoTranslateLanguage: string): string | null => {
|
||||||
if (!autoTranslateLanguage) {
|
if (!autoTranslateLanguage) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import { MarkdownAST } from '@rocket.chat/message-parser';
|
||||||
import { MessageTypeLoad } from '../lib/constants';
|
import { MessageTypeLoad } from '../lib/constants';
|
||||||
import { IAttachment } from './IAttachment';
|
import { IAttachment } from './IAttachment';
|
||||||
import { IReaction } from './IReaction';
|
import { IReaction } from './IReaction';
|
||||||
import { TThreadMessageModel } from './IThreadMessage';
|
import { IThreadMessage, TThreadMessageModel } from './IThreadMessage';
|
||||||
import { TThreadModel } from './IThread';
|
import { IThread, TThreadModel } from './IThread';
|
||||||
import { IUrl, IUrlFromServer } from './IUrl';
|
import { IUrl, IUrlFromServer } from './IUrl';
|
||||||
|
|
||||||
export type MessageType =
|
export type MessageType =
|
||||||
|
@ -146,9 +146,13 @@ export interface IMessage extends IMessageFromServer {
|
||||||
editedAt?: string | Date;
|
editedAt?: string | Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TMessageModel = IMessage & Model;
|
export type TMessageModel = IMessage &
|
||||||
|
Model & {
|
||||||
|
asPlain: () => IMessage;
|
||||||
|
};
|
||||||
|
|
||||||
export type TAnyMessageModel = TMessageModel | TThreadModel | TThreadMessageModel;
|
export type TAnyMessageModel = TMessageModel | TThreadModel | TThreadMessageModel;
|
||||||
|
export type TAnyMessage = IMessage | IThread | IThreadMessage;
|
||||||
export type TTypeMessages = IMessageFromServer | ILoadMoreMessage | IMessage;
|
export type TTypeMessages = IMessageFromServer | ILoadMoreMessage | IMessage;
|
||||||
|
|
||||||
// Read receipts to ReadReceiptView and chat.getMessageReadReceipts
|
// Read receipts to ReadReceiptView and chat.getMessageReadReceipts
|
||||||
|
|
|
@ -109,7 +109,6 @@ export interface ISubscription {
|
||||||
|
|
||||||
export type TSubscriptionModel = ISubscription &
|
export type TSubscriptionModel = ISubscription &
|
||||||
Model & {
|
Model & {
|
||||||
unsubscribe: () => Promise<any>;
|
|
||||||
asPlain: () => ISubscription;
|
asPlain: () => ISubscription;
|
||||||
};
|
};
|
||||||
export type TSubscription = TSubscriptionModel | ISubscription;
|
export type TSubscription = TSubscriptionModel | ISubscription;
|
||||||
|
|
|
@ -38,4 +38,7 @@ export interface IThread extends IMessage {
|
||||||
draftMessage?: string;
|
draftMessage?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TThreadModel = IThread & Model;
|
export type TThreadModel = IThread &
|
||||||
|
Model & {
|
||||||
|
asPlain: () => IThread;
|
||||||
|
};
|
||||||
|
|
|
@ -6,4 +6,7 @@ export interface IThreadMessage extends IMessage {
|
||||||
tmsg?: string;
|
tmsg?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TThreadMessageModel = IThreadMessage & Model;
|
export type TThreadMessageModel = IThreadMessage &
|
||||||
|
Model & {
|
||||||
|
asPlain: () => IThreadMessage;
|
||||||
|
};
|
||||||
|
|
|
@ -85,4 +85,45 @@ export default class Message extends Model {
|
||||||
@json('md', sanitizer) md;
|
@json('md', sanitizer) md;
|
||||||
|
|
||||||
@field('comment') comment;
|
@field('comment') comment;
|
||||||
|
|
||||||
|
asPlain() {
|
||||||
|
return {
|
||||||
|
msg: this.msg,
|
||||||
|
t: this.t,
|
||||||
|
ts: this.ts,
|
||||||
|
u: this.u,
|
||||||
|
alias: this.alias,
|
||||||
|
parseUrls: this.parseUrls,
|
||||||
|
groupable: this.groupable,
|
||||||
|
avatar: this.avatar,
|
||||||
|
emoji: this.emoji,
|
||||||
|
attachments: this.attachments,
|
||||||
|
urls: this.urls,
|
||||||
|
_updatedAt: this._updatedAt,
|
||||||
|
status: this.status,
|
||||||
|
pinned: this.pinned,
|
||||||
|
starred: this.starred,
|
||||||
|
editedBy: this.editedBy,
|
||||||
|
reactions: this.reactions,
|
||||||
|
role: this.role,
|
||||||
|
drid: this.drid,
|
||||||
|
dcount: this.dcount,
|
||||||
|
dlm: this.dlm,
|
||||||
|
tmid: this.tmid,
|
||||||
|
tcount: this.tcount,
|
||||||
|
tlm: this.tlm,
|
||||||
|
replies: this.replies,
|
||||||
|
mentions: this.mentions,
|
||||||
|
channels: this.channels,
|
||||||
|
unread: this.unread,
|
||||||
|
autoTranslate: this.autoTranslate,
|
||||||
|
translations: this.translations,
|
||||||
|
tmsg: this.tmsg,
|
||||||
|
blocks: this.blocks,
|
||||||
|
e2e: this.e2e,
|
||||||
|
tshow: this.tshow,
|
||||||
|
md: this.md,
|
||||||
|
comment: this.comment
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,4 +77,41 @@ export default class Thread extends Model {
|
||||||
@field('e2e') e2e;
|
@field('e2e') e2e;
|
||||||
|
|
||||||
@field('draft_message') draftMessage;
|
@field('draft_message') draftMessage;
|
||||||
|
|
||||||
|
asPlain() {
|
||||||
|
return {
|
||||||
|
msg: this.msg,
|
||||||
|
t: this.t,
|
||||||
|
ts: this.ts,
|
||||||
|
u: this.u,
|
||||||
|
alias: this.alias,
|
||||||
|
parseUrls: this.parseUrls,
|
||||||
|
groupable: this.groupable,
|
||||||
|
avatar: this.avatar,
|
||||||
|
emoji: this.emoji,
|
||||||
|
attachments: this.attachments,
|
||||||
|
urls: this.urls,
|
||||||
|
_updatedAt: this._updatedAt,
|
||||||
|
status: this.status,
|
||||||
|
pinned: this.pinned,
|
||||||
|
starred: this.starred,
|
||||||
|
editedBy: this.editedBy,
|
||||||
|
reactions: this.reactions,
|
||||||
|
role: this.role,
|
||||||
|
drid: this.drid,
|
||||||
|
dcount: this.dcount,
|
||||||
|
dlm: this.dlm,
|
||||||
|
tmid: this.tmid,
|
||||||
|
tcount: this.tcount,
|
||||||
|
tlm: this.tlm,
|
||||||
|
replies: this.replies,
|
||||||
|
mentions: this.mentions,
|
||||||
|
channels: this.channels,
|
||||||
|
unread: this.unread,
|
||||||
|
autoTranslate: this.autoTranslate,
|
||||||
|
translations: this.translations,
|
||||||
|
e2e: this.e2e,
|
||||||
|
draftMessage: this.draftMessage
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,4 +77,41 @@ export default class ThreadMessage extends Model {
|
||||||
@field('draft_message') draftMessage;
|
@field('draft_message') draftMessage;
|
||||||
|
|
||||||
@field('e2e') e2e;
|
@field('e2e') e2e;
|
||||||
|
|
||||||
|
asPlain() {
|
||||||
|
return {
|
||||||
|
msg: this.msg,
|
||||||
|
t: this.t,
|
||||||
|
ts: this.ts,
|
||||||
|
u: this.u,
|
||||||
|
rid: this.rid,
|
||||||
|
alias: this.alias,
|
||||||
|
parseUrls: this.parseUrls,
|
||||||
|
groupable: this.groupable,
|
||||||
|
avatar: this.avatar,
|
||||||
|
emoji: this.emoji,
|
||||||
|
attachments: this.attachments,
|
||||||
|
urls: this.urls,
|
||||||
|
_updatedAt: this._updatedAt,
|
||||||
|
status: this.status,
|
||||||
|
pinned: this.pinned,
|
||||||
|
starred: this.starred,
|
||||||
|
editedBy: this.editedBy,
|
||||||
|
reactions: this.reactions,
|
||||||
|
role: this.role,
|
||||||
|
drid: this.drid,
|
||||||
|
dcount: this.dcount,
|
||||||
|
dlm: this.dlm,
|
||||||
|
tcount: this.tcount,
|
||||||
|
tlm: this.tlm,
|
||||||
|
replies: this.replies,
|
||||||
|
mentions: this.mentions,
|
||||||
|
channels: this.channels,
|
||||||
|
unread: this.unread,
|
||||||
|
autoTranslate: this.autoTranslate,
|
||||||
|
translations: this.translations,
|
||||||
|
draftMessage: this.draftMessage,
|
||||||
|
e2e: this.e2e
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { addUserTyping, clearUserTyping, removeUserTyping } from '../../../actio
|
||||||
import { debounce } from '../helpers';
|
import { debounce } from '../helpers';
|
||||||
import { subscribeRoom, unsubscribeRoom } from '../../../actions/room';
|
import { subscribeRoom, unsubscribeRoom } from '../../../actions/room';
|
||||||
import { Encryption } from '../../encryption';
|
import { Encryption } from '../../encryption';
|
||||||
import { IMessage, TMessageModel, TSubscriptionModel, TThreadMessageModel, TThreadModel } from '../../../definitions';
|
import { IMessage, TMessageModel, TThreadMessageModel, TThreadModel } from '../../../definitions';
|
||||||
import { IDDPMessage } from '../../../definitions/IDDPMessage';
|
import { IDDPMessage } from '../../../definitions/IDDPMessage';
|
||||||
import sdk from '../../services/sdk';
|
import sdk from '../../services/sdk';
|
||||||
import { readMessages } from '../readMessages';
|
import { readMessages } from '../readMessages';
|
||||||
|
@ -33,7 +33,7 @@ export default class RoomSubscription {
|
||||||
private _threadsBatch: { [key: string]: TThreadModel };
|
private _threadsBatch: { [key: string]: TThreadModel };
|
||||||
private threadMessagesBatch: {};
|
private threadMessagesBatch: {};
|
||||||
private _threadMessagesBatch: { [key: string]: TThreadMessageModel };
|
private _threadMessagesBatch: { [key: string]: TThreadMessageModel };
|
||||||
private promises?: Promise<TSubscriptionModel[]>;
|
private promises?: Promise<any>;
|
||||||
private connectedListener?: Promise<any>;
|
private connectedListener?: Promise<any>;
|
||||||
private disconnectedListener?: Promise<any>;
|
private disconnectedListener?: Promise<any>;
|
||||||
private notifyRoomListener?: Promise<any>;
|
private notifyRoomListener?: Promise<any>;
|
||||||
|
@ -79,7 +79,7 @@ export default class RoomSubscription {
|
||||||
if (this.promises) {
|
if (this.promises) {
|
||||||
try {
|
try {
|
||||||
const subscriptions = (await this.promises) || [];
|
const subscriptions = (await this.promises) || [];
|
||||||
subscriptions.forEach(sub => sub.unsubscribe().catch(() => console.log('unsubscribeRoom')));
|
subscriptions.forEach((sub: any) => sub.unsubscribe().catch(() => console.log('unsubscribeRoom')));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { event, Value } from 'react-native-reanimated';
|
||||||
import { Observable, Subscription } from 'rxjs';
|
import { Observable, Subscription } from 'rxjs';
|
||||||
|
|
||||||
import ActivityIndicator from '../../../containers/ActivityIndicator';
|
import ActivityIndicator from '../../../containers/ActivityIndicator';
|
||||||
import { MessageType, TAnyMessageModel, TMessageModel, TThreadMessageModel, TThreadModel } from '../../../definitions';
|
import { MessageType, TAnyMessage, TMessageModel, TThreadMessageModel, TThreadModel } from '../../../definitions';
|
||||||
import database from '../../../lib/database';
|
import database from '../../../lib/database';
|
||||||
import { compareServerVersion, debounce } from '../../../lib/methods/helpers';
|
import { compareServerVersion, debounce } from '../../../lib/methods/helpers';
|
||||||
import { animateNextTransition } from '../../../lib/methods/helpers/layoutAnimation';
|
import { animateNextTransition } from '../../../lib/methods/helpers/layoutAnimation';
|
||||||
|
@ -20,6 +20,7 @@ import { loadMissedMessages, loadThreadMessages } from '../../../lib/methods';
|
||||||
import { Services } from '../../../lib/services';
|
import { Services } from '../../../lib/services';
|
||||||
import { TSupportedThemes, withTheme } from '../../../theme';
|
import { TSupportedThemes, withTheme } from '../../../theme';
|
||||||
import { MESSAGE_TYPE_ANY_LOAD, themes } from '../../../lib/constants';
|
import { MESSAGE_TYPE_ANY_LOAD, themes } from '../../../lib/constants';
|
||||||
|
import { TMessage } from '../definitions';
|
||||||
|
|
||||||
const QUERY_SIZE = 50;
|
const QUERY_SIZE = 50;
|
||||||
|
|
||||||
|
@ -53,7 +54,7 @@ export interface IListContainerProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IListContainerState {
|
interface IListContainerState {
|
||||||
messages: TAnyMessageModel[];
|
messages: TMessage[];
|
||||||
refreshing: boolean;
|
refreshing: boolean;
|
||||||
highlightedMessage: string | null;
|
highlightedMessage: string | null;
|
||||||
}
|
}
|
||||||
|
@ -185,47 +186,16 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
if (rid) {
|
if (rid) {
|
||||||
this.unsubscribeMessages();
|
this.unsubscribeMessages();
|
||||||
this.messagesSubscription = this.messagesObservable?.subscribe(messages => {
|
this.messagesSubscription = this.messagesObservable?.subscribe(messages => {
|
||||||
// @ts-ignore is this enough cols?
|
let data = messages.map(m => {
|
||||||
messages = messages.map(m => {
|
|
||||||
if ((MESSAGE_TYPE_ANY_LOAD as MessageType[]).includes(m.t)) {
|
if ((MESSAGE_TYPE_ANY_LOAD as MessageType[]).includes(m.t)) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return m.asPlain();
|
||||||
id: m.id,
|
|
||||||
_id: m._id,
|
|
||||||
msg: m.msg,
|
|
||||||
ts: m.ts,
|
|
||||||
status: m.status,
|
|
||||||
attachments: m.attachments,
|
|
||||||
urls: m.urls,
|
|
||||||
reactions: m.reactions,
|
|
||||||
t: m.t,
|
|
||||||
avatar: m.avatar,
|
|
||||||
emoji: m.emoji,
|
|
||||||
u: m.u,
|
|
||||||
alias: m.alias,
|
|
||||||
editedBy: m.editedBy,
|
|
||||||
role: m.role,
|
|
||||||
drid: m.drid,
|
|
||||||
dcount: m.dcount,
|
|
||||||
dlm: m.dlm,
|
|
||||||
tmid: m.tmid,
|
|
||||||
tcount: m.tcount,
|
|
||||||
tlm: m.tlm,
|
|
||||||
tmsg: m.tmsg,
|
|
||||||
mentions: m.mentions,
|
|
||||||
channels: m.channels,
|
|
||||||
unread: m.unread,
|
|
||||||
blocks: m.blocks,
|
|
||||||
autoTranslate: m.autoTranslate,
|
|
||||||
replies: m.replies,
|
|
||||||
md: m.md,
|
|
||||||
comment: m.comment
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tmid && this.thread) {
|
if (tmid && this.thread) {
|
||||||
messages = [...messages, this.thread];
|
data = [...messages, this.thread];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,7 +203,7 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
* hide system message is enabled
|
* hide system message is enabled
|
||||||
*/
|
*/
|
||||||
if (compareServerVersion(serverVersion, 'lowerThan', '3.16.0') || hideSystemMessages.length) {
|
if (compareServerVersion(serverVersion, 'lowerThan', '3.16.0') || hideSystemMessages.length) {
|
||||||
messages = messages.filter(m => !m.t || !hideSystemMessages?.includes(m.t));
|
data = messages.filter(m => !m.t || !hideSystemMessages?.includes(m.t));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.mounted) {
|
if (this.mounted) {
|
||||||
|
@ -241,10 +211,10 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
listRef.current?.prepareForLayoutAnimationRender();
|
listRef.current?.prepareForLayoutAnimationRender();
|
||||||
animateNextTransition();
|
animateNextTransition();
|
||||||
}
|
}
|
||||||
this.setState({ messages });
|
this.setState({ messages: data });
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.state.messages = messages;
|
this.state.messages = data;
|
||||||
}
|
}
|
||||||
// TODO: move it away from here
|
// TODO: move it away from here
|
||||||
this.readThreads();
|
this.readThreads();
|
||||||
|
@ -297,7 +267,7 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getLastMessage = (): TMessageModel | TThreadMessageModel | null => {
|
getLastMessage = (): TAnyMessage | null => {
|
||||||
const { messages } = this.state;
|
const { messages } = this.state;
|
||||||
if (messages.length > 0) {
|
if (messages.length > 0) {
|
||||||
return messages[0];
|
return messages[0];
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import { TAnyMessage, TMessageModel } from '../../definitions';
|
||||||
|
|
||||||
|
export type TMessage = TAnyMessage | TMessageModel;
|
|
@ -69,7 +69,7 @@ import {
|
||||||
ISubscription,
|
ISubscription,
|
||||||
IVisitor,
|
IVisitor,
|
||||||
SubscriptionType,
|
SubscriptionType,
|
||||||
TAnyMessageModel,
|
TAnyMessage,
|
||||||
TMessageModel,
|
TMessageModel,
|
||||||
TSubscriptionModel,
|
TSubscriptionModel,
|
||||||
TThreadModel,
|
TThreadModel,
|
||||||
|
@ -101,6 +101,7 @@ import {
|
||||||
import { Services } from '../../lib/services';
|
import { Services } from '../../lib/services';
|
||||||
import { withActionSheet, IActionSheetProvider } from '../../containers/ActionSheet';
|
import { withActionSheet, IActionSheetProvider } from '../../containers/ActionSheet';
|
||||||
import { goRoom, TGoRoomItem } from '../../lib/methods/helpers/goRoom';
|
import { goRoom, TGoRoomItem } from '../../lib/methods/helpers/goRoom';
|
||||||
|
import { TMessage } from './definitions';
|
||||||
|
|
||||||
type TStateAttrsUpdate = keyof IRoomViewState;
|
type TStateAttrsUpdate = keyof IRoomViewState;
|
||||||
|
|
||||||
|
@ -193,7 +194,7 @@ interface IRoomViewState {
|
||||||
member: any;
|
member: any;
|
||||||
lastOpen: Date | null;
|
lastOpen: Date | null;
|
||||||
reactionsModalVisible: boolean;
|
reactionsModalVisible: boolean;
|
||||||
selectedMessage?: TAnyMessageModel;
|
selectedMessage?: TAnyMessage;
|
||||||
canAutoTranslate: boolean;
|
canAutoTranslate: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
editing: boolean;
|
editing: boolean;
|
||||||
|
@ -225,7 +226,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
private retryFindTimeout?: ReturnType<typeof setTimeout>;
|
private retryFindTimeout?: ReturnType<typeof setTimeout>;
|
||||||
private messageErrorActions?: IMessageErrorActions | null;
|
private messageErrorActions?: IMessageErrorActions | null;
|
||||||
private messageActions?: IMessageActions | null;
|
private messageActions?: IMessageActions | null;
|
||||||
private replyInDM?: TAnyMessageModel;
|
private replyInDM?: TAnyMessage;
|
||||||
// Type of InteractionManager.runAfterInteractions
|
// Type of InteractionManager.runAfterInteractions
|
||||||
private didMountInteraction?: {
|
private didMountInteraction?: {
|
||||||
then: (onfulfilled?: (() => any) | undefined, onrejected?: (() => any) | undefined) => Promise<any>;
|
then: (onfulfilled?: (() => any) | undefined, onrejected?: (() => any) | undefined) => Promise<any>;
|
||||||
|
@ -781,7 +782,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
errorActionsShow = (message: TAnyMessageModel) => {
|
errorActionsShow = (message: TAnyMessage) => {
|
||||||
this.messagebox?.current?.closeEmojiAndAction(this.messageErrorActions?.showMessageErrorActions, message);
|
this.messagebox?.current?.closeEmojiAndAction(this.messageErrorActions?.showMessageErrorActions, message);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -790,7 +791,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
this.messagebox?.current?.closeEmojiAndAction(showActionSheet, options);
|
this.messagebox?.current?.closeEmojiAndAction(showActionSheet, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
onEditInit = (message: TAnyMessageModel) => {
|
onEditInit = (message: TAnyMessage) => {
|
||||||
const newMessage = {
|
const newMessage = {
|
||||||
id: message.id,
|
id: message.id,
|
||||||
subscription: {
|
subscription: {
|
||||||
|
@ -806,7 +807,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
this.setState({ selectedMessage: undefined, editing: false });
|
this.setState({ selectedMessage: undefined, editing: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
onEditRequest = async (message: TAnyMessageModel) => {
|
onEditRequest = async (message: TAnyMessage) => {
|
||||||
this.setState({ selectedMessage: undefined, editing: false });
|
this.setState({ selectedMessage: undefined, editing: false });
|
||||||
try {
|
try {
|
||||||
await Services.editMessage(message);
|
await Services.editMessage(message);
|
||||||
|
@ -815,7 +816,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onReplyInit = (message: TAnyMessageModel, mention: boolean) => {
|
onReplyInit = (message: TAnyMessage, mention: boolean) => {
|
||||||
// If there's a thread already, we redirect to it
|
// If there's a thread already, we redirect to it
|
||||||
if (mention && !!message.tlm) {
|
if (mention && !!message.tlm) {
|
||||||
return this.onThreadPress(message);
|
return this.onThreadPress(message);
|
||||||
|
@ -843,7 +844,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onReactionInit = (message: TAnyMessageModel) => {
|
onReactionInit = (message: TAnyMessage) => {
|
||||||
this.messagebox?.current?.closeEmojiAndAction(() => {
|
this.messagebox?.current?.closeEmojiAndAction(() => {
|
||||||
this.setState({ selectedMessage: message }, this.showReactionPicker);
|
this.setState({ selectedMessage: message }, this.showReactionPicker);
|
||||||
});
|
});
|
||||||
|
@ -854,7 +855,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
this.setState({ selectedMessage: undefined }, hideActionSheet);
|
this.setState({ selectedMessage: undefined }, hideActionSheet);
|
||||||
};
|
};
|
||||||
|
|
||||||
onMessageLongPress = (message: TAnyMessageModel) => {
|
onMessageLongPress = (message: TAnyMessage) => {
|
||||||
// if it's a thread message on main room, we disable the long press
|
// if it's a thread message on main room, we disable the long press
|
||||||
if (message.tmid && !this.tmid) {
|
if (message.tmid && !this.tmid) {
|
||||||
return;
|
return;
|
||||||
|
@ -884,7 +885,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onReactionLongPress = (message: TAnyMessageModel) => {
|
onReactionLongPress = (message: TAnyMessage) => {
|
||||||
this.setState({ selectedMessage: message });
|
this.setState({ selectedMessage: message });
|
||||||
const { showActionSheet } = this.props;
|
const { showActionSheet } = this.props;
|
||||||
const { selectedMessage } = this.state;
|
const { selectedMessage } = this.state;
|
||||||
|
@ -910,7 +911,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
};
|
};
|
||||||
|
|
||||||
onDiscussionPress = debounce(
|
onDiscussionPress = debounce(
|
||||||
async (item: TAnyMessageModel) => {
|
async (item: TAnyMessage) => {
|
||||||
const { isMasterDetail } = this.props;
|
const { isMasterDetail } = this.props;
|
||||||
if (!item.drid) return;
|
if (!item.drid) return;
|
||||||
const sub = await getRoomInfo(item.drid);
|
const sub = await getRoomInfo(item.drid);
|
||||||
|
@ -945,7 +946,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
onThreadPress = debounce((item: TAnyMessageModel) => this.navToThread(item), 1000, true);
|
onThreadPress = debounce((item: TAnyMessage) => this.navToThread(item), 1000, true);
|
||||||
|
|
||||||
shouldNavigateToRoom = (message: IMessage) => {
|
shouldNavigateToRoom = (message: IMessage) => {
|
||||||
if (message.tmid && message.tmid === this.tmid) {
|
if (message.tmid && message.tmid === this.tmid) {
|
||||||
|
@ -1154,7 +1155,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
navToThread = async (item: TAnyMessageModel | { tmid: string }) => {
|
navToThread = async (item: TAnyMessage | { tmid: string }) => {
|
||||||
const { roomUserId } = this.state;
|
const { roomUserId } = this.state;
|
||||||
const { navigation } = this.props;
|
const { navigation } = this.props;
|
||||||
|
|
||||||
|
@ -1203,7 +1204,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
navToRoom = async (message: TAnyMessageModel) => {
|
navToRoom = async (message: TAnyMessage) => {
|
||||||
const { isMasterDetail } = this.props;
|
const { isMasterDetail } = this.props;
|
||||||
const roomInfo = await getRoomInfo(message.rid);
|
const roomInfo = await getRoomInfo(message.rid);
|
||||||
|
|
||||||
|
@ -1292,7 +1293,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
isIgnored = (message: TAnyMessageModel): boolean => {
|
isIgnored = (message: TAnyMessage): boolean => {
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
if ('id' in room) {
|
if ('id' in room) {
|
||||||
return room?.ignored?.includes?.(message?.u?._id) ?? false;
|
return room?.ignored?.includes?.(message?.u?._id) ?? false;
|
||||||
|
@ -1300,7 +1301,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
onLoadMoreMessages = (loaderItem: TAnyMessageModel) => {
|
onLoadMoreMessages = (loaderItem: TMessageModel) => {
|
||||||
const { room } = this.state;
|
const { room } = this.state;
|
||||||
return RoomServices.getMoreMessages({
|
return RoomServices.getMoreMessages({
|
||||||
rid: room.rid,
|
rid: room.rid,
|
||||||
|
@ -1315,7 +1316,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
Navigation.navigate('CannedResponsesListView', { rid: room.rid });
|
Navigation.navigate('CannedResponsesListView', { rid: room.rid });
|
||||||
};
|
};
|
||||||
|
|
||||||
renderItem = (item: TAnyMessageModel, previousItem: TAnyMessageModel, highlightedMessage?: string) => {
|
renderItem = (item: TMessage, previousItem: TMessage, highlightedMessage?: string) => {
|
||||||
const { room, lastOpen, canAutoTranslate } = this.state;
|
const { room, lastOpen, canAutoTranslate } = this.state;
|
||||||
const { user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl, Message_Read_Receipt_Enabled, theme } =
|
const { user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl, Message_Read_Receipt_Enabled, theme } =
|
||||||
this.props;
|
this.props;
|
||||||
|
@ -1336,7 +1337,7 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
if (item.t && MESSAGE_TYPE_ANY_LOAD.includes(item.t as MessageTypeLoad)) {
|
if (item.t && MESSAGE_TYPE_ANY_LOAD.includes(item.t as MessageTypeLoad)) {
|
||||||
content = (
|
content = (
|
||||||
<LoadMore
|
<LoadMore
|
||||||
load={() => this.onLoadMoreMessages(item)}
|
load={() => this.onLoadMoreMessages(item as TMessageModel)}
|
||||||
type={item.t}
|
type={item.t}
|
||||||
runOnRender={item.t === MessageTypeLoad.MORE && !previousItem}
|
runOnRender={item.t === MessageTypeLoad.MORE && !previousItem}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { SubscriptionType, TAnyMessageModel } from '../../../definitions';
|
import { SubscriptionType, TMessageModel } from '../../../definitions';
|
||||||
import { loadNextMessages, loadMessagesForRoom } from '../../../lib/methods';
|
import { loadNextMessages, loadMessagesForRoom } from '../../../lib/methods';
|
||||||
import { MessageTypeLoad } from '../../../lib/constants';
|
import { MessageTypeLoad } from '../../../lib/constants';
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ const getMoreMessages = ({
|
||||||
rid: string;
|
rid: string;
|
||||||
t: SubscriptionType;
|
t: SubscriptionType;
|
||||||
tmid?: string;
|
tmid?: string;
|
||||||
loaderItem: TAnyMessageModel;
|
loaderItem: TMessageModel;
|
||||||
}): Promise<void> => {
|
}): Promise<void> => {
|
||||||
if ([MessageTypeLoad.MORE, MessageTypeLoad.PREVIOUS_CHUNK].includes(loaderItem.t as MessageTypeLoad)) {
|
if ([MessageTypeLoad.MORE, MessageTypeLoad.PREVIOUS_CHUNK].includes(loaderItem.t as MessageTypeLoad)) {
|
||||||
return loadMessagesForRoom({
|
return loadMessagesForRoom({
|
||||||
|
|
Loading…
Reference in New Issue