rosterManage

rosterManage

好友管理

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.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.getImage({
      ...

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, true).then((res) => {
  context.commit('setRosterInfo', res);
});
this.$store.getters.im.rosterManage.asyncGetRosterInfo(this.getApp().getLinkUid(), true).then((res) => {
  this.parseManufacturer();
});

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.nick_name || rosterInfo.username || rosterInfo.user_id,
      id: rosterInfo.user_id,
      avatar: rootState.im.sysManage.getImage({
        avatar: rosterInfo.avatar
      })
    };
  });
  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].nick_name || umaps[sx].username);
});
x.mentionStr = content;
      const cuid = this.im.userManage.getUid();
      const umaps = this.im.rosterManage.getAllRosterDetail();
      const fromUid = toNumber(this.message.from);
      const fromUserObj = umaps[fromUid] || {};
      let username = '';
      let has_nick = false;
      for (let i = 0; i < this.getMemberList.length; i++) {
        if (this.getMemberList[i].user_id === fromUid) {
          username = this.getMemberList[i].display_name;
          has_nick = this.getMemberList[i].has_nick;
          break;
        }
      }
      let avatar = this.im.sysManage.getImage({ avatar: fromUserObj.avatar });
      if (fromUid === cuid) {
        username = '我';
        avatar = this.im.sysManage.getImage({ avatar: this.getUserProfile.avatar });
      } else if (this.checkHideMemberInfo(fromUid) && !has_nick) {
        let original = username + fromUid;
        const md5hash = CryptoJS.MD5(original);
        let output = md5hash.toString(CryptoJS.enc.Base64);
        if (output.length > 12) {
...
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.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.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.nick_name || suser.username || r.user_id;
});
this.notices = res;
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.im.sysManage.getImage({ avatar: fromUserObj.avatar });

if (fromUid === cuid) {
  username = '我';
  avatar = this.im.sysManage.getImage({ avatar: this.getUserProfile.avatar });
} else if (0 == fromUid) {
  username = this.system_roster.name;
  avatar = this.system_roster.avatar;
}
return { username, avatar };

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);

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);
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);

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...
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) {
    //
  }
}
 let info = this.$store.getters.im.rosterManage.getRosterInfo(this.getApp().getLinkUid());
 if (info && info.public_info) {
   try {
     let public_info = JSON.parse(info.public_info);
     if (!public_info.manufacturer) {
       this.initAvatar();
     } else {
       //console.log('Use manufacturer:', JSON.stringify(public_info.manufacturer));
       this.manufacturer = this.mergeJson(this.manufacturer, public_info.manufacturer);
       if (!public_info.manufacturer.bussiness) {
         this.manufacturer.bussiness = {};
       }
       if (!public_info.manufacturer.wechat) {
         this.manufacturer.wechat = {};
       }
       //console.log('mergeJson finish:', JSON.stringify(this.manufacturer));
       this.initAvatar();
       this.hasParseManufacturer = true;
     }
   } catch (ex) {
     this.initAvatar();
   }
...

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 hasAt = item.hasAt;
// 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.g...
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.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.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

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;
});

© 2019-2024 美信拓扑 | 官网 | 网站地图 该文件修订时间: 2024-12-07 06:49:06