Chore: dehydrate small server requests away from rocketchat.js (#3740)

This commit is contained in:
Diego Mello 2022-02-15 15:50:55 -03:00 committed by GitHub
parent c7f4e5531c
commit 1ffa592201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 861 additions and 594 deletions

View File

@ -12,7 +12,7 @@ export enum SubscriptionType {
DIRECT = 'd',
CHANNEL = 'c',
OMNICHANNEL = 'l',
THREAD = 'thread'
THREAD = 'thread' // FIXME: this is not a type of subscription
}
export interface IVisitor {

View File

@ -1,5 +1,6 @@
import type { IMessage } from '../../IMessage';
import type { IRoom } from '../../IRoom';
import { PaginatedResult } from '../helpers/PaginatedResult';
export type ChatEndpoints = {
'chat.getMessage': {
@ -20,9 +21,15 @@ export type ChatEndpoints = {
};
};
'chat.getThreadsList': {
GET: (params: { rid: IRoom['_id']; type: 'unread' | 'following' | 'all'; text?: string; offset: number; count: number }) => {
GET: (params: {
rid: IRoom['_id'];
type: 'unread' | 'following' | 'all';
text?: string;
offset: number;
count: number;
}) => PaginatedResult<{
threads: IMessage[];
total: number;
};
}>;
};
};

View File

@ -0,0 +1,14 @@
const types = {
c: 'channels',
d: 'im',
p: 'groups',
l: 'channels'
};
// TODO: refactor this
export type RoomTypes = keyof typeof types;
type ApiTypes = typeof types[RoomTypes];
const roomTypeToApiType = (t: RoomTypes): ApiTypes => types[t];
export default roomTypeToApiType;

View File

@ -13,7 +13,6 @@ import { selectServerFailure } from '../../actions/server';
import { updateSettings } from '../../actions/settings';
import { shareSelectServer, shareSetSettings, shareSetUser } from '../../actions/share';
import defaultSettings from '../../constants/settings';
import { TEAM_TYPE } from '../../definitions/ITeam';
import I18n from '../../i18n';
import { getDeviceToken } from '../../notifications/push';
import { getBundleId, isIOS } from '../../utils/deviceInfo';
@ -61,10 +60,12 @@ import clearCache from './methods/clearCache';
import getPermalinkMessage from './methods/getPermalinkMessage';
import getRoom from './methods/getRoom';
import isGroupChat from './methods/isGroupChat';
import roomTypeToApiType from './methods/roomTypeToApiType';
import getUserInfo from './services/getUserInfo';
// Services
import sdk from './services/sdk';
import toggleFavorite from './services/toggleFavorite';
import * as restAPis from './services/restApi';
const TOKEN_KEY = 'reactnativemeteor_usertoken';
const CURRENT_SERVER = 'currentServer';
@ -81,6 +82,7 @@ const RocketChat = {
TOKEN_KEY,
CURRENT_SERVER,
CERTIFICATE_KEY,
...restAPis,
callJitsi,
callJitsiWithoutServer,
async subscribeRooms() {
@ -99,19 +101,6 @@ const RocketChat = {
}
},
canOpenRoom,
createChannel({ name, users, type, readOnly, broadcast, encrypted, teamId }) {
const params = {
name,
members: users,
readOnly,
extraData: {
broadcast,
encrypted,
...(teamId && { teamId })
}
};
return this.post(type ? 'groups.create' : 'channels.create', params);
},
async getWebsocketInfo({ server }) {
const sdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl: useSsl(server) });
@ -491,30 +480,6 @@ const RocketChat = {
}
return result;
},
e2eSetUserPublicAndPrivateKeys(public_key, private_key) {
// RC 2.2.0
return this.post('e2e.setUserPublicAndPrivateKeys', { public_key, private_key });
},
e2eRequestSubscriptionKeys() {
// RC 0.72.0
return this.methodCallWrapper('e2e.requestSubscriptionKeys');
},
e2eGetUsersOfRoomWithoutKey(rid) {
// RC 0.70.0
return this.sdk.get('e2e.getUsersOfRoomWithoutKey', { rid });
},
e2eSetRoomKeyID(rid, keyID) {
// RC 0.70.0
return this.post('e2e.setRoomKeyID', { rid, keyID });
},
e2eUpdateGroupKey(uid, rid, key) {
// RC 0.70.0
return this.post('e2e.updateGroupKey', { uid, rid, key });
},
e2eRequestRoomKey(rid, e2eKeyId) {
// RC 0.70.0
return this.methodCallWrapper('stream-notify-room-users', `${rid}/e2ekeyRequest`, rid, e2eKeyId);
},
e2eResetOwnKey() {
this.unsubscribeRooms();
@ -522,25 +487,6 @@ const RocketChat = {
return this.methodCallWrapper('e2e.resetOwnE2EKey');
},
updateJitsiTimeout(roomId) {
// RC 0.74.0
return this.post('video-conference/jitsi.update-timeout', { roomId });
},
register(credentials) {
// RC 0.50.0
return this.post('users.register', credentials, false);
},
forgotPassword(email) {
// RC 0.64.0
return this.post('users.forgotPassword', { email }, false);
},
sendConfirmationEmail(email) {
return this.methodCallWrapper('sendConfirmationEmail', email);
},
loginTOTP(params, loginEmailPassword, isFromWebView = false) {
return new Promise(async (resolve, reject) => {
try {
@ -769,17 +715,6 @@ const RocketChat = {
// return [];
}
},
spotlight(search, usernames, type) {
// RC 0.51.0
return this.methodCallWrapper('spotlight', search, usernames, type);
},
createDirectMessage(username) {
// RC 0.59.0
return sdk.post('im.create', { username });
},
createGroupChat() {
const { users } = reduxStore.getState().selectedUsers;
const usernames = users.map(u => u.name).join(',');
@ -787,114 +722,6 @@ const RocketChat = {
// RC 3.1.0
return this.post('im.create', { usernames });
},
createDiscussion({ prid, pmid, t_name, reply, users, encrypted }) {
// RC 1.0.0
return this.post('rooms.createDiscussion', {
prid,
pmid,
t_name,
reply,
users,
encrypted
});
},
getDiscussions({ roomId, offset, count, text }) {
const params = {
roomId,
offset,
count,
...(text && { text })
};
// RC 2.4.0
return this.sdk.get('chat.getDiscussions', params);
},
createTeam({ name, users, type, readOnly, broadcast, encrypted }) {
const params = {
name,
users,
type: type ? TEAM_TYPE.PRIVATE : TEAM_TYPE.PUBLIC,
room: {
readOnly,
extraData: {
broadcast,
encrypted
}
}
};
// RC 3.13.0
return this.post('teams.create', params);
},
addRoomsToTeam({ teamId, rooms }) {
// RC 3.13.0
return this.post('teams.addRooms', { teamId, rooms });
},
removeTeamRoom({ roomId, teamId }) {
// RC 3.13.0
return sdk.post('teams.removeRoom', { roomId, teamId });
},
leaveTeam({ teamId, rooms }) {
// RC 3.13.0
return this.post('teams.leave', {
teamId,
// RC 4.2.0
...(rooms?.length && { rooms })
});
},
removeTeamMember({ teamId, userId, rooms }) {
// RC 3.13.0
return this.post('teams.removeMember', {
teamId,
userId,
// RC 4.2.0
...(rooms?.length && { rooms })
});
},
updateTeamRoom({ roomId, isDefault }) {
// RC 3.13.0
return this.post('teams.updateRoom', { roomId, isDefault });
},
deleteTeam({ teamId, roomsToRemove }) {
// RC 3.13.0
return this.post('teams.delete', { teamId, roomsToRemove });
},
teamListRoomsOfUser({ teamId, userId }) {
// RC 3.13.0
return this.sdk.get('teams.listRoomsOfUser', { teamId, userId });
},
getTeamInfo({ teamId }) {
// RC 3.13.0
return this.sdk.get('teams.info', { teamId });
},
convertChannelToTeam({ rid, name, type }) {
const params = {
...(type === 'c'
? {
channelId: rid,
channelName: name
}
: {
roomId: rid,
roomName: name
})
};
return this.sdk.post(type === 'c' ? 'channels.convertToTeam' : 'groups.convertToTeam', params);
},
convertTeamToChannel({ teamId, selected }) {
const params = {
teamId,
...(selected.length && { roomsToRemove: selected })
};
return this.sdk.post('teams.convertToChannel', params);
},
joinRoom(roomId, joinCode, type) {
// TODO: join code
// RC 0.48.0
if (type === 'p') {
return this.methodCallWrapper('joinRoom', roomId);
}
return this.post('channels.join', { roomId, joinCode });
},
triggerBlockAction,
triggerSubmitView,
triggerCancel,
@ -933,37 +760,11 @@ const RocketChat = {
return setting;
});
},
deleteMessage(messageId, rid) {
// RC 0.48.0
return this.post('chat.delete', { msgId: messageId, roomId: rid });
},
async editMessage(message) {
const { rid, msg } = await Encryption.encryptMessage(message);
// RC 0.49.0
return this.post('chat.update', { roomId: rid, msgId: message.id, text: msg });
},
markAsUnread({ messageId }) {
return this.post('subscriptions.unread', { firstUnreadMessage: { _id: messageId } });
},
toggleStarMessage(messageId, starred) {
if (starred) {
// RC 0.59.0
return this.post('chat.unStarMessage', { messageId });
}
// RC 0.59.0
return this.post('chat.starMessage', { messageId });
},
togglePinMessage(messageId, pinned) {
if (pinned) {
// RC 0.59.0
return this.post('chat.unPinMessage', { messageId });
}
// RC 0.59.0
return this.post('chat.pinMessage', { messageId });
},
reportMessage(messageId) {
return this.post('chat.reportMessage', { messageId, description: 'Message reported by user' });
},
getRoom,
getPermalinkMessage,
getPermalinkChannel(channel) {
@ -997,31 +798,7 @@ const RocketChat = {
const name = UI_Use_Real_Name ? user.name : user.username;
return this.methodCall('stream-notify-room', `${room}/typing`, name, typing);
},
setUserPresenceAway() {
return this.methodCall('UserPresence:away');
},
setUserPresenceOnline() {
return this.methodCall('UserPresence:online');
},
setUserPreferences(userId, data) {
// RC 0.62.0
return this.sdk.post('users.setPreferences', { userId, data });
},
setUserStatus(status, message) {
// RC 1.2.0
return this.post('users.setStatus', { status, message });
},
setReaction(emoji, messageId) {
// RC 0.62.2
return this.post('chat.react', { emoji, messageId });
},
toggleFavorite,
toggleRead(read, roomId) {
if (read) {
return this.post('subscriptions.unread', { roomId });
}
return this.post('subscriptions.read', { rid: roomId });
},
async getRoomMembers({ rid, allUsers, roomType, type, filter, skip = 0, limit = 10 }) {
const serverVersion = reduxStore.getState().server.version;
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.16.0')) {
@ -1043,104 +820,7 @@ const RocketChat = {
methodCallWrapper(method, ...params) {
return sdk.methodCallWrapper(method, ...params);
},
getUserRoles() {
// RC 0.27.0
return this.methodCallWrapper('getUserRoles');
},
getRoomCounters(roomId, t) {
// RC 0.65.0
return this.sdk.get(`${this.roomTypeToApiType(t)}.counters`, { roomId });
},
getChannelInfo(roomId) {
// RC 0.48.0
return this.sdk.get('channels.info', { roomId });
},
getUserInfo,
getUserPreferences(userId) {
// RC 0.62.0
return this.sdk.get('users.getPreferences', { userId });
},
getRoomInfo(roomId) {
// RC 0.72.0
return this.sdk.get('rooms.info', { roomId });
},
getVisitorInfo(visitorId) {
// RC 2.3.0
return this.sdk.get('livechat/visitors.info', { visitorId });
},
getTeamListRoom({ teamId, count, offset, type, filter }) {
const params = {
teamId,
count,
offset,
type
};
if (filter) {
params.filter = filter;
}
// RC 3.13.0
return this.sdk.get('teams.listRooms', params);
},
closeLivechat(rid, comment) {
// RC 0.29.0
return this.methodCallWrapper('livechat:closeRoom', rid, comment, { clientAction: true });
},
editLivechat(userData, roomData) {
// RC 0.55.0
return this.methodCallWrapper('livechat:saveInfo', userData, roomData);
},
returnLivechat(rid) {
// RC 0.72.0
return this.methodCallWrapper('livechat:returnAsInquiry', rid);
},
forwardLivechat(transferData) {
// RC 0.36.0
return this.methodCallWrapper('livechat:transfer', transferData);
},
getDepartmentInfo(departmentId) {
// RC 2.2.0
return this.sdk.get(`livechat/department/${departmentId}?includeAgents=false`);
},
getDepartments() {
// RC 2.2.0
return this.sdk.get('livechat/department');
},
usersAutoComplete(selector) {
// RC 2.4.0
return this.sdk.get('users.autocomplete', { selector });
},
getRoutingConfig() {
// RC 2.0.0
return this.methodCallWrapper('livechat:getRoutingConfig');
},
getTagsList() {
// RC 2.0.0
return this.methodCallWrapper('livechat:getTagsList');
},
getAgentDepartments(uid) {
// RC 2.4.0
return this.sdk.get(`livechat/agents/${uid}/departments?enabledDepartmentsOnly=true`);
},
getCustomFields() {
// RC 2.2.0
return this.sdk.get('livechat/custom-fields');
},
getListCannedResponse({ scope = '', departmentId = '', offset = 0, count = 25, text = '' }) {
const params = {
offset,
count,
...(departmentId && { departmentId }),
...(text && { text }),
...(scope && { scope })
};
// RC 3.17.0
return this.sdk.get('canned-responses', params);
},
getUidDirectMessage(room) {
const { id: userId } = reduxStore.getState().login.user;
@ -1169,79 +849,7 @@ const RocketChat = {
isUnread = isUnread && (item.unread > 0 || item.alert === true); // either its unread count > 0 or its alert
return !isUnread;
},
isGroupChat,
toggleBlockUser(rid, blocked, block) {
if (block) {
// RC 0.49.0
return this.methodCallWrapper('blockUser', { rid, blocked });
}
// RC 0.49.0
return this.methodCallWrapper('unblockUser', { rid, blocked });
},
leaveRoom(roomId, t) {
// RC 0.48.0
return this.post(`${this.roomTypeToApiType(t)}.leave`, { roomId });
},
deleteRoom(roomId, t) {
// RC 0.49.0
return this.post(`${this.roomTypeToApiType(t)}.delete`, { roomId });
},
toggleMuteUserInRoom(rid, username, mute) {
if (mute) {
// RC 0.51.0
return this.methodCallWrapper('muteUserInRoom', { rid, username });
}
// RC 0.51.0
return this.methodCallWrapper('unmuteUserInRoom', { rid, username });
},
toggleRoomOwner({ roomId, t, userId, isOwner }) {
if (isOwner) {
// RC 0.49.4
return this.post(`${this.roomTypeToApiType(t)}.addOwner`, { roomId, userId });
}
// RC 0.49.4
return this.post(`${this.roomTypeToApiType(t)}.removeOwner`, { roomId, userId });
},
toggleRoomLeader({ roomId, t, userId, isLeader }) {
if (isLeader) {
// RC 0.58.0
return this.post(`${this.roomTypeToApiType(t)}.addLeader`, { roomId, userId });
}
// RC 0.58.0
return this.post(`${this.roomTypeToApiType(t)}.removeLeader`, { roomId, userId });
},
toggleRoomModerator({ roomId, t, userId, isModerator }) {
if (isModerator) {
// RC 0.49.4
return this.post(`${this.roomTypeToApiType(t)}.addModerator`, { roomId, userId });
}
// RC 0.49.4
return this.post(`${this.roomTypeToApiType(t)}.removeModerator`, { roomId, userId });
},
removeUserFromRoom({ roomId, t, userId }) {
// RC 0.48.0
return this.post(`${this.roomTypeToApiType(t)}.kick`, { roomId, userId });
},
ignoreUser({ rid, userId, ignore }) {
return this.sdk.get('chat.ignoreUser', { rid, userId, ignore });
},
toggleArchiveRoom(roomId, t, archive) {
if (archive) {
// RC 0.48.0
return this.post(`${this.roomTypeToApiType(t)}.archive`, { roomId });
}
// RC 0.48.0
return this.post(`${this.roomTypeToApiType(t)}.unarchive`, { roomId });
},
hideRoom(roomId, t) {
return this.post(`${this.roomTypeToApiType(t)}.close`, { roomId });
},
saveRoomSettings(rid, params) {
// RC 0.55.0
return this.methodCallWrapper('saveRoomSettings', rid, params);
},
post(...args) {
return sdk.post(...args);
},
@ -1253,28 +861,12 @@ const RocketChat = {
// RC 3.1.0
return this.post('users.2fa.sendEmailCode', { emailOrUsername: username });
},
saveUserProfile(data, customFields) {
// RC 0.62.2
return this.post('users.updateOwnBasicInfo', { data, customFields });
},
saveUserPreferences(data) {
// RC 0.62.0
return this.post('users.setPreferences', { data });
},
saveNotificationSettings(roomId, notifications) {
// RC 0.63.0
return this.post('rooms.saveNotification', { roomId, notifications });
},
addUsersToRoom(rid) {
let { users } = reduxStore.getState().selectedUsers;
users = users.map(u => u.name);
// RC 0.51.0
return this.methodCallWrapper('addUsersToRoom', { rid, users });
},
getSingleMessage(msgId) {
// RC 0.47.0
return this.sdk.get('chat.getMessage', { msgId });
},
hasRole(role) {
const shareUser = reduxStore.getState().share.user;
const loginUser = reduxStore.getState().login.user;
@ -1283,10 +875,6 @@ const RocketChat = {
return userRoles.indexOf(r => r === role) > -1;
},
getRoomRoles(roomId, type) {
// RC 0.65.0
return this.sdk.get(`${this.roomTypeToApiType(type)}.roles`, { roomId });
},
/**
* Permissions: array of permissions' roles from redux. Example: [['owner', 'admin'], ['leader']]
* Returns an array of boolean for each permission from permissions arg
@ -1318,18 +906,6 @@ const RocketChat = {
log(e);
}
},
getAvatarSuggestion() {
// RC 0.51.0
return this.methodCallWrapper('getAvatarSuggestion');
},
resetAvatar(userId) {
// RC 0.55.0
return this.post('users.resetAvatar', { userId });
},
setAvatarFromService({ data, contentType = '', service = null }) {
// RC 0.51.0
return this.methodCallWrapper('setAvatarFromService', data, contentType, service);
},
async getAllowCrashReport() {
const allowCrashReport = await AsyncStorage.getItem(CRASH_REPORT_KEY);
if (allowCrashReport === null) {
@ -1406,79 +982,7 @@ const RocketChat = {
const availableOAuth = ['facebook', 'github', 'gitlab', 'google', 'linkedin', 'meteor-developer', 'twitter', 'wordpress'];
return availableOAuth.includes(authName) ? 'oauth' : 'not_supported';
},
getUsernameSuggestion() {
// RC 0.65.0
return this.sdk.get('users.getUsernameSuggestion');
},
roomTypeToApiType(t) {
const types = {
c: 'channels',
d: 'im',
p: 'groups',
l: 'channels'
};
return types[t];
},
getFiles(roomId, type, offset) {
// RC 0.59.0
return this.sdk.get(`${this.roomTypeToApiType(type)}.files`, {
roomId,
offset,
sort: { uploadedAt: -1 }
});
},
getMessages(roomId, type, query, offset) {
// RC 0.59.0
return this.sdk.get(`${this.roomTypeToApiType(type)}.messages`, {
roomId,
query,
offset,
sort: { ts: -1 }
});
},
getReadReceipts(messageId) {
return this.sdk.get('chat.getMessageReadReceipts', {
messageId
});
},
searchMessages(roomId, searchText, count, offset) {
// RC 0.60.0
return this.sdk.get('chat.search', {
roomId,
searchText,
count,
offset
});
},
toggleFollowMessage(mid, follow) {
// RC 1.0
if (follow) {
return this.post('chat.followMessage', { mid });
}
return this.post('chat.unfollowMessage', { mid });
},
getThreadsList({ rid, count, offset, text }) {
const params = {
rid,
count,
offset,
sort: { ts: -1 }
};
if (text) {
params.text = text;
}
// RC 1.0
return this.sdk.get('chat.getThreadsList', params);
},
getSyncThreadsList({ rid, updatedSince }) {
// RC 1.0
return this.sdk.get('chat.syncThreadsList', {
rid,
updatedSince
});
},
roomTypeToApiType,
readThreads(tmid) {
const serverVersion = reduxStore.getState().server.version;
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.4.0')) {
@ -1487,35 +991,6 @@ const RocketChat = {
}
return Promise.resolve();
},
runSlashCommand(command, roomId, params, triggerId, tmid) {
// RC 0.60.2
return this.post('commands.run', {
command,
roomId,
params,
triggerId,
tmid
});
},
getCommandPreview(command, roomId, params) {
// RC 0.65.0
return this.sdk.get('commands.preview', {
command,
roomId,
params
});
},
executeCommandPreview(command, params, roomId, previewItem, triggerId, tmid) {
// RC 0.65.0
return this.post('commands.preview', {
command,
params,
roomId,
previewItem,
triggerId,
tmid
});
},
_setUser(ddpMessage) {
this.activeUsers = this.activeUsers || {};
const { user } = reduxStore.getState().login;
@ -1550,15 +1025,6 @@ const RocketChat = {
},
getUserPresence,
subscribeUsersPresence,
getDirectory({ query, count, offset, sort }) {
// RC 1.0
return this.sdk.get('directory', {
query,
count,
offset,
sort
});
},
canAutoTranslate() {
try {
const { AutoTranslate_Enabled } = reduxStore.getState().settings;
@ -1573,15 +1039,6 @@ const RocketChat = {
return false;
}
},
saveAutoTranslate({ rid, field, value, options }) {
return this.methodCallWrapper('autoTranslate.saveSettings', rid, field, value, options);
},
getSupportedLanguagesAutoTranslate() {
return this.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en');
},
translateMessage(message, targetLanguage) {
return this.methodCallWrapper('autoTranslate.translateMessage', message, targetLanguage);
},
getSenderName(sender) {
const { UI_Use_Real_Name: useRealName } = reduxStore.getState().settings;
return useRealName ? sender.name : sender.username;
@ -1606,19 +1063,6 @@ const RocketChat = {
return room.uids?.length + room.usernames?.join();
}
return room.prid ? room.fname : room.name;
},
findOrCreateInvite({ rid, days, maxUses }) {
// RC 2.4.0
return this.post('findOrCreateInvite', { rid, days, maxUses });
},
validateInviteToken(token) {
// RC 2.4.0
return this.post('validateInviteToken', { token });
},
useInviteToken(token) {
// RC 2.4.0
return this.post('useInviteToken', { token });
}
};

View File

@ -0,0 +1,804 @@
import sdk from './sdk';
import { TEAM_TYPE } from '../../../definitions/ITeam';
import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType';
export const createChannel = ({
name,
users,
type,
readOnly,
broadcast,
encrypted,
teamId
}: {
name: string;
users: string[];
type: boolean;
readOnly: boolean;
broadcast: boolean;
encrypted: boolean;
teamId: string;
}): any => {
const params = {
name,
members: users,
readOnly,
extraData: {
broadcast,
encrypted,
...(teamId && { teamId })
}
};
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(type ? 'groups.create' : 'channels.create', params);
};
export const e2eSetUserPublicAndPrivateKeys = (public_key: string, private_key: string): any =>
// RC 2.2.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('e2e.setUserPublicAndPrivateKeys', { public_key, private_key });
export const e2eRequestSubscriptionKeys = (): any =>
// RC 0.72.0
sdk.methodCallWrapper('e2e.requestSubscriptionKeys');
export const e2eGetUsersOfRoomWithoutKey = (rid: string): any =>
// RC 0.70.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('e2e.getUsersOfRoomWithoutKey', { rid });
export const e2eSetRoomKeyID = (rid: string, keyID: string): any =>
// RC 0.70.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('e2e.setRoomKeyID', { rid, keyID });
export const e2eUpdateGroupKey = (uid: string, rid: string, key: string): any =>
// RC 0.70.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('e2e.updateGroupKey', { uid, rid, key });
export const e2eRequestRoomKey = (rid: string, e2eKeyId: string) =>
// RC 0.70.0
sdk.methodCallWrapper('stream-notify-room-users', `${rid}/e2ekeyRequest`, rid, e2eKeyId);
export const updateJitsiTimeout = (roomId: string): any =>
// RC 0.74.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('video-conference/jitsi.update-timeout', { roomId });
export const register = (credentials: any): any =>
// RC 0.50.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.register', credentials);
export const forgotPassword = (email: string): any =>
// RC 0.64.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.forgotPassword', { email });
export const sendConfirmationEmail = (email: string) => sdk.methodCallWrapper('sendConfirmationEmail', email);
export const spotlight = (search: string, usernames: string, type: { users: boolean; rooms: boolean }) =>
// RC 0.51.0
sdk.methodCallWrapper('spotlight', search, usernames, type);
export const createDirectMessage = (username: string) =>
// RC 0.59.0
sdk.post('im.create', { username });
export const createDiscussion = ({
prid,
pmid,
t_name,
reply,
users,
encrypted
}: {
prid: string;
pmid?: string;
t_name: string;
reply?: string;
users?: string[];
encrypted?: boolean;
}) =>
// RC 1.0.0
sdk.post('rooms.createDiscussion', {
prid,
pmid,
t_name,
reply,
users,
encrypted
});
export const getDiscussions = ({
roomId,
offset,
count,
text
}: {
roomId: string | undefined;
text?: string | undefined;
offset: number;
count: number;
}) => {
const params = {
roomId,
offset,
count,
...(text && { text })
};
// RC 2.4.0
return sdk.get('chat.getDiscussions', params);
};
export const createTeam = ({
name,
users,
type,
readOnly,
broadcast,
encrypted
}: {
name: string;
users: string[];
type: boolean;
readOnly: boolean;
broadcast: boolean;
encrypted: boolean;
}): any => {
const params = {
name,
users,
type: type ? TEAM_TYPE.PRIVATE : TEAM_TYPE.PUBLIC,
room: {
readOnly,
extraData: {
broadcast,
encrypted
}
}
};
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('teams.create', params);
};
export const addRoomsToTeam = ({ teamId, rooms }: { teamId: string; rooms: string[] }): any =>
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('teams.addRooms', { teamId, rooms });
export const removeTeamRoom = ({ roomId, teamId }: { roomId: string; teamId: string }) =>
// RC 3.13.0
sdk.post('teams.removeRoom', { roomId, teamId });
export const leaveTeam = ({ teamId, rooms }: { teamId: string; rooms: string[] }): any =>
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('teams.leave', {
teamId,
// RC 4.2.0
...(rooms?.length && { rooms })
});
export const removeTeamMember = ({ teamId, userId, rooms }: { teamId: string; userId: string; rooms: string[] }): any =>
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('teams.removeMember', {
teamId,
userId,
// RC 4.2.0
...(rooms?.length && { rooms })
});
export const updateTeamRoom = ({ roomId, isDefault }: { roomId: string; isDefault: boolean }): any =>
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('teams.updateRoom', { roomId, isDefault });
export const deleteTeam = ({ teamId, roomsToRemove }: { teamId: string; roomsToRemove: string[] }): any =>
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('teams.delete', { teamId, roomsToRemove });
export const teamListRoomsOfUser = ({ teamId, userId }: { teamId: string; userId: string }): any =>
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('teams.listRoomsOfUser', { teamId, userId });
export const getTeamInfo = ({ teamId }: { teamId: string }): any =>
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('teams.info', { teamId });
export const convertChannelToTeam = ({ rid, name, type }: { rid: string; name: string; type: 'c' | 'p' }): any => {
const params = {
...(type === 'c'
? {
channelId: rid,
channelName: name
}
: {
roomId: rid,
roomName: name
})
};
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(type === 'c' ? 'channels.convertToTeam' : 'groups.convertToTeam', params);
};
export const convertTeamToChannel = ({ teamId, selected }: { teamId: string; selected: string[] }): any => {
const params = {
teamId,
...(selected.length && { roomsToRemove: selected })
};
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('teams.convertToChannel', params);
};
export const joinRoom = (roomId: string, joinCode: string, type: 'c' | 'p'): any => {
// TODO: join code
// RC 0.48.0
if (type === 'p') {
return sdk.methodCallWrapper('joinRoom', roomId);
}
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('channels.join', { roomId, joinCode });
};
export const deleteMessage = (messageId: string, rid: string): any =>
// RC 0.48.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('chat.delete', { msgId: messageId, roomId: rid });
export const markAsUnread = ({ messageId }: { messageId: string }): any =>
// RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('subscriptions.unread', { firstUnreadMessage: { _id: messageId } });
export const toggleStarMessage = (messageId: string, starred: boolean): any => {
if (starred) {
// RC 0.59.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('chat.unStarMessage', { messageId });
}
// RC 0.59.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('chat.starMessage', { messageId });
};
export const togglePinMessage = (messageId: string, pinned: boolean): any => {
if (pinned) {
// RC 0.59.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('chat.unPinMessage', { messageId });
}
// RC 0.59.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('chat.pinMessage', { messageId });
};
export const reportMessage = (messageId: string): any =>
// RC 0.64.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('chat.reportMessage', { messageId, description: 'Message reported by user' });
export const setUserPreferences = (userId: string, data: any): any =>
// RC 0.62.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.setPreferences', { userId, data });
export const setUserStatus = (status?: string, message?: string): any =>
// RC 1.2.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.setStatus', { status, message });
export const setReaction = (emoji: string, messageId: string): any =>
// RC 0.62.2
// TODO: missing definitions from server
// @ts-ignore
sdk.post('chat.react', { emoji, messageId });
export const toggleRead = (read: boolean, roomId: string): any => {
if (read) {
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('subscriptions.unread', { roomId });
}
// TODO: missing definitions from server
// @ts-ignore
return sdk.post('subscriptions.read', { rid: roomId });
};
export const getUserRoles = () =>
// RC 0.27.0
sdk.methodCallWrapper('getUserRoles');
export const getRoomCounters = (roomId: string, t: RoomTypes): any =>
// RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get(`${roomTypeToApiType(t)}.counters`, { roomId });
export const getChannelInfo = (roomId: string): any =>
// RC 0.48.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('channels.info', { roomId });
export const getUserPreferences = (userId: string): any =>
// RC 0.62.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('users.getPreferences', { userId });
export const getRoomInfo = (roomId: string) =>
// RC 0.72.0
sdk.get('rooms.info', { roomId });
export const getVisitorInfo = (visitorId: string) =>
// RC 2.3.0
sdk.get('livechat/visitors.info', { visitorId });
export const setUserPresenceAway = () => sdk.methodCall('UserPresence:away');
export const setUserPresenceOnline = () => sdk.methodCall('UserPresence:online');
export const getTeamListRoom = ({
teamId,
count,
offset,
type,
filter
}: {
teamId: string;
count: number;
offset: number;
type: string;
filter: any;
}): any => {
const params: any = {
teamId,
count,
offset,
type
};
if (filter) {
params.filter = filter;
}
// RC 3.13.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.get('teams.listRooms', params);
};
export const closeLivechat = (rid: string, comment: string) =>
// RC 0.29.0
sdk.methodCallWrapper('livechat:closeRoom', rid, comment, { clientAction: true });
export const editLivechat = (userData: any, roomData: any) =>
// RC 0.55.0
sdk.methodCallWrapper('livechat:saveInfo', userData, roomData);
export const returnLivechat = (rid: string) =>
// RC 0.72.0
sdk.methodCallWrapper('livechat:returnAsInquiry', rid);
export const forwardLivechat = (transferData: any) =>
// RC 0.36.0
sdk.methodCallWrapper('livechat:transfer', transferData);
export const getDepartmentInfo = (departmentId: string): any =>
// RC 2.2.0
sdk.get(`livechat/department/${departmentId}?includeAgents=false`);
export const getDepartments = () =>
// RC 2.2.0
sdk.get('livechat/department');
export const usersAutoComplete = (selector: any) =>
// RC 2.4.0
sdk.get('users.autocomplete', { selector });
export const getRoutingConfig = () =>
// RC 2.0.0
sdk.methodCallWrapper('livechat:getRoutingConfig');
export const getTagsList = () =>
// RC 2.0.0
sdk.methodCallWrapper('livechat:getTagsList');
export const getAgentDepartments = (uid: string): any =>
// RC 2.4.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get(`livechat/agents/${uid}/departments?enabledDepartmentsOnly=true`);
export const getCustomFields = () =>
// RC 2.2.0
sdk.get('livechat/custom-fields');
export const getListCannedResponse = ({ scope = '', departmentId = '', offset = 0, count = 25, text = '' }): any => {
const params = {
offset,
count,
...(departmentId && { departmentId }),
...(text && { text }),
...(scope && { scope })
};
// RC 3.17.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.get('canned-responses', params);
};
export const toggleBlockUser = (rid: string, blocked: string, block: boolean) => {
if (block) {
// RC 0.49.0
return sdk.methodCallWrapper('blockUser', { rid, blocked });
}
// RC 0.49.0
return sdk.methodCallWrapper('unblockUser', { rid, blocked });
};
export const leaveRoom = (roomId: string, t: RoomTypes): any =>
// RC 0.48.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post(`${roomTypeToApiType(t)}.leave`, { roomId });
export const deleteRoom = (roomId: string, t: RoomTypes): any =>
// RC 0.49.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post(`${roomTypeToApiType(t)}.delete`, { roomId });
export const toggleMuteUserInRoom = (rid: string, username: string, mute: boolean) => {
if (mute) {
// RC 0.51.0
return sdk.methodCallWrapper('muteUserInRoom', { rid, username });
}
// RC 0.51.0
return sdk.methodCallWrapper('unmuteUserInRoom', { rid, username });
};
export const toggleRoomOwner = ({
roomId,
t,
userId,
isOwner
}: {
roomId: string;
t: RoomTypes;
userId: string;
isOwner: boolean;
}): any => {
if (isOwner) {
// RC 0.49.4
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.addOwner`, { roomId, userId });
}
// RC 0.49.4
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.removeOwner`, { roomId, userId });
};
export const toggleRoomLeader = ({
roomId,
t,
userId,
isLeader
}: {
roomId: string;
t: RoomTypes;
userId: string;
isLeader: boolean;
}): any => {
if (isLeader) {
// RC 0.58.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.addLeader`, { roomId, userId });
}
// RC 0.58.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.removeLeader`, { roomId, userId });
};
export const toggleRoomModerator = ({
roomId,
t,
userId,
isModerator
}: {
roomId: string;
t: RoomTypes;
userId: string;
isModerator: boolean;
}): any => {
if (isModerator) {
// RC 0.49.4
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.addModerator`, { roomId, userId });
}
// RC 0.49.4
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.removeModerator`, { roomId, userId });
};
export const removeUserFromRoom = ({ roomId, t, userId }: { roomId: string; t: RoomTypes; userId: string }): any =>
// RC 0.48.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post(`${roomTypeToApiType(t)}.kick`, { roomId, userId });
export const ignoreUser = ({ rid, userId, ignore }: { rid: string; userId: string; ignore: boolean }): any =>
// RC 0.64.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('chat.ignoreUser', { rid, userId, ignore });
export const toggleArchiveRoom = (roomId: string, t: RoomTypes, archive: boolean): any => {
if (archive) {
// RC 0.48.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.archive`, { roomId });
}
// RC 0.48.0
// TODO: missing definitions from server
// @ts-ignore
return sdk.post(`${roomTypeToApiType(t)}.unarchive`, { roomId });
};
export const hideRoom = (roomId: string, t: RoomTypes): any =>
// RC 0.48.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post(`${roomTypeToApiType(t)}.close`, { roomId });
export const saveRoomSettings = (rid: string, params: any) =>
// RC 0.55.0
sdk.methodCallWrapper('saveRoomSettings', rid, params);
export const saveUserProfile = (data: any, customFields?: any): any =>
// RC 0.62.2
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.updateOwnBasicInfo', { data, customFields });
export const saveUserPreferences = (data: any): any =>
// RC 0.62.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.setPreferences', { data });
export const saveNotificationSettings = (roomId: string, notifications: any): any =>
// RC 0.63.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('rooms.saveNotification', { roomId, notifications });
export const getSingleMessage = (msgId: string) =>
// RC 0.47.0
sdk.get('chat.getMessage', { msgId });
export const getRoomRoles = (roomId: string, type: RoomTypes): any =>
// RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get(`${roomTypeToApiType(type)}.roles`, { roomId });
export const getAvatarSuggestion = () =>
// RC 0.51.0
sdk.methodCallWrapper('getAvatarSuggestion');
export const resetAvatar = (userId: string): any =>
// RC 0.55.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('users.resetAvatar', { userId });
export const setAvatarFromService = ({
data,
contentType = '',
service = null
}: {
data: any;
contentType?: string;
service?: string | null;
}) =>
// RC 0.51.0
sdk.methodCallWrapper('setAvatarFromService', data, contentType, service);
export const getUsernameSuggestion = (): any =>
// RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('users.getUsernameSuggestion');
export const getFiles = (roomId: string, type: RoomTypes, offset: number): any =>
// RC 0.59.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get(`${roomTypeToApiType(type)}.files`, {
roomId,
offset,
sort: { uploadedAt: -1 }
});
export const getMessages = (roomId: string, type: RoomTypes, query: any, offset: number): any =>
// RC 0.59.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get(`${roomTypeToApiType(type)}.messages`, {
roomId,
query,
offset,
sort: { ts: -1 }
});
export const getReadReceipts = (messageId: string): any =>
// RC 0.63.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('chat.getMessageReadReceipts', {
messageId
});
export const searchMessages = (roomId: string, searchText: string, count: number, offset: number): any =>
// RC 0.60.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('chat.search', {
roomId,
searchText,
count,
offset
});
export const toggleFollowMessage = (mid: string, follow: boolean) => {
// RC 1.0
if (follow) {
return sdk.post('chat.followMessage', { mid });
}
return sdk.post('chat.unfollowMessage', { mid });
};
export const getThreadsList = ({ rid, count, offset, text }: { rid: string; count: number; offset: number; text?: string }) => {
const params: any = {
rid,
count,
offset,
sort: { ts: -1 }
};
if (text) {
params.text = text;
}
// RC 1.0
return sdk.get('chat.getThreadsList', params);
};
export const getSyncThreadsList = ({ rid, updatedSince }: { rid: string; updatedSince: string }): any =>
// RC 1.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('chat.syncThreadsList', {
rid,
updatedSince
});
export const runSlashCommand = (command: string, roomId: string, params: any, triggerId?: string, tmid?: string): any =>
// RC 0.60.2
// TODO: missing definitions from server
// @ts-ignore
sdk.post('commands.run', {
command,
roomId,
params,
triggerId,
tmid
});
export const getCommandPreview = (command: string, roomId: string, params: any): any =>
// RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('commands.preview', {
command,
roomId,
params
});
export const executeCommandPreview = (
command: string,
params: any,
roomId: string,
previewItem: any,
triggerId: string,
tmid?: string
): any =>
// RC 0.65.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('commands.preview', {
command,
params,
roomId,
previewItem,
triggerId,
tmid
});
export const getDirectory = ({ query, count, offset, sort }: { query: any; count: number; offset: number; sort: any }): any =>
// RC 1.0
// TODO: missing definitions from server
// @ts-ignore
sdk.get('directory', {
query,
count,
offset,
sort
});
export const saveAutoTranslate = ({ rid, field, value, options }: { rid: string; field: string; value: any; options: any }) =>
sdk.methodCallWrapper('autoTranslate.saveSettings', rid, field, value, options);
export const getSupportedLanguagesAutoTranslate = () => sdk.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en');
export const translateMessage = (message: any, targetLanguage: string) =>
sdk.methodCallWrapper('autoTranslate.translateMessage', message, targetLanguage);
export const findOrCreateInvite = ({ rid, days, maxUses }: { rid: string; days: number; maxUses: number }): any =>
// RC 2.4.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('findOrCreateInvite', { rid, days, maxUses });
export const validateInviteToken = (token: string): any =>
// RC 2.4.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('validateInviteToken', { token });
export const useInviteToken = (token: string): any =>
// RC 2.4.0
// TODO: missing definitions from server
// @ts-ignore
sdk.post('useInviteToken', { token });

View File

@ -5,14 +5,7 @@ import isEmpty from 'lodash/isEmpty';
import { twoFactor } from '../../../utils/twoFactor';
import { useSsl } from '../../../utils/url';
import reduxStore from '../../createStore';
import {
Serialized,
OperationResult,
MatchPathPattern,
OperationParams,
PathFor,
ResultFor
} from '../../../definitions/rest/helpers';
import { Serialized, MatchPathPattern, OperationParams, PathFor, ResultFor } from '../../../definitions/rest/helpers';
class Sdk {
private sdk: typeof Rocketchat;
@ -53,7 +46,7 @@ class Sdk {
>
? void
: Serialized<OperationParams<'GET', MatchPathPattern<TPath>>>
): Promise<Serialized<OperationResult<'GET', MatchPathPattern<TPath>>>> {
): Promise<Serialized<ResultFor<'GET', MatchPathPattern<TPath>>>> {
return this.sdk.get(endpoint, params);
}

View File

@ -50,6 +50,7 @@ export const goRoom = async ({
// if user is using the search we need first to join/create room
try {
const { username } = item;
// @ts-ignore
const result = await RocketChat.createDirectMessage(username);
if (result.success) {
return navigate({

View File

@ -42,12 +42,12 @@ interface IAddExistingChannelViewProps {
const QUERY_SIZE = 50;
class AddExistingChannelView extends React.Component<IAddExistingChannelViewProps, IAddExistingChannelViewState> {
private teamId?: string;
private teamId: string;
constructor(props: IAddExistingChannelViewProps) {
super(props);
this.query();
this.teamId = props.route?.params?.teamId;
this.teamId = props.route?.params?.teamId ?? '';
this.state = {
search: [],
channels: [],

View File

@ -30,14 +30,14 @@ class AutoTranslateView extends React.Component<IAutoTranslateViewProps, any> {
});
private mounted: boolean;
private rid: string | undefined;
private rid: string;
private roomObservable: any;
private subscription: any;
constructor(props: IAutoTranslateViewProps) {
super(props);
this.mounted = false;
this.rid = props.route.params?.rid;
this.rid = props.route.params?.rid ?? '';
const room = props.route.params?.room;
if (room && room.observe) {

View File

@ -91,7 +91,7 @@ const CannedResponsesListView = ({ navigation, route }: ICannedResponsesListView
const getDepartments = debounce(async () => {
try {
const res = await RocketChat.getDepartments();
const res: any = await RocketChat.getDepartments();
if (res.success) {
setDepartments([...fixedScopes, ...res.departments]);
}

View File

@ -157,7 +157,7 @@ class DirectoryView extends React.Component<IDirectoryViewProps, any> {
this.goRoom({ rid: result.room._id, name: item.username, t: 'd' });
}
} else if (['p', 'c'].includes(item.t) && !item.teamMain) {
const { room } = await RocketChat.getRoomInfo(item._id);
const { room }: any = await RocketChat.getRoomInfo(item._id);
this.goRoom({
rid: item._id,
name: item.name,

View File

@ -63,7 +63,7 @@ const DiscussionsView = ({ navigation, route }: IDiscussionsViewProps): JSX.Elem
setLoading(true);
try {
const result = await RocketChat.getDiscussions({
const result: any = await RocketChat.getDiscussions({
roomId: rid,
offset: isSearching ? search.length : discussions.length,
count: API_FETCH_COUNT,

View File

@ -65,7 +65,7 @@ const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }: IForward
const getDepartments = async () => {
try {
const result = await RocketChat.getDepartments();
const result: any = await RocketChat.getDepartments();
if (result.success) {
setDepartments(
result.departments.map((department: ILivechatDepartment) => ({ label: department.name, value: department._id }))
@ -80,7 +80,7 @@ const ForwardLivechatView = ({ forwardRoom, navigation, route, theme }: IForward
try {
const { servedBy: { _id: agentId } = {} } = room;
const _id = agentId && { $ne: agentId };
const result = await RocketChat.usersAutoComplete({
const result: any = await RocketChat.usersAutoComplete({
conditions: { _id, status: { $ne: 'offline' }, statusLivechat: 'available' },
term
});

View File

@ -113,7 +113,7 @@ const LivechatEditView = ({
const visitor = route.params?.roomUser ?? {};
const getCustomFields = async () => {
const result = await RocketChat.getCustomFields();
const result: any = await RocketChat.getCustomFields();
if (result.success && result.customFields?.length) {
const visitorCustomFields = result.customFields
.filter((field: IField) => field.visibility !== 'hidden' && field.scope === 'visitor')

View File

@ -68,7 +68,7 @@ interface IMessageItem {
name?: string;
description?: string;
msg?: string;
starred: string;
starred: boolean;
pinned: boolean;
}
@ -193,6 +193,7 @@ 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 };
},
@ -222,6 +223,7 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
name: I18n.t('Mentions'),
fetchFunc: () => {
const { messages } = this.state;
// @ts-ignore
return RocketChat.getMessages(this.rid, this.t, { 'mentions._id': { $in: [user.id] } }, messages.length);
},
noDataMsg: I18n.t('No_mentioned_messages'),
@ -233,6 +235,7 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
name: I18n.t('Starred'),
fetchFunc: () => {
const { messages } = this.state;
// @ts-ignore
return RocketChat.getMessages(this.rid, this.t, { 'starred._id': { $in: [user.id] } }, messages.length);
},
noDataMsg: I18n.t('No_starred_messages'),
@ -252,6 +255,7 @@ class MessagesView extends React.Component<IMessagesViewProps, any> {
name: I18n.t('Pinned'),
fetchFunc: () => {
const { messages } = this.state;
// @ts-ignore
return RocketChat.getMessages(this.rid, this.t, { pinned: true }, messages.length);
},
noDataMsg: I18n.t('No_pinned_messages'),

View File

@ -38,14 +38,14 @@ class NotificationPreferencesView extends React.Component<INotificationPreferenc
});
private mounted: boolean;
private rid: string | undefined;
private rid: string;
private roomObservable?: Observable<Model>;
private subscription?: Subscription;
constructor(props: INotificationPreferencesView) {
super(props);
this.mounted = false;
this.rid = props.route.params?.rid;
this.rid = props.route.params?.rid ?? '';
const room = props.route.params?.room;
this.state = {
room: room || {}

View File

@ -345,7 +345,7 @@ class TeamChannelsView extends React.Component<ITeamChannelsViewProps, ITeamChan
logEvent(events.TC_GO_ROOM);
const { navigation, isMasterDetail } = this.props;
try {
const { room } = await RocketChat.getRoomInfo(item._id);
const { room } = (await RocketChat.getRoomInfo(item._id)) as any;
const params = {
rid: item._id,
name: RocketChat.getRoomTitle(room),

View File

@ -43,13 +43,13 @@ import { SubscriptionType, TSubscriptionModel } from '../../definitions/ISubscri
const API_FETCH_COUNT = 50;
interface IResultFetch {
threads: IThreadResult[];
count: number;
offset: number;
total: number;
success: boolean;
}
// interface IResultFetch {
// threads: IThreadResult[];
// count: number;
// offset: number;
// total: number;
// success: boolean;
// }
interface IThreadMessagesViewState {
loading: boolean;
@ -339,7 +339,7 @@ class ThreadMessagesView extends React.Component<IThreadMessagesViewProps, IThre
this.setState({ loading: true });
try {
const result: IResultFetch = await RocketChat.getThreadsList({
const result: any = await RocketChat.getThreadsList({
rid: this.rid,
count: API_FETCH_COUNT,
offset: messages.length,