feat: initial
This commit is contained in:
434
src/core/index.ts
Normal file
434
src/core/index.ts
Normal file
@@ -0,0 +1,434 @@
|
||||
import ffi from 'ffi-napi';
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import type { LibOpenIMSDK } from 'libOpenIMSDK';
|
||||
import { UserModuleApi, setupUserModule } from './modules/user';
|
||||
import { InitConfig, LoginParams } from '@/types/params';
|
||||
import { BaseResponse, SelfUserInfo } from '@/types/entity';
|
||||
import { ErrorCode } from '@/constant/api';
|
||||
import { LoginStatus } from '@/types/enum';
|
||||
import { NativeEvent, eventMapping } from '@/constant/callback';
|
||||
import Emitter from '@/utils/emitter';
|
||||
import { type FriendModuleApi, setupFriendModule } from './modules/friend';
|
||||
import { type GroupModuleApi, setupGroupModule } from './modules/group';
|
||||
import {
|
||||
type ConversationModuleApi,
|
||||
setupConversationModule,
|
||||
} from './modules/conversation';
|
||||
import { type MessageModuleApi, setupMessageModule } from './modules/message';
|
||||
|
||||
const CB_I_S = ffi.Function('void', ['int', 'string']);
|
||||
const CB_S_I_S_S = ffi.Function('void', ['string', 'int', 'string', 'string']);
|
||||
const CB_S_I_S_S_I = ffi.Function('void', [
|
||||
'string',
|
||||
'int',
|
||||
'string',
|
||||
'string',
|
||||
'int',
|
||||
]);
|
||||
|
||||
class OpenIMSDK
|
||||
extends Emitter
|
||||
implements
|
||||
UserModuleApi,
|
||||
FriendModuleApi,
|
||||
GroupModuleApi,
|
||||
ConversationModuleApi,
|
||||
MessageModuleApi
|
||||
{
|
||||
libOpenIMSDK: LibOpenIMSDK;
|
||||
listenerCallback: Buffer;
|
||||
|
||||
constructor(libPath: string) {
|
||||
super();
|
||||
this.libOpenIMSDK = ffi.Library(libPath, {
|
||||
set_group_listener: ['void', [CB_I_S]],
|
||||
set_conversation_listener: ['void', [CB_I_S]],
|
||||
set_advanced_msg_listener: ['void', [CB_I_S]],
|
||||
set_batch_msg_listener: ['void', [CB_I_S]],
|
||||
set_user_listener: ['void', [CB_I_S]],
|
||||
set_friend_listener: ['void', [CB_I_S]],
|
||||
set_custom_business_listener: ['void', [CB_I_S]],
|
||||
init_sdk: ['uint8', [CB_I_S, 'string', 'string']],
|
||||
un_init_sdk: ['void', ['string']],
|
||||
login: ['void', [CB_S_I_S_S, 'string', 'string', 'string']],
|
||||
logout: ['void', [CB_S_I_S_S, 'string']],
|
||||
network_status_changed: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_login_status: ['int', ['string']],
|
||||
get_login_user: ['string', []],
|
||||
create_text_message: ['string', ['string', 'string']],
|
||||
create_advanced_text_message: ['string', ['string', 'string', 'string']],
|
||||
create_text_at_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_location_message: [
|
||||
'string',
|
||||
['string', 'string', 'double', 'double'],
|
||||
],
|
||||
create_custom_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_quote_message: ['string', ['string', 'string', 'string']],
|
||||
create_advanced_quote_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_card_message: ['string', ['string', 'string']],
|
||||
create_video_message_from_full_path: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'long long', 'string'],
|
||||
],
|
||||
create_image_message_from_full_path: ['string', ['string', 'string']],
|
||||
create_sound_message_from_full_path: [
|
||||
'string',
|
||||
['string', 'string', 'long long'],
|
||||
],
|
||||
create_file_message_from_full_path: [
|
||||
'string',
|
||||
['string', 'string', 'string'],
|
||||
],
|
||||
create_image_message: ['string', ['string', 'string']],
|
||||
create_image_message_by_url: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_sound_message_by_url: ['string', ['string', 'string']],
|
||||
create_sound_message: ['string', ['string', 'string', 'long long']],
|
||||
create_video_message_by_url: ['string', ['string', 'string']],
|
||||
create_video_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'long long', 'string'],
|
||||
],
|
||||
create_file_message_by_url: ['string', ['string', 'string']],
|
||||
create_file_message: ['string', ['string', 'string', 'string']],
|
||||
create_merger_message: [
|
||||
'string',
|
||||
['string', 'string', 'string', 'string'],
|
||||
],
|
||||
create_face_message: ['string', ['string', 'int', 'string']],
|
||||
create_forward_message: ['string', ['string', 'string']],
|
||||
get_all_conversation_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_advanced_history_message_list: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string'],
|
||||
],
|
||||
send_message: [
|
||||
'void',
|
||||
[CB_S_I_S_S_I, 'string', 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
|
||||
// User related functions
|
||||
get_users_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_users_info_from_srv: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_self_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_self_user_info: ['void', [CB_S_I_S_S, 'string']],
|
||||
update_msg_sender_info: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string'],
|
||||
],
|
||||
subscribe_users_status: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
unsubscribe_users_status: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_subscribe_users_status: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_user_status: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
|
||||
// Friend related functions
|
||||
get_specified_friends_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_friend_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_friend_list_page: ['void', [CB_S_I_S_S, 'string', 'int', 'int']],
|
||||
search_friends: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
check_friend: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
add_friend: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_friend_remark: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
delete_friend: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_friend_application_list_as_recipient: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string'],
|
||||
],
|
||||
get_friend_application_list_as_applicant: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string'],
|
||||
],
|
||||
accept_friend_application: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
refuse_friend_application: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
add_black: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_black_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
remove_black: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
|
||||
// Group related functions
|
||||
create_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
join_group: ['void', [CB_S_I_S_S, 'string', 'string', 'string', 'int']],
|
||||
quit_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
dismiss_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
change_group_mute: ['void', [CB_S_I_S_S, 'string', 'string', 'int']],
|
||||
change_group_member_mute: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'int'],
|
||||
],
|
||||
set_group_member_role_level: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'int'],
|
||||
],
|
||||
set_group_member_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
get_joined_group_list: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_specified_groups_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
search_groups: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_group_info: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
set_group_verification: ['void', [CB_S_I_S_S, 'string', 'string', 'int']],
|
||||
set_group_look_member_info: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'int'],
|
||||
],
|
||||
set_group_apply_member_friend: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'int'],
|
||||
],
|
||||
get_group_member_list: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'int', 'int', 'int'],
|
||||
],
|
||||
get_group_member_owner_and_admin: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string'],
|
||||
],
|
||||
get_group_member_list_by_join_time_filter: [
|
||||
'void',
|
||||
[
|
||||
CB_S_I_S_S,
|
||||
'string',
|
||||
'string',
|
||||
'int',
|
||||
'int',
|
||||
'long long',
|
||||
'long long',
|
||||
'string',
|
||||
],
|
||||
],
|
||||
get_specified_group_members_info: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string'],
|
||||
],
|
||||
kick_group_member: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
transfer_group_owner: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string'],
|
||||
],
|
||||
invite_user_to_group: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
get_group_application_list_as_recipient: ['void', [CB_S_I_S_S, 'string']],
|
||||
get_group_application_list_as_applicant: ['void', [CB_S_I_S_S, 'string']],
|
||||
accept_group_application: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
refuse_group_application: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
set_group_member_nickname: [
|
||||
'void',
|
||||
[CB_S_I_S_S, 'string', 'string', 'string', 'string'],
|
||||
],
|
||||
search_group_members: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
is_join_group: ['void', [CB_S_I_S_S, 'string', 'string']],
|
||||
}) as LibOpenIMSDK;
|
||||
|
||||
this.listenerCallback = ffi.Callback(
|
||||
'void',
|
||||
['int', 'string'],
|
||||
(event: NativeEvent, data) => {
|
||||
const cbEvent = eventMapping[event];
|
||||
this.emit(cbEvent, data);
|
||||
console.log(`listener callback - Event: ${cbEvent}, Data: ${data}`);
|
||||
}
|
||||
);
|
||||
|
||||
Object.assign(this, setupUserModule(this));
|
||||
Object.assign(this, setupFriendModule(this));
|
||||
Object.assign(this, setupGroupModule(this));
|
||||
Object.assign(this, setupConversationModule(this));
|
||||
Object.assign(this, setupMessageModule(this));
|
||||
}
|
||||
|
||||
baseCallbackWrap = <T>(
|
||||
resolve: (response: BaseResponse<T>) => void,
|
||||
reject: (response: BaseResponse<T>) => void
|
||||
) =>
|
||||
ffi.Callback(
|
||||
'void',
|
||||
['string', 'int', 'string', 'string'],
|
||||
(operationID, errCode: number, errMsg, data) => {
|
||||
let realData;
|
||||
try {
|
||||
realData = JSON.parse(data);
|
||||
} catch (error) {
|
||||
realData = data;
|
||||
}
|
||||
const response: BaseResponse<T> = {
|
||||
errCode,
|
||||
errMsg,
|
||||
data: realData,
|
||||
operationID,
|
||||
};
|
||||
if (errCode === 0) {
|
||||
resolve(response);
|
||||
} else {
|
||||
reject(response);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
asyncRetunWrap = <T>(operationID: string, data: unknown) =>
|
||||
new Promise<BaseResponse<T>>((resolve, reject) => {
|
||||
const hasError = !data && !operationID.includes('unInitSDK');
|
||||
if (data && typeof data === 'string') {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch (error) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
const response = {
|
||||
errCode: hasError ? ErrorCode.UnknownError : 0,
|
||||
errMsg: '',
|
||||
data: data as T,
|
||||
operationID,
|
||||
};
|
||||
if (response.errCode === 0) {
|
||||
resolve(response);
|
||||
} else {
|
||||
reject(response);
|
||||
}
|
||||
});
|
||||
|
||||
setListener = () => {
|
||||
this.libOpenIMSDK.set_user_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_friend_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_group_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_conversation_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_advanced_msg_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_batch_msg_listener(this.listenerCallback);
|
||||
this.libOpenIMSDK.set_custom_business_listener(this.listenerCallback);
|
||||
};
|
||||
|
||||
initSDK = (param: InitConfig, opid = uuidV4()) =>
|
||||
new Promise<boolean>((resolve, reject) => {
|
||||
const flag = this.libOpenIMSDK.init_sdk(
|
||||
this.listenerCallback,
|
||||
opid,
|
||||
JSON.stringify(param)
|
||||
);
|
||||
if (!flag) {
|
||||
reject(!!flag);
|
||||
return;
|
||||
}
|
||||
this.setListener();
|
||||
resolve(!!flag);
|
||||
});
|
||||
|
||||
login = (param: LoginParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse>((resolve, reject) => {
|
||||
const loginCallback = this.baseCallbackWrap(resolve, reject);
|
||||
this.libOpenIMSDK.login(loginCallback, opid, param.userID, param.token);
|
||||
});
|
||||
|
||||
getLoginStatus = (opid = uuidV4()) =>
|
||||
this.asyncRetunWrap<LoginStatus>(
|
||||
opid,
|
||||
this.libOpenIMSDK.get_login_status(opid)
|
||||
);
|
||||
|
||||
getLoginUser = (opid = uuidV4()) =>
|
||||
this.asyncRetunWrap<SelfUserInfo>(opid, this.libOpenIMSDK.get_login_user());
|
||||
|
||||
logout = (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse>((resolve, reject) => {
|
||||
const logoutCallback = this.baseCallbackWrap(resolve, reject);
|
||||
this.libOpenIMSDK.logout(logoutCallback, opid);
|
||||
});
|
||||
|
||||
unInitSDK = (opid = uuidV4()) =>
|
||||
this.asyncRetunWrap(
|
||||
opid,
|
||||
this.libOpenIMSDK.un_init_sdk(`unInitSDK-${opid}`)
|
||||
);
|
||||
|
||||
// implements user api
|
||||
getSelfUserInfo!: UserModuleApi['getSelfUserInfo'];
|
||||
|
||||
// implements friend api
|
||||
acceptFriendApplication!: FriendModuleApi['acceptFriendApplication'];
|
||||
addBlack!: FriendModuleApi['addBlack'];
|
||||
addFriend!: FriendModuleApi['addFriend'];
|
||||
checkFriend!: FriendModuleApi['checkFriend'];
|
||||
deleteFriend!: FriendModuleApi['deleteFriend'];
|
||||
getBlackList!: FriendModuleApi['getBlackList'];
|
||||
getFriendApplicationListAsApplicant!: FriendModuleApi['getFriendApplicationListAsApplicant'];
|
||||
getFriendApplicationListAsRecipient!: FriendModuleApi['getFriendApplicationListAsRecipient'];
|
||||
getFriendList!: FriendModuleApi['getFriendList'];
|
||||
getSpecifiedFriendsInfo!: FriendModuleApi['getSpecifiedFriendsInfo'];
|
||||
refuseFriendApplication!: FriendModuleApi['refuseFriendApplication'];
|
||||
removeBlack!: FriendModuleApi['removeBlack'];
|
||||
searchFriends!: FriendModuleApi['searchFriends'];
|
||||
setFriendRemark!: FriendModuleApi['setFriendRemark'];
|
||||
|
||||
// implements group api
|
||||
createGroup!: GroupModuleApi['createGroup'];
|
||||
joinGroup!: GroupModuleApi['joinGroup'];
|
||||
inviteUserToGroup!: GroupModuleApi['inviteUserToGroup'];
|
||||
getJoinedGroupList!: GroupModuleApi['getJoinedGroupList'];
|
||||
searchGroups!: GroupModuleApi['searchGroups'];
|
||||
getSpecifiedGroupsInfo!: GroupModuleApi['getSpecifiedGroupsInfo'];
|
||||
setGroupInfo!: GroupModuleApi['setGroupInfo'];
|
||||
getGroupApplicationListAsRecipient!: GroupModuleApi['getGroupApplicationListAsRecipient'];
|
||||
getGroupApplicationListAsApplicant!: GroupModuleApi['getGroupApplicationListAsApplicant'];
|
||||
acceptGroupApplication!: GroupModuleApi['acceptGroupApplication'];
|
||||
refuseGroupApplication!: GroupModuleApi['refuseGroupApplication'];
|
||||
getGroupMemberList!: GroupModuleApi['getGroupMemberList'];
|
||||
getSpecifiedGroupMembersInfo!: GroupModuleApi['getSpecifiedGroupMembersInfo'];
|
||||
searchGroupMembers!: GroupModuleApi['searchGroupMembers'];
|
||||
setGroupMemberInfo!: GroupModuleApi['setGroupMemberInfo'];
|
||||
getGroupMemberOwnerAndAdmin!: GroupModuleApi['getGroupMemberOwnerAndAdmin'];
|
||||
getGroupMemberListByJoinTimeFilter!: GroupModuleApi['getGroupMemberListByJoinTimeFilter'];
|
||||
kickGroupMember!: GroupModuleApi['kickGroupMember'];
|
||||
changeGroupMemberMute!: GroupModuleApi['changeGroupMemberMute'];
|
||||
changeGroupMute!: GroupModuleApi['changeGroupMute'];
|
||||
transferGroupOwner!: GroupModuleApi['transferGroupOwner'];
|
||||
dismissGroup!: GroupModuleApi['dismissGroup'];
|
||||
quitGroup!: GroupModuleApi['quitGroup'];
|
||||
|
||||
// implements conversation api
|
||||
getAllConversationList!: ConversationModuleApi['getAllConversationList'];
|
||||
|
||||
// implements message api
|
||||
createTextMessage!: MessageModuleApi['createTextMessage'];
|
||||
createTextAtMessage!: MessageModuleApi['createTextAtMessage'];
|
||||
createLocationMessage!: MessageModuleApi['createLocationMessage'];
|
||||
createCustomMessage!: MessageModuleApi['createCustomMessage'];
|
||||
createQuoteMessage!: MessageModuleApi['createQuoteMessage'];
|
||||
createCardMessage!: MessageModuleApi['createCardMessage'];
|
||||
createMergerMessage!: MessageModuleApi['createMergerMessage'];
|
||||
createFaceMessage!: MessageModuleApi['createFaceMessage'];
|
||||
createForwardMessage!: MessageModuleApi['createForwardMessage'];
|
||||
createImageMessage!: MessageModuleApi['createImageMessage'];
|
||||
createImageMessageFromFullPath!: MessageModuleApi['createImageMessageFromFullPath'];
|
||||
createImageMessageByUrl!: MessageModuleApi['createImageMessageByUrl'];
|
||||
createVideoMessage!: MessageModuleApi['createVideoMessage'];
|
||||
createVideoMessageFromFullPath!: MessageModuleApi['createVideoMessageFromFullPath'];
|
||||
createVideoMessageByUrl!: MessageModuleApi['createVideoMessageByUrl'];
|
||||
createSoundMessage!: MessageModuleApi['createSoundMessage'];
|
||||
createSoundMessageFromFullPath!: MessageModuleApi['createSoundMessageFromFullPath'];
|
||||
createSoundMessageByUrl!: MessageModuleApi['createSoundMessageByUrl'];
|
||||
createFileMessage!: MessageModuleApi['createFileMessage'];
|
||||
createFileMessageFromFullPath!: MessageModuleApi['createFileMessageFromFullPath'];
|
||||
createFileMessageByUrl!: MessageModuleApi['createFileMessageByUrl'];
|
||||
getAdvancedHistoryMessageList!: MessageModuleApi['getAdvancedHistoryMessageList'];
|
||||
sendMessage!: MessageModuleApi['sendMessage'];
|
||||
}
|
||||
|
||||
export default OpenIMSDK;
|
||||
179
src/core/modules/conversation.ts
Normal file
179
src/core/modules/conversation.ts
Normal file
@@ -0,0 +1,179 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import { BaseResponse, ConversationItem } from '@/types/entity';
|
||||
import OpenIMSDK from '..';
|
||||
|
||||
export function setupConversationModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
// getAllConversationList: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<ConversationItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_all_conversation_list(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem[]>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
// getConversationListSplit: (
|
||||
// params: SplitConversationParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<ConversationItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_conversation_list_split(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// params.offset,
|
||||
// params.count
|
||||
// );
|
||||
// }),
|
||||
// getOneConversation: (params: GetOneConversationParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<ConversationItem>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_one_conversation(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem>(resolve, reject),
|
||||
// opid,
|
||||
// params.sessionType,
|
||||
// params.sourceID
|
||||
// );
|
||||
// }),
|
||||
// getMultipleConversation: (conversationIDList: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<ConversationItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_multiple_conversation(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// conversationIDList
|
||||
// );
|
||||
// }),
|
||||
// getConversationIDBySessionType: (
|
||||
// params: GetOneConversationParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<ConversationItem>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_conversation_id_by_session_type(
|
||||
// openIMSDK.baseCallbackWrap<ConversationItem>(resolve, reject),
|
||||
// opid,
|
||||
// params.sourceID,
|
||||
// params.sessionType
|
||||
// );
|
||||
// }),
|
||||
// getTotalUnreadMsgCount: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<number>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_total_unread_msg_count(
|
||||
// openIMSDK.baseCallbackWrap<number>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
// markConversationMessageAsRead: (conversationID: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.mark_conversation_message_as_read(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
// setConversationDraft: (
|
||||
// params: SetConversationDraftParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_draft(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.draftText
|
||||
// );
|
||||
// }),
|
||||
// pinConversation: (params: PinConversationParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.pin_conversation(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.isPinned ? 1 : 0
|
||||
// );
|
||||
// }),
|
||||
// setConversationRecvMessageOpt: (
|
||||
// params: SetConversationRecvOptParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_recv_message_opt(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.opt
|
||||
// );
|
||||
// }),
|
||||
// setConversationPrivateChat: (
|
||||
// params: SetConversationPrivateParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_private_chat(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.isPrivate
|
||||
// );
|
||||
// }),
|
||||
// setConversationBurnDuration: (
|
||||
// params: SetBurnDurationParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_conversation_burn_duration(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.burnDuration
|
||||
// );
|
||||
// }),
|
||||
// resetConversationGroupAtType: (groupID: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.reset_conversation_group_at_type(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// groupID
|
||||
// );
|
||||
// }),
|
||||
// hideConversation: (conversationID: string, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.hide_conversation(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
// hideAllConversation: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.hide_all_conversation(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
// clearConversationAndDeleteAllMsg: (
|
||||
// conversationID: string,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.clear_conversation_and_delete_all_msg(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
// deleteConversationAndDeleteAllMsg: (
|
||||
// conversationID: string,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_conversation_and_delete_all_msg(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// conversationID
|
||||
// );
|
||||
// }),
|
||||
};
|
||||
}
|
||||
|
||||
export interface ConversationModuleApi {
|
||||
getAllConversationList: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<ConversationItem[]>>;
|
||||
}
|
||||
181
src/core/modules/friend.ts
Normal file
181
src/core/modules/friend.ts
Normal file
@@ -0,0 +1,181 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import OpenIMSDK from '..';
|
||||
import {
|
||||
AccessFriendParams,
|
||||
SearchFriendParams,
|
||||
RemarkFriendParams,
|
||||
} from '@/types/params';
|
||||
|
||||
import {
|
||||
BaseResponse,
|
||||
BlackUserItem,
|
||||
FriendApplicationItem,
|
||||
FriendshipInfo,
|
||||
FullUserItem,
|
||||
SearchedFriendsInfo,
|
||||
} from '@/types/entity';
|
||||
|
||||
export function setupFriendModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
acceptFriendApplication: (params: AccessFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.accept_friend_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
addBlack: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.add_black(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
addFriend: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.add_friend(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
checkFriend: (userIDList: string[], opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FriendshipInfo[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.check_friend(
|
||||
openIMSDK.baseCallbackWrap<FriendshipInfo[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
deleteFriend: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.delete_friend(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
getBlackList: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<BlackUserItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_black_list(
|
||||
openIMSDK.baseCallbackWrap<BlackUserItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getFriendApplicationListAsApplicant: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FriendApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_friend_application_list_as_applicant(
|
||||
openIMSDK.baseCallbackWrap<FriendApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getFriendApplicationListAsRecipient: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FriendApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_friend_application_list_as_recipient(
|
||||
openIMSDK.baseCallbackWrap<FriendApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getFriendList: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FullUserItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_friend_list(
|
||||
openIMSDK.baseCallbackWrap<FullUserItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getSpecifiedFriendsInfo: (userIDList: string[], opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<FullUserItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_specified_friends_info(
|
||||
openIMSDK.baseCallbackWrap<FullUserItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
refuseFriendApplication: (params: AccessFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.refuse_friend_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
removeBlack: (userID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.remove_black(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
userID
|
||||
);
|
||||
}),
|
||||
|
||||
searchFriends: (params: SearchFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<SearchedFriendsInfo[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.search_friends(
|
||||
openIMSDK.baseCallbackWrap<SearchedFriendsInfo[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
setFriendRemark: (params: RemarkFriendParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_friend_remark(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export interface FriendModuleApi {
|
||||
acceptFriendApplication: (
|
||||
params: AccessFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
addBlack: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
addFriend: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
checkFriend: (
|
||||
userIDList: string[],
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FriendshipInfo[]>>;
|
||||
deleteFriend: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
getBlackList: (opid?: string) => Promise<BaseResponse<BlackUserItem[]>>;
|
||||
getFriendApplicationListAsApplicant: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FriendApplicationItem[]>>;
|
||||
getFriendApplicationListAsRecipient: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FriendApplicationItem[]>>;
|
||||
getFriendList: (opid?: string) => Promise<BaseResponse<FullUserItem[]>>;
|
||||
getSpecifiedFriendsInfo: (
|
||||
userIDList: string[],
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<FullUserItem[]>>;
|
||||
refuseFriendApplication: (
|
||||
params: AccessFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
removeBlack: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
searchFriends: (
|
||||
params: SearchFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<SearchedFriendsInfo[]>>;
|
||||
setFriendRemark: (
|
||||
params: RemarkFriendParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
}
|
||||
348
src/core/modules/group.ts
Normal file
348
src/core/modules/group.ts
Normal file
@@ -0,0 +1,348 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import {
|
||||
BaseResponse,
|
||||
GroupApplicationItem,
|
||||
GroupItem,
|
||||
GroupMemberItem,
|
||||
} from '@/types/entity';
|
||||
import OpenIMSDK from '..';
|
||||
import {
|
||||
CreateGroupParams,
|
||||
JoinGroupParams,
|
||||
OpreateGroupParams,
|
||||
SearchGroupParams,
|
||||
SetGroupinfoParams,
|
||||
AccessGroupParams,
|
||||
GetGroupMemberParams,
|
||||
getGroupMembersInfoParams,
|
||||
SearchGroupMemberParams,
|
||||
UpdateMemberInfoParams,
|
||||
GetGroupMemberByTimeParams,
|
||||
ChangeGroupMemberMuteParams,
|
||||
ChangeGroupMuteParams,
|
||||
TransferGroupParams,
|
||||
} from '@/types/params';
|
||||
|
||||
export function setupGroupModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
createGroup: (params: CreateGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.create_group(
|
||||
openIMSDK.baseCallbackWrap<GroupItem>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
joinGroup: (params: JoinGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.join_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.reqMsg,
|
||||
params.joinSource
|
||||
);
|
||||
}),
|
||||
|
||||
inviteUserToGroup: (params: OpreateGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.invite_user_to_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.reason,
|
||||
JSON.stringify(params.userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
getJoinedGroupList: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_joined_group_list(
|
||||
openIMSDK.baseCallbackWrap<GroupItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
searchGroups: (params: SearchGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.search_groups(
|
||||
openIMSDK.baseCallbackWrap<GroupItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
getSpecifiedGroupsInfo: (groupIDList: string[], opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_specified_groups_info(
|
||||
openIMSDK.baseCallbackWrap<GroupItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(groupIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
setGroupInfo: (params: SetGroupinfoParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_group_info(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupApplicationListAsRecipient: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_application_list_as_recipient(
|
||||
openIMSDK.baseCallbackWrap<GroupApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupApplicationListAsApplicant: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupApplicationItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_application_list_as_applicant(
|
||||
openIMSDK.baseCallbackWrap<GroupApplicationItem[]>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
acceptGroupApplication: (params: AccessGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.accept_group_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.fromUserID,
|
||||
params.handleMsg
|
||||
);
|
||||
}),
|
||||
|
||||
refuseGroupApplication: (params: AccessGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.refuse_group_application(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.fromUserID,
|
||||
params.handleMsg
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupMemberList: (params: GetGroupMemberParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_member_list(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.filter,
|
||||
params.offset,
|
||||
params.count
|
||||
);
|
||||
}),
|
||||
|
||||
getSpecifiedGroupMembersInfo: (
|
||||
params: getGroupMembersInfoParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_specified_group_members_info(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
JSON.stringify(params.userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
searchGroupMembers: (params: SearchGroupMemberParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.search_group_members(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
setGroupMemberInfo: (params: UpdateMemberInfoParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_group_member_info(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupMemberOwnerAndAdmin: (groupID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_member_owner_and_admin(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
groupID
|
||||
);
|
||||
}),
|
||||
|
||||
getGroupMemberListByJoinTimeFilter: (
|
||||
params: GetGroupMemberByTimeParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_group_member_list_by_join_time_filter(
|
||||
openIMSDK.baseCallbackWrap<GroupMemberItem[]>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.offset,
|
||||
params.count,
|
||||
params.joinTimeBegin,
|
||||
params.joinTimeEnd,
|
||||
JSON.stringify(params.filterUserIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
kickGroupMember: (params: OpreateGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.kick_group_member(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.reason,
|
||||
JSON.stringify(params.userIDList)
|
||||
);
|
||||
}),
|
||||
|
||||
changeGroupMemberMute: (
|
||||
params: ChangeGroupMemberMuteParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.change_group_member_mute(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.userID,
|
||||
params.mutedSeconds
|
||||
);
|
||||
}),
|
||||
|
||||
changeGroupMute: (params: ChangeGroupMuteParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.change_group_mute(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.isMute ? 1 : 0
|
||||
);
|
||||
}),
|
||||
|
||||
transferGroupOwner: (params: TransferGroupParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.transfer_group_owner(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
params.groupID,
|
||||
params.newOwnerUserID
|
||||
);
|
||||
}),
|
||||
|
||||
dismissGroup: (groupID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.dismiss_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
groupID
|
||||
);
|
||||
}),
|
||||
|
||||
quitGroup: (groupID: string, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.quit_group(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
groupID
|
||||
);
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export interface GroupModuleApi {
|
||||
createGroup: (
|
||||
params: CreateGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupItem>>;
|
||||
joinGroup: (
|
||||
params: JoinGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
inviteUserToGroup: (
|
||||
params: OpreateGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getJoinedGroupList: (opid?: string) => Promise<BaseResponse<GroupItem[]>>;
|
||||
searchGroups: (
|
||||
params: SearchGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupItem[]>>;
|
||||
getSpecifiedGroupsInfo: (
|
||||
groupIDList: string[],
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupItem[]>>;
|
||||
setGroupInfo: (
|
||||
params: SetGroupinfoParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getGroupApplicationListAsRecipient: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupApplicationItem[]>>;
|
||||
getGroupApplicationListAsApplicant: (
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupApplicationItem[]>>;
|
||||
acceptGroupApplication: (
|
||||
params: AccessGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
refuseGroupApplication: (
|
||||
params: AccessGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getGroupMemberList: (
|
||||
params: GetGroupMemberParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
getSpecifiedGroupMembersInfo: (
|
||||
params: getGroupMembersInfoParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
searchGroupMembers: (
|
||||
params: SearchGroupMemberParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
setGroupMemberInfo: (
|
||||
params: UpdateMemberInfoParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
getGroupMemberOwnerAndAdmin: (
|
||||
groupID: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
getGroupMemberListByJoinTimeFilter: (
|
||||
params: GetGroupMemberByTimeParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<GroupMemberItem[]>>;
|
||||
kickGroupMember: (
|
||||
params: OpreateGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
changeGroupMemberMute: (
|
||||
params: ChangeGroupMemberMuteParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
changeGroupMute: (
|
||||
params: ChangeGroupMuteParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
transferGroupOwner: (
|
||||
params: TransferGroupParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<void>>;
|
||||
dismissGroup: (groupID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
quitGroup: (groupID: string, opid?: string) => Promise<BaseResponse<void>>;
|
||||
}
|
||||
500
src/core/modules/message.ts
Normal file
500
src/core/modules/message.ts
Normal file
@@ -0,0 +1,500 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import OpenIMSDK from '..';
|
||||
import {
|
||||
AdvancedGetMessageResult,
|
||||
BaseResponse,
|
||||
CardElem,
|
||||
MessageItem,
|
||||
} from '@/types/entity';
|
||||
import {
|
||||
AtMsgParams,
|
||||
CustomMsgParams,
|
||||
FaceMessageParams,
|
||||
FileMsgByPathParams,
|
||||
FileMsgByUrlParams,
|
||||
GetAdvancedHistoryMsgParams,
|
||||
ImageMsgByUrlParams,
|
||||
LocationMsgParams,
|
||||
MergerMsgParams,
|
||||
QuoteMsgParams,
|
||||
SendMsgParams,
|
||||
SoundMsgByPathParams,
|
||||
SoundMsgByUrlParams,
|
||||
VideoMsgByPathParams,
|
||||
VideoMsgByUrlParams,
|
||||
} from '@/types/params';
|
||||
|
||||
export function setupMessageModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
createTextMessage: (content: string, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_text_message(opid, content)
|
||||
),
|
||||
|
||||
createTextAtMessage: (params: AtMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_text_at_message(
|
||||
opid,
|
||||
params.text,
|
||||
JSON.stringify(params.atUserIDList),
|
||||
JSON.stringify(params.atUsersInfo),
|
||||
JSON.stringify(params.message)
|
||||
)
|
||||
),
|
||||
|
||||
createLocationMessage: (params: LocationMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_location_message(
|
||||
opid,
|
||||
params.description,
|
||||
params.longitude,
|
||||
params.latitude
|
||||
)
|
||||
),
|
||||
|
||||
createCustomMessage: (params: CustomMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_custom_message(
|
||||
opid,
|
||||
params.data,
|
||||
params.extension,
|
||||
params.description
|
||||
)
|
||||
),
|
||||
|
||||
createQuoteMessage: (params: QuoteMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_quote_message(
|
||||
opid,
|
||||
params.text,
|
||||
params.message
|
||||
)
|
||||
),
|
||||
|
||||
createCardMessage: (params: CardElem, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_card_message(opid, JSON.stringify(params))
|
||||
),
|
||||
|
||||
createMergerMessage: (params: MergerMsgParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_merger_message(
|
||||
opid,
|
||||
JSON.stringify(params.messageList),
|
||||
params.title,
|
||||
JSON.stringify(params.summaryList)
|
||||
)
|
||||
),
|
||||
|
||||
createFaceMessage: (params: FaceMessageParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_face_message(
|
||||
opid,
|
||||
params.index,
|
||||
params.data
|
||||
)
|
||||
),
|
||||
|
||||
createForwardMessage: (message: MessageItem, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_forward_message(
|
||||
opid,
|
||||
JSON.stringify(message)
|
||||
)
|
||||
),
|
||||
|
||||
createImageMessage: (imagePath: string, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_image_message(opid, imagePath)
|
||||
),
|
||||
|
||||
createImageMessageFromFullPath: (imagePath: string, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_image_message_from_full_path(
|
||||
opid,
|
||||
imagePath
|
||||
)
|
||||
),
|
||||
|
||||
createImageMessageByUrl: (params: ImageMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_image_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params.sourcePicture),
|
||||
JSON.stringify(params.bigPicture),
|
||||
JSON.stringify(params.snapshotPicture)
|
||||
)
|
||||
),
|
||||
|
||||
createVideoMessage: (params: VideoMsgByPathParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_video_message(
|
||||
opid,
|
||||
params.videoPath,
|
||||
params.videoType,
|
||||
params.duration,
|
||||
params.snapshotPath
|
||||
)
|
||||
),
|
||||
|
||||
createVideoMessageFromFullPath: (
|
||||
params: VideoMsgByPathParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_video_message_from_full_path(
|
||||
opid,
|
||||
params.videoPath,
|
||||
params.videoType,
|
||||
params.duration,
|
||||
params.snapshotPath
|
||||
)
|
||||
),
|
||||
|
||||
createVideoMessageByUrl: (params: VideoMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_video_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
)
|
||||
),
|
||||
|
||||
createSoundMessage: (params: SoundMsgByPathParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_sound_message(
|
||||
opid,
|
||||
params.soundPath,
|
||||
params.duration
|
||||
)
|
||||
),
|
||||
|
||||
createSoundMessageFromFullPath: (
|
||||
params: SoundMsgByPathParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_sound_message_from_full_path(
|
||||
opid,
|
||||
params.soundPath,
|
||||
params.duration
|
||||
)
|
||||
),
|
||||
|
||||
createSoundMessageByUrl: (params: SoundMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_sound_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
)
|
||||
),
|
||||
|
||||
createFileMessage: (params: FileMsgByPathParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_file_message(
|
||||
opid,
|
||||
params.filePath,
|
||||
params.fileName
|
||||
)
|
||||
),
|
||||
|
||||
createFileMessageFromFullPath: (
|
||||
params: FileMsgByPathParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_file_message_from_full_path(
|
||||
opid,
|
||||
params.filePath,
|
||||
params.fileName
|
||||
)
|
||||
),
|
||||
|
||||
createFileMessageByUrl: (params: FileMsgByUrlParams, opid = uuidV4()) =>
|
||||
openIMSDK.asyncRetunWrap<MessageItem>(
|
||||
opid,
|
||||
openIMSDK.libOpenIMSDK.create_file_message_by_url(
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
)
|
||||
),
|
||||
|
||||
sendMessage: (params: SendMsgParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<MessageItem>>((resolve, reject) => {
|
||||
const offlinePushInfo = params.offlinePushInfo ?? {
|
||||
title: 'You has a new message.',
|
||||
desc: 'You has a new message.',
|
||||
ex: '',
|
||||
iOSPushSound: '+1',
|
||||
iOSBadgeCount: true,
|
||||
};
|
||||
openIMSDK.libOpenIMSDK.send_message(
|
||||
openIMSDK.baseCallbackWrap<MessageItem>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params.message),
|
||||
params.recvID,
|
||||
params.groupID,
|
||||
JSON.stringify(offlinePushInfo)
|
||||
);
|
||||
}),
|
||||
|
||||
// sendMessageNotOss: (params: SendMsgParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<MessageItem>>((resolve, reject) => {
|
||||
// const offlinePushInfo = params.offlinePushInfo ?? {
|
||||
// title: 'You has a new message.',
|
||||
// desc: 'You has a new message.',
|
||||
// ex: '',
|
||||
// iOSPushSound: '+1',
|
||||
// iOSBadgeCount: true,
|
||||
// };
|
||||
// openIMSDK.libOpenIMSDK.send_message_not_oss(
|
||||
// openIMSDK.baseCallbackWrap<MessageItem>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.message),
|
||||
// params.recvID,
|
||||
// params.groupID,
|
||||
// JSON.stringify(offlinePushInfo)
|
||||
// );
|
||||
// }),
|
||||
|
||||
// typingStatusUpdate: (params: TypingUpdateParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.typing_status_update(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.recvID,
|
||||
// params.msgTip
|
||||
// );
|
||||
// }),
|
||||
|
||||
// revokeMessage: (params: OpreateMessageParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.revoke_message(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteMessage: (params: OpreateMessageParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_message(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteMessageFromLocalStorage: (params: OpreateMessageParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_message_from_local_storage(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteAllMsgFromLocal: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_all_msg_from_local(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// );
|
||||
// }),
|
||||
|
||||
// deleteAllMsgFromLocalAndSvr: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.delete_all_msg_from_local_and_svr(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// );
|
||||
// }),
|
||||
|
||||
// searchLocalMessages: (params: SearchLocalParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<MessageItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.search_local_messages(
|
||||
// openIMSDK.baseCallbackWrap<MessageItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params)
|
||||
// );
|
||||
// }),
|
||||
|
||||
getAdvancedHistoryMessageList: (
|
||||
params: GetAdvancedHistoryMsgParams,
|
||||
opid = uuidV4()
|
||||
) =>
|
||||
new Promise<BaseResponse<AdvancedGetMessageResult>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_advanced_history_message_list(
|
||||
openIMSDK.baseCallbackWrap<AdvancedGetMessageResult>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
// getAdvancedHistoryMessageListReverse: (
|
||||
// params: GetAdvancedHistoryMsgParams, opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<AdvancedGetMessageResult>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_advanced_history_message_list_reverse(
|
||||
// openIMSDK.baseCallbackWrap<AdvancedGetMessageResult>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params)
|
||||
// );
|
||||
// }),
|
||||
// findMessageList: (params: FindMessageParams[], opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<MessageItem[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.find_message_list(
|
||||
// openIMSDK.baseCallbackWrap<MessageItem[]>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params)
|
||||
// );
|
||||
// }),
|
||||
// insertGroupMessageToLocalStorage: (params: InsertGroupMsgParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.insert_group_message_to_local_storage(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.message),
|
||||
// params.groupID,
|
||||
// params.sendID
|
||||
// );
|
||||
// }),
|
||||
// insertSingleMessageToLocalStorage: (params: InsertSingleMsgParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.insert_single_message_to_local_storage(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.message),
|
||||
// params.recvID,
|
||||
// params.sendID
|
||||
// );
|
||||
// }),
|
||||
// setMessageLocalEx: (params: SetMessageLocalExParams, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_message_local_ex(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// params.conversationID,
|
||||
// params.clientMsgID,
|
||||
// params.localEx
|
||||
// );
|
||||
// }),
|
||||
};
|
||||
}
|
||||
|
||||
export interface MessageModuleApi {
|
||||
createTextMessage: (
|
||||
content: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createTextAtMessage: (
|
||||
params: AtMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createLocationMessage: (
|
||||
params: LocationMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createCustomMessage: (
|
||||
params: CustomMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createQuoteMessage: (
|
||||
params: QuoteMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createCardMessage: (
|
||||
params: CardElem,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createMergerMessage: (
|
||||
params: MergerMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFaceMessage: (
|
||||
params: FaceMessageParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createForwardMessage: (
|
||||
message: MessageItem,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createImageMessage: (
|
||||
imagePath: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createImageMessageFromFullPath: (
|
||||
imagePath: string,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createImageMessageByUrl: (
|
||||
params: ImageMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createVideoMessage: (
|
||||
params: VideoMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createVideoMessageFromFullPath: (
|
||||
params: VideoMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createVideoMessageByUrl: (
|
||||
params: VideoMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createSoundMessage: (
|
||||
params: SoundMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createSoundMessageFromFullPath: (
|
||||
params: SoundMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createSoundMessageByUrl: (
|
||||
params: SoundMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFileMessage: (
|
||||
params: FileMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFileMessageFromFullPath: (
|
||||
params: FileMsgByPathParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
createFileMessageByUrl: (
|
||||
params: FileMsgByUrlParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
getAdvancedHistoryMessageList: (
|
||||
params: GetAdvancedHistoryMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<AdvancedGetMessageResult>>;
|
||||
sendMessage: (
|
||||
params: SendMsgParams,
|
||||
opid?: string
|
||||
) => Promise<BaseResponse<MessageItem>>;
|
||||
}
|
||||
86
src/core/modules/user.ts
Normal file
86
src/core/modules/user.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
import { BaseResponse, SelfUserInfo } from '@/types/entity';
|
||||
import OpenIMSDK from '..';
|
||||
import { SetSelfInfoParams } from '@/types/params';
|
||||
|
||||
export function setupUserModule(openIMSDK: OpenIMSDK) {
|
||||
return {
|
||||
getSelfUserInfo: (opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<SelfUserInfo>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.get_self_user_info(
|
||||
openIMSDK.baseCallbackWrap<SelfUserInfo>(resolve, reject),
|
||||
opid
|
||||
);
|
||||
}),
|
||||
|
||||
setSelfInfo: (params: SetSelfInfoParams, opid = uuidV4()) =>
|
||||
new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
openIMSDK.libOpenIMSDK.set_self_info(
|
||||
openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
opid,
|
||||
JSON.stringify(params)
|
||||
);
|
||||
}),
|
||||
|
||||
// getUsersInfoWithCache: (
|
||||
// params: GetUserInfoWithCacheParams,
|
||||
// opid = uuidV4()
|
||||
// ) =>
|
||||
// new Promise<BaseResponse<FullUserItemWithCache[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_users_info_with_cache(
|
||||
// openIMSDK.baseCallbackWrap<FullUserItemWithCache[]>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(params.userIDList),
|
||||
// params.groupID ?? ''
|
||||
// );
|
||||
// }),
|
||||
|
||||
// subscribeUsersStatus: (userIDList: string[], opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<UserOnlineState>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.subscribe_users_status(
|
||||
// openIMSDK.baseCallbackWrap<UserOnlineState>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(userIDList)
|
||||
// );
|
||||
// }),
|
||||
|
||||
// unsubscribeUsersStatus: (userIDList: string[], opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.unsubscribe_users_status(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// JSON.stringify(userIDList)
|
||||
// );
|
||||
// }),
|
||||
|
||||
// getSubscribeUsersStatus: (opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<UserOnlineState[]>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.get_subscribe_users_status(
|
||||
// openIMSDK.baseCallbackWrap<UserOnlineState[]>(resolve, reject),
|
||||
// opid
|
||||
// );
|
||||
// }),
|
||||
|
||||
// setAppBackgroundStatus: (isInBackground: boolean, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_app_background_status(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// isInBackground
|
||||
// );
|
||||
// }),
|
||||
|
||||
// setGlobalRecvMessageOpt: (msgReceiveOptType: MessageReceiveOptType, opid = uuidV4()) =>
|
||||
// new Promise<BaseResponse<void>>((resolve, reject) => {
|
||||
// openIMSDK.libOpenIMSDK.set_global_recv_message_opt(
|
||||
// openIMSDK.baseCallbackWrap<void>(resolve, reject),
|
||||
// opid,
|
||||
// msgReceiveOptType
|
||||
// );
|
||||
// }),
|
||||
};
|
||||
}
|
||||
|
||||
export interface UserModuleApi {
|
||||
getSelfUserInfo: (opid?: string) => Promise<BaseResponse<SelfUserInfo>>;
|
||||
}
|
||||
Reference in New Issue
Block a user