|
|
|
@ -9,24 +9,24 @@
|
|
|
|
|
|
|
|
|
|
<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);
|
|
|
|
|
sdk.Base.startListenAllMsg();
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('get login msg count fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadContactList() {
|
|
|
|
@ -44,51 +44,51 @@
|
|
|
|
|
|
|
|
|
|
function initUnreadMsgAndContact() {
|
|
|
|
|
sdk.Base.getRecentContact({
|
|
|
|
|
count: 40,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
console.log('get contact msg count success', data);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
console.log('set read state success', data);
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log('set read state fail', error);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function startListenMsg(touid) {
|
|
|
|
@ -106,16 +106,26 @@
|
|
|
|
|
item = null,
|
|
|
|
|
len = items.length;
|
|
|
|
|
|
|
|
|
|
for(var i = 0; i < len; i++) {
|
|
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
|
|
item = items[i].split("=");
|
|
|
|
|
var name = decodeURIComponent(item[0]),
|
|
|
|
|
value = decodeURIComponent(item[1]);
|
|
|
|
|
if(name) {
|
|
|
|
|
if (name) {
|
|
|
|
|
args[name] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
function updateContractList(data) {
|
|
|
|
|
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 {
|
|
|
|
|
unreadMap[msg_uid] = 1;
|
|
|
|
|
}
|
|
|
|
|
loadContactList();
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
<script>
|
|
|
|
|
window.onload = function () {
|
|
|
|
|