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)
- .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>
- .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.username,
id: rosterInfo.user_id
};
});
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
};
});
// this.forwardMembers.groupps = [].concat(retObj);
context.commit('setGroupList', [].concat(retObj));
});
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;
rootState.im.rosterManage.asyncGetRosterInfo(state.sid).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(() => {
alert('好友已删除');
});
const also_delete_other_devices = true;
this.$store.getters.im.sysManage.deleteConversation(this.getSid, also_delete_other_devices);
this.$store.getters.im.rosterManage.asyncDeleteRoster({ user_id: this.getSid }).then(() => {
alert('好友已删除');
});
const also_delete_other_devices = true;
this.$store.getters.im.sysManage.deleteConversation(this.getSid, also_delete_other_devices);
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));
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.asnycGetRosterListDetailByIds(res).then(() => {
const allMaps = rootState.im.rosterManage.getAllRosterDetail() || {};
const retObj = res.map((i) => {
const rosterInfo = allMaps[i] || { user_id: i };
return {
name: rosterInfo.username,
id: rosterInfo.user_id
};
});
context.commit('setRosterList', [].concat(retObj));
});
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].alias || umaps[sx].username);
});
x.mentionStr = content;
const umaps = this.$store.getters.im.rosterManage.getAllRosterDetail();
const str = umaps[from].username + ' 在群中提到了您!';
this.mentionMessage = str;
const cuid = this.im.userManage.getUid();
const umaps = this.im.rosterManage.getAllRosterDetail();
const fromUid = toNumber(this.message.from);
const fromUserObj = umaps[fromUid] || {};
let username = fromUserObj.username || '';
let avatar = this.getImage({ url: fromUserObj.avatar, type: 'group' });
if (fromUid === cuid) {
username = '我';
}
return { username, avatar };
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.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.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;
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
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);
//do not read message sent by oneself
const im = this.$store.getters.im;
if (im) im.rosterManage.readRosterMessage(this.getSid, this.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);
//do not read message sent by oneself
const im = this.$store.getters.im;
if (im) im.rosterManage.readRosterMessage(this.getSid, this.message.id);
rosterManage.recallMessage(uid, mid)
撤回消息,只能撤回5分钟内的
Kind: static method of rosterManage
Param | Type | Description |
---|---|---|
uid | number |
会话ID |
mid | number |
消息ID |
Example
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.recallMessage(this.getSid, idStr);
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.recallMessage(this.getSid, idStr);
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.recallMessage(this.getSid, idStr);
rosterManage.unreadMessage(uid, mid)
设置消息成未读
Kind: static method of rosterManage
Param | Type | Description |
---|---|---|
uid | number |
会话ID |
mid | number |
消息ID |
Example
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.unreadMessage(this.getSid, idStr);
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.unreadMessage(this.getSid, idStr);
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.unreadMessage(this.getSid, idStr);
rosterManage.deleteMessage(uid, mid)
删除消息
Kind: static method of rosterManage
Param | Type | Description |
---|---|---|
uid | number |
会话ID |
mid | number |
消息ID |
Example
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.deleteMessage(this.getSid, idStr);
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.deleteMessage(this.getSid, idStr);
const idStr = numToString(this.message.id).toString();
this.im.rosterManage.deleteMessage(this.getSid, idStr);
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 app_id = this.$store.state.im.userManage.getAppid();
const uid = this.$store.state.im.userManage.getUid();
const rInfo = this.$store.state.im.rosterManage.getRosterInfo(uid);
const info = this.getCallInviteInfo;
if (info) {
this.refreshUserInfo(info.initiator);
this.$store.getters.im.rtcManage.joinRoom({
server: this.$store.state.im.sysManage.getServers(app_id).rtc,
id: this.$store.state.im.userManage.getUid(),
roomId: info.roomId,
caller: false,
pin: info.pin,
hasVideo: false,
hasAudio: true,
remoteAudio: document.getElementById('roster_remote_only_audio'),
getThrough: this.getThrough,
hangupCall: this.hangupCall
});
} else {
this.refreshUserInfo(this.getSid);
this.$store.getters.im.rtcManage.initRTCEngine({
server: this.$store.state.im.sysManage.getServers(app_id).rtc,
id: this.$store.state.im.userManage.getUid(),
nam...
const app_id = this.$store.state.im.userManage.getAppid();
const uid = this.$store.getters.im.userManage.getUid();
const rInfo = this.$store.getters.im.rosterManage.getRosterInfo(uid);
const info = this.getCallInviteInfo;
if (info) {
this.refreshUserInfo(info.initiator);
this.$store.getters.im.rtcManage.joinRoom({
server: this.$store.state.im.sysManage.getServers(app_id).rtc,
id: this.$store.state.im.userManage.getUid(),
roomId: info.roomId,
caller: false,
pin: info.pin,
hasVideo: true,
hasAudio: true,
width: 360,
height: 640,
localVideo: document.getElementById('roster_local_video'),
remoteVideo: document.getElementById('roster_remote_video'),
remoteAudio: document.getElementById('roster_remote_audio'),
getThrough: this.getThrough,
hangupCall: this.hangupCall
});
} else {
this.refreshUserInfo(this.getSid);
this.$stor...
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 content = item.content;
const timestamp = item.timestamp;
// const img = allRosterMap[id] && allRosterMap[id].avatar;
let avatar = ''; //(img && this.client.signatureUrl(img, { expires: 600, process: 'image/resize,w_50' })) || '/image/roster.png';
const unreadCount = item.type == 'roster' ? rootState.im.rosterManage.getUnreadCount(id) : rootState.im.groupManage.getUnreadCount(id);
const unread = unreadCount > 0 ? unreadCount : 0;
totalUnreadCount += unread;
if (item.type === 'roster') {
//roster
const sroster = allRosterMap[id] || {};
name = sroster.nick_name || sroster.username || id;
avatar = sroster.avatar;
} else if (item.type === 'group') {
//group
const sgroup = allGroupMap[id] || {};
name = sgroup.name || id;
avatar = sgroup.avatar;
}
avatar = rootState.im.sysManage.getImage({
avatar,
...
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
const { user_id, username } = this.userInfo;
const alias = username;
this.$store.getters.im.rosterManage.asyncApply({ user_id, alias }).then(() => {
alert('请求已发送成功!');
});
const { user_id, username } = this.searchResult;
const alias = this.alias || username;
this.$store.getters.im.rosterManage.asyncApply({ user_id, alias }).then(() => {
alert('请求已发送成功!');
});
const { user_id, username } = this.userInfo;
const alias = username;
this.$store.getters.im.rosterManage.asyncApply({ user_id, alias }).then(() => {
alert('请求已发送成功!');
});
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.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.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.alias | string |
备注名称 |
params.mute_notification | boolean |
是否接收消息提醒 |
Example
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;
});
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;
});