Skip to content

Commit

Permalink
notification opposite site to add friend
Browse files Browse the repository at this point in the history
  • Loading branch information
scalad committed May 10, 2017
1 parent 67849cf commit 0b81137
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/scala/com/silence/websocket/WebSocket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class WebSocket {
case "addFriend" => {
WebSocketUtil.addFriend(uid, mess)
}
case "agreeAddFriend" => {
if (WebSocketUtil.getSessions.get(mess.getTo.getId) != null) {
WebSocketUtil.sendMessage(message, WebSocketUtil.getSessions.get(mess.getTo.getId))
}
}
case "unHandMessage" => {
val result = WebSocketUtil.countUnHandMessage(uid)
WebSocketUtil.sendMessage(gson.toJson(result), session)
Expand Down
9 changes: 7 additions & 2 deletions src/main/webapp/static/html/msgbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@
,from_group = li.data('fromgroup')
,user = cache[uid]
,messageBoxId = li.data('messageboxid');
console.log(messageBoxId);
//选择分组
parent.layui.layim.setFriendGroup({
type: 'friend'
,username: user.username
,avatar: user.avatar
,group: parent.layui.layim.cache().friend //获取好友分组数据
,submit: function(group, index){

//实际部署时,请开启下述注释,并改成你的接口地址
$.post('/user/agreeFriend', {
uid: uid //对方用户ID
Expand All @@ -141,6 +139,13 @@
,id: uid //好友ID
,sign: user.sign //好友签名
});
//通知对方添加我
socket.send(JSON.stringify({
type:"agreeAddFriend",
mine:layim.cache().mine,
to:{"id":uid},
msg:'{"group":'+from_group +'}'
}));
parent.layer.close(index);
othis.parent().html('已同意');
},"json");
Expand Down
15 changes: 15 additions & 0 deletions src/main/webapp/static/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,23 @@ layui.use(['layim', 'jquery', 'laytpl'], function(layim){
layim.msgbox(1);
break;
};
//同意添加好友时添加dao好友列表中
case "agreeAddFriend": {
var group = eval("(" + json.msg + ")");
layim.addList({
type: 'friend'
,avatar: json.mine.avatar
,username: json.mine.username
,groupid: group.group
,id: json.mine.id
,sign: json.mine.sign
});
layer.alert("用户'"+json.mine.username+"'已同意添加你为好友!", {icon: 0,time:0,title:"添加信息"});
break;
}
}
},

sendData:function(data){
this.waitForConnection(function () {
socket.send(data);
Expand Down

0 comments on commit 0b81137

Please sign in to comment.