Synchronize open channel on client on reconnection
This commit is contained in:
parent
ee4de6a871
commit
1ca16816c2
@ -79,15 +79,19 @@ socket.on("auth", function(data) {
|
|||||||
|
|
||||||
for (const network of vueApp.networks) {
|
for (const network of vueApp.networks) {
|
||||||
for (const chan of network.channels) {
|
for (const chan of network.channels) {
|
||||||
for (const msg of chan.messages) {
|
if (chan.messages.length > 0) {
|
||||||
if (msg.id > lastMessage) {
|
const id = chan.messages[chan.messages.length - 1].id;
|
||||||
lastMessage = msg.id;
|
|
||||||
|
if (lastMessage < id) {
|
||||||
|
lastMessage = id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit("auth", {user, token, lastMessage});
|
const openChannel = (vueApp.activeChannel && vueApp.activeChannel.channel.id) || null;
|
||||||
|
|
||||||
|
socket.emit("auth", {user, token, lastMessage, openChannel});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,11 +331,23 @@ function indexRequest(req, res) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeClient(socket, client, token, lastMessage) {
|
function initializeClient(socket, client, token, lastMessage, openChannel) {
|
||||||
socket.emit("authorized");
|
socket.emit("authorized");
|
||||||
|
|
||||||
client.clientAttach(socket.id, token);
|
client.clientAttach(socket.id, token);
|
||||||
|
|
||||||
|
// Client sends currently active channel on reconnect,
|
||||||
|
// pass it into `open` directly so it is verified and updated if necessary
|
||||||
|
if (openChannel) {
|
||||||
|
client.open(socket.id, openChannel);
|
||||||
|
|
||||||
|
// If client provided channel passes checks, use it. if client has invalid
|
||||||
|
// channel open (or windows like settings) then use last known server active channel
|
||||||
|
openChannel = client.attachedClients[socket.id].openChannel || client.lastActiveChannel;
|
||||||
|
} else {
|
||||||
|
openChannel = client.lastActiveChannel;
|
||||||
|
}
|
||||||
|
|
||||||
if (Helper.config.fileUpload.enable) {
|
if (Helper.config.fileUpload.enable) {
|
||||||
new Uploader(socket);
|
new Uploader(socket);
|
||||||
}
|
}
|
||||||
@ -624,9 +636,9 @@ function initializeClient(socket, client, token, lastMessage) {
|
|||||||
socket.emit("init", {
|
socket.emit("init", {
|
||||||
applicationServerKey: manager.webPush.vapidKeys.publicKey,
|
applicationServerKey: manager.webPush.vapidKeys.publicKey,
|
||||||
pushSubscription: client.config.sessions[token],
|
pushSubscription: client.config.sessions[token],
|
||||||
active: client.lastActiveChannel,
|
active: openChannel,
|
||||||
networks: client.networks.map((network) =>
|
networks: client.networks.map((network) =>
|
||||||
network.getFilteredClone(client.lastActiveChannel, lastMessage)
|
network.getFilteredClone(openChannel, lastMessage)
|
||||||
),
|
),
|
||||||
token: tokenToSend,
|
token: tokenToSend,
|
||||||
});
|
});
|
||||||
@ -705,7 +717,7 @@ function performAuthentication(data) {
|
|||||||
let token = null;
|
let token = null;
|
||||||
|
|
||||||
const finalInit = () => {
|
const finalInit = () => {
|
||||||
initializeClient(socket, client, token, data.lastMessage || -1);
|
initializeClient(socket, client, token, data.lastMessage || -1, data.openChannel);
|
||||||
|
|
||||||
if (!Helper.config.public) {
|
if (!Helper.config.public) {
|
||||||
client.manager.updateUser(client.name, {
|
client.manager.updateUser(client.name, {
|
||||||
|
Loading…
Reference in New Issue
Block a user