react-native-agora-chat
Version:
react native chat sdk
99 lines (95 loc) • 3.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ChatUserInfoManager = void 0;
var _Consts = require("./__internal__/Consts");
var _Native = require("./__internal__/Native");
var _ChatClient = require("./ChatClient");
var _ChatConst = require("./common/ChatConst");
var _ChatUserInfo = require("./common/ChatUserInfo");
/**
* The user information manager for updating and getting user attributes.
*/
class ChatUserInfoManager extends _Native.Native {
static TAG = 'ChatUserInfoManager';
constructor() {
super();
}
/**
* Modifies the user attributes of the current user.
*
* @params The parameter set.
* - [nickName] The nickname of the user.
* - [avatarUrl] The avatar URL of the user.
* - [mail] The email address of the user.
* - [phone] The phone number of the user.
* - [gender] The gender of the user. The value can only be `0`, `1`, or `2`. Other values are invalid.
* - `0`: (Default) Unknown;
* - `1`: Male;
* - `2`: Female.
* - [sign] The signature of the user.
* - [birth] The birthday of the user.
* - [ext] The custom extension information of the user. You can set it to an empty string or type custom information and encapsulate them as a JSON string.
*
* @throws A description of the exception. See {@link ChatError}.
*/
async updateOwnUserInfo(params) {
_ChatConst.chatlog.log(`${ChatUserInfoManager.TAG}: updateOwnUserInfo: `, params);
const userId = await _ChatClient.ChatClient.getInstance().getCurrentUsername();
const ret = await this.fetchUserInfoById([userId]);
if (ret.has(userId)) {
let userInfo = new _ChatUserInfo.ChatUserInfo(ret.get(userId));
userInfo = Object.assign(userInfo, params);
let r = await _Native.Native._callMethod(_Consts.MTupdateOwnUserInfo, {
[_Consts.MTupdateOwnUserInfo]: {
userInfo
}
});
ChatUserInfoManager.checkErrorFromResult(r);
}
}
/**
* Gets the user attributes of the specified users.
*
* @param userIds The user ID array.
* @returns A map that contains key-value pairs where the key is the user ID and the value is user attributes,see {@link ChatUserInfo}.
*
* @throws A description of the exception. See {@link ChatError}.
*/
async fetchUserInfoById(userIds) {
_ChatConst.chatlog.log(`${ChatUserInfoManager.TAG}: fetchUserInfoById: `, userIds);
let r = await _Native.Native._callMethod(_Consts.MTfetchUserInfoById, {
[_Consts.MTfetchUserInfoById]: {
userIds: userIds
}
});
ChatUserInfoManager.checkErrorFromResult(r);
const ret = new Map();
Object.entries(r === null || r === void 0 ? void 0 : r[_Consts.MTfetchUserInfoById]).forEach(value => {
const userInfo = new _ChatUserInfo.ChatUserInfo(value[1]);
ret.set(value[0], userInfo);
});
return ret;
}
/**
* Gets attributes of the current user from the server.
*
* @returns The obtained user attributes. See {@link ChatUserInfo}.
*
* @throws A description of the exception. See {@link ChatError}.
*/
async fetchOwnInfo() {
_ChatConst.chatlog.log(`${ChatUserInfoManager.TAG}: fetchOwnInfo: `);
const id = await _ChatClient.ChatClient.getInstance().getCurrentUsername();
if (id) {
const ret = await this.fetchUserInfoById([id]);
if (ret.size > 0) {
return ret.get(id);
}
}
return undefined;
}
}
exports.ChatUserInfoManager = ChatUserInfoManager;
//# sourceMappingURL=ChatUserInfoManager.js.map