Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Migrate REST API - getFiles to Typescript #3873

Merged
merged 2 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions app/definitions/IAttachment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IUser } from './IUser';

export interface IAttachment {
ts: string | Date;
title: string;
Expand All @@ -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<IUser, '_id' | 'username' | 'name'>;
}
13 changes: 5 additions & 8 deletions app/definitions/rest/v1/channels.ts
Original file line number Diff line number Diff line change
@@ -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;
};
};
Expand Down
9 changes: 6 additions & 3 deletions app/definitions/rest/v1/groups.ts
Original file line number Diff line number Diff line change
@@ -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;
};
};
Expand Down
9 changes: 6 additions & 3 deletions app/definitions/rest/v1/im.ts
Original file line number Diff line number Diff line change
@@ -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': {
Expand All @@ -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;
};
};
Expand Down
8 changes: 4 additions & 4 deletions app/lib/rocketchat/services/restApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,15 +590,15 @@ export const getUsernameSuggestion = () =>
// RC 0.65.0
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,
Expand Down
5 changes: 3 additions & 2 deletions app/views/MessagesView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
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',
Expand Down