mirror of
https://github.com/thelounge/thelounge
synced 2024-11-22 20:13:07 +00:00
Only send messages newer than last seen id
This commit is contained in:
parent
05fc00d9be
commit
cffa957e34
1 changed files with 16 additions and 3 deletions
|
@ -236,7 +236,7 @@ function index(req, res, next) {
|
|||
res.render("index", data);
|
||||
}
|
||||
|
||||
function initializeClient(socket, client, token) {
|
||||
function initializeClient(socket, client, token, lastMessage) {
|
||||
socket.emit("authorized");
|
||||
|
||||
socket.on("disconnect", function() {
|
||||
|
@ -400,11 +400,24 @@ function initializeClient(socket, client, token) {
|
|||
socket.join(client.id);
|
||||
|
||||
const sendInitEvent = (tokenToSend) => {
|
||||
let networks = client.networks;
|
||||
|
||||
if (lastMessage > -1) {
|
||||
// We need a deep cloned object because we are going to remove unneeded messages
|
||||
networks = _.cloneDeep(networks);
|
||||
|
||||
networks.forEach((network) => {
|
||||
network.channels.forEach((channel) => {
|
||||
channel.messages = channel.messages.filter((m) => m.id > lastMessage);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
socket.emit("init", {
|
||||
applicationServerKey: manager.webPush.vapidKeys.publicKey,
|
||||
pushSubscription: client.config.sessions[token],
|
||||
active: client.lastActiveChannel,
|
||||
networks: client.networks,
|
||||
networks: networks,
|
||||
token: tokenToSend
|
||||
});
|
||||
};
|
||||
|
@ -434,7 +447,7 @@ function performAuthentication(data) {
|
|||
const socket = this;
|
||||
let client;
|
||||
|
||||
const finalInit = () => initializeClient(socket, client, data.token || null);
|
||||
const finalInit = () => initializeClient(socket, client, data.token || null, data.lastMessage || -1);
|
||||
|
||||
const initClient = () => {
|
||||
client.ip = getClientIp(socket.request);
|
||||
|
|
Loading…
Reference in a new issue