Skip to content
Open

Fix #22

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ let msgType = require("./components/chat/msgtype");
let disp = require("./utils/broadcast");
let logout = false;

import { onGetSilentConfig } from './components/chat/pushStorage'

function ack(receiveMsg) {
// 处理未读消息回执
var bodyId = receiveMsg.id; // 需要发送已读回执的消息id
Expand Down Expand Up @@ -36,6 +38,8 @@ function getCurrentRoute() {
return "/";
}



// // 不包含陌生人版本(不接收陌生人消息)
// function calcUnReadSpot(message) {
// let myName = uni.getStorageSync("myUsername");
Expand Down Expand Up @@ -63,6 +67,8 @@ function getCurrentRoute() {
// 包含陌生人版本
function calcUnReadSpot(message) {
let myName = uni.getStorageSync("myUsername");
let pushObj = uni.getStorageSync("pushStorageData")
let pushAry = pushObj[myName] || []
uni.getStorageInfo({
success: function (res) {
let storageKeys = res.keys;
Expand All @@ -74,11 +80,12 @@ function calcUnReadSpot(message) {
}
});
let count = newChatMsgKeys.reduce(function (result, curMember, idx) {
let newName = curMember.split(myName)[0]
let chatMsgs;
chatMsgs = uni.getStorageSync(curMember) || [];
if (pushAry.includes(newName)) return result
return result + chatMsgs.length;
}, 0);

getApp().globalData.unReadMessageNum = count;
disp.fire("em.unreadspot", message);
},
Expand Down Expand Up @@ -242,6 +249,8 @@ export default {
});
me.globalData.conn.closed = true;
WebIM.conn.close();
// uni.removeStorageSync('pushStorageData');
// uni.clearStorageSync();
},

onInviteMessage(message) {
Expand All @@ -263,7 +272,6 @@ export default {

//onPresence为旧版 ,建议参考最新增删好友api文档 :http://docs-im.easemob.com/im/web/basics/buddy
onPresence(message) {

switch (message.type) {
case "unsubscribe":
break;
Expand All @@ -276,7 +284,7 @@ export default {
return;
}
}
msgStorage.saveReceiveMsg(message, 'INFORM'); //存添加好友消息,方便展示通知
msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知
me.globalData.saveFriendList.push(message);
disp.fire("em.subscribe");

Expand Down Expand Up @@ -309,16 +317,20 @@ export default {
break;
case "invite":
// 防止重复添加
for (let i = 0; i < me.globalData.saveGroupInvitedList.length; i++) {
for (
let i = 0;
i < me.globalData.saveGroupInvitedList.length;
i++
) {
if (me.globalData.saveGroupInvitedList[i].from === message.from) {
me.globalData.saveGroupInvitedList[i] = message;
disp.fire("em.invite.joingroup")
disp.fire("em.invite.joingroup");
return;
}
}
me.globalData.saveGroupInvitedList.push(message);
disp.fire("em.invite.joingroup");
msgStorage.saveReceiveMsg(message, 'INFORM'); //存添加好友消息,方便展示通知
msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知
break;
case "unavailable":
disp.fire("em.contacts.remove");
Expand Down Expand Up @@ -358,6 +370,7 @@ export default {

calcUnReadSpot(message);
ack(message);
onGetSilentConfig(message);
},

onAudioMessage(message) {
Expand All @@ -370,6 +383,7 @@ export default {

calcUnReadSpot(message);
ack(message);
onGetSilentConfig(message);
}
},

Expand All @@ -383,6 +397,7 @@ export default {

calcUnReadSpot(message);
ack(message);
onGetSilentConfig(message);
}
},

Expand All @@ -402,6 +417,7 @@ export default {

calcUnReadSpot(message);
ack(message);
onGetSilentConfig(message);
}
},

Expand All @@ -415,6 +431,7 @@ export default {

calcUnReadSpot(message);
ack(message);
onGetSilentConfig(message);
}
},

Expand All @@ -428,6 +445,7 @@ export default {

calcUnReadSpot(message);
ack(message);
onGetSilentConfig(message);
}
},

Expand All @@ -441,6 +459,7 @@ export default {

calcUnReadSpot(message);
ack(message);
onGetSilentConfig(message);
}
},

Expand Down
45 changes: 45 additions & 0 deletions components/chat/pushStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

var WebIM = require("../../utils/WebIM")["default"];
export function pushStorageSave(data) {
// JSON.parse(uni.getStorageSync("pushStorageData")) ||
let currentLoginUser = WebIM.conn.context.userId
let newObj = uni.getStorageSync("pushStorageData") || {};
let newAry = newObj[currentLoginUser] || [];
const { userId, type } = data;
if (!newAry.includes(userId) && type === "add") {
newAry = newAry.concat(userId);
} else if (newAry.includes(userId) && type === "remove") {
newAry = newAry.filter(item => item !== userId);
}
newObj[currentLoginUser] = newAry;
uni.setStorage({
key: 'pushStorageData',
data: newObj,
success: function (params) {
console.log('uni.setStorage>>>', uni.getStorageSync("pushStorageData"));
}
});
};

export function onGetSilentConfig(message) {
const currentLoginUser = WebIM.conn.context.userId;
const { from, to, type } = message;
let pushObj = uni.getStorageSync('pushStorageData') || {};
let pushAry = pushObj[currentLoginUser] || [];
const option = {
conversationId: type === "chat" ? from : to,
type: type === "chat" ? "singleChat" : "groupChat",
};
WebIM.conn.getSilentModeForConversation(option).then((res) => {
if (res.data.type === "NONE") {
if (!pushAry.includes(option.conversationId)) {
pushAry.push(option.conversationId)
}
}
pushObj.pushAry = pushAry;
uni.setStorage({
key: 'pushStorageData',
data: pushObj
});
});
}
42 changes: 40 additions & 2 deletions pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@
"style": {
"navigationBarTitleText": "chatting",
"backgroundTextStyle": "dark",
"enablePullDownRefresh": true
"enablePullDownRefresh": true,
"app-plus": {
"titleNView":{
"buttons":[{
"text":"...",
"fontSrc": "./static/iconfont/iconfont.ttf",
"fontSize": "24",
"float": "right"
}]
}
}
}
},
{
Expand Down Expand Up @@ -135,7 +145,19 @@
"navigationBarBackgroundColor": "#f2f2f2",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "群聊",
"enablePullDownRefresh": true
"enablePullDownRefresh": true,
"app-plus": {
"titleNView": {
"buttons": [
{
"text": "...",
"fontSrc": "./static/iconfont/iconfont.ttf",
"fontSize": "24",
"float": "right"
}
]
}
}
}
// "style": {
// "navigationBarTitleText": "uni-app",
Expand Down Expand Up @@ -172,6 +194,22 @@
"navigationBarTextStyle": "black",
"navigationBarTitleText": "emedia"
}
},
{
"path": "pages/moreMenu/moreMenu",
"style": {
"navigationBarBackgroundColor": "#f2f2f2",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "好友配置"
}
},
{
"path": "pages/searchMsg/searchMsg",
"style": {
"navigationBarBackgroundColor": "#f2f2f2",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "历史记录"
}
}
],
"globalStyle": {
Expand Down
16 changes: 13 additions & 3 deletions pages/chat/chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
<view class="list_box">
<view class="list_left" :data-username="item.username">
<view class="list_pic">
<view class="em-msgNum" v-if="item.unReadCount > 0 || item.unReadCount == '99+'">{{ item.unReadCount
}}</view>
<view class="em-msgNum" v-if="(item.unReadCount > 0 || item.unReadCount == '99+') && !pushConfigData.includes(item.chatType === 'chat' ? item.username : item.info.to)">
{{ item.unReadCount}}</view>

<image :src="
item.chatType == 'groupchat' ||
Expand Down Expand Up @@ -166,7 +166,9 @@ export default {
popButton: ["删除该聊天"],
showPop: false,
popStyle: "",
currentVal: ''
currentVal: '',

pushConfigData: []
};
},

Expand Down Expand Up @@ -207,6 +209,14 @@ export default {
//监听未读消息数
disp.on("em.unreadspot", function (message) {
me.getChatList();
let currentLoginUser = WebIM.conn.context.userId;
let id = message && message.chatType === 'groupchat' ? message?.to : message?.from;
let pushObj = uni.getStorageSync("pushStorageData");
let pushAry = pushObj[currentLoginUser] || []
me.setData({
pushConfigData:pushAry,
});
// if (message && pushValue.includes(id)) return
me.setData({
// arr: me.getChatList(),
unReadSpotNum:
Expand Down
9 changes: 7 additions & 2 deletions pages/chatroom/chatroom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
});
},

onUnload() {
onUnload(options) {
disp.fire("em.chatroom.leave");
},

Expand All @@ -49,7 +49,12 @@ export default {
uni.navigateTo({
url: "../emedia/index?srcData="+JSON.stringify(msg)
});
}
},
onNavigationBarButtonTap(e) {
uni.navigateTo({
url: `/pages/moreMenu/moreMenu?username=${this.username.your}&type=singleChat`
})
},
}
};
</script>
Expand Down
6 changes: 6 additions & 0 deletions pages/groupChatRoom/groupChatRoom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ export default {
// desp: "开始初始化nvue",
// })
},

onNavigationBarButtonTap(e) {
uni.navigateTo({
url: `/pages/moreMenu/moreMenu?username=${this.username.groupId}&type=groupChat`
})
},
onClickMsg(msg){
}
}
Expand Down
Loading