rosterManage
rosterManage
好友管理
- rosterManage
- .asyncGetRosterIdList(force) ⇒
Promise.<Array.<number>> - .asyncGetRosterInfo(roster_id, force) ⇒
Promise.<RosterItem> - .asyncDeleteRoster(param) ⇒
Promise.<boolean> - .asnycGetRosterListDetailByIds(roster_ids) ⇒
Promise.<Array.<module:types~RosterItem>> - .getAllRosterDetail() ⇒
Array.<RosterItem> - .asyncGetUserProfile(force) ⇒
Promise.<UserProfile> - .getRosterMessageByRid(uid) ⇒
Array.<Meta> - .readRosterMessage(roster_id, mid)
- .recallMessage(uid, mid)
- .unreadMessage(uid, mid)
- .deleteMessage(uid, mid)
- .appendMessageContent(uid, mid, content)
- .replaceMessage(uid, mid, content, config, ext)
- .getRosterInfo(rid) ⇒
RosterItem - .getUnreadCount(uid) ⇒
number - .asyncGetApplyList(params) ⇒
Promise.<Array.<module:types~RosterApplication>> - .asyncGetBlockedlist(params) ⇒
Promise.<Array.<number>> - .asyncBlockeAdd(params) ⇒
Promise.<boolean> - .asyncBlockeRemove(params) ⇒
Promise.<boolean> - .asyncApply(params) ⇒
Promise.<boolean> - .asyncAccept(params) ⇒
Promise.<boolean> - .asyncDecline(params) ⇒
Promise.<boolean> - .asyncUpdateRosterExt(params) ⇒
Promise.<boolean> - .asyncUpdateRosterAlias(params) ⇒
Promise.<boolean> - .asyncSearchRosterByName(params) ⇒
Promise.<RosterItem> - .asyncSearchRosterById(params) ⇒
Promise.<RosterItem>
- .asyncGetRosterIdList(force) ⇒
rosterManage.asyncGetRosterIdList(force) ⇒ Promise.<Array.<number>>
获取好友id列表
Kind: static method of rosterManage
Returns: Promise.<Array.<number>> - 用户ID列表
| Param | Type | Description |
|---|---|---|
| force | boolean |
是否强制从服务器拉取:true - 从服务器获取, false - 从本地存储获取 |
Example
this.im.rosterManage.asyncGetRosterIdList().then((res) => {
this.rosters = res;
});contactRequestFlag.rosterList = true;
rootState.im.rosterManage.asyncGetRosterIdList().then((res) => {
rootState.im.rosterManage.asnycGetRosterListDetailByIds(res).then(() => {
const allMaps = rootState.im.rosterManage.getAllRosterDetail() || {};
const retObj = res.map((i) => {
const rosterInfo = allMaps[i] || { user_id: i };
rosterInfo.avatar = rootState.im.sysManage.getImage({
avatar: rosterInfo.avatar
});
const unreadCount = rootState.im.rosterManage.getUnreadCount(i);
return Object.assign(
{
unreadCount
},
rosterInfo
);
});
context.commit('setRosterList', retObj);
contactRequestFlag.rosterList = false;
});
});rootState.im.rosterManage.asyncGetRosterIdList().then((res) => {
rootState.im.rosterManage.asnycGetRosterListDetailByIds(res).then(() => {
const allMaps = rootState.im.rosterManage.getAllRosterDetail() || {};
const retObj = res.map((i) => {
const rosterInfo = allMaps[i] || { user_id: i };
return {
name: rosterInfo.alias || rosterInfo.nick_name || rosterInfo.username || rosterInfo.user_id,
id: rosterInfo.user_id,
avatar: rootState.im.sysManage.getImage({
avatar: rosterInfo.avatar
})
};
});
context.commit('setRosterList', [].concat(retObj));
});
});
rootState.im.groupManage.asyncGetJoinedGroups(/**true**/).then((res) => {
res = res || [];
const retObj = res.map((i) => {
return {
name: i.name,
id: i.group_id,
avatar: rootState.im.sysManage.get...
rosterManage.asyncGetRosterInfo(roster_id, force) ⇒ Promise.<RosterItem>
获取好友信息
Kind: static method of rosterManage
Returns: Promise.<RosterItem> - 好友信息
| Param | Type | Description |
|---|---|---|
| roster_id | number |
好友ID |
| force | boolean |
是否强制从服务器拉取: true - 从服务器拉取, false - 优先从本地存储获取 |
Example
const { rootState, state } = context;
if (state.sid === 0) {
context.commit('setRosterInfo', {
user_id: 0,
username: t('系统通知'),
nick_name: t('系统通知'),
alias: '',
avatar: '/image/setting.png'
});
return;
}
rootState.im.rosterManage.asyncGetRosterInfo(state.sid, true).then((res) => {
context.commit('setRosterInfo', res);
});
rosterManage.asyncDeleteRoster(param) ⇒ Promise.<boolean>
删除好友
Kind: static method of rosterManage
Returns: Promise.<boolean> - 请求结果
| Param | Type | Description |
|---|---|---|
| param | object |
参数 |
| param.user_id | number |
好友的用户ID |
Example
this.$store.getters.im.rosterManage.asyncDeleteRoster({ user_id: this.getSid }).then(() => {
const also_delete_other_devices = true;
this.$store.getters.im.sysManage.deleteConversation(this.getSid, also_delete_other_devices);
this.$store.dispatch('contact/actionGetConversationList');
this.$store.dispatch('content/actionSetType', {
sid: undefined,
type: ''
});
this.$message.success(this.$t('好友已删除'));
});this.$store.getters.im.rosterManage.asyncDeleteRoster({ user_id: this.getSid }).then(() => {
const also_delete_other_devices = true;
this.$store.getters.im.sysManage.deleteConversation(this.getSid, also_delete_other_devices);
this.$store.dispatch('contact/actionGetConversationList');
this.$store.dispatch('content/actionSetType', {
sid: undefined,
type: ''
});
this.$message.success(this.$t('好友已删除'));
});
rosterManage.asnycGetRosterListDetailByIds(roster_ids) ⇒ Promise.<Array.<module:types~RosterItem>>
根据id列表获取用户详细信息
Kind: static method of rosterManage
Returns: Promise.<Array.<module:types~RosterItem>> - 用户详细信息列表
| Param | Type | Description |
|---|---|---|
| roster_ids | Array.<number> |
用户ID列表 |
Example
this.im.rosterManage.asnycGetRosterListDetailByIds(rosterIds).then(() => {
this.dealNoticeList(applicationlist);
});promistAllAarr.push(this.im.rosterManage.asnycGetRosterListDetailByIds(rosterIds));requests.push(im.rosterManage.asnycGetRosterListDetailByIds(uniqueRosterIds));rootState.im.rosterManage.asnycGetRosterListDetailByIds(res).then(() => {
const allMaps = rootState.im.rosterManage.getAllRosterDetail() || {};
const retObj = res.map((i) => {
const rosterInfo = allMaps[i] || { user_id: i };
rosterInfo.avatar = rootState.im.sysManage.getImage({
avatar: rosterInfo.avatar
});
const unreadCount = rootState.im.rosterManage.getUnreadCount(i);
return Object.assign(
{
unreadCount
},
rosterInfo
);
});
context.commit('setRosterList', retObj);
contactRequestFlag.rosterList = false;
});
rosterManage.getAllRosterDetail() ⇒ Array.<RosterItem>
获取缓存的所有用户详细信息
Kind: static method of rosterManage
Returns: Array.<RosterItem> - 用户详细信息列表
Example
// 如果有mention的
// const uid = im.userManage.getUid();
const umaps = this.im.rosterManage.getAllRosterDetail();
// const fromUid = toNumber(from.uid);
// const hasIndex = sa.mentionList.findIndex(x => x + '' === uid + '');
// if (hasIndex > -1) {
// fire('groupMention', { uid: fromUid });
// }
config.mentionList.forEach((sx) => {
content = content.replace('{' + sx + '}', umaps[sx].nick_name || umaps[sx].username);
});
x.mentionStr = content;const allRosterMap = this.im.rosterManage.getAllRosterDetail();
const rosterIds = [];
applicationlist.forEach((x) => {
const { applicant_id } = x;
if (allRosterMap[applicant_id] && allRosterMap[applicant_id].username) {
//
} else {
rosterIds.push(applicant_id);
}
});
if (rosterIds.length) {
this.im.rosterManage.asnycGetRosterListDetailByIds(rosterIds).then(() => {
this.dealNoticeList(applicationlist);
});
} else {
this.dealNoticeList(applicationlist);
}const rmap = this.im.rosterManage.getAllRosterDetail();
const gmap = this.im.groupManage.getAllGroupDetail();
const sret = applicationlist.map((item) => {
const { status, group_id, applicant_id, expired_time, reason } = item;
const suser = rmap[applicant_id] || {};
const user_name = suser.alias || suser.nick_name || suser.username || item.inviter_id;
const sgroup = gmap[group_id] || {};
const group_name = sgroup.name || item.group_id;
return {
user_name,
group_name,
group_id,
expired_time,
applicant_id,
status,
reason
};
});
this.notices = sret;const allRosterMap = this.im.rosterManage.getAllRosterDetail();
const allGroupMap = this.im.groupManage.getAllGroupDetail();
const rosterIds = [];
const groupIds = [];
applicationlist.forEach((x) => {
const { inviter_id, group_id } = x;
if (allRosterMap[inviter_id] && allRosterMap[inviter_id].username) {
//
} else {
rosterIds.push(inviter_id);
}
if (!allGroupMap[group_id]) {
groupIds.push(group_id);
}
});
const promistAllAarr = [];
if (groupIds.length) {
promistAllAarr.push(this.im.groupManage.asyncGetGroupListDetail(groupIds));
}
if (groupIds.length) {
promistAllAarr.push(this.im.rosterManage.asnycGetRosterListDetailByIds(rosterIds));
}
if (promistAllAarr.length) {
Promise.all(promistAllAarr).then(() => {
this.dealNoticeList(applicationlist);
});
} else {
this.dealNoticeLis...const rmap = this.im.rosterManage.getAllRosterDetail();
const gmap = this.im.groupManage.getAllGroupDetail();
const sret = applicationlist.map((item) => {
const { group_id, inviter_id, expired_time, status } = item;
const suser = rmap[inviter_id] || {};
const user_name = suser.alias || suser.nick_name || suser.username || item.inviter_id;
const sgroup = gmap[group_id] || {};
const group_name = sgroup.name || item.group_id;
return {
user_name,
group_name,
group_id,
expired_time,
user_id: inviter_id,
status
};
});
this.notices = sret;const rosterMaps = this.im.rosterManage.getAllRosterDetail();
res.forEach((r) => {
const suser = rosterMaps[r.user_id] || {};
r.user_name = suser.alias || suser.nick_name || suser.username || r.user_id;
});
this.notices = res;const im = this.im;
if (!im || !Array.isArray(items) || !items.length) {
return Promise.resolve();
}
const rosterMap = im.rosterManage.getAllRosterDetail() || {};
const groupMap = im.groupManage.getAllGroupDetail() || {};
const rosterIds = [];
const groupIds = [];
items.forEach((item) => {
const payload = item.payload || {};
const fromUid = payload.from && typeof payload.from.uid !== 'undefined' ? Number(payload.from.uid) : 0;
const to = Array.isArray(payload.to) ? payload.to : [];
const gid = payload.gid && typeof payload.gid.uid !== 'undefined' ? Number(payload.gid.uid) : 0;
if (fromUid > 0 && !(rosterMap[fromUid] && rosterMap[fromUid].username)) {
rosterIds.push(fromUid);
}
to.forEach((entry) => {
const uid = entry && typeof entry.uid !== 'undefined' ? Number(entry.uid) : 0;
if (uid > 0 && !(rosterMap[uid] && rosterMap[uid].username)) ...
rosterManage.asyncGetUserProfile(force) ⇒ Promise.<UserProfile>
获取自己的用户信息
Kind: static method of rosterManage
Returns: Promise.<UserProfile> - 用户信息
| Param | Type | Description |
|---|---|---|
| force | boolean |
是否强制从服务器拉取: true - 从服务器拉取, false - 优先从本地存储获取 |
Example
rosterManage.getRosterMessageByRid(uid) ⇒ Array.<Meta>
根据会话ID获取聊天消息
Kind: static method of rosterManage
Returns: Array.<Meta> - 聊天消息列表
| Param | Type | Description |
|---|---|---|
| uid | number |
会话ID |
Example
const fallbackMessages = item.type === 'roster' ? rootState.im.rosterManage.getRosterMessageByRid(id) : rootState.im.groupManage.getGruopMessage(id);
fallbackPreview = deriveRecentPreviewFromMessage(fallbackMessages && fallbackMessages.length ? fallbackMessages[fallbackMessages.length - 1] : null);localMessages = rootState.im.rosterManage.getRosterMessageByRid(state.sid);
rosterManage.readRosterMessage(roster_id, mid)
修改消息状态为已读
Kind: static method of rosterManage
| Param | Type | Description |
|---|---|---|
| roster_id | number |
会话ID |
| mid | number |
消息ID: 如果不设置 表示把这个会话所有消息设为已读 |
Example
//do not read message sent by oneself
this.$store.getters.im.rosterManage.readRosterMessage(this.getSid, message.id);this.$store.state.im.rosterManage.readRosterMessage(fromUid, message.id);//do not read message sent by oneself
this.$store.getters.im.rosterManage.readRosterMessage(this.getSid, message.id);
rosterManage.recallMessage(uid, mid)
撤回消息,只能撤回5分钟内的
Kind: static method of rosterManage
| Param | Type | Description |
|---|---|---|
| uid | number |
会话ID |
| mid | number |
消息ID |
Example
rosterManage.unreadMessage(uid, mid)
设置消息成未读
Kind: static method of rosterManage
| Param | Type | Description |
|---|---|---|
| uid | number |
会话ID |
| mid | number |
消息ID |
Example
rosterManage.deleteMessage(uid, mid)
删除消息
Kind: static method of rosterManage
| Param | Type | Description |
|---|---|---|
| uid | number |
会话ID |
| mid | number |
消息ID |
Example
rosterManage.appendMessageContent(uid, mid, content)
追加消息内容
Kind: static method of rosterManage
| Param | Type | Description |
|---|---|---|
| uid | number |
会话ID |
| mid | number |
消息ID |
| content | string |
消息追加内容 |
Example
rosterManage.replaceMessage(uid, mid, content, config, ext)
更新消息内容
Kind: static method of rosterManage
| Param | Type | Default | Description |
|---|---|---|---|
| uid | number |
会话ID | |
| mid | number |
消息ID | |
| content | string |
消息更新内容 | |
| config | string | object |
null |
消息更新配置 |
| ext | string | object |
null |
消息更新扩展信息 |
Example
rosterManage.getRosterInfo(rid) ⇒ RosterItem
获取好友信息
Kind: static method of rosterManage
Returns: RosterItem - 好友信息
| Param | Type | Description |
|---|---|---|
| rid | number |
好友ID |
Example
//mention消息
/**
static const std::string kMentionAll = “mentionAll”; // bool
static const std::string kMentionList = “mentionList”; // vector<int64_t>
static const std::string kMentionedMessage = “mentionedMessage”; // string
static const std::string kPushMessage = “pushMessage”; // string
static const std::string kSenderNickname = “senderNickname”; // string
*/
const mentionAll = false;
const mentionList = this.mentionSelectedUids.map((x) => x - 0);
const mentionedMessage = '';
const pushMessage = '';
const uid = this.im.userManage.getUid();
const rInfo = this.im.rosterManage.getRosterInfo(uid);
const senderNickname = rInfo.username || rInfo.user_id + '';
this.im.sysManage.sendMentionMessage({
gid: this.getSid,
// txt: this.willsendMessage,
txt: this.message,
mentionAl...const cachedInfo = this.$store.getters.im.rosterManage.getRosterInfo(userId) || {};
const deletedStatusText = err.code === USER_NOT_EXIST_ERROR_CODE ? this.$t('用户不存在') : this.$t('用户已注销');
return Object.assign({}, cachedInfo, {
user_id: userId,
is_deleted: true,
deleted_status_text: deletedStatusText,
avatar: this.$store.getters.im.sysManage.getImage({
avatar: cachedInfo.avatar,
type: 'roster'
})
});const cachedInfo = this.$store.getters.im.rosterManage.getRosterInfo(userId) || {};
const deletedStatusText = err.code === USER_NOT_EXIST_ERROR_CODE ? this.$t('用户不存在') : this.$t('用户已注销');
return Object.assign({}, cachedInfo, {
user_id: userId,
is_deleted: true,
deleted_status_text: deletedStatusText,
avatar: this.$store.getters.im.sysManage.getImage({
avatar: cachedInfo.avatar,
type: 'roster'
})
});let info = this.$store.getters.im.rosterManage.getRosterInfo(this.getApp().getLinkUid());
if (info && info.public_info) {
let jManufacturer = {};
try {
jManufacturer = JSON.parse(info.public_info);
if (jManufacturer && jManufacturer.manufacturer && jManufacturer.manufacturer.avatar) {
this.avatar = jManufacturer.manufacturer.avatar;
this.parseAvatar = true;
}
} catch (ex) {
//
}
}
rosterManage.getUnreadCount(uid) ⇒ number
获取指定会话的未读数
Kind: static method of rosterManage
Returns: number - 未读数
| Param | Type | Description |
|---|---|---|
| uid | number |
会话ID |
Example
let name;
const id = item.id;
const draft = typeof item.draft === 'string' ? item.draft : '';
const hasDraft = !!draft.trim();
const needsFallbackContent = !hasDraft && !item.content;
const needsFallbackTimestamp = (!hasDraft && !item.timestamp) || (hasDraft && !item.draftTimestamp && !item.timestamp);
let fallbackPreview = {
content: '',
timestamp: ''
};
if (needsFallbackContent || needsFallbackTimestamp) {
const fallbackMessages = item.type === 'roster' ? rootState.im.rosterManage.getRosterMessageByRid(id) : rootState.im.groupManage.getGruopMessage(id);
fallbackPreview = deriveRecentPreviewFromMessage(fallbackMessages && fallbackMessages.length ? fallbackMessages[fallbackMessages.length - 1] : null);
}
const content = hasDraft ? draft : item.content || fallbackPreview.content;
const timestamp = hasDraft ? item.draftTimestamp || item.timestamp || fallbackPreview.timestamp : ite...const rosterInfo = allMaps[i] || { user_id: i };
rosterInfo.avatar = rootState.im.sysManage.getImage({
avatar: rosterInfo.avatar
});
const unreadCount = rootState.im.rosterManage.getUnreadCount(i);
return Object.assign(
{
unreadCount
},
rosterInfo
);
rosterManage.asyncGetApplyList(params) ⇒ Promise.<Array.<module:types~RosterApplication>>
获取好友申请列表
Kind: static method of rosterManage
Returns: Promise.<Array.<module:types~RosterApplication>> - 好友申请列表
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.cursor | number |
从哪开始获取:可以传空字符串表示从头开始取 |
Example
this.im.rosterManage.asyncGetApplyList({ cursor: '' }).then((res = []) => {
const rosterMaps = this.im.rosterManage.getAllRosterDetail();
res.forEach((r) => {
const suser = rosterMaps[r.user_id] || {};
r.user_name = suser.alias || suser.nick_name || suser.username || r.user_id;
});
this.notices = res;
});
rosterManage.asyncGetBlockedlist(params) ⇒ Promise.<Array.<number>>
获取黑名单
Kind: static method of rosterManage
Returns: Promise.<Array.<number>> - 用户ID列表
| Param | Type | Description |
|---|---|---|
| params | object |
参数:空对象 |
Example
rosterManage.asyncBlockeAdd(params) ⇒ Promise.<boolean>
加入黑名单
Kind: static method of rosterManage
Returns: Promise.<boolean> - 是否成功
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
Example
rosterManage.asyncBlockeRemove(params) ⇒ Promise.<boolean>
移除黑名单
Kind: static method of rosterManage
Returns: Promise.<boolean> - 是否成功
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
Example
rosterManage.asyncApply(params) ⇒ Promise.<boolean>
请求加为好友
Kind: static method of rosterManage
Returns: Promise.<boolean> - 是否成功
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
| params.alias | string |
备注 |
Example
if (this.isDeletedUser) return;
const { user_id } = this.userInfo;
const alias = '';
this.$store.getters.im.rosterManage.asyncApply({ user_id, alias }).then(() => {
alert(this.$t('请求已发送成功!'));
});const { user_id } = this.searchResult;
const alias = this.alias;
this.$store.getters.im.rosterManage.asyncApply({ user_id, alias }).then(() => {
alert(this.$t('请求已发送成功!'));
this.clickAddrosterCloseHandler();
});if (this.isDeletedUser) return;
const { user_id } = this.userInfo;
const alias = '';
this.$store.getters.im.rosterManage.asyncApply({ user_id, alias }).then(() => {
alert(this.$t('请求已发送成功!'));
});
rosterManage.asyncAccept(params) ⇒ Promise.<boolean>
通过好友申请
Kind: static method of rosterManage
Returns: Promise.<boolean> - 是否成功
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
Example
this.im.rosterManage.asyncAccept({ user_id }).then(() => {
alert(this.$t('您已通过该好友的申请'));
this.requireNotice();
});
rosterManage.asyncDecline(params) ⇒ Promise.<boolean>
拒绝好友申请
Kind: static method of rosterManage
Returns: Promise.<boolean> - 是否成功
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
Example
this.im.rosterManage.asyncDecline({ user_id }).then(() => {
alert(this.$t('您已拒绝该好友的申请'));
this.requireNotice();
});
rosterManage.asyncUpdateRosterExt(params) ⇒ Promise.<boolean>
修改好友扩展字段
Kind: static method of rosterManage
Returns: Promise.<boolean> - 是否成功
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
| params.ext | string |
扩展字段 |
| params.mute_notification | boolean |
是否接收消息提醒 |
Example
rosterManage.asyncUpdateRosterAlias(params) ⇒ Promise.<boolean>
修改好友扩展别名字段
Kind: static method of rosterManage
Returns: Promise.<boolean> - 是否成功
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
| params.alias | string |
备注名称 |
| params.mute_notification | boolean |
是否接收消息提醒 |
Example
if (!value) {
value = '';
}
im.rosterManage.asyncUpdateRosterAlias({ user_id: this.userInfo.user_id, alias: value }).then(() => {
this.refreshUserInfo(this.getSid);
this.$message.success(this.$t('修改成功'));
});if (!value) {
value = '';
}
im.rosterManage.asyncUpdateRosterAlias({ user_id: this.userInfo.user_id, alias: value }).then(() => {
this.refreshUserInfo(this.getSid);
this.$message.success(this.$t('修改成功'));
});
rosterManage.asyncSearchRosterByName(params) ⇒ Promise.<RosterItem>
按名称搜索用户
Kind: static method of rosterManage
Returns: Promise.<RosterItem> - 用户信息
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.username | string |
用户名 |
Example
rosterManage.asyncSearchRosterById(params) ⇒ Promise.<RosterItem>
按ID搜索用户
Kind: static method of rosterManage
Returns: Promise.<RosterItem> - 用户信息
| Param | Type | Description |
|---|---|---|
| params | object |
参数 |
| params.user_id | number |
用户ID |
Example
this.$store.getters.im.rosterManage.asyncSearchRosterById({ user_id: newSid }).then((res) => {
res.avatar = this.$store.getters.im.sysManage.getImage({
avatar: res.avatar,
type: 'roster'
});
this.userInfo = res;
});this.$store.getters.im.rosterManage.asyncSearchRosterById({ user_id: newSid }).then((res) => {
res.avatar = this.$store.getters.im.sysManage.getImage({
avatar: res.avatar,
type: 'roster'
});
this.userInfo = res;
});this.$store.getters.im.rosterManage.asyncSearchRosterById({ user_id: newSid }).then((res) => {
res.avatar = this.$store.getters.im.sysManage.getImage({
avatar: res.avatar,
type: 'roster'
});
this.userInfo = res;
});
