This commit is contained in:
luyuan 2020-08-06 16:22:40 +08:00
parent e6b7b50a1e
commit e11f20885f
Signed by: theluyuan
GPG Key ID: A7972FD973317FF3

View File

@ -8,14 +8,15 @@
import GoEasyIM from './goeasy-im-1.0.9'; import GoEasyIM from './goeasy-im-1.0.9';
import restApi from './restapi'; import restApi from './restapi';
function Friend(uuid, name, avatar,time = "") { function Friend(uuid, name, avatar,time = "", text = "",date = "") {
this.uuid = uuid; this.uuid = uuid;
this.name = name; this.name = name;
this.avatar = avatar; this.avatar = avatar;
this.online = false; this.online = false;
this.unReadMessage = 0; this.unReadMessage = 0;
this.text = ""; this.text = text;
this.time = time; this.time = time;
this.date = date
} }
function Group(uuid, name, avatar) { function Group(uuid, name, avatar) {
@ -90,6 +91,7 @@ IMService.prototype.initialContacts = function (friendList) {
} }
value = JSON.parse(value) value = JSON.parse(value)
let that = this let that = this
console.log(value)
for(let i of value){ for(let i of value){
const token = uni.getStorageSync('token'); const token = uni.getStorageSync('token');
console.log(token) console.log(token)
@ -104,9 +106,28 @@ IMService.prototype.initialContacts = function (friendList) {
}, },
success(res){ success(res){
console.log(res) console.log(res)
that.friends[i[0]] = new Friend(res.data.data.member_id, res.data.data.member_nickname, res.data.data.member_avatar,i[1]); that.friends[i[0]] = new Friend(res.data.data.member_id, res.data.data.member_nickname, res.data.data.member_avatar,i[1],i[2]);
console.log(that.friends) console.log(that.friends)
let sorts = function (friends){
let paixu = function (a,b){
if(a.date > b.date){
return 0;
}else{
return 1;
}
}
friends.sort(paixu)
}
that.friendsarr = []
for(let i in that.friends){
console.log(i)
that.friendsarr.push(that.friends[i])
}
sorts(that.friendsarr)
that.onFriendListChange(that.friends); that.onFriendListChange(that.friends);
} }
}) })
} }
@ -235,7 +256,7 @@ IMService.prototype.initialIMListeners = function () {
// return ; // return ;
let sorts = function (friends){ let sorts = function (friends){
let paixu = function (a,b){ let paixu = function (a,b){
if(a.item > b.item){ if(a.date > b.date){
return 0; return 0;
}else{ }else{
return 1; return 1;
@ -267,6 +288,7 @@ IMService.prototype.initialIMListeners = function () {
friend.unReadMessage++; friend.unReadMessage++;
friend.text = message.type != "text" ? "其他消息" : message.payload.text friend.text = message.type != "text" ? "其他消息" : message.payload.text
let time = new Date(message.timestamp) let time = new Date(message.timestamp)
friend.date = message.timestamp
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
console.log(that.friends) console.log(that.friends)
that.friendsarr = [] that.friendsarr = []
@ -277,9 +299,11 @@ IMService.prototype.initialIMListeners = function () {
sorts(that.friendsarr) sorts(that.friendsarr)
let arr = [] let arr = []
for(let i in that.friends){ for(let i in that.friends){
arr.push([that.friends[i].uuid,that.friends[i].time]) arr.push([that.friends[i].uuid,that.friends[i].time,that.friends[i].text,that.friends[i].date])
uni.setStorageSync('imlist',JSON.stringify(arr))
} }
console.log(arr)
uni.setStorageSync('imlist',JSON.stringify(arr))
that.onFriendListChange(that.friends); that.onFriendListChange(that.friends);
} }
@ -289,6 +313,7 @@ IMService.prototype.initialIMListeners = function () {
friend.unReadMessage++; friend.unReadMessage++;
friend.text = message.type != "text" ? "其他消息" : message.payload.text friend.text = message.type != "text" ? "其他消息" : message.payload.text
let time = new Date(message.timestamp) let time = new Date(message.timestamp)
friend.date = message.timestamp
friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() friend.time = time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds()
console.log(this.friends) console.log(this.friends)
that.friendsarr = [] that.friendsarr = []
@ -296,6 +321,12 @@ IMService.prototype.initialIMListeners = function () {
that.friendsarr.push(this.friends[i]) that.friendsarr.push(this.friends[i])
} }
sorts(that.friendsarr) sorts(that.friendsarr)
let arr = []
for(let i in that.friends){
arr.push([that.friends[i].uuid,that.friends[i].time,that.friends[i].text,that.friends[i].date])
}
console.log(arr)
uni.setStorageSync('imlist',JSON.stringify(arr))
this.onFriendListChange(this.friends); this.onFriendListChange(this.friends);
} }