|
|
|
@ -9,24 +9,27 @@
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var unreadMap = {};
|
|
|
|
|
var sdk = new WSDK();
|
|
|
|
|
var sdk = new WSDK();
|
|
|
|
|
|
|
|
|
|
var queryParam = getQueryString();
|
|
|
|
|
|
|
|
|
|
function login() {
|
|
|
|
|
sdk.Base.login({
|
|
|
|
|
uid: queryParam['uid'],
|
|
|
|
|
appkey: '24960261',
|
|
|
|
|
credential: 'xxxxxx',
|
|
|
|
|
timeout: 4000,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
initUnreadMsgAndContact();
|
|
|
|
|
console.log('login success', data);
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('get login msg count fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
uid: queryParam['uid'],
|
|
|
|
|
appkey: '24960261',
|
|
|
|
|
credential: 'xxxxxx',
|
|
|
|
|
timeout: 4000,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
initUnreadMsgAndContact();
|
|
|
|
|
sdk.Event.on('MSG_RECEIVED', function (data) {
|
|
|
|
|
console.log(data);
|
|
|
|
|
});
|
|
|
|
|
sdk.Base.startListenAllMsg();
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
login();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadContactList() {
|
|
|
|
@ -37,58 +40,55 @@
|
|
|
|
|
$("#contact").html(str);
|
|
|
|
|
var contact_list = '';
|
|
|
|
|
for (var key in unreadMap) {
|
|
|
|
|
contact_list += "<li>" + key + ":" + unreadMap[key] + "</li>";
|
|
|
|
|
contact_list +=
|
|
|
|
|
"<li onclick=switchToUser('" + key + "')>" + key + ":" + unreadMap[key] + "</li>";
|
|
|
|
|
}
|
|
|
|
|
$("#contact_list").html(contact_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initUnreadMsgAndContact() {
|
|
|
|
|
sdk.Base.getRecentContact({
|
|
|
|
|
count: 40,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
console.log('get contact msg count success', data);
|
|
|
|
|
|
|
|
|
|
var cnts = data.data.cnts;
|
|
|
|
|
for (var i = cnts.length - 1; i >= 0; i--) {
|
|
|
|
|
unreadMap[sdk.Base.getNick(cnts[i].to)] = 0;
|
|
|
|
|
}
|
|
|
|
|
getUnreadMsgCount();
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('get contact msg count fail', error);
|
|
|
|
|
}
|
|
|
|
|
count: 40,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
var cnts = data.data.cnts;
|
|
|
|
|
for (var i = cnts.length - 1; i >= 0; i--) {
|
|
|
|
|
unreadMap[sdk.Base.getNick(cnts[i].to)] = 0;
|
|
|
|
|
}
|
|
|
|
|
getUnreadMsgCount();
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('get contact msg count fail', error);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getUnreadMsgCount() {
|
|
|
|
|
sdk.Base.getUnreadMsgCount({
|
|
|
|
|
count: 40,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
console.log('get unread msg count success', data);
|
|
|
|
|
var unreads = data.data;
|
|
|
|
|
for (var i = unreads.length - 1; i >= 0; i--) {
|
|
|
|
|
unreadMap[sdk.Base.getNick(unreads[i].contact)] =
|
|
|
|
|
unreads[i].msgCount;
|
|
|
|
|
}
|
|
|
|
|
loadContactList();
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('get recent contact fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
count: 40,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
var unreads = data.data;
|
|
|
|
|
for (var i = unreads.length - 1; i >= 0; i--) {
|
|
|
|
|
unreadMap[sdk.Base.getNick(unreads[i].contact)] =
|
|
|
|
|
unreads[i].msgCount;
|
|
|
|
|
}
|
|
|
|
|
loadContactList();
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('get recent contact fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setReadState(touid) {
|
|
|
|
|
sdk.Chat.setReadState({
|
|
|
|
|
touid: touid,
|
|
|
|
|
timestamp: Math.floor((+new Date()) / 1000),
|
|
|
|
|
success: function (data) {
|
|
|
|
|
console.log('set read state success', data);
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('set read state fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
touid: touid,
|
|
|
|
|
timestamp: Math.floor((+new Date()) / 1000),
|
|
|
|
|
success: function (data) {
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('set read state fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startListenMsg(touid) {
|
|
|
|
@ -116,16 +116,33 @@
|
|
|
|
|
}
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateContractList(data) {
|
|
|
|
|
var msg =data.msgs[0];
|
|
|
|
|
var msg = data.msgs[0];
|
|
|
|
|
var msg_uid = sdk.Base.getNick(msg.from);
|
|
|
|
|
if(unreadMap[msg_uid]){
|
|
|
|
|
unreadMap[msg_uid] = unreadMap[msg_uid]+1;
|
|
|
|
|
}else {
|
|
|
|
|
if (unreadMap[msg_uid]) {
|
|
|
|
|
unreadMap[msg_uid] = unreadMap[msg_uid] + 1;
|
|
|
|
|
} else {
|
|
|
|
|
unreadMap[msg_uid] = 1;
|
|
|
|
|
}
|
|
|
|
|
loadContactList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function switchToUser(touid) {
|
|
|
|
|
parent.switchTouid(touid);
|
|
|
|
|
sdk.Chat.setReadState({
|
|
|
|
|
touid: touid,
|
|
|
|
|
timestamp: Math.floor((+new Date()) / 1000),
|
|
|
|
|
success: function(data){
|
|
|
|
|
console.log('set read state success', data);
|
|
|
|
|
},
|
|
|
|
|
error: function(error){
|
|
|
|
|
console.log('set read state fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
unreadMap[touid]=0;
|
|
|
|
|
loadContactList();
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
window.onload = function () {
|
|
|
|
|