mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-07-05 19:10:52 +00:00
re-coded recents array code.
This commit is contained in:
parent
56f56292bc
commit
f11813d759
1 changed files with 47 additions and 44 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="recents">
|
<div class="recents">
|
||||||
<virtual-list :size="50" :remain="20" v-if="loaded" >
|
<virtual-list :size="50" :remain="20" v-if="loaded">
|
||||||
<FriendsTemplate
|
<FriendsTemplate
|
||||||
v-for="(channel, key) of channels"
|
v-for="(channel, key) of recentsArr"
|
||||||
:key="key"
|
:key="key"
|
||||||
:recents="true"
|
:recents="true"
|
||||||
:friend="channel"
|
:friend="channel"
|
||||||
|
|
@ -33,54 +33,57 @@ export default {
|
||||||
return this.$store.getters.user;
|
return this.$store.getters.user;
|
||||||
},
|
},
|
||||||
channels() {
|
channels() {
|
||||||
const json = this.$store.getters.channels;
|
return this.$store.getters.channels;
|
||||||
|
},
|
||||||
|
sortedChannels() {
|
||||||
|
const channels = Object.values(this.channels).reverse();
|
||||||
|
const sorted = channels
|
||||||
|
.concat()
|
||||||
|
.sort((a, b) => b.lastMessaged - a.lastMessaged);
|
||||||
|
return sorted;
|
||||||
|
},
|
||||||
|
recentsArr() {
|
||||||
const notifications = this.$store.getters.notifications;
|
const notifications = this.$store.getters.notifications;
|
||||||
|
|
||||||
const keys = Object.keys(json);
|
const unOpenedDms = [];
|
||||||
let result = [];
|
const highPriority = [];
|
||||||
keys.forEach(key => {
|
const lowPriority = [];
|
||||||
if (
|
|
||||||
json[key].recipients &&
|
|
||||||
json[key].recipients.length > 0 &&
|
|
||||||
!json[key].server_id &&
|
|
||||||
json[key].recipients[0].uniqueID !== this.user.uniqueID
|
|
||||||
)
|
|
||||||
result.push(json[key]);
|
|
||||||
});
|
|
||||||
|
|
||||||
result.sort(function(a, b) {
|
for (let index = 0; index < this.sortedChannels.length; index++) {
|
||||||
const notificationA = notifications.find(item => {
|
const channel = this.sortedChannels[index];
|
||||||
return item.channelID === a.channelID;
|
if (channel.server_id) continue;
|
||||||
});
|
const recipient = channel.recipients[0];
|
||||||
const notificationB = notifications.find(item => {
|
|
||||||
return item.channelID === b.channelID;
|
|
||||||
});
|
|
||||||
// make notifications more prority.
|
|
||||||
if (notificationA) return -1;
|
|
||||||
if (notificationB) return 1;
|
|
||||||
if (a.lastMessaged === undefined) return 1;
|
|
||||||
if (b.lastMessaged === undefined) return -1;
|
|
||||||
return b.lastMessaged - a.lastMessaged;
|
|
||||||
});
|
|
||||||
|
|
||||||
// gets unopened dms
|
const notified = notifications.find(
|
||||||
const notificationsFiltered = notifications.filter(item => {
|
n =>
|
||||||
if (json[item.channelID] && json[item.channelID].server_id) return;
|
n.sender.uniqueID === recipient.uniqueID &&
|
||||||
const find = result.find(resFind => {
|
n.channelID === channel.channelID
|
||||||
return resFind.channelID === item.channelID;
|
);
|
||||||
});
|
|
||||||
if (!find) {
|
if (notified) {
|
||||||
return true;
|
highPriority.push(channel);
|
||||||
|
} else {
|
||||||
|
lowPriority.push(channel);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
for (let index in notificationsFiltered) {
|
|
||||||
notificationsFiltered[index].creator = "dummy";
|
|
||||||
notificationsFiltered[index].recipients = [
|
|
||||||
notificationsFiltered[index].sender
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
result = notificationsFiltered.concat(result);
|
|
||||||
return result;
|
for (let index = 0; index < notifications.length; index++) {
|
||||||
|
const element = notifications[index];
|
||||||
|
if (this.channels[element.channelID]) continue;
|
||||||
|
const recipient = {
|
||||||
|
username: element.sender.username,
|
||||||
|
tag: element.sender.tag,
|
||||||
|
avatar: element.sender.avatar,
|
||||||
|
uniqueID: element.sender.uniqueID
|
||||||
|
};
|
||||||
|
unOpenedDms.push({
|
||||||
|
recipients: [recipient],
|
||||||
|
channelID: element.channelID,
|
||||||
|
lastMessaged: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...unOpenedDms, ...highPriority, ...lowPriority];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue