master
kira 6 years ago
parent d6a91a1c03
commit 3b6609ad03

@ -11,10 +11,10 @@
<script src="https://g.alicdn.com/aliww/h5.openim.sdk/1.0.6/scripts/wsdk.js"></script>
<script>
window.onload = function () {
window.uid = getQueryString('uid');
window.touid = getQueryString('uid');
window.password = getQueryString('p');
window.appKey = getQueryString('key');
window.uid = getQueryString('uid');
window.touid = getQueryString('uid');
window.password = getQueryString('p');
window.appKey = getQueryString('key');
WKIT.init({
container: document.getElementById('J_demo'),
width: 700,
@ -62,8 +62,9 @@
var cnts = data.data.cnts;
for (var i = cnts.length - 1; i >= 0; i--) {
var unreadmapEle = {msgCount: 0};
window.sdk.unreadMap[getName(WKIT.Conn.sdk.Base.getNick(
cnts[i].from))] = unreadmapEle;
window.sdk.unreadMap[getName(
WKIT.Conn.sdk.Base.getNick(
cnts[i].from))] = unreadmapEle;
}
getUnreadMsgCount();
},
@ -81,17 +82,22 @@
var unreads = data.data;
var uids = "";
for (var i = unreads.length - 1; i >= 0; i--) {
window.sdk.unreadMap[getName(WKIT.Conn.sdk.Base.getNick(unreads[i].contact))].msgCount =
window.sdk.unreadMap[getName(
WKIT.Conn.sdk.Base.getNick(
unreads[i].contact))].msgCount =
unreads[i].msgCount;
var nick = getName(WKIT.Conn.sdk.Base.getNick(unreads[i].contact));
if(nick.length<=6){
uids += nick+",";
}else {
var nick = getName(
WKIT.Conn.sdk.Base.getNick(
unreads[i].contact));
if (nick.length <= 6) {
uids += nick + ",";
} else {
uids += nick.substring(0,uid.length-5) + ",";
uids +=
nick.substring(0, uid.length - 5)
+ ",";
}
}
console.log("unreadMap",window.sdk.unreadMap);
window.sdk.loadContactList(uids);
},
error: function (error) {
@ -103,7 +109,17 @@
function updateContractList(data) {
var msg = data.msgs[0];
var msg_uid = getName(WKIT.Conn.sdk.Base.getNick(msg.from))
if (window.uid = msg_uid) {
WKIT.Conn.sdk.Chat.setReadState({
touid: msg_uid,
timestamp: Math.floor((+new Date()) / 1000),
success: function (data) {
},
error: function (error) {
console.log('set read state fail', error);
}
});
}
if (window.sdk.unreadMap[msg_uid]) {
window.sdk.unreadMap[msg_uid].msgCount = window.sdk.unreadMap[msg_uid].msgCount + 1;
@ -111,7 +127,7 @@
var unreadMapEle = {msgCount: 1}
window.sdk.unreadMap[msg_uid] = unreadMapEle;
}
window.sdk.loadContactList(msg_uid.substr(0,msg_uid-6));
window.sdk.loadContactList(msg_uid.substr(0, msg_uid - 6));
}
function initLayout() {
@ -121,17 +137,21 @@
}
function getName(uid) {
if(uid.substring(uid.length-5,uid.length-4)=='_'){
var prefix = uid.substring(0,uid.length-5);
var suffix =uid.substring(uid.length-5,uid.length).toUpperCase();
return prefix+suffix;
if (uid.substring(uid.length - 5, uid.length - 4) == '_') {
var prefix = uid.substring(0, uid.length - 5);
var suffix = uid.substring(uid.length - 5, uid.length).toUpperCase();
return prefix + suffix;
}
return uid;
}
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
if (r != null) {
return unescape(r[2]);
}
return null;
}
</script>

@ -7,7 +7,6 @@
<script src="https://g.alicdn.com/aliww/h5.openim.sdk/1.0.6/scripts/wsdk.js"
charset="UTF-8"></script>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<style>
li {
float: left;
@ -112,6 +111,7 @@
</style>
<script>
var unreadMap = {};
function searchContact() {
var uid = $('#searchText').val();
var searchContactList = {};
@ -151,7 +151,10 @@
dataType: 'json',
success: function (resp) {
for (var i = 0; i <= resp.length - 1; i++) {
unreadMap[resp[i].nick].headimg = resp[i].headimg;
var ele = unreadMap[resp[i].nick];
if (ele) {
ele.headimg = resp[i].headimg;
}
}
showContactList(unreadMap);
}

@ -15,7 +15,7 @@
uid: 'kira3_PINE',
appkey: 24980715,
credential: 'xxxxxx',
touid: 'kira7',
touid: 'kiraservant2',
logo: 'http://img.alicdn.com/tps/i3/TB12LD9IFXXXXb3XpXXSyFWJXXX-82-82.png',
});
}

Loading…
Cancel
Save