rosterManage

rosterManage

Friend management

rosterManage.asyncGetRosterIdList(force) ⇒ Promise.<Array.<number>>

Get friend id list

Kind: static method of rosterManage
Returns: Promise.<Array.<number>> - List of user IDs

Param Type Description
force boolean Whether to force pull from server: true - pull from server, false - pull from local storage

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>

Get friend information

Kind: static method of rosterManage
Returns: Promise.<RosterItem> - Friend info

Param Type Description
roster_id number Friend ID
force boolean Whether to force pull from server: true - pull from server, false - prefer to pull from local storage

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>

Delete friend

Kind: static method of rosterManage
Returns: Promise.<boolean> - Request results

Param Type Description
param object Parameter
param.user_id number Friend's user 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>>

Get user details by id list

Kind: static method of rosterManage
Returns: Promise.<Array.<module:types~RosterItem>> - List of user details

Param Type Description
roster_ids Array.<number> List of user IDs

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>

Get all cached user details

Kind: static method of rosterManage
Returns: Array.<RosterItem> - List of user details
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>

Get your own user info

Kind: static method of rosterManage
Returns: Promise.<UserProfile> - User information

Param Type Description
force boolean Whether to force pull from server: true - pull from server, false - prefer to pull from local storage

Example

rosterManage.getRosterMessageByRid(uid) ⇒ Array.<Meta>

Get chat messages based-on session ID

Kind: static method of rosterManage
Returns: Array.<Meta> - List of chat messages

Param Type Description
uid number SessionID

Example

localMessages = rootState.im.rosterManage.getRosterMessageByRid(state.sid);

rosterManage.readRosterMessage(roster_id, mid)

Modify message status to read

Kind: static method of rosterManage

Param Type Description
roster_id number SessionID
mid number MessageID

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)

Revoke a message, only valid for last 5 minutes

Kind: static method of rosterManage

Param Type Description
uid number SessionID
mid number MessageID

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)

Set message to unread

Kind: static method of rosterManage

Param Type Description
uid number SessionID
mid number MessageID

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)

Delete message

Kind: static method of rosterManage

Param Type Description
uid number SessionID
mid number MessageID

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.getRosterInfo(rid) ⇒ RosterItem

Get friend information

Kind: static method of rosterManage
Returns: RosterItem - Friend info

Param Type Description
rid number Friend 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

Get the number of unread messages for a given conversation

Kind: static method of rosterManage
Returns: number - Number of unreads

Param Type Description
uid number SessionID

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

Get friend request list

Kind: static method of rosterManage
Returns: Promise.<Array.<module:types~RosterApplication>> - List of friend requests

Param Type Description
params object Parameter
params.cursor number Get from where: you can pass an empty string to get from the beginning

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

Get blacklist

Kind: static method of rosterManage
Returns: Promise.<Array.<number>> - List of user IDs

Param Type Description
params object Parameter:Empty object

Example

rosterManage.asyncBlockeAdd(params) ⇒ Promise.<boolean>

Add to blacklist

Kind: static method of rosterManage
Returns: Promise.<boolean> - Success or not

Param Type Description
params object Parameter
params.user_id number User ID

Example

rosterManage.asyncBlockeRemove(params) ⇒ Promise.<boolean>

Remove blacklist

Kind: static method of rosterManage
Returns: Promise.<boolean> - Success or not

Param Type Description
params object Parameter
params.user_id number User ID

Example

rosterManage.asyncApply(params) ⇒ Promise.<boolean>

Request to add friend

Kind: static method of rosterManage
Returns: Promise.<boolean> - Success or not

Param Type Description
params object Parameter
params.user_id number User ID
params.alias string Comment

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>

Approve add-friend request

Kind: static method of rosterManage
Returns: Promise.<boolean> - Success or not

Param Type Description
params object Parameter
params.user_id number User ID

Example

this.im.rosterManage.asyncAccept({ user_id }).then(() => {
  alert('您已通过该好友的申请');
  this.requireNotice();
});

rosterManage.asyncDecline(params) ⇒ Promise.<boolean>

Reject friend request

Kind: static method of rosterManage
Returns: Promise.<boolean> - Success or not

Param Type Description
params object Parameter
params.user_id number User ID

Example

this.im.rosterManage.asyncDecline({ user_id }).then(() => {
  alert('您已拒绝该好友的申请');
  this.requireNotice();
});

rosterManage.asyncUpdateRosterExt(params) ⇒ Promise.<boolean>

Modify the Friend extension field

Kind: static method of rosterManage
Returns: Promise.<boolean> - Success or not

Param Type Description
params object Parameter
params.user_id number User ID
params.ext string Extension field
params.alias string Name in comment
params.mute_notification boolean Whether to receive message alert

Example

rosterManage.asyncSearchRosterByName(params) ⇒ Promise.<RosterItem>

Search for user by name

Kind: static method of rosterManage
Returns: Promise.<RosterItem> - User information

Param Type Description
params object Parameter
params.username string Username

Example

rosterManage.asyncSearchRosterById(params) ⇒ Promise.<RosterItem>

Search for user by ID

Kind: static method of rosterManage
Returns: Promise.<RosterItem> - User information

Param Type Description
params object Parameter
params.user_id number User 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 MaximTop | Homepage | Site Map Last modified time: 2024-12-07 06:49:06