mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-26 09:38:32 +01:00
feat(tavern): unified global chat with persistent history in the tavern
The tavern used ephemeral, room-scoped chat with no backlog, so entering it showed a blank log. Wire it to the shared global chat provider instead: - TavernManager takes a globalChatProvider (the lobby's chat provider) and publishes tavern messages to the 'global' scope, so tavern + lobby share ONE conversation that persists to Postgres and (when NOSTR_CHAT_ENABLED) fans out over relay.smirk.cash. Falls back to the old tavern-scoped ephemeral provider when none is injected. - On join, the tavern sends the recent global backlog (chat_history) to the joiner so history shows immediately. - tavern.html: render chat_history on join and accept global-scope broadcasts (not just this room's), so lobby<->tavern messages flow both ways. Tests: +3 (join sends backlog, chat routes to global scope, legacy fallback stays tavern-scoped). Suite 55 suites / 394 tests green.
This commit is contained in:
+14
-1
@@ -323,7 +323,10 @@
|
||||
|
||||
// ---- Chat --------------------------------------------------------------------
|
||||
socket.on('chat_broadcast', function (m) {
|
||||
if (!m || !state.channel || m.scope !== state.channel) return;
|
||||
if (!m) return;
|
||||
// Accept the unified GLOBAL chat (no scope / 'global') as well as this tavern's room.
|
||||
var isGlobal = !m.scope || m.scope === 'global';
|
||||
if (!isGlobal && m.scope !== state.channel) return;
|
||||
addChatLine(m.username, m.message);
|
||||
// Show a speech bubble above the speaker's avatar.
|
||||
if (tavernLife && m.socketId) {
|
||||
@@ -335,6 +338,16 @@
|
||||
socket.on('tavern_notice', function (n) {
|
||||
if (n && n.message) addSystemLine(n.message);
|
||||
});
|
||||
// Global chat backlog sent on join — render it so the tavern shows history, not a blank log.
|
||||
socket.on('chat_history', function (payload) {
|
||||
var msgs = payload && payload.messages;
|
||||
if (!msgs || !msgs.length) return;
|
||||
for (var i = 0; i < msgs.length; i++) {
|
||||
var mm = msgs[i] || {};
|
||||
var uname = mm.username || mm.playerId || (mm.socketId ? String(mm.socketId).slice(0, 6) : '???');
|
||||
addChatLine(uname, mm.message || '');
|
||||
}
|
||||
});
|
||||
function addSystemLine(text) {
|
||||
var line = document.createElement('div');
|
||||
line.className = 'cline csys';
|
||||
|
||||
Reference in New Issue
Block a user