2022-03-14 15:55:32 +00:00
|
|
|
import {
|
2023-09-05 12:20:06 +00:00
|
|
|
IAvatarSuggestion,
|
2022-03-14 15:55:32 +00:00
|
|
|
IMessage,
|
2022-03-15 19:53:24 +00:00
|
|
|
INotificationPreferences,
|
|
|
|
IPreviewItem,
|
2023-09-05 12:20:06 +00:00
|
|
|
IProfileParams,
|
2022-03-15 14:41:23 +00:00
|
|
|
IRoom,
|
2022-03-15 19:53:24 +00:00
|
|
|
IRoomNotifications,
|
2023-09-05 12:20:06 +00:00
|
|
|
IServerRoom,
|
2022-05-07 02:11:07 +00:00
|
|
|
IUser,
|
2023-08-01 14:45:56 +00:00
|
|
|
RoomType,
|
2023-09-05 12:20:06 +00:00
|
|
|
SubscriptionType
|
2022-04-07 16:53:07 +00:00
|
|
|
} from '../../definitions';
|
2023-09-05 12:20:06 +00:00
|
|
|
import { TParams } from '../../definitions/ILivechatEditView';
|
|
|
|
import { ILivechatTag } from '../../definitions/ILivechatTag';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { ISpotlight } from '../../definitions/ISpotlight';
|
|
|
|
import { TEAM_TYPE } from '../../definitions/ITeam';
|
2023-09-05 12:20:06 +00:00
|
|
|
import { OperationParams, ResultFor } from '../../definitions/rest/helpers';
|
|
|
|
import { SubscriptionsEndpoints } from '../../definitions/rest/v1/subscriptions';
|
2022-04-07 16:53:07 +00:00
|
|
|
import { Encryption } from '../encryption';
|
2022-05-13 14:52:37 +00:00
|
|
|
import { RoomTypes, roomTypeToApiType, unsubscribeRooms } from '../methods';
|
2022-06-06 14:17:51 +00:00
|
|
|
import { compareServerVersion, getBundleId, isIOS } from '../methods/helpers';
|
2023-09-05 12:20:06 +00:00
|
|
|
import { getDeviceToken } from '../notifications';
|
|
|
|
import { store as reduxStore } from '../store/auxStore';
|
|
|
|
import sdk from './sdk';
|
2022-02-15 18:50:55 +00:00
|
|
|
|
|
|
|
export const createChannel = ({
|
|
|
|
name,
|
|
|
|
users,
|
|
|
|
type,
|
|
|
|
readOnly,
|
|
|
|
broadcast,
|
|
|
|
encrypted,
|
|
|
|
teamId
|
|
|
|
}: {
|
|
|
|
name: string;
|
|
|
|
users: string[];
|
|
|
|
type: boolean;
|
|
|
|
readOnly: boolean;
|
|
|
|
broadcast: boolean;
|
|
|
|
encrypted: boolean;
|
|
|
|
teamId: string;
|
2022-03-02 19:40:27 +00:00
|
|
|
}) => {
|
2022-02-15 18:50:55 +00:00
|
|
|
const params = {
|
|
|
|
name,
|
|
|
|
members: users,
|
|
|
|
readOnly,
|
|
|
|
extraData: {
|
|
|
|
broadcast,
|
|
|
|
encrypted,
|
|
|
|
...(teamId && { teamId })
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return sdk.post(type ? 'groups.create' : 'channels.create', params);
|
|
|
|
};
|
|
|
|
|
2022-02-24 21:59:57 +00:00
|
|
|
export const e2eSetUserPublicAndPrivateKeys = (public_key: string, private_key: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 2.2.0
|
|
|
|
sdk.post('e2e.setUserPublicAndPrivateKeys', { public_key, private_key });
|
|
|
|
|
2022-03-04 02:12:36 +00:00
|
|
|
export const e2eRequestSubscriptionKeys = (): Promise<boolean> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.72.0
|
|
|
|
sdk.methodCallWrapper('e2e.requestSubscriptionKeys');
|
|
|
|
|
2022-03-02 19:53:41 +00:00
|
|
|
export const e2eGetUsersOfRoomWithoutKey = (rid: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.70.0
|
|
|
|
sdk.get('e2e.getUsersOfRoomWithoutKey', { rid });
|
|
|
|
|
2022-03-04 13:51:39 +00:00
|
|
|
export const e2eSetRoomKeyID = (rid: string, keyID: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.70.0
|
|
|
|
sdk.post('e2e.setRoomKeyID', { rid, keyID });
|
|
|
|
|
|
|
|
export const e2eUpdateGroupKey = (uid: string, rid: string, key: string): any =>
|
|
|
|
// RC 0.70.0
|
|
|
|
sdk.post('e2e.updateGroupKey', { uid, rid, key });
|
|
|
|
|
2022-03-08 12:52:16 +00:00
|
|
|
export const e2eRequestRoomKey = (rid: string, e2eKeyId: string): Promise<{ message: { msg?: string }; success: boolean }> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.70.0
|
|
|
|
sdk.methodCallWrapper('stream-notify-room-users', `${rid}/e2ekeyRequest`, rid, e2eKeyId);
|
|
|
|
|
2023-01-12 13:32:33 +00:00
|
|
|
export const e2eAcceptSuggestedGroupKey = (rid: string): Promise<{ success: boolean }> =>
|
|
|
|
// RC 5.5
|
|
|
|
sdk.post('e2e.acceptSuggestedGroupKey', { rid });
|
|
|
|
|
|
|
|
export const e2eRejectSuggestedGroupKey = (rid: string): Promise<{ success: boolean }> =>
|
|
|
|
// RC 5.5
|
|
|
|
sdk.post('e2e.rejectSuggestedGroupKey', { rid });
|
|
|
|
|
2022-03-05 02:29:12 +00:00
|
|
|
export const updateJitsiTimeout = (roomId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.74.0
|
|
|
|
sdk.post('video-conference/jitsi.update-timeout', { roomId });
|
|
|
|
|
2022-03-02 20:08:56 +00:00
|
|
|
export const register = (credentials: { name: string; email: string; pass: string; username: string }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.50.0
|
|
|
|
sdk.post('users.register', credentials);
|
|
|
|
|
2022-03-04 14:18:06 +00:00
|
|
|
export const forgotPassword = (email: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.64.0
|
|
|
|
sdk.post('users.forgotPassword', { email });
|
|
|
|
|
2022-03-02 19:19:34 +00:00
|
|
|
export const sendConfirmationEmail = (email: string): Promise<{ message: string; success: boolean }> =>
|
|
|
|
sdk.methodCallWrapper('sendConfirmationEmail', email);
|
2022-02-15 18:50:55 +00:00
|
|
|
|
2022-10-31 16:43:47 +00:00
|
|
|
export const spotlight = (
|
|
|
|
search: string,
|
|
|
|
usernames: string[],
|
|
|
|
type: { users: boolean; rooms: boolean },
|
|
|
|
rid?: string
|
|
|
|
): Promise<ISpotlight> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.51.0
|
2022-10-31 16:43:47 +00:00
|
|
|
rid
|
|
|
|
? sdk.methodCallWrapper('spotlight', search, usernames, type, rid)
|
|
|
|
: sdk.methodCallWrapper('spotlight', search, usernames, type);
|
2022-02-15 18:50:55 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}: {
|
2022-03-04 00:23:11 +00:00
|
|
|
roomId: string;
|
2022-02-15 18:50:55 +00:00
|
|
|
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;
|
2022-03-02 20:17:42 +00:00
|
|
|
}) => {
|
2022-02-15 18:50:55 +00:00
|
|
|
const params = {
|
|
|
|
name,
|
2022-10-18 11:39:06 +00:00
|
|
|
members: users,
|
2022-02-15 18:50:55 +00:00
|
|
|
type: type ? TEAM_TYPE.PRIVATE : TEAM_TYPE.PUBLIC,
|
|
|
|
room: {
|
|
|
|
readOnly,
|
|
|
|
extraData: {
|
|
|
|
broadcast,
|
|
|
|
encrypted
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// RC 3.13.0
|
|
|
|
return sdk.post('teams.create', params);
|
|
|
|
};
|
2022-03-02 20:28:58 +00:00
|
|
|
export const addRoomsToTeam = ({ teamId, rooms }: { teamId: string; rooms: string[] }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 3.13.0
|
|
|
|
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 })
|
|
|
|
});
|
|
|
|
|
2022-03-02 20:39:04 +00:00
|
|
|
export const removeTeamMember = ({ teamId, userId, rooms }: { teamId: string; userId: string; rooms: string[] }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 3.13.0
|
|
|
|
sdk.post('teams.removeMember', {
|
|
|
|
teamId,
|
|
|
|
userId,
|
|
|
|
// RC 4.2.0
|
|
|
|
...(rooms?.length && { rooms })
|
|
|
|
});
|
|
|
|
|
2022-03-03 02:22:59 +00:00
|
|
|
export const updateTeamRoom = ({ roomId, isDefault }: { roomId: string; isDefault: boolean }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 3.13.0
|
|
|
|
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 });
|
|
|
|
|
2022-03-03 04:58:14 +00:00
|
|
|
export const teamListRoomsOfUser = ({ teamId, userId }: { teamId: string; userId: string }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 3.13.0
|
|
|
|
sdk.get('teams.listRoomsOfUser', { teamId, userId });
|
|
|
|
|
2022-03-02 17:44:42 +00:00
|
|
|
export const convertChannelToTeam = ({ rid, name, type }: { rid: string; name: string; type: 'c' | 'p' }) => {
|
2023-06-12 14:17:43 +00:00
|
|
|
const serverVersion = reduxStore.getState().server.version;
|
|
|
|
let params;
|
|
|
|
if (type === 'c') {
|
|
|
|
// https://github.com/RocketChat/Rocket.Chat/pull/25279
|
|
|
|
params = compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.8.0')
|
|
|
|
? { channelId: rid }
|
|
|
|
: {
|
2022-02-15 18:50:55 +00:00
|
|
|
channelId: rid,
|
|
|
|
channelName: name
|
2023-06-12 14:17:43 +00:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
params = {
|
|
|
|
roomId: rid,
|
|
|
|
roomName: name
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-02-15 18:50:55 +00:00
|
|
|
return sdk.post(type === 'c' ? 'channels.convertToTeam' : 'groups.convertToTeam', params);
|
|
|
|
};
|
|
|
|
|
2022-03-02 21:29:30 +00:00
|
|
|
export const convertTeamToChannel = ({ teamId, selected }: { teamId: string; selected: string[] }) => {
|
2022-02-15 18:50:55 +00:00
|
|
|
const params = {
|
|
|
|
teamId,
|
|
|
|
...(selected.length && { roomsToRemove: selected })
|
|
|
|
};
|
|
|
|
return sdk.post('teams.convertToChannel', params);
|
|
|
|
};
|
|
|
|
|
2022-03-07 16:07:40 +00:00
|
|
|
export const joinRoom = (roomId: string, joinCode: string | null, type: 'c' | 'p') => {
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.48.0
|
|
|
|
if (type === 'p') {
|
2022-03-07 16:07:40 +00:00
|
|
|
return sdk.methodCallWrapper('joinRoom', roomId) as Promise<boolean>;
|
2022-02-15 18:50:55 +00:00
|
|
|
}
|
|
|
|
return sdk.post('channels.join', { roomId, joinCode });
|
|
|
|
};
|
|
|
|
|
2022-03-02 21:45:05 +00:00
|
|
|
export const deleteMessage = (messageId: string, rid: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.48.0
|
|
|
|
sdk.post('chat.delete', { msgId: messageId, roomId: rid });
|
|
|
|
|
2022-03-02 17:06:30 +00:00
|
|
|
export const markAsUnread = ({ messageId }: { messageId: string }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.65.0
|
|
|
|
sdk.post('subscriptions.unread', { firstUnreadMessage: { _id: messageId } });
|
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
export const toggleStarMessage = (messageId: string, starred?: boolean) => {
|
2022-02-15 18:50:55 +00:00
|
|
|
if (starred) {
|
|
|
|
// RC 0.59.0
|
|
|
|
return sdk.post('chat.unStarMessage', { messageId });
|
|
|
|
}
|
|
|
|
// RC 0.59.0
|
|
|
|
return sdk.post('chat.starMessage', { messageId });
|
|
|
|
};
|
|
|
|
|
2022-05-11 02:22:17 +00:00
|
|
|
export const togglePinMessage = (messageId: string, pinned?: boolean) => {
|
2022-02-15 18:50:55 +00:00
|
|
|
if (pinned) {
|
|
|
|
// RC 0.59.0
|
|
|
|
return sdk.post('chat.unPinMessage', { messageId });
|
|
|
|
}
|
|
|
|
// RC 0.59.0
|
|
|
|
return sdk.post('chat.pinMessage', { messageId });
|
|
|
|
};
|
|
|
|
|
2024-01-03 21:14:31 +00:00
|
|
|
export const reportUser = (userId: string, description: string) =>
|
|
|
|
// RC 6.4.0
|
|
|
|
sdk.post('moderation.reportUser', { userId, description });
|
|
|
|
|
2022-03-05 03:40:41 +00:00
|
|
|
export const reportMessage = (messageId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.64.0
|
|
|
|
sdk.post('chat.reportMessage', { messageId, description: 'Message reported by user' });
|
|
|
|
|
2022-03-03 01:53:44 +00:00
|
|
|
export const setUserPreferences = (userId: string, data: Partial<INotificationPreferences>) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.62.0
|
|
|
|
sdk.post('users.setPreferences', { userId, data });
|
|
|
|
|
2022-03-07 15:00:39 +00:00
|
|
|
export const setUserStatus = (status: string, message: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 1.2.0
|
2022-07-06 20:05:13 +00:00
|
|
|
sdk.methodCall('setUserStatus', status, message);
|
2022-02-15 18:50:55 +00:00
|
|
|
|
2022-03-05 03:28:36 +00:00
|
|
|
export const setReaction = (emoji: string, messageId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.62.2
|
|
|
|
sdk.post('chat.react', { emoji, messageId });
|
|
|
|
|
2023-09-05 12:20:06 +00:00
|
|
|
/**
|
|
|
|
* Toggles the read status of a room.
|
|
|
|
*
|
|
|
|
* @param isRead - Whether to mark the room as read or unread.
|
|
|
|
* @param roomId - The ID of the room.
|
|
|
|
* @param includeThreads - Optional flag to include threads when marking as read.
|
|
|
|
* @returns A promise from the sdk post method.
|
|
|
|
*/
|
|
|
|
export const toggleReadStatus = (
|
|
|
|
isRead: boolean,
|
|
|
|
roomId: string,
|
|
|
|
includeThreads?: boolean
|
|
|
|
): Promise<ResultFor<'POST', keyof SubscriptionsEndpoints>> => {
|
|
|
|
let endpoint: keyof SubscriptionsEndpoints;
|
|
|
|
let payload: OperationParams<'POST', keyof SubscriptionsEndpoints> = { roomId };
|
|
|
|
|
|
|
|
if (isRead) {
|
|
|
|
endpoint = 'subscriptions.unread';
|
|
|
|
} else {
|
|
|
|
endpoint = 'subscriptions.read';
|
|
|
|
payload = { rid: roomId };
|
|
|
|
if (includeThreads) {
|
|
|
|
payload.readThreads = includeThreads;
|
|
|
|
}
|
2022-02-15 18:50:55 +00:00
|
|
|
}
|
2023-09-05 12:20:06 +00:00
|
|
|
|
|
|
|
return sdk.post(endpoint, payload);
|
2022-02-15 18:50:55 +00:00
|
|
|
};
|
|
|
|
|
2022-03-07 16:48:33 +00:00
|
|
|
export const getRoomCounters = (
|
|
|
|
roomId: string,
|
|
|
|
t: SubscriptionType.CHANNEL | SubscriptionType.GROUP | SubscriptionType.OMNICHANNEL
|
|
|
|
) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.65.0
|
|
|
|
sdk.get(`${roomTypeToApiType(t)}.counters`, { roomId });
|
|
|
|
|
2022-03-08 13:46:33 +00:00
|
|
|
export const getChannelInfo = (roomId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.48.0
|
|
|
|
sdk.get('channels.info', { roomId });
|
|
|
|
|
2022-03-10 00:16:20 +00:00
|
|
|
export const getUserPreferences = (userId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.62.0
|
|
|
|
sdk.get('users.getPreferences', { userId });
|
|
|
|
|
|
|
|
export const getRoomInfo = (roomId: string) =>
|
|
|
|
// RC 0.72.0
|
|
|
|
sdk.get('rooms.info', { roomId });
|
|
|
|
|
2023-08-01 14:45:56 +00:00
|
|
|
export const getRoomByTypeAndName = (roomType: RoomType, roomName: string): Promise<IServerRoom> =>
|
|
|
|
sdk.methodCallWrapper('getRoomByTypeAndName', roomType, roomName);
|
|
|
|
|
2022-02-15 18:50:55 +00:00
|
|
|
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;
|
2022-03-08 17:59:17 +00:00
|
|
|
}) => {
|
2022-02-15 18:50:55 +00:00
|
|
|
const params: any = {
|
|
|
|
teamId,
|
|
|
|
count,
|
|
|
|
offset,
|
|
|
|
type
|
|
|
|
};
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
params.filter = filter;
|
|
|
|
}
|
|
|
|
// RC 3.13.0
|
|
|
|
return sdk.get('teams.listRooms', params);
|
|
|
|
};
|
|
|
|
|
2022-07-15 20:06:27 +00:00
|
|
|
export const closeLivechat = (rid: string, comment?: string, tags?: string[]) => {
|
|
|
|
// RC 3.2.0
|
|
|
|
let params;
|
|
|
|
if (tags && tags?.length) {
|
|
|
|
params = { tags };
|
|
|
|
}
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.29.0
|
2022-07-15 20:06:27 +00:00
|
|
|
return sdk.methodCallWrapper('livechat:closeRoom', rid, comment, { clientAction: true, ...params });
|
|
|
|
};
|
2022-02-15 18:50:55 +00:00
|
|
|
|
2022-03-14 13:23:20 +00:00
|
|
|
export const editLivechat = (userData: TParams, roomData: TParams): Promise<{ error?: string }> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.55.0
|
|
|
|
sdk.methodCallWrapper('livechat:saveInfo', userData, roomData);
|
|
|
|
|
2022-03-07 16:39:02 +00:00
|
|
|
export const returnLivechat = (rid: string): Promise<boolean> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.72.0
|
|
|
|
sdk.methodCallWrapper('livechat:returnAsInquiry', rid);
|
|
|
|
|
2022-04-20 20:53:11 +00:00
|
|
|
export const onHoldLivechat = (roomId: string) => sdk.post('livechat/room.onHold', { roomId });
|
|
|
|
|
2022-02-15 18:50:55 +00:00
|
|
|
export const forwardLivechat = (transferData: any) =>
|
|
|
|
// RC 0.36.0
|
|
|
|
sdk.methodCallWrapper('livechat:transfer', transferData);
|
|
|
|
|
2022-03-02 19:00:51 +00:00
|
|
|
export const getDepartmentInfo = (departmentId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 2.2.0
|
|
|
|
sdk.get(`livechat/department/${departmentId}?includeAgents=false`);
|
|
|
|
|
2022-02-17 14:57:30 +00:00
|
|
|
export const getDepartments = (args?: { count: number; offset: number; text: string }) => {
|
|
|
|
let params;
|
|
|
|
if (args) {
|
|
|
|
params = {
|
|
|
|
text: args.text,
|
|
|
|
count: args.count,
|
|
|
|
offset: args.offset
|
|
|
|
};
|
|
|
|
}
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 2.2.0
|
2022-02-17 14:57:30 +00:00
|
|
|
return sdk.get('livechat/department', params);
|
|
|
|
};
|
2022-02-15 18:50:55 +00:00
|
|
|
|
|
|
|
export const usersAutoComplete = (selector: any) =>
|
|
|
|
// RC 2.4.0
|
|
|
|
sdk.get('users.autocomplete', { selector });
|
|
|
|
|
2022-03-02 19:32:11 +00:00
|
|
|
export const getRoutingConfig = (): Promise<{
|
|
|
|
previewRoom: boolean;
|
|
|
|
showConnecting: boolean;
|
|
|
|
showQueue: boolean;
|
|
|
|
showQueueLink: boolean;
|
|
|
|
returnQueue: boolean;
|
|
|
|
enableTriggerAction: boolean;
|
|
|
|
autoAssignAgent: boolean;
|
|
|
|
}> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 2.0.0
|
|
|
|
sdk.methodCallWrapper('livechat:getRoutingConfig');
|
|
|
|
|
2022-07-15 20:06:27 +00:00
|
|
|
export const getTagsList = (): Promise<ILivechatTag[]> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 2.0.0
|
|
|
|
sdk.methodCallWrapper('livechat:getTagsList');
|
|
|
|
|
2022-03-08 15:04:41 +00:00
|
|
|
export const getAgentDepartments = (uid: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 2.4.0
|
|
|
|
sdk.get(`livechat/agents/${uid}/departments?enabledDepartmentsOnly=true`);
|
|
|
|
|
|
|
|
export const getCustomFields = () =>
|
|
|
|
// RC 2.2.0
|
|
|
|
sdk.get('livechat/custom-fields');
|
|
|
|
|
2022-03-08 14:30:45 +00:00
|
|
|
export const getListCannedResponse = ({ scope = '', departmentId = '', offset = 0, count = 25, text = '' }) => {
|
2022-02-15 18:50:55 +00:00
|
|
|
const params = {
|
|
|
|
offset,
|
|
|
|
count,
|
|
|
|
...(departmentId && { departmentId }),
|
|
|
|
...(text && { text }),
|
|
|
|
...(scope && { scope })
|
|
|
|
};
|
|
|
|
|
|
|
|
// RC 3.17.0
|
|
|
|
return sdk.get('canned-responses', params);
|
|
|
|
};
|
|
|
|
|
2022-03-03 17:52:00 +00:00
|
|
|
export const toggleBlockUser = (rid: string, blocked: string, block: boolean): Promise<boolean> => {
|
2022-02-15 18:50:55 +00:00
|
|
|
if (block) {
|
|
|
|
// RC 0.49.0
|
|
|
|
return sdk.methodCallWrapper('blockUser', { rid, blocked });
|
|
|
|
}
|
|
|
|
// RC 0.49.0
|
|
|
|
return sdk.methodCallWrapper('unblockUser', { rid, blocked });
|
|
|
|
};
|
|
|
|
|
2022-03-07 12:20:12 +00:00
|
|
|
export const leaveRoom = (roomId: string, t: RoomTypes) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.48.0
|
|
|
|
sdk.post(`${roomTypeToApiType(t)}.leave`, { roomId });
|
|
|
|
|
2022-03-07 12:33:58 +00:00
|
|
|
export const deleteRoom = (roomId: string, t: RoomTypes) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.49.0
|
|
|
|
sdk.post(`${roomTypeToApiType(t)}.delete`, { roomId });
|
|
|
|
|
2022-03-07 15:23:28 +00:00
|
|
|
export const toggleMuteUserInRoom = (
|
|
|
|
rid: string,
|
|
|
|
username: string,
|
|
|
|
mute: boolean
|
|
|
|
): Promise<{ message: { msg: string; result: boolean }; success: boolean }> => {
|
2022-02-15 18:50:55 +00:00
|
|
|
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;
|
2022-02-25 16:43:42 +00:00
|
|
|
t: SubscriptionType;
|
2022-02-15 18:50:55 +00:00
|
|
|
userId: string;
|
|
|
|
isOwner: boolean;
|
2022-03-07 15:40:38 +00:00
|
|
|
}) => {
|
|
|
|
const type = t as SubscriptionType.CHANNEL;
|
2022-02-15 18:50:55 +00:00
|
|
|
if (isOwner) {
|
|
|
|
// RC 0.49.4
|
2022-03-07 15:40:38 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.addOwner`, { roomId, userId });
|
2022-02-15 18:50:55 +00:00
|
|
|
}
|
|
|
|
// RC 0.49.4
|
2022-03-07 15:40:38 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.removeOwner`, { roomId, userId });
|
2022-02-15 18:50:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleRoomLeader = ({
|
|
|
|
roomId,
|
|
|
|
t,
|
|
|
|
userId,
|
|
|
|
isLeader
|
|
|
|
}: {
|
|
|
|
roomId: string;
|
2022-02-25 16:43:42 +00:00
|
|
|
t: SubscriptionType;
|
2022-02-15 18:50:55 +00:00
|
|
|
userId: string;
|
|
|
|
isLeader: boolean;
|
2022-03-07 15:52:22 +00:00
|
|
|
}) => {
|
|
|
|
const type = t as SubscriptionType.CHANNEL;
|
2022-02-15 18:50:55 +00:00
|
|
|
if (isLeader) {
|
|
|
|
// RC 0.58.0
|
2022-03-07 15:52:22 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.addLeader`, { roomId, userId });
|
2022-02-15 18:50:55 +00:00
|
|
|
}
|
|
|
|
// RC 0.58.0
|
2022-03-07 15:52:22 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.removeLeader`, { roomId, userId });
|
2022-02-15 18:50:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleRoomModerator = ({
|
|
|
|
roomId,
|
|
|
|
t,
|
|
|
|
userId,
|
|
|
|
isModerator
|
|
|
|
}: {
|
|
|
|
roomId: string;
|
2022-02-25 16:43:42 +00:00
|
|
|
t: SubscriptionType;
|
2022-02-15 18:50:55 +00:00
|
|
|
userId: string;
|
|
|
|
isModerator: boolean;
|
2022-03-07 14:47:06 +00:00
|
|
|
}) => {
|
|
|
|
const type = t as SubscriptionType.CHANNEL;
|
2022-02-15 18:50:55 +00:00
|
|
|
if (isModerator) {
|
|
|
|
// RC 0.49.4
|
2022-03-07 14:47:06 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.addModerator`, { roomId, userId });
|
2022-02-15 18:50:55 +00:00
|
|
|
}
|
|
|
|
// RC 0.49.4
|
2022-03-07 14:47:06 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.removeModerator`, { roomId, userId });
|
2022-02-15 18:50:55 +00:00
|
|
|
};
|
|
|
|
|
2022-03-07 12:44:11 +00:00
|
|
|
export const removeUserFromRoom = ({ roomId, t, userId }: { roomId: string; t: RoomTypes; userId: string }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.48.0
|
|
|
|
sdk.post(`${roomTypeToApiType(t)}.kick`, { roomId, userId });
|
|
|
|
|
2022-03-07 14:08:45 +00:00
|
|
|
export const ignoreUser = ({ rid, userId, ignore }: { rid: string; userId: string; ignore: boolean }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.64.0
|
|
|
|
sdk.get('chat.ignoreUser', { rid, userId, ignore });
|
|
|
|
|
2022-03-02 21:19:07 +00:00
|
|
|
export const toggleArchiveRoom = (roomId: string, t: SubscriptionType, archive: boolean) => {
|
|
|
|
const type = t as SubscriptionType.CHANNEL | SubscriptionType.GROUP;
|
2022-02-15 18:50:55 +00:00
|
|
|
if (archive) {
|
|
|
|
// RC 0.48.0
|
2022-03-02 21:19:07 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.archive`, { roomId });
|
2022-02-15 18:50:55 +00:00
|
|
|
}
|
|
|
|
// RC 0.48.0
|
2022-03-02 21:19:07 +00:00
|
|
|
return sdk.post(`${roomTypeToApiType(type)}.unarchive`, { roomId });
|
2022-02-15 18:50:55 +00:00
|
|
|
};
|
|
|
|
|
2022-03-07 12:57:57 +00:00
|
|
|
export const hideRoom = (roomId: string, t: RoomTypes) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.48.0
|
|
|
|
sdk.post(`${roomTypeToApiType(t)}.close`, { roomId });
|
|
|
|
|
2022-03-03 18:15:06 +00:00
|
|
|
export const saveRoomSettings = (
|
|
|
|
rid: string,
|
|
|
|
params: {
|
|
|
|
roomName?: string;
|
2023-04-10 14:59:00 +00:00
|
|
|
roomAvatar?: string | null;
|
2022-03-03 18:15:06 +00:00
|
|
|
roomDescription?: string;
|
|
|
|
roomTopic?: string;
|
|
|
|
roomAnnouncement?: string;
|
|
|
|
roomType?: SubscriptionType;
|
|
|
|
readOnly?: boolean;
|
|
|
|
reactWhenReadOnly?: boolean;
|
|
|
|
systemMessages?: string[];
|
|
|
|
joinCode?: string;
|
|
|
|
encrypted?: boolean;
|
|
|
|
}
|
|
|
|
): Promise<{ result: boolean; rid: string }> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.55.0
|
|
|
|
sdk.methodCallWrapper('saveRoomSettings', rid, params);
|
|
|
|
|
2022-05-07 02:11:07 +00:00
|
|
|
export const saveUserProfile = (
|
|
|
|
data: IProfileParams | Pick<IProfileParams, 'username'>,
|
|
|
|
customFields?: { [key: string | number]: string }
|
|
|
|
) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.62.2
|
|
|
|
sdk.post('users.updateOwnBasicInfo', { data, customFields });
|
|
|
|
|
2022-03-09 16:49:52 +00:00
|
|
|
export const saveUserPreferences = (data: Partial<INotificationPreferences>) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.62.0
|
|
|
|
sdk.post('users.setPreferences', { data });
|
|
|
|
|
2022-03-09 17:04:25 +00:00
|
|
|
export const saveNotificationSettings = (roomId: string, notifications: IRoomNotifications) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.63.0
|
|
|
|
sdk.post('rooms.saveNotification', { roomId, notifications });
|
|
|
|
|
|
|
|
export const getSingleMessage = (msgId: string) =>
|
|
|
|
// RC 0.47.0
|
|
|
|
sdk.get('chat.getMessage', { msgId });
|
|
|
|
|
2022-03-15 00:11:34 +00:00
|
|
|
export const getRoomRoles = (
|
|
|
|
roomId: string,
|
|
|
|
type: SubscriptionType.CHANNEL | SubscriptionType.GROUP | SubscriptionType.OMNICHANNEL
|
|
|
|
) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.65.0
|
|
|
|
sdk.get(`${roomTypeToApiType(type)}.roles`, { roomId });
|
|
|
|
|
2023-04-10 14:59:00 +00:00
|
|
|
export const getAvatarSuggestion = (): Promise<{ [service: string]: IAvatarSuggestion }> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.51.0
|
|
|
|
sdk.methodCallWrapper('getAvatarSuggestion');
|
|
|
|
|
2022-03-10 12:37:54 +00:00
|
|
|
export const resetAvatar = (userId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.55.0
|
|
|
|
sdk.post('users.resetAvatar', { userId });
|
|
|
|
|
|
|
|
export const setAvatarFromService = ({
|
|
|
|
data,
|
|
|
|
contentType = '',
|
|
|
|
service = null
|
|
|
|
}: {
|
|
|
|
data: any;
|
|
|
|
contentType?: string;
|
|
|
|
service?: string | null;
|
2022-03-10 13:17:22 +00:00
|
|
|
}): Promise<void> =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.51.0
|
|
|
|
sdk.methodCallWrapper('setAvatarFromService', data, contentType, service);
|
|
|
|
|
2022-03-10 13:44:55 +00:00
|
|
|
export const getUsernameSuggestion = () =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.65.0
|
|
|
|
sdk.get('users.getUsernameSuggestion');
|
|
|
|
|
2022-03-10 15:29:33 +00:00
|
|
|
export const getFiles = (roomId: string, type: SubscriptionType, offset: number) => {
|
|
|
|
const t = type as SubscriptionType.DIRECT | SubscriptionType.CHANNEL | SubscriptionType.GROUP;
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.59.0
|
2022-03-10 15:29:33 +00:00
|
|
|
return sdk.get(`${roomTypeToApiType(t)}.files`, {
|
2022-02-15 18:50:55 +00:00
|
|
|
roomId,
|
|
|
|
offset,
|
|
|
|
sort: { uploadedAt: -1 }
|
|
|
|
});
|
2022-03-10 15:29:33 +00:00
|
|
|
};
|
2022-02-15 18:50:55 +00:00
|
|
|
|
2022-03-10 15:00:50 +00:00
|
|
|
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;
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.59.0
|
2022-03-10 15:00:50 +00:00
|
|
|
return sdk.get(`${roomTypeToApiType(t)}.messages`, {
|
2022-02-15 18:50:55 +00:00
|
|
|
roomId,
|
|
|
|
query,
|
|
|
|
offset,
|
|
|
|
sort: { ts: -1 }
|
|
|
|
});
|
2022-03-10 15:00:50 +00:00
|
|
|
};
|
2022-02-15 18:50:55 +00:00
|
|
|
|
2022-03-14 13:32:22 +00:00
|
|
|
export const getReadReceipts = (messageId: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.63.0
|
|
|
|
sdk.get('chat.getMessageReadReceipts', {
|
|
|
|
messageId
|
|
|
|
});
|
|
|
|
|
2022-03-10 15:17:49 +00:00
|
|
|
export const searchMessages = (roomId: string, searchText: string, count: number, offset: number) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.60.0
|
|
|
|
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 }) => {
|
2022-03-17 02:24:22 +00:00
|
|
|
const params = {
|
2022-02-15 18:50:55 +00:00
|
|
|
rid,
|
|
|
|
count,
|
2022-03-17 02:24:22 +00:00
|
|
|
offset
|
|
|
|
} as { rid: string; count: number; offset: number; text?: string };
|
2022-02-15 18:50:55 +00:00
|
|
|
if (text) {
|
|
|
|
params.text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
// RC 1.0
|
|
|
|
return sdk.get('chat.getThreadsList', params);
|
|
|
|
};
|
|
|
|
|
2022-03-16 01:25:48 +00:00
|
|
|
export const getSyncThreadsList = ({ rid, updatedSince }: { rid: string; updatedSince: string }) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 1.0
|
|
|
|
sdk.get('chat.syncThreadsList', {
|
|
|
|
rid,
|
|
|
|
updatedSince
|
|
|
|
});
|
|
|
|
|
2022-03-16 01:14:50 +00:00
|
|
|
export const runSlashCommand = (command: string, roomId: string, params: string, triggerId?: string, tmid?: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.60.2
|
|
|
|
sdk.post('commands.run', {
|
|
|
|
command,
|
|
|
|
roomId,
|
|
|
|
params,
|
|
|
|
triggerId,
|
2022-09-08 20:58:50 +00:00
|
|
|
...(tmid && { tmid })
|
2022-02-15 18:50:55 +00:00
|
|
|
});
|
|
|
|
|
2022-03-15 02:16:53 +00:00
|
|
|
export const getCommandPreview = (command: string, roomId: string, params: string) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.65.0
|
|
|
|
sdk.get('commands.preview', {
|
|
|
|
command,
|
|
|
|
roomId,
|
|
|
|
params
|
|
|
|
});
|
|
|
|
|
|
|
|
export const executeCommandPreview = (
|
|
|
|
command: string,
|
2022-03-15 14:41:23 +00:00
|
|
|
params: string,
|
2022-02-15 18:50:55 +00:00
|
|
|
roomId: string,
|
2022-03-15 14:41:23 +00:00
|
|
|
previewItem: IPreviewItem,
|
2022-02-15 18:50:55 +00:00
|
|
|
triggerId: string,
|
|
|
|
tmid?: string
|
2022-03-15 14:41:23 +00:00
|
|
|
) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 0.65.0
|
|
|
|
sdk.post('commands.preview', {
|
|
|
|
command,
|
|
|
|
params,
|
|
|
|
roomId,
|
|
|
|
previewItem,
|
|
|
|
triggerId,
|
|
|
|
tmid
|
|
|
|
});
|
|
|
|
|
2022-03-15 16:47:40 +00:00
|
|
|
export const getDirectory = ({
|
|
|
|
query,
|
|
|
|
count,
|
|
|
|
offset,
|
|
|
|
sort
|
|
|
|
}: {
|
|
|
|
query: { [key: string]: string };
|
|
|
|
count: number;
|
|
|
|
offset: number;
|
|
|
|
sort: { [key: string]: number };
|
|
|
|
}) =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 1.0
|
|
|
|
sdk.get('directory', {
|
|
|
|
query,
|
|
|
|
count,
|
|
|
|
offset,
|
|
|
|
sort
|
|
|
|
});
|
|
|
|
|
2022-03-16 00:54:43 +00:00
|
|
|
export const saveAutoTranslate = ({
|
|
|
|
rid,
|
|
|
|
field,
|
|
|
|
value,
|
|
|
|
options
|
|
|
|
}: {
|
|
|
|
rid: string;
|
|
|
|
field: string;
|
|
|
|
value: string;
|
|
|
|
options?: { defaultLanguage: string };
|
|
|
|
}) => sdk.methodCallWrapper('autoTranslate.saveSettings', rid, field, value, options ?? null);
|
2022-02-15 18:50:55 +00:00
|
|
|
|
2022-04-14 17:29:32 +00:00
|
|
|
export const getSupportedLanguagesAutoTranslate = (): Promise<{ language: string; name: string }[]> =>
|
|
|
|
sdk.methodCallWrapper('autoTranslate.getSupportedLanguages', 'en');
|
2022-02-15 18:50:55 +00:00
|
|
|
|
2022-05-27 17:33:21 +00:00
|
|
|
export const translateMessage = (messageId: string, targetLanguage: string) =>
|
|
|
|
sdk.post('autotranslate.translateMessage', { messageId, targetLanguage });
|
2022-02-15 18:50:55 +00:00
|
|
|
|
|
|
|
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 });
|
|
|
|
|
2022-04-11 18:01:43 +00:00
|
|
|
export const inviteToken = (token: string): any =>
|
2022-02-15 18:50:55 +00:00
|
|
|
// RC 2.4.0
|
|
|
|
// TODO: missing definitions from server
|
|
|
|
// @ts-ignore
|
|
|
|
sdk.post('useInviteToken', { token });
|
2022-03-14 14:18:53 +00:00
|
|
|
|
2022-03-15 19:53:24 +00:00
|
|
|
export const readThreads = (tmid: string): Promise<void> => {
|
2022-03-16 19:46:23 +00:00
|
|
|
const serverVersion = reduxStore.getState().server.version;
|
2022-03-15 19:53:24 +00:00
|
|
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.4.0')) {
|
|
|
|
// RC 3.4.0
|
|
|
|
return sdk.methodCallWrapper('readThreads', tmid);
|
|
|
|
}
|
|
|
|
return Promise.resolve();
|
|
|
|
};
|
|
|
|
|
2022-03-15 00:43:59 +00:00
|
|
|
export const createGroupChat = () => {
|
|
|
|
const { users } = reduxStore.getState().selectedUsers;
|
|
|
|
const usernames = users.map(u => u.name).join(',');
|
|
|
|
|
|
|
|
// RC 3.1.0
|
|
|
|
return sdk.post('im.create', { usernames });
|
|
|
|
};
|
|
|
|
|
2022-03-15 00:29:48 +00:00
|
|
|
export const addUsersToRoom = (rid: string): Promise<boolean> => {
|
|
|
|
const { users: selectedUsers } = reduxStore.getState().selectedUsers;
|
|
|
|
const users = selectedUsers.map(u => u.name);
|
|
|
|
// RC 0.51.0
|
|
|
|
return sdk.methodCallWrapper('addUsersToRoom', { rid, users });
|
|
|
|
};
|
|
|
|
|
2022-03-14 15:55:32 +00:00
|
|
|
export const emitTyping = (room: IRoom, typing = true) => {
|
2023-02-14 18:49:16 +00:00
|
|
|
const { login, settings, server } = reduxStore.getState();
|
2022-03-14 15:55:32 +00:00
|
|
|
const { UI_Use_Real_Name } = settings;
|
2023-02-14 18:49:16 +00:00
|
|
|
const { version: serverVersion } = server;
|
2022-03-14 15:55:32 +00:00
|
|
|
const { user } = login;
|
|
|
|
const name = UI_Use_Real_Name ? user.name : user.username;
|
2023-02-14 18:49:16 +00:00
|
|
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '4.0.0')) {
|
|
|
|
return sdk.methodCall('stream-notify-room', `${room}/user-activity`, name, typing ? ['user-typing'] : []);
|
|
|
|
}
|
2022-03-14 15:55:32 +00:00
|
|
|
return sdk.methodCall('stream-notify-room', `${room}/typing`, name, typing);
|
|
|
|
};
|
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
export function e2eResetOwnKey(): Promise<boolean | {}> {
|
2022-03-14 14:56:49 +00:00
|
|
|
// {} when TOTP is enabled
|
2022-05-13 14:52:37 +00:00
|
|
|
unsubscribeRooms();
|
2022-03-14 14:56:49 +00:00
|
|
|
|
|
|
|
// RC 0.72.0
|
|
|
|
return sdk.methodCallWrapper('e2e.resetOwnE2EKey');
|
|
|
|
}
|
|
|
|
|
2024-01-25 14:11:07 +00:00
|
|
|
export const editMessage = async (message: Pick<IMessage, 'id' | 'msg' | 'rid'>) => {
|
|
|
|
const { rid, msg } = await Encryption.encryptMessage(message as IMessage);
|
2022-03-14 14:18:53 +00:00
|
|
|
// RC 0.49.0
|
|
|
|
return sdk.post('chat.update', { roomId: rid, msgId: message.id, text: msg });
|
|
|
|
};
|
2022-03-16 00:29:48 +00:00
|
|
|
|
2022-03-16 20:04:16 +00:00
|
|
|
export const registerPushToken = () =>
|
|
|
|
new Promise<void>(async resolve => {
|
|
|
|
const token = getDeviceToken();
|
|
|
|
if (token) {
|
|
|
|
const type = isIOS ? 'apn' : 'gcm';
|
|
|
|
const data = {
|
|
|
|
value: token,
|
|
|
|
type,
|
|
|
|
appName: getBundleId
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
// RC 0.60.0
|
|
|
|
await sdk.post('push.token', data);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return resolve();
|
|
|
|
});
|
|
|
|
|
2022-03-16 19:46:23 +00:00
|
|
|
export const removePushToken = (): Promise<boolean | void> => {
|
|
|
|
const token = getDeviceToken();
|
|
|
|
if (token) {
|
|
|
|
// RC 0.60.0
|
|
|
|
return sdk.current.del('push.token', { token });
|
|
|
|
}
|
|
|
|
return Promise.resolve();
|
|
|
|
};
|
|
|
|
|
2022-03-16 00:29:48 +00:00
|
|
|
export const sendEmailCode = () => {
|
|
|
|
const { username } = reduxStore.getState().login.user as IUser;
|
|
|
|
// RC 3.1.0
|
|
|
|
return sdk.post('users.2fa.sendEmailCode', { emailOrUsername: username });
|
|
|
|
};
|
2022-03-16 01:37:49 +00:00
|
|
|
|
|
|
|
export const getRoomMembers = async ({
|
|
|
|
rid,
|
|
|
|
allUsers,
|
|
|
|
roomType,
|
|
|
|
type,
|
|
|
|
filter,
|
|
|
|
skip = 0,
|
|
|
|
limit = 10
|
|
|
|
}: {
|
|
|
|
rid: string;
|
|
|
|
allUsers: boolean;
|
|
|
|
type: 'all' | 'online';
|
|
|
|
roomType: SubscriptionType;
|
2022-08-19 17:27:04 +00:00
|
|
|
filter: string;
|
2022-03-16 01:37:49 +00:00
|
|
|
skip: number;
|
|
|
|
limit: number;
|
|
|
|
}) => {
|
|
|
|
const t = roomType as SubscriptionType.CHANNEL | SubscriptionType.GROUP | SubscriptionType.DIRECT;
|
|
|
|
const serverVersion = reduxStore.getState().server.version;
|
|
|
|
if (compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '3.16.0')) {
|
|
|
|
const params = {
|
|
|
|
roomId: rid,
|
|
|
|
offset: skip,
|
|
|
|
count: limit,
|
|
|
|
...(type !== 'all' && { 'status[]': type }),
|
|
|
|
...(filter && { filter })
|
|
|
|
};
|
|
|
|
// RC 3.16.0
|
|
|
|
const result = await sdk.get(`${roomTypeToApiType(t)}.members`, params);
|
|
|
|
if (result.success) {
|
|
|
|
return result?.members;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// RC 0.42.0
|
|
|
|
const result = await sdk.methodCallWrapper('getUsersOfRoom', rid, allUsers, { skip, limit });
|
2022-08-19 17:27:04 +00:00
|
|
|
return result?.records;
|
2022-03-16 01:37:49 +00:00
|
|
|
};
|
2022-03-21 16:56:38 +00:00
|
|
|
|
|
|
|
export const e2eFetchMyKeys = async () => {
|
|
|
|
// RC 0.70.0
|
|
|
|
const result = await sdk.get('e2e.fetchMyKeys');
|
|
|
|
// snake_case -> camelCase
|
|
|
|
if (result.success) {
|
|
|
|
return {
|
|
|
|
success: result.success,
|
|
|
|
publicKey: result.public_key,
|
|
|
|
privateKey: result.private_key
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return result;
|
2022-03-25 18:09:02 +00:00
|
|
|
};
|
2022-04-04 19:15:29 +00:00
|
|
|
|
|
|
|
export const logoutOtherLocations = () => {
|
|
|
|
const { id } = reduxStore.getState().login.user;
|
|
|
|
return sdk.post('users.removeOtherTokens', { userId: id as string });
|
|
|
|
};
|
|
|
|
|
|
|
|
export function getUserInfo(userId: string) {
|
|
|
|
// RC 0.48.0
|
|
|
|
return sdk.get('users.info', { userId });
|
|
|
|
}
|
|
|
|
|
|
|
|
export const toggleFavorite = (roomId: string, favorite: boolean) => sdk.post('rooms.favorite', { roomId, favorite });
|
2022-06-22 12:24:25 +00:00
|
|
|
|
2023-03-01 18:26:56 +00:00
|
|
|
export const videoConferenceJoin = (callId: string, cam?: boolean, mic?: boolean) =>
|
|
|
|
sdk.post('video-conference.join', { callId, state: { cam: !!cam, mic: mic === undefined ? true : mic } });
|
|
|
|
|
|
|
|
export const videoConferenceGetCapabilities = () => sdk.get('video-conference.capabilities');
|
2022-06-27 18:04:20 +00:00
|
|
|
|
2023-07-04 00:03:39 +00:00
|
|
|
export const videoConferenceStart = (roomId: string) => sdk.post('video-conference.start', { roomId, allowRinging: true });
|
|
|
|
|
|
|
|
export const videoConferenceCancel = (callId: string) => sdk.post('video-conference.cancel', { callId });
|
2022-06-27 18:04:20 +00:00
|
|
|
|
2022-06-23 19:59:57 +00:00
|
|
|
export const saveUserProfileMethod = (
|
|
|
|
params: IProfileParams,
|
|
|
|
customFields = {},
|
|
|
|
twoFactorOptions: {
|
|
|
|
twoFactorCode: string;
|
|
|
|
twoFactorMethod: string;
|
|
|
|
} | null
|
|
|
|
) => sdk.current.methodCall('saveUserProfile', params, customFields, twoFactorOptions);
|
|
|
|
|
2022-06-22 12:24:25 +00:00
|
|
|
export const deleteOwnAccount = (password: string, confirmRelinquish = false): any =>
|
|
|
|
// RC 0.67.0
|
|
|
|
sdk.post('users.deleteOwnAccount', { password, confirmRelinquish });
|
2023-07-04 00:03:39 +00:00
|
|
|
|
2023-08-04 14:09:36 +00:00
|
|
|
export const postMessage = (roomId: string, text: string) => sdk.post('chat.postMessage', { roomId, text });
|
|
|
|
|
2023-07-04 00:03:39 +00:00
|
|
|
export const notifyUser = (type: string, params: Record<string, any>): Promise<boolean> =>
|
|
|
|
sdk.methodCall('stream-notify-user', type, params);
|
2023-08-11 20:35:24 +00:00
|
|
|
|
|
|
|
export const getUsersRoles = (): Promise<boolean> => sdk.methodCall('getUserRoles');
|
2023-10-19 13:38:57 +00:00
|
|
|
|
|
|
|
export const getSupportedVersionsCloud = (uniqueId?: string, domain?: string) =>
|
|
|
|
fetch(`https://releases.rocket.chat/v2/server/supportedVersions?uniqueId=${uniqueId}&domain=${domain}&source=mobile`);
|