|
@@ -3,133 +3,158 @@ let msgPackager = require("./msgpackager.js");
|
|
|
let msgType = require("./msgtype.js");
|
|
|
let msgStorage = new Disp();
|
|
|
let disp = require("./broadcast.js");
|
|
|
+let WebIM = wx.WebIM = require("./WebIM")["default"];
|
|
|
+
|
|
|
msgStorage.saveReceiveMsg = function (receiveMsg, type) {
|
|
|
+ console.info('receiveMsg', receiveMsg);
|
|
|
+ let users = [receiveMsg.from, receiveMsg.to];
|
|
|
let sendableMsg;
|
|
|
- if (type == msgType.IMAGE) {
|
|
|
- sendableMsg = {
|
|
|
- id: receiveMsg.id,
|
|
|
- type: type,
|
|
|
- body: {
|
|
|
+
|
|
|
+ WebIM.conn.fetchUserInfoById(users).then((res) => {
|
|
|
+ console.log(res);
|
|
|
+ let fromInfo = {};
|
|
|
+ let toInfo = {};
|
|
|
+ for (let k in res.data) {
|
|
|
+ if (k == receiveMsg.from) {
|
|
|
+ fromInfo = res.data[k];
|
|
|
+ } else {
|
|
|
+ toInfo = res.data[k];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.info('from and to ', fromInfo, toInfo);
|
|
|
+
|
|
|
+ if (type == msgType.IMAGE) {
|
|
|
+ sendableMsg = {
|
|
|
id: receiveMsg.id,
|
|
|
- from: receiveMsg.from,
|
|
|
- to: receiveMsg.to,
|
|
|
- type: receiveMsg.type,
|
|
|
- ext: receiveMsg.ext,
|
|
|
- chatType: receiveMsg.type,
|
|
|
- toJid: "",
|
|
|
+ type: type,
|
|
|
body: {
|
|
|
- type: type,
|
|
|
- url: receiveMsg.url,
|
|
|
- filename: receiveMsg.filename,
|
|
|
- filetype: receiveMsg.filetype,
|
|
|
- size: {
|
|
|
- width: receiveMsg.width,
|
|
|
- height: receiveMsg.height
|
|
|
+ id: receiveMsg.id,
|
|
|
+ from: receiveMsg.from,
|
|
|
+ to: receiveMsg.to,
|
|
|
+ type: receiveMsg.type,
|
|
|
+ ext: receiveMsg.ext,
|
|
|
+ chatType: receiveMsg.type,
|
|
|
+ toJid: "",
|
|
|
+ body: {
|
|
|
+ type: type,
|
|
|
+ url: receiveMsg.url,
|
|
|
+ filename: receiveMsg.filename,
|
|
|
+ filetype: receiveMsg.filetype,
|
|
|
+ size: {
|
|
|
+ width: receiveMsg.width,
|
|
|
+ height: receiveMsg.height
|
|
|
+ },
|
|
|
},
|
|
|
},
|
|
|
- },
|
|
|
- };
|
|
|
- }
|
|
|
- else if (type == msgType.TEXT || type == msgType.EMOJI) {
|
|
|
- sendableMsg = {
|
|
|
- id: receiveMsg.id,
|
|
|
- type: type,
|
|
|
- body: {
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else if (type == msgType.TEXT || type == msgType.EMOJI) {
|
|
|
+ sendableMsg = {
|
|
|
id: receiveMsg.id,
|
|
|
- from: receiveMsg.from,
|
|
|
- to: receiveMsg.to,
|
|
|
- type: receiveMsg.type,
|
|
|
- ext: receiveMsg.ext,
|
|
|
- chatType: receiveMsg.type,
|
|
|
- toJid: "",
|
|
|
+ type: type,
|
|
|
body: {
|
|
|
- type: type,
|
|
|
- msg: receiveMsg.data,
|
|
|
+ id: receiveMsg.id,
|
|
|
+ from: receiveMsg.from,
|
|
|
+ fromInfo: fromInfo,
|
|
|
+ to: receiveMsg.to,
|
|
|
+ toInfo: toInfo,
|
|
|
+ type: receiveMsg.type,
|
|
|
+ ext: receiveMsg.ext,
|
|
|
+ chatType: receiveMsg.type,
|
|
|
+ toJid: "",
|
|
|
+ body: {
|
|
|
+ type: type,
|
|
|
+ msg: receiveMsg.data,
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- value: receiveMsg.data
|
|
|
- };
|
|
|
- }
|
|
|
- else if (type == msgType.FILE) {
|
|
|
- sendableMsg = {
|
|
|
- id: receiveMsg.id,
|
|
|
- type: type,
|
|
|
- body: {
|
|
|
+ value: receiveMsg.data
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else if (type == msgType.FILE) {
|
|
|
+ sendableMsg = {
|
|
|
id: receiveMsg.id,
|
|
|
- length: receiveMsg.file_length,
|
|
|
- from: receiveMsg.from,
|
|
|
- to: receiveMsg.to,
|
|
|
- type: receiveMsg.type,
|
|
|
- ext: receiveMsg.ext,
|
|
|
- chatType: receiveMsg.type,
|
|
|
- toJid: "",
|
|
|
+ type: type,
|
|
|
body: {
|
|
|
- type: type,
|
|
|
- url: receiveMsg.url,
|
|
|
- filename: receiveMsg.filename,
|
|
|
- msg: "当前不支持此格式消息展示",
|
|
|
+ id: receiveMsg.id,
|
|
|
+ length: receiveMsg.file_length,
|
|
|
+ from: receiveMsg.from,
|
|
|
+ to: receiveMsg.to,
|
|
|
+ type: receiveMsg.type,
|
|
|
+ ext: receiveMsg.ext,
|
|
|
+ chatType: receiveMsg.type,
|
|
|
+ toJid: "",
|
|
|
+ body: {
|
|
|
+ type: type,
|
|
|
+ url: receiveMsg.url,
|
|
|
+ filename: receiveMsg.filename,
|
|
|
+ msg: "当前不支持此格式消息展示",
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- value: receiveMsg.data
|
|
|
- };
|
|
|
- }
|
|
|
- else if (type == msgType.AUDIO) {
|
|
|
- sendableMsg = {
|
|
|
- id: receiveMsg.id,
|
|
|
- type: type,
|
|
|
- accessToken: receiveMsg.token || receiveMsg.accessToken,
|
|
|
- body: {
|
|
|
+ value: receiveMsg.data
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else if (type == msgType.AUDIO) {
|
|
|
+ sendableMsg = {
|
|
|
id: receiveMsg.id,
|
|
|
- length: receiveMsg.length,
|
|
|
- from: receiveMsg.from,
|
|
|
- to: receiveMsg.to,
|
|
|
- type: receiveMsg.type,
|
|
|
- ext: receiveMsg.ext,
|
|
|
- chatType: receiveMsg.type,
|
|
|
- toJid: "",
|
|
|
+ type: type,
|
|
|
+ accessToken: receiveMsg.token || receiveMsg.accessToken,
|
|
|
body: {
|
|
|
- type: type,
|
|
|
- url: receiveMsg.url,
|
|
|
- filename: receiveMsg.filename,
|
|
|
- filetype: receiveMsg.filetype,
|
|
|
+ id: receiveMsg.id,
|
|
|
+ length: receiveMsg.length,
|
|
|
from: receiveMsg.from,
|
|
|
- to: receiveMsg.to
|
|
|
+ to: receiveMsg.to,
|
|
|
+ type: receiveMsg.type,
|
|
|
+ ext: receiveMsg.ext,
|
|
|
+ chatType: receiveMsg.type,
|
|
|
+ toJid: "",
|
|
|
+ body: {
|
|
|
+ type: type,
|
|
|
+ url: receiveMsg.url,
|
|
|
+ filename: receiveMsg.filename,
|
|
|
+ filetype: receiveMsg.filetype,
|
|
|
+ from: receiveMsg.from,
|
|
|
+ to: receiveMsg.to
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- };
|
|
|
- }
|
|
|
- else if (type == msgType.VIDEO) {
|
|
|
- sendableMsg = {
|
|
|
- id: receiveMsg.id,
|
|
|
- type: type,
|
|
|
- accessToken: receiveMsg.token || receiveMsg.accessToken,
|
|
|
- body: {
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else if (type == msgType.VIDEO) {
|
|
|
+ sendableMsg = {
|
|
|
id: receiveMsg.id,
|
|
|
- length: receiveMsg.length,
|
|
|
- from: receiveMsg.from,
|
|
|
- to: receiveMsg.to,
|
|
|
- type: receiveMsg.type,
|
|
|
- ext: receiveMsg.ext,
|
|
|
- chatType: receiveMsg.type,
|
|
|
- toJid: "",
|
|
|
+ type: type,
|
|
|
+ accessToken: receiveMsg.token || receiveMsg.accessToken,
|
|
|
body: {
|
|
|
- type: type,
|
|
|
- url: receiveMsg.url,
|
|
|
- filename: receiveMsg.filename,
|
|
|
- filetype: receiveMsg.filetype,
|
|
|
+ id: receiveMsg.id,
|
|
|
+ length: receiveMsg.length,
|
|
|
from: receiveMsg.from,
|
|
|
- to: receiveMsg.to
|
|
|
+ to: receiveMsg.to,
|
|
|
+ type: receiveMsg.type,
|
|
|
+ ext: receiveMsg.ext,
|
|
|
+ chatType: receiveMsg.type,
|
|
|
+ toJid: "",
|
|
|
+ body: {
|
|
|
+ type: type,
|
|
|
+ url: receiveMsg.url,
|
|
|
+ filename: receiveMsg.filename,
|
|
|
+ filetype: receiveMsg.filetype,
|
|
|
+ from: receiveMsg.from,
|
|
|
+ to: receiveMsg.to
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- };
|
|
|
- }
|
|
|
- else {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.saveMsg(sendableMsg, type, receiveMsg);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.saveMsg(sendableMsg, type, receiveMsg);
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
};
|
|
|
+
|
|
|
msgStorage.saveMsg = function (sendableMsg, type, receiveMsg) {
|
|
|
- //console.log('sendableMsgsendableMsg', sendableMsg)
|
|
|
+ console.log('sendableMsgsendableMsg', sendableMsg)
|
|
|
let me = this;
|
|
|
let myName = wx.getStorageSync("myUsername");
|
|
|
let sessionKey;
|