session.js
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* 会话模块
*/
'use strict'
YX.fn.session = function () {
}
/**
* 最近联系人显示
* @return {void}
*/
YX.fn.buildSessions = function(id) {
var data = {
sessions:this.cache.getSessions(),
personSubscribes: this.cache.getPersonSubscribes()
}
if(!this.sessions){
var options = {
data:data,
onclickavatar:this.showInfo.bind(this),
onclickitem:this.openChatBox.bind(this),
infoprovider:this.infoProvider.bind(this),
}
this.sessions = new NIMUIKit.SessionList(options)
this.sessions.inject($('#sessions').get(0))
}else{
this.sessions.update(data)
}
//导航上加未读示例
this.showUnread()
this.doPoint()
//已读回执处理
this.markMsgRead(id)
var $node = $(".m-unread .u-unread")
$node.on('mouseenter', function () {
$node.text('×')
})
$node.on('mouseleave', function () {
$node.text(this.totalUnread)
}.bind(this))
$node.on('click', function (event) {
this.nim.resetAllSessionUnread()
event.preventDefault()
}.bind(this))
}
// 导航上加未读数
YX.fn.showUnread = function () {
var counts = $("#sessions .panel_count")
this.totalUnread = 0
if(counts.length!==0){
if(this.totalUnread !=="99+"){
for (var i = counts.length - 1; i >= 0; i--) {
if($(counts[i]).text()==="99+"){
this.totalUnread = "99+"
break
}
this.totalUnread +=parseInt($(counts[i]).text(),10)
}
}
}
var $node = $(".m-unread .u-unread")
$node.text(this.totalUnread)
this.totalUnread?$node.removeClass("hide"):$node.addClass("hide")
}