Chore: Migrate REST API - getMessages to Typescript (#3875)

This commit is contained in:
Alex Junior 2022-03-10 12:00:50 -03:00 committed by AlexAlexandre
parent 697a303f2f
commit 6a148b9e5f
6 changed files with 55 additions and 8 deletions

View File

@ -87,6 +87,17 @@ export interface IMessageFromServer {
drid?: string; drid?: string;
dcount?: number; dcount?: number;
dml: string | Date; dml: string | Date;
starred?:
| {
_id: string;
}
| boolean;
pinned?: boolean;
pinnedAt?: string | Date;
pinnedBy?: {
_id: string;
username: string;
};
} }
export interface ILoadMoreMessage { export interface ILoadMoreMessage {
@ -106,7 +117,11 @@ export interface IMessage extends IMessageFromServer {
emoji?: string; emoji?: string;
status?: number; status?: number;
pinned?: boolean; pinned?: boolean;
starred?: boolean; starred?:
| {
_id: string;
}
| boolean;
editedBy?: IEditedBy; editedBy?: IEditedBy;
reactions?: IReaction[]; reactions?: IReaction[];
role?: string; role?: string;

View File

@ -96,4 +96,14 @@ export type ChannelsEndpoints = {
'channels.removeLeader': { 'channels.removeLeader': {
POST: (params: { roomId: string; userId: string }) => {}; POST: (params: { roomId: string; userId: string }) => {};
}; };
'channels.messages': {
GET: (params: {
roomId: IServerRoom['_id'];
query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean };
offset: number;
sort: { ts: number };
}) => {
messages: IMessageFromServer[];
};
};
}; };

View File

@ -72,4 +72,14 @@ export type GroupsEndpoints = {
'groups.leave': { 'groups.leave': {
POST: (params: { roomId: string }) => {}; POST: (params: { roomId: string }) => {};
}; };
'groups.messages': {
GET: (params: {
roomId: IServerRoom['_id'];
query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean };
offset: number;
sort: { ts: number };
}) => {
messages: IMessageFromServer[];
};
};
}; };

View File

@ -58,4 +58,14 @@ export type ImEndpoints = {
'im.leave': { 'im.leave': {
POST: (params: { roomId: string }) => {}; POST: (params: { roomId: string }) => {};
}; };
'im.messages': {
GET: (params: {
roomId: IServerRoom['_id'];
query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean };
offset: number;
sort: { ts: number };
}) => {
messages: IMessageFromServer[];
};
};
}; };

View File

@ -602,16 +602,21 @@ export const getFiles = (roomId: string, type: SubscriptionType, offset: number)
}); });
}; };
export const getMessages = (roomId: string, type: RoomTypes, query: any, offset: number): any => export const getMessages = (
roomId: string,
type: SubscriptionType,
query: { 'mentions._id': { $in: string[] } } | { 'starred._id': { $in: string[] } } | { pinned: boolean },
offset: number
) => {
const t = type as SubscriptionType.DIRECT | SubscriptionType.CHANNEL | SubscriptionType.GROUP;
// RC 0.59.0 // RC 0.59.0
// TODO: missing definitions from server return sdk.get(`${roomTypeToApiType(t)}.messages`, {
// @ts-ignore
sdk.get(`${roomTypeToApiType(type)}.messages`, {
roomId, roomId,
query, query,
offset, offset,
sort: { ts: -1 } sort: { ts: -1 }
}); });
};
export const getReadReceipts = (messageId: string): any => export const getReadReceipts = (messageId: string): any =>
// RC 0.63.0 // RC 0.63.0

View File

@ -227,7 +227,6 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
name: I18n.t('Mentions'), name: I18n.t('Mentions'),
fetchFunc: () => { fetchFunc: () => {
const { messages } = this.state; const { messages } = this.state;
// @ts-ignore
return RocketChat.getMessages(this.rid, this.t, { 'mentions._id': { $in: [user.id] } }, messages.length); return RocketChat.getMessages(this.rid, this.t, { 'mentions._id': { $in: [user.id] } }, messages.length);
}, },
noDataMsg: I18n.t('No_mentioned_messages'), noDataMsg: I18n.t('No_mentioned_messages'),
@ -240,7 +239,6 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
name: I18n.t('Starred'), name: I18n.t('Starred'),
fetchFunc: () => { fetchFunc: () => {
const { messages } = this.state; const { messages } = this.state;
// @ts-ignore
return RocketChat.getMessages(this.rid, this.t, { 'starred._id': { $in: [user.id] } }, messages.length); return RocketChat.getMessages(this.rid, this.t, { 'starred._id': { $in: [user.id] } }, messages.length);
}, },
noDataMsg: I18n.t('No_starred_messages'), noDataMsg: I18n.t('No_starred_messages'),
@ -261,7 +259,6 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
name: I18n.t('Pinned'), name: I18n.t('Pinned'),
fetchFunc: () => { fetchFunc: () => {
const { messages } = this.state; const { messages } = this.state;
// @ts-ignore
return RocketChat.getMessages(this.rid, this.t, { pinned: true }, messages.length); return RocketChat.getMessages(this.rid, this.t, { pinned: true }, messages.length);
}, },
noDataMsg: I18n.t('No_pinned_messages'), noDataMsg: I18n.t('No_pinned_messages'),