diff --git a/app/definitions/IAttachment.ts b/app/definitions/IAttachment.ts index 788d58763..06ad1859c 100644 --- a/app/definitions/IAttachment.ts +++ b/app/definitions/IAttachment.ts @@ -1,3 +1,5 @@ +import { IUser } from './IUser'; + export interface IAttachment { ts: string | Date; title: string; @@ -23,3 +25,30 @@ export interface IAttachment { color?: string; thumb_url?: string; } + +export interface IServerAttachment { + _id: string; + name: string; + size: number; + type: string; + rid: string; + userId: string; + AmazonS3: { path: string }; + store: string; + identify: { + format: string; + size: { + width: number; + height: number; + }; + }; + complete: boolean; + etag: string; + path: string; + progress: boolean; + token: string; + uploadedAt: string | Date; + uploading: boolean; + url: string; + user: Pick; +} diff --git a/app/definitions/rest/v1/channels.ts b/app/definitions/rest/v1/channels.ts index 3e0c72e8a..7eb2bdb0d 100644 --- a/app/definitions/rest/v1/channels.ts +++ b/app/definitions/rest/v1/channels.ts @@ -1,18 +1,15 @@ import { ITeam } from '../../ITeam'; -import type { IMessage, IMessageFromServer } from '../../IMessage'; +import type { IMessageFromServer } from '../../IMessage'; import type { IServerRoom } from '../../IRoom'; import type { IUser } from '../../IUser'; +import { IServerAttachment } from '../../IAttachment'; export type ChannelsEndpoints = { 'channels.files': { - GET: (params: { - roomId: IServerRoom['_id']; - offset: number; + GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => { + files: IServerAttachment[]; count: number; - sort: string | { uploadedAt: number }; - query: string; - }) => { - files: IMessage[]; + offset: number; total: number; }; }; diff --git a/app/definitions/rest/v1/groups.ts b/app/definitions/rest/v1/groups.ts index 22ff41495..2768b7070 100644 --- a/app/definitions/rest/v1/groups.ts +++ b/app/definitions/rest/v1/groups.ts @@ -1,12 +1,15 @@ import { ITeam } from '../../ITeam'; -import type { IMessage, IMessageFromServer } from '../../IMessage'; +import type { IMessageFromServer } from '../../IMessage'; import type { IServerRoom } from '../../IRoom'; import type { IUser } from '../../IUser'; +import { IServerAttachment } from '../../IAttachment'; export type GroupsEndpoints = { 'groups.files': { - GET: (params: { roomId: IServerRoom['_id']; count: number; sort: string | { uploadedAt: number }; query: string }) => { - files: IMessage[]; + GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => { + files: IServerAttachment[]; + count: number; + offset: number; total: number; }; }; diff --git a/app/definitions/rest/v1/im.ts b/app/definitions/rest/v1/im.ts index 9b2de6c60..c320cef30 100644 --- a/app/definitions/rest/v1/im.ts +++ b/app/definitions/rest/v1/im.ts @@ -1,6 +1,7 @@ -import type { IMessage, IMessageFromServer } from '../../IMessage'; +import type { IMessageFromServer } from '../../IMessage'; import type { IServerRoom, RoomID, RoomType } from '../../IRoom'; import type { IUser } from '../../IUser'; +import { IServerAttachment } from '../../IAttachment'; export type ImEndpoints = { 'im.create': { @@ -25,8 +26,10 @@ export type ImEndpoints = { }; }; 'im.files': { - GET: (params: { roomId: IServerRoom['_id']; count: number; sort: string | { uploadedAt: number }; query: string }) => { - files: IMessage[]; + GET: (params: { roomId: IServerRoom['_id']; offset: number; sort: string | { uploadedAt: number } }) => { + files: IServerAttachment[]; + count: number; + offset: number; total: number; }; }; diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/rocketchat/services/restApi.ts index 99eea86f4..bedefb538 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/rocketchat/services/restApi.ts @@ -596,15 +596,15 @@ export const getUsernameSuggestion = (): any => // @ts-ignore sdk.get('users.getUsernameSuggestion'); -export const getFiles = (roomId: string, type: RoomTypes, offset: number): any => +export const getFiles = (roomId: string, type: SubscriptionType, offset: number) => { + const t = type as SubscriptionType.DIRECT | SubscriptionType.CHANNEL | SubscriptionType.GROUP; // RC 0.59.0 - // TODO: missing definitions from server - // @ts-ignore - sdk.get(`${roomTypeToApiType(type)}.files`, { + return sdk.get(`${roomTypeToApiType(t)}.files`, { roomId, offset, sort: { uploadedAt: -1 } }); +}; export const getMessages = (roomId: string, type: RoomTypes, query: any, offset: number): any => // RC 0.59.0 diff --git a/app/views/MessagesView/index.tsx b/app/views/MessagesView/index.tsx index b3b6a8494..d8b2d82df 100644 --- a/app/views/MessagesView/index.tsx +++ b/app/views/MessagesView/index.tsx @@ -196,9 +196,10 @@ class MessagesView extends React.Component { name: I18n.t('Files'), fetchFunc: async () => { const { messages } = this.state; - // @ts-ignore const result = await RocketChat.getFiles(this.rid, this.t, messages.length); - return { ...result, messages: result.files }; + if (result.success) { + return { ...result, messages: result.files }; + } }, noDataMsg: I18n.t('No_files'), testID: 'room-files-view',