Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions app/definitions/IMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ export type E2EType = 'pending' | 'done';
export interface ILastMessage {
_id: string;
rid: string;
tshow: boolean;
t: MessageType;
tmid: string;
msg: string;
e2e: E2EType;
ts: Date;
tshow?: boolean;
t?: MessageType;
tmid?: string;
msg?: string;
e2e?: E2EType;
ts: string | Date;
u: IUserMessage;
_updatedAt: Date;
urls: string[];
mentions: IUserMention[];
channels: IUserChannel[];
md: MarkdownAST;
attachments: IAttachment[];
reactions: IReaction[];
unread: boolean;
status: boolean;
_updatedAt: string | Date;
urls?: IUrl[];
mentions?: IUserMention[];
channels?: IUserChannel[];
md?: MarkdownAST;
attachments?: IAttachment[];
reactions?: IReaction[];
unread?: boolean;
status?: number;
}

export interface IMessage {
Expand Down Expand Up @@ -95,7 +95,7 @@ export interface IMessage {
translations?: ITranslations[];
tmsg?: string;
blocks?: any;
e2e?: string;
e2e?: E2EType;
tshow?: boolean;
md?: MarkdownAST;
subscription?: { id: string };
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/helpers/buildMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IMessage } from '../../../definitions';
import messagesStatus from '../../../constants/messagesStatus';
import normalizeMessage from './normalizeMessage';

export default (message: IMessage): IMessage => {
export default (message: IMessage): IMessage | null => {
Comment thread
gerzonc marked this conversation as resolved.
Outdated
message.status = messagesStatus.SENT;
return normalizeMessage(message);
};
11 changes: 9 additions & 2 deletions app/lib/methods/helpers/mergeSubscriptionsRooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import { store as reduxStore } from '../../auxStore';
import { compareServerVersion } from '../../utils';
import findSubscriptionsRooms from './findSubscriptionsRooms';
import normalizeMessage from './normalizeMessage';
import { ISubscription, IServerRoom, IServerSubscription, IServerSubscriptionItem, IServerRoomItem } from '../../../definitions';
import {
ISubscription,
IServerRoom,
IServerSubscription,
IServerSubscriptionItem,
IServerRoomItem,
IMessage
} from '../../../definitions';
// TODO: delete and update

export const merge = (
Expand All @@ -18,7 +25,7 @@ export const merge = (
if (room) {
room = EJSON.fromJSONValue(room) as ISubscription;
if (room._updatedAt) {
subscription.lastMessage = normalizeMessage(room.lastMessage);
subscription.lastMessage = normalizeMessage(room.lastMessage) as IMessage;
Comment thread
gerzonc marked this conversation as resolved.
Outdated
subscription.description = room.description;
subscription.topic = room.topic;
subscription.announcement = room.announcement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import moment from 'moment';

import parseUrls from './parseUrls';
import type { IAttachment, IMessage } from '../../../definitions';

function normalizeAttachments(msg) {
type TMsg = IMessage & IAttachment;

function normalizeAttachments(msg: TMsg) {
if (typeof msg.attachments !== typeof [] || !msg.attachments || !msg.attachments.length) {
msg.attachments = [];
}
Expand All @@ -11,17 +14,17 @@ function normalizeAttachments(msg) {
if (att.ts) {
att.ts = moment(att.ts).toDate();
}
att = normalizeAttachments(att);
att = normalizeAttachments(att as IMessage & IAttachment);
Comment thread
gerzonc marked this conversation as resolved.
Outdated
return att;
});
return msg;
}

export default msg => {
export default (msg: any): IMessage | null => {
Comment thread
diegolmello marked this conversation as resolved.
Outdated
if (!msg) {
return null;
}
msg = normalizeAttachments(msg);
msg = normalizeAttachments(msg as TMsg);
msg.reactions = msg.reactions || [];
msg.unread = msg.unread || false;
// TODO: api problems
Expand All @@ -30,18 +33,19 @@ export default msg => {
// } else {
// msg.reactions = Object.keys(msg.reactions).map(key => ({ emoji: key, usernames: msg.reactions[key].usernames.map(username => ({ value: username })) }));
// }

if (!Array.isArray(msg.reactions)) {
msg.reactions = Object.keys(msg.reactions).map(key => ({
_id: `${msg._id}${key}`,
emoji: key,
usernames: msg.reactions[key].usernames
usernames: msg.reactions ? msg.reactions[key].usernames : []
}));
}
if (msg.translations && Object.keys(msg.translations).length) {
msg.translations = Object.keys(msg.translations).map(key => ({
_id: `${msg._id}${key}`,
language: key,
value: msg.translations[key]
value: msg.translations ? msg.translations[key] : ''
}));
msg.autoTranslate = true;
}
Expand Down
4 changes: 2 additions & 2 deletions app/lib/methods/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import log from '../../utils/log';
import random from '../../utils/random';
import { Encryption } from '../encryption';
import { E2E_MESSAGE_TYPE, E2E_STATUS } from '../encryption/constants';
import { IMessage, IUser, TMessageModel } from '../../definitions';
import { E2EType, IMessage, IUser, TMessageModel } from '../../definitions';
import sdk from '../rocketchat/services/sdk';

const changeMessageStatus = async (id: string, status: number, tmid?: string, message?: IMessage) => {
Expand Down Expand Up @@ -197,7 +197,7 @@ export default async function (rid: string, msg: string, tmid: string, user: IUs
}
m.t = message.t;
if (message.t === E2E_MESSAGE_TYPE) {
m.e2e = E2E_STATUS.DONE;
m.e2e = E2E_STATUS.DONE as E2EType;
}
})
);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/updateMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default async function updateMessages({
.query(Q.where('subscription_id', rid), Q.where('id', Q.oneOf(messagesIds)))
.fetch();

update = update.map(m => buildMessage(m));
update = update.map(m => buildMessage(m) as IMessage);

// filter loaders to delete
let loadersToDelete: TMessageModel[] = allMessagesRecords.filter(i1 =>
Expand Down
3 changes: 2 additions & 1 deletion app/views/ThreadMessagesView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { LISTENER } from '../../containers/Toast';
import SearchHeader from '../../containers/SearchHeader';
import { ChatsStackParamList } from '../../stacks/types';
import { IThreadResult, TThreadModel } from '../../definitions/IThread';
import { IMessage } from '../../definitions/IMessage';
import { Filter } from './filters';
import DropdownItemHeader from './Dropdown/DropdownItemHeader';
import Dropdown from './Dropdown';
Expand Down Expand Up @@ -287,7 +288,7 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
}

if (update && update.length) {
update = update.map(m => buildMessage(m));
update = update.map(m => buildMessage(m) as IMessage);
// filter threads
threadsToCreate = update.filter(i1 => !allThreadsRecords.find((i2: { id: string }) => i1._id === i2.id));
threadsToUpdate = allThreadsRecords.filter((i1: { id: string }) => update.find(i2 => i1.id === i2._id));
Expand Down