diff --git a/pages/im/components/sentPopups.nvue b/pages/im/components/sentPopups.nvue index 6772875..a91ba04 100644 --- a/pages/im/components/sentPopups.nvue +++ b/pages/im/components/sentPopups.nvue @@ -64,7 +64,7 @@ } }, computed: { - user() { + sender() { return this.$store.getters.sender } }, @@ -87,8 +87,7 @@ sourceType: ['album'], success: res => { im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0], - this.user, ( - res) => { + this.sender, (res) => { this.success() }) } @@ -99,8 +98,7 @@ sourceType: ['camera'], success: res => { im.sentImage(this.conversationType, this.targetId, res.tempFilePaths[0], - this.user, ( - res) => { + this.sender, (res) => { this.success() }) } diff --git a/pages/im/components/sentText.nvue b/pages/im/components/sentText.nvue index ee7ef6b..fe3396b 100644 --- a/pages/im/components/sentText.nvue +++ b/pages/im/components/sentText.nvue @@ -29,7 +29,7 @@ disabled() { return this.inputTxt.length === 0 }, - user() { + sender() { return this.$store.getters.sender } }, @@ -50,7 +50,7 @@ sent() { if (!this.disabled) { RongIMLib.clearTextMessageDraft(this.conversationType, this.targetId) - im.sentText(this.conversationType, this.targetId, this.inputTxt, this.user, () => { + im.sentText(this.conversationType, this.targetId, this.inputTxt, this.sender, () => { this.$emit('success') this.inputTxt = '' }) diff --git a/pages/im/components/sentVoice.nvue b/pages/im/components/sentVoice.nvue index 65ef4cf..30a60c1 100644 --- a/pages/im/components/sentVoice.nvue +++ b/pages/im/components/sentVoice.nvue @@ -36,7 +36,7 @@ } }, computed: { - user() { + sender() { return this.$store.getters.sender } }, @@ -85,8 +85,7 @@ // 监听录音结束 this.recorderManager.onStop(res => { im.sentVoice(this.conversationType, this.targetId, res.tempFilePath, (this.maxRecordTime - - this - .recordTime), this.user, () => { + this.recordTime), this.sender, () => { setTimeout(() => { this.$emit('success') }, 500) diff --git a/pages/im/group/chat.nvue b/pages/im/group/chat.nvue index a601c61..a6d6faa 100644 --- a/pages/im/group/chat.nvue +++ b/pages/im/group/chat.nvue @@ -4,7 +4,7 @@ + :src="contact(item.senderUserId).portraitUrl" /> @@ -60,11 +60,11 @@ sentTime: 0 } } - }, - contact() { - return function(targetId) { - return this.$store.getters.contactInfo(targetId) - } + }, + contact() { + return function(targetId) { + return this.$store.getters.contactInfo(targetId) + } } }, onLoad(e) { @@ -108,7 +108,7 @@ this.latestMessage.sentTime, 1, false, - (messages) => { + (messages) => { this.messages = this.messages.concat(messages) this.scrollBottom() }) @@ -122,7 +122,7 @@ 100, true, (messages) => { - this.messages = messages.reverse() + this.messages = messages.reverse() this.scrollBottom() }) }, diff --git a/pages/im/private/chat.nvue b/pages/im/private/chat.nvue index 1dba707..bf07114 100644 --- a/pages/im/private/chat.nvue +++ b/pages/im/private/chat.nvue @@ -8,7 +8,7 @@ + :src="contact(item.senderUserId).portraitUrl" /> @@ -69,6 +69,11 @@ sentTime: 0 } } + }, + contact() { + return function(targetId) { + return this.$store.getters.contactInfo(targetId) + } } }, onLoad(e) { @@ -113,6 +118,7 @@ 1, false, (messages) => { + console.log(messages); this.messages = this.messages.concat(messages) this.scrollBottom() }) @@ -125,7 +131,8 @@ 0, 100, true, - (messages) => { + (messages) => { + console.log(messages); this.messages = messages.reverse() this.scrollBottom() }) diff --git a/public/userAuth.js b/public/userAuth.js index faf4df5..55f0691 100644 --- a/public/userAuth.js +++ b/public/userAuth.js @@ -109,8 +109,7 @@ class userAuth { .access_token) // 在这里,登录成功,链接IM服务 getImToken().then(res => { - console.log('在这获取IM-TOKEN', res); - im.connect(res.token, res.userInfo) + im.connect(res.token, res.userInfo, () => {}) }) resolve() }).catch(err => { diff --git a/utils/im/index.js b/utils/im/index.js index 59e44cc..53ca2e9 100644 --- a/utils/im/index.js +++ b/utils/im/index.js @@ -71,14 +71,14 @@ const connect = (token, userInfo, callback) => { }) }) }, - fail: () => { + fail: () => { // 程序是首次运行,初始化加载好友和群组信息 - Promise.all([getFriends(), getMyGroups()]).then(result => { + Promise.all([getFriends(), getMyGroups()]).then(result => { result.map(contacts => { contacts.map(item => { store.dispatch('initContact', item) }) - }) + }) uni.setStorageSync(FK, userInfo.targetId) }) } @@ -141,16 +141,16 @@ const addListeners = () => { }).catch(err => { console.log('ERR', err) }) - } - if (!store.getters.contactIsExist(message.senderUserId)) { - getUserInfo(message.senderUserId).then(res => { - store.dispatch('initContact', res) - }).catch(err => { - console.log('ERR', err) - }) + } + if (!store.getters.contactIsExist(message.senderUserId)) { + getUserInfo(message.senderUserId).then(res => { + store.dispatch('initContact', res) + }).catch(err => { + console.log('ERR', err) + }) } newMessage(message) - } else if (message.objectName === RongIMLib.ObjectName.ProfileNotification) { + } else if (message.objectName === RongIMLib.ObjectName.ProfileNotification) { // 更新会话信息 store.dispatch('updateContact', JSON.parse(message.content.data)) // 调用完更新之后,删除这条消息 diff --git a/utils/im/message.js b/utils/im/message.js index 53e51d1..add384b 100644 --- a/utils/im/message.js +++ b/utils/im/message.js @@ -151,14 +151,15 @@ const sentImage = (conversationType, targetId, imageUrl, user, callback) => { }) } -const sentGif = (conversationType, targetId, gifUrl, time, callback) => { +const sentGif = (conversationType, targetId, gifUrl, time, user, callback) => { const msg = { conversationType: conversationType, targetId: String(targetId), content: { objectName: 'RC:GIFMsg', local: 'file:///' + plus.io.convertLocalFileSystemURL(gifUrl), - duration: time + duration: time, + userInfo: user } } RongIMLib.sendMediaMessage(msg, { @@ -177,14 +178,15 @@ const sentGif = (conversationType, targetId, gifUrl, time, callback) => { }) } -const sendFile = (conversationType, targetId, fileUrl, time, callback) => { +const sendFile = (conversationType, targetId, fileUrl, time, user, callback) => { const msg = { conversationType: conversationType, targetId: String(targetId), content: { objectName: 'RC:FileMsg', local: 'file:///' + plus.io.convertLocalFileSystemURL(fileUrl), - duration: time + duration: time, + userInfo: user } } RongIMLib.sendMediaMessage(msg, { @@ -204,7 +206,7 @@ const sendFile = (conversationType, targetId, fileUrl, time, callback) => { } export default { - getMessageList, + getMessageList, getPendingList, sentText, sentVoice,