Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
6 changes: 4 additions & 2 deletions app/definitions/IMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MarkdownAST } from '@rocket.chat/message-parser';

import { IAttachment } from './IAttachment';
import { IReaction } from './IReaction';
import { IUrl, IUrlFromServer } from './IUrl';

export type MessageType = 'jitsi_call_started' | 'discussion-created' | 'e2e' | 'load_more' | 'rm' | 'uj';

Expand Down Expand Up @@ -30,6 +31,7 @@ export interface IEditedBy {
export type TOnLinkPress = (link: string) => void;

export interface ITranslations {
[index: string]: string;
_id: string;
language: string;
value: string;
Expand Down Expand Up @@ -71,7 +73,7 @@ export interface IMessage {
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: string[];
urls?: IUrl[] | IUrlFromServer[];
_updatedAt: Date;
status?: number;
pinned?: boolean;
Expand All @@ -84,7 +86,7 @@ export interface IMessage {
dlm?: Date;
tmid?: string;
tcount?: number;
tlm?: Date;
tlm?: string | Date;
replies?: string[];
mentions?: IUserMention[];
channels?: IUserChannel[];
Expand Down
1 change: 1 addition & 0 deletions app/definitions/IReaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface IReaction {
[index: string]: string | string[];
_id: string;
emoji: string;
usernames: string[];
Expand Down
22 changes: 11 additions & 11 deletions app/definitions/IThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MarkdownAST } from '@rocket.chat/message-parser';
import { IAttachment } from './IAttachment';
import { IEditedBy, IUserChannel, IUserMention, IUserMessage, MessageType } from './IMessage';
import { IReaction } from './IReaction';
import { IUrl } from './IUrl';
import { IUrl, IUrlFromServer } from './IUrl';

interface IFileThread {
_id: string;
Expand All @@ -15,21 +15,21 @@ interface IFileThread {
export interface IThreadResult {
_id: string;
rid: string;
ts: string;
msg: string;
ts: string | Date;
msg?: string;
file?: IFileThread;
files?: IFileThread[];
groupable?: boolean;
attachments?: IAttachment[];
md?: MarkdownAST;
u: IUserMessage;
_updatedAt: string;
urls: IUrl[];
mentions: IUserMention[];
channels: IUserChannel[];
replies: string[];
tcount: number;
tlm: string;
_updatedAt: string | Date;
urls?: IUrl[] | IUrlFromServer[];
mentions?: IUserMention[];
channels?: IUserChannel[];
replies?: string[];
tcount?: number;
tlm?: string | Date;
}

export interface IThread {
Expand All @@ -47,7 +47,7 @@ export interface IThread {
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: IUrl[];
urls?: IUrl[] | IUrlFromServer[];
status?: number;
pinned?: boolean;
starred?: boolean;
Expand Down
5 changes: 3 additions & 2 deletions app/definitions/IThreadMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Model from '@nozbe/watermelondb/Model';
import { IAttachment } from './IAttachment';
import { IEditedBy, ITranslations, IUserChannel, IUserMention, IUserMessage, MessageType } from './IMessage';
import { IReaction } from './IReaction';
import { IUrl, IUrlFromServer } from './IUrl';

export interface IThreadMessage {
tmsg?: string;
Expand All @@ -17,7 +18,7 @@ export interface IThreadMessage {
avatar?: string;
emoji?: string;
attachments?: IAttachment[];
urls?: string[];
urls?: IUrl[] | IUrlFromServer[];
_updatedAt?: Date;
status?: number;
pinned?: boolean;
Expand All @@ -30,7 +31,7 @@ export interface IThreadMessage {
dlm?: Date;
tmid?: string;
tcount?: number;
tlm?: Date;
tlm?: string | Date;
replies?: string[];
mentions?: IUserMention[];
channels?: IUserChannel[];
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, IUrlFromServer } 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: IMessage) => {
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,22 +33,24 @@ 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 => ({
msg.reactions = Object.keys(msg.reactions).map((key: string) => ({
_id: `${msg._id}${key}`,
emoji: key,
usernames: msg.reactions[key].usernames
usernames: msg.reactions ? msg.reactions[key as unknown as number].usernames : []
Comment thread
gerzonc marked this conversation as resolved.
Outdated
}));
}
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]
// @ts-ignore
value: msg.translations ? msg.translations[key] : ''
}));
msg.autoTranslate = true;
}
msg.urls = msg.urls ? parseUrls(msg.urls) : [];
msg.urls = msg.urls ? parseUrls(msg.urls as IUrlFromServer[]) : [];
msg._updatedAt = new Date();
// loadHistory returns msg.starred as object
// stream-room-msgs returns msg.starred as an array
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