sendMessage(type, data) {
let message;
if (!type) {
return;
}
const self = this;
if (type == FILE_TYPE.TEXT_TYPE || type == FILE_TYPE.POST_TYPE) {
this.imClient.then(function (conversation) {
if (type == FILE_TYPE.TEXT_TYPE) {
message = new TextMessage(data.value);
} else if (type == FILE_TYPE.POST_TYPE) {
message = new TextMessage(data.content);
message.setAttributes({'title': data.title, 'type': data.type});
}
return conversation.send(message);
}).then(function (resultMessage) {
self.updateUI(type, data, resultMessage);
});
} else { // 发送富文本消息
this.imClient.then(function (conversation) {
const file = new AV.File(data.name, data.file);
file.save({
onprogress: function (e) {
console.log(e);
}
}).then(function () {
if (type == FILE_TYPE.IMAGE_TYPE) {
message = new ImageMessage(file);
} else if (type == FILE_TYPE.VIDEO_TYPE) {
message = new AudioMessage(file);
} else if (type == FILE_TYPE.FILE_TYPE) {
message = new FileMessage(file);
}
// message.setText(data.text);
let isConnect;
if (data.connect) {
isConnect = true;
for (let i = 0; i < data.connect.length; i++) {
data.connect[i] = {member: data.connect[i], connectSuccess: false};
}
}
message.setAttributes({connect: data.connect, isConnect: isConnect});
return conversation.send(message);
}).then(function (resultMessage) {
self.updateUI(type, data, resultMessage);
});
});
}
}
client.on('message', function messageHandler(message, conversation) {
conversation.read();
console.log(message);
let isConnect;
// 判断是否交接
if (message.content._lcattrs) {
if (message.content.lcattrs.connect && $.inArray(this.user, message.content.lcattrs)) {
// 需要确认交接
isConnect = true;
}
}
self.updateUI(message.content._lctype, null, message);
setTimeout(function () {
$('.postList').scrollTop($('.postList')[0].scrollHeight);
}, 100);
});