mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
fix: #12017, unreliable forum updated messaging
- Removed payload from event:nodebb.ready event (ready to remove for v4 in favour) - Send hostname/cache-buster payload in meta.reconnected method instead
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
const io = require('socket.io-client');
|
||||
// eslint-disable-next-line no-redeclare
|
||||
const $ = require('jquery');
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
const { alert } = require('alerts');
|
||||
|
||||
app = window.app || {};
|
||||
|
||||
@@ -113,23 +115,6 @@ app = window.app || {};
|
||||
console.warn('[socket.io] ', data.eventName, 'is now deprecated in favour of', data.replacement);
|
||||
});
|
||||
|
||||
socket.removeAllListeners('event:nodebb.ready');
|
||||
socket.on('event:nodebb.ready', function (data) {
|
||||
if ((data.hostname === app.upstreamHost) && (!app.cacheBuster || app.cacheBuster !== data['cache-buster'])) {
|
||||
app.cacheBuster = data['cache-buster'];
|
||||
require(['alerts'], function (alerts) {
|
||||
alerts.alert({
|
||||
alert_id: 'forum_updated',
|
||||
title: '[[global:updated.title]]',
|
||||
message: '[[global:updated.message]]',
|
||||
clickfn: function () {
|
||||
window.location.reload();
|
||||
},
|
||||
type: 'warning',
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
socket.on('event:livereload', function () {
|
||||
if (app.user.isAdmin && !ajaxify.currentPage.match(/admin/)) {
|
||||
window.location.reload();
|
||||
@@ -156,7 +141,7 @@ app = window.app || {};
|
||||
});
|
||||
}
|
||||
|
||||
function onConnect() {
|
||||
async function onConnect() {
|
||||
if (!reconnecting) {
|
||||
hooks.fire('action:connected');
|
||||
} else {
|
||||
@@ -171,7 +156,19 @@ app = window.app || {};
|
||||
|
||||
reJoinCurrentRoom();
|
||||
|
||||
socket.emit('meta.reconnected');
|
||||
const { 'cache-buster': hash, hostname } = await socket.emit('meta.reconnected');
|
||||
if ((hostname === app.upstreamHost) && (!app.cacheBuster || app.cacheBuster !== hash)) {
|
||||
app.cacheBuster = hash;
|
||||
alert({
|
||||
alert_id: 'forum_updated',
|
||||
title: '[[global:updated.title]]',
|
||||
message: '[[global:updated.message]]',
|
||||
clickfn: function () {
|
||||
window.location.reload();
|
||||
},
|
||||
type: 'warning',
|
||||
});
|
||||
}
|
||||
|
||||
hooks.fire('action:reconnected');
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
const os = require('os');
|
||||
|
||||
const user = require('../user');
|
||||
const meta = require('../meta');
|
||||
const topics = require('../topics');
|
||||
|
||||
const SocketMeta = module.exports;
|
||||
@@ -13,7 +15,10 @@ SocketMeta.reconnected = function (socket, data, callback) {
|
||||
topics.pushUnreadCount(socket.uid);
|
||||
user.notifications.pushCount(socket.uid);
|
||||
}
|
||||
callback();
|
||||
callback(null, {
|
||||
'cache-buster': meta.config['cache-buster'],
|
||||
hostname: os.hostname(),
|
||||
});
|
||||
};
|
||||
|
||||
/* Rooms */
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const nconf = require('nconf');
|
||||
const express = require('express');
|
||||
const chalk = require('chalk');
|
||||
@@ -85,10 +84,7 @@ exports.listen = async function () {
|
||||
await initializeNodeBB();
|
||||
winston.info('🎉 NodeBB Ready');
|
||||
|
||||
require('./socket.io').server.emit('event:nodebb.ready', {
|
||||
'cache-buster': meta.config['cache-buster'],
|
||||
hostname: os.hostname(),
|
||||
});
|
||||
require('./socket.io').server.emit('event:nodebb.ready', {});
|
||||
|
||||
plugins.hooks.fire('action:nodebb.ready');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user