sysManage

sysManage

sysManage.sendRosterMessage(msg) ⇒ number

发送单聊消息

Kind: static method of sysManage
Returns: number - 客户端生成的消息ID

Param Type Description
msg object 消息体
msg.uid string 接收者ID
msg.content string 消息内容
msg.type string 消息类型: text - 文本, image - 图片, audio - 语音, video - 视频,file - 文件, location - 位置, command - 命令, forward - 转发
msg.ext string | object 扩展字段
msg.attachment string | object 附件信息

Example

const message = {
  uid: this.getSid,
  content: '',
  type: 'location',
  attachment: {
    lat: 40.024422,
    lon: 116.398376,
    addr: '奥林匹克森林公园'
  }
};
this.im.sysManage.sendRosterMessage(message);
if (/^\s*$/.test(this.message)) {
  this.message = '';
  return;
}

// 如果需要自定义消息,直接使用 ext 字段即可
this.im.sysManage.sendRosterMessage({
  content: this.message,
  uid: this.getSid
  // ext: "自定义消息字段",
});
setTimeout(() => {
  this.message = '';
}, 200);
const fileInfo = {
  dName: file.name,
  fLen: file.size,
  width: 0,
  height: 0
};
fileInfo.url = res.url;
this.im.sysManage.sendRosterMessage({
  type: this.fileType,
  uid: this.getSid,
  content: '',
  attachment: fileInfo
});
this.$refs.fileRef.value = '';
const message = {
  uid: this.getSid,
  content: '',
  type: 'location',
  attachment: {
    lat: 40.024422,
    lon: 116.398376,
    addr: '奥林匹克森林公园'
  }
};
this.im.sysManage.sendRosterMessage(message);
if (/^\s*$/.test(this.message)) {
  this.message = this.placeholder;
  if (/^\s*$/.test(this.message)) return;
}

// 如果需要自定义消息,直接使用 ext 字段即可
this.im.sysManage.sendRosterMessage({
  content: this.message,
  uid: this.getSid
  // ext: "自定义消息字段",
});
setTimeout(() => {
  this.message = '';
}, 200);
const fileInfo = {
  dName: file.name,
  fLen: file.size,
  width: 0,
  height: 0
};
fileInfo.url = res.url;
this.im.sysManage.sendRosterMessage({
  type: this.fileType,
  uid: this.getSid,
  content: '',
  attachment: fileInfo
});
this.$refs.fileRef.value = '';

sysManage.sendGroupMessage(msg) ⇒ number

发送群聊消息

Kind: static method of sysManage
Returns: number - 客户端生成的消息ID

Param Type Description
msg object 发送消息体
msg.gid string 群组ID
msg.content string 消息内容
msg.type string 消息类型: text - 文本, image - 图片, audio - 语音, video - 视频,file - 文件, location - 位置, command - 命令, forward - 转发
msg.ext string | object 扩展字段
msg.attachment string | object 附件信息
msg.priority number 设置消息的扩散优先级,默认为0。0表示扩散,数字越小扩散的越多。

Example

const message = {
  gid: this.getSid,
  content: '',
  type: 'location',
  attachment: {
    lat: 40.024422,
    lon: 116.398376,
    addr: '奥林匹克森林公园'
  }
};
this.im.sysManage.sendGroupMessage(message);
if (!txt) return;

// 如果需要自定义消息,直接使用 ext 字段即可
this.im.sysManage.sendGroupMessage({
  // type: 'text', // image , file, 默认 text, 可省略
  content: txt,
  gid: this.getSid,
  // ext: "自定义消息字段",
  priority: 0
});
const fileInfo = {
  dName: file.name,
  fLen: file.size,
  width: 0,
  height: 0
};
fileInfo.url = res.url;
this.im.sysManage.sendGroupMessage({
  type: this.fileType,
  gid: this.getSid,
  content: '',
  attachment: fileInfo,
  //ext: '自定义消息字段',
  priority: 0
});
this.$refs.fileRef.value = '';
if (/^\s*$/.test(this.message)) {
  this.message = this.placeholder;
  if (/^\s*$/.test(this.message)) return;
}

// 如果需要自定义消息,直接使用 ext 字段即可
this.im.sysManage.sendGroupMessage({
  // type: 'text', // image , file, 默认 text, 可省略
  content: this.message,
  gid: this.getSid,
  // ext: "自定义消息字段",
  priority: 0
});

setTimeout(() => {
  this.message = '';
}, 200);
const fileInfo = {
  dName: file.name,
  fLen: file.size,
  width: 0,
  height: 0
};
fileInfo.url = res.url;
this.im.sysManage.sendGroupMessage({
  type: this.fileType,
  gid: this.getSid,
  content: '',
  attachment: fileInfo,
  //ext: '自定义消息字段',
  priority: 0
});
this.$refs.fileRef.value = '';

sysManage.requireHistoryMessage(uid, sid, amount)

请求历史消息

Kind: static method of sysManage

Param Type Description
uid number 会话ID
sid number 消息ID: 从哪个消息向前拉取,传0表示从最新一条消息开始拉取。
amount number 拉取的条数

Example

const { rootState, state } = context;
const mid = this.queryHistoryMessageId || 0; // Query historys older than the message with id:mid, 0 means from the last message;
const amount = 20; // Batch size of one time history message query.
rootState.im.sysManage.requireHistoryMessage(state.sid, mid, amount);

context.commit('recordHistoryQuery');

sysManage.sendMentionMessage(params) ⇒ number

群发送@消息

Kind: static method of sysManage
Returns: number - 客户端生成的消息ID

Param Type Description
params object
params.gid number 群ID
params.txt string 消息文本内容
params.mentionAll boolean 是否@所有人
params.mentionList Array.<number> @的成员ID列表
params.mentionedMessage string @消息的显示内容
params.mentionedMessage string @消息的推送内容
params.senderNickname string 发送者昵称

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

sysManage.sendInputStatusMessage(uid, status) ⇒ number

发送输入状态消息

Kind: static method of sysManage
Returns: number - 客户端生成的消息ID

Param Type Description
uid number 会话ID
status string 状态: nothing - 未输入, typing - 正在输入

Example

this.im.sysManage.sendInputStatusMessage(this.getSid, 'typing');
this.im.sysManage.sendInputStatusMessage(this.getSid, 'nothing');
this.im.sysManage.sendInputStatusMessage(this.getSid, 'typing');
this.changeSendButtonBackground();
this.im.sysManage.sendInputStatusMessage(this.getSid, 'nothing');
this.changeSendButtonBackground();

sysManage.forwardMessage(param) ⇒ number

转发消息

Kind: static method of sysManage
Returns: number - 客户端生成的消息ID

Param Type Description
param object 参数
param.uid number 接收方用户ID(仅转发单聊时设置)
param.gid number 接收方群组ID(仅转发群聊时设置)
param.mid number 要转发的消息ID

Example

const { rootState, state } = context;
const { type, id: xid } = param; //type: group, roster; id: uid,gid
const fmsg = {};
if (type === 'roster') {
  fmsg.uid = xid;
} else {
  fmsg.gid = xid;
}
fmsg.message = state.forwardMessage;
rootState.im.sysManage.forwardMessage(fmsg);
const fmsg = {};
if (type === 'roster') {
  fmsg.uid = xid;
} else {
  fmsg.gid = xid;
}
fmsg.message = message;
rootState.im.sysManage.forwardMessage(fmsg);

sysManage.getMessageStatus(cid, mid, isGroup) ⇒ string

获取消息的状态

Kind: static method of sysManage
Returns: string - 消息状态: unread - 未读, delivered - 已投递, read - 已读

Param Type Default Description
cid number 会话ID
mid number 消息ID
isGroup boolean false 是否是群聊

Example

const fromUid = toNumber(this.message.from);
const toUid = toNumber(this.message.to);
const uid = this.im.userManage.getUid();
const cid = fromUid === uid ? toUid : fromUid;

// status will be unread / delivered / read
return this.im.sysManage.getMessageStatus(cid, this.message.id);
const fromUid = toNumber(this.message.from);
const toUid = toNumber(this.message.to);
const uid = this.im.userManage.getUid();
const cid = fromUid === uid ? toUid : fromUid;

// status will be unread / delivered / read
return this.im.sysManage.getMessageStatus(cid, this.message.id);

sysManage.asyncFileUpload(param) ⇒ Promise.<FileUploadResult>

上传文件

Kind: static method of sysManage
Returns: Promise.<FileUploadResult> - 文件上传结果

Param Type Description
param object 参数
param.group_d number 群组ID
param.toType number 接收者类型:rosterAvatar - 用户头像, chat - 聊天文件, groupAvatar - 群头像
param.to_id number 接收者ID
param.file File 文件
param.fileType string 文件类型:file - 普通聊天文件, audio - 语音聊天文件(amr格式),image - 图片聊天文件, video - 视频聊天文件, audio-mp3 - 语音聊天文件(mp3格式), shareFile - 普通共享文件, shareAudio - 语音共享文件, shareImage - 图片共享文件, shareVideo - 视频共享文件
param.chatType number 聊天类型: roster - 单聊, group - 群聊
param.processCallback fileUploadProgress 上传进度回调

Example

sysManage.getImage(param) ⇒ string

拼装图片路径

Kind: static method of sysManage
Returns: string - 图片地址

Param Type Description
param object
param.avatar string 文件地址
param.type string 类型: roster - 用户, group - 群
param.thumbnail boolean 是否缩略图:默认为true
param.sdefault string 默认图片地址

Example

x.avatar = im.sysManage.getImage({
  avatar: x.avatar,
  sdefault: '/static/pages/image/r.png'
});
return x;
res.avatar = this.$store.getters.im.sysManage.getImage({
  avatar: res.avatar,
  type: 'group'
});
this.groupInfo = res;
const uid = this.$store.getters.im.userManage.getUid();
const user = this.getMemberList.find((x) => x.user_id === uid);
this.cardName = (user && (user.display_name || user.name)) || '';
if (!this.cardName) {
  this.$store.getters.im.groupManage
    .asyncGetMemberDisplayName({
      group_id: newSid,
      user_list: [uid]
    })
    .then((res) => {
      if (!res || !res.length) {
        return;
      }
      res.forEach((item) => {
        this.cardName = item.display_name;
      });
    });
}
return this.im.sysManage.getImage({
  avatar
});
return this.im.sysManage.getImage({
  avatar
});
      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) {
...
username = '我';
avatar = this.im.sysManage.getImage({ avatar: this.getUserProfile.avatar });
if (!url) {
  const attach = this.message.attach || {};
  url = attach.url;
}
return this.im.sysManage.getImage({ avatar: url, type, thumbnail });
res.avatar = this.$store.getters.im.sysManage.getImage({
  avatar: res.avatar,
  type: 'roster'
});
this.userInfo = res;

sysManage.deleteConversation(id, other_devices)

删除会话

Kind: static method of sysManage

Param Type Default Description
id number 会话ID
other_devices boolean true 是否同时删除其它设备上的会话

Example

const also_delete_other_devices = true;
this.$store.getters.im.sysManage.deleteConversation(id, also_delete_other_devices);
alert('会话删除成功');

this.$store.dispatch('contact/actionGetConversationList');
this.$store.dispatch('header/actionChangeHeaderStatus', 'conversation');
this.$store.dispatch('content/actionSetType', {
  sid: undefined
});
if (this.isOwner) {
  //dismiss
  this.$store.getters.im.groupManage.asyncDestroy({ group_id: this.getSid }).then(() => {
    alert('您已解散了此群。。');
  });
} else {
  //leave
  this.$store.getters.im.groupManage.asyncLeave({ group_id: this.getSid }).then(() => {
    alert('您已退出了此群。。');
  });
}

const also_delete_other_devices = true;
this.$store.getters.im.sysManage.deleteConversation(this.getSid, also_delete_other_devices);
const also_delete_other_devices = true;
this.$store.getters.im.sysManage.deleteConversation(id, also_delete_other_devices);
alert('会话删除成功');

this.$store.dispatch('contact/actionGetConversationList');
this.$store.dispatch('header/actionChangeHeaderStatus', 'conversation');
this.$store.dispatch('content/actionSetType', {
  sid: undefined
});
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);
if (this.isOwner) {
  //dismiss
  this.$store.getters.im.groupManage.asyncDestroy({ group_id: this.getSid }).then(() => {
    alert('您已解散了此群。。');
  });
} else {
  //leave
  this.$store.getters.im.groupManage.asyncLeave({ group_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);

sysManage.asyncGetGroupAvatarUploadUrl(params) ⇒ Promise.<FileUpload>

获取上传群头像URL

Kind: static method of sysManage
Returns: Promise.<FileUpload> - 文件上传信息

Param Type Description
params object 参数
params.group_id number 群组ID

sysManage.asyncGetFileUploadChatFileUrl(params) ⇒ Promise.<FileUpload>

获取聊天文件上传地址

Kind: static method of sysManage
Returns: Promise.<FileUpload> - 文件上传信息

Param Type Description
params object 参数
params.file_type number 文件类型: 100 - 普通聊天文件, 101 - 语音聊天文件(amr格式),102 - 图片聊天文件, 103 - 视频聊天文件, 104 - 语音聊天文件(mp3格式)200 - 普通共享文件, 201 - 语音共享文件, 202 - 图片共享文件, 203 - 视频共享文件
params.to_type number 会话类型: 1 - 用户,2 - 群组
params.to_id number 会话ID

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