mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-04-25 15:40:31 -05:00
Spotlights: Automatically refresh pages on spotlight change
This commit is contained in:
parent
d33bbfeba5
commit
11ab3d83f8
|
|
@ -70,9 +70,11 @@ export const pages: Chat.PageTable = {
|
|||
if (!spotlights[room.roomid]) {
|
||||
buf += `<p>This room has no daily spotlights.</p></div>`;
|
||||
} else {
|
||||
for (const key in spotlights[room.roomid]) {
|
||||
const sortedKeys = Utils.sortBy(Object.keys(spotlights[room.roomid]));
|
||||
for (const key of sortedKeys) {
|
||||
buf += `<table style="margin-bottom:30px;"><th colspan="2"><h3>${key}:</h3></th>`;
|
||||
for (const [i] of spotlights[room.roomid][key].entries()) {
|
||||
const keys = Utils.sortBy(spotlights[room.roomid][key], str => str.description);
|
||||
for (const [i] of keys.entries()) {
|
||||
const html = await renderSpotlight(room.roomid, key, i);
|
||||
buf += `<tr><td>${i ? i : 'Current'}</td><td>${html}</td></tr>`;
|
||||
if (!user.can('announce', null, room)) break;
|
||||
|
|
@ -114,6 +116,7 @@ export const commands: Chat.ChatCommands = {
|
|||
this.modlog(`DAILY REMOVE`, key);
|
||||
this.sendReply(`The daily spotlight named '${key}' has been successfully removed.`);
|
||||
}
|
||||
Chat.refreshPageFor(`spotlights-${room.roomid}`, room);
|
||||
},
|
||||
swapdailies: 'swapdaily',
|
||||
swapdaily(target, room, user) {
|
||||
|
|
@ -144,6 +147,7 @@ export const commands: Chat.ChatCommands = {
|
|||
|
||||
this.modlog(`DAILY QUEUE SWAP`, key, `${indexA} with ${indexB}`);
|
||||
this.privateModAction(`${user.name} swapped the queued dailies for '${key}' at queue numbers ${indexA} and ${indexB}.`);
|
||||
Chat.refreshPageFor(`spotlights-${room.roomid}`, room);
|
||||
},
|
||||
queuedaily: 'setdaily',
|
||||
queuedailyat: 'setdaily',
|
||||
|
|
@ -211,6 +215,7 @@ export const commands: Chat.ChatCommands = {
|
|||
}
|
||||
}
|
||||
saveSpotlights();
|
||||
Chat.refreshPageFor(`spotlights-${room.roomid}`, room);
|
||||
},
|
||||
async daily(target, room, user) {
|
||||
room = this.requireRoom();
|
||||
|
|
|
|||
|
|
@ -797,20 +797,6 @@ export async function getBattleLog(battle: string): Promise<BattleInfo | null> {
|
|||
return null;
|
||||
}
|
||||
|
||||
function refreshPageFor(page: string, roomid: RoomID, ignoreUsers?: ID[]) {
|
||||
const room = Rooms.get(roomid);
|
||||
if (room) {
|
||||
for (const curUser of Object.values(room.users)) {
|
||||
if (ignoreUsers?.includes(curUser.id)) continue;
|
||||
for (const conn of curUser.connections) {
|
||||
if (conn.openPages?.has(page)) {
|
||||
void Chat.parse(`/j view-${page}`, room, curUser, conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent a desynchronization issue when hotpatching
|
||||
for (const room of Rooms.rooms.values()) {
|
||||
if (!room.settings.isHelp || !room.game) continue;
|
||||
|
|
@ -1589,7 +1575,7 @@ export const pages: Chat.PageTable = {
|
|||
ticket.claimed = user.id;
|
||||
writeTickets();
|
||||
notifyStaff();
|
||||
refreshPageFor(`help-text-${ticket.userid}`, 'staff', [user.id]);
|
||||
Chat.refreshPageFor(`help-text-${ticket.userid}`, 'staff', false, [user.id]);
|
||||
} else if (ticket.claimed) {
|
||||
buf += `<strong>Claimed:</strong> ${ticket.claimed}<br /><br />`;
|
||||
}
|
||||
|
|
@ -2194,7 +2180,7 @@ export const commands: Chat.ChatCommands = {
|
|||
// force a refresh for everyone in it, otherwise we potentially get two punishments at once
|
||||
// from different people clicking at the same time and reading it separately.
|
||||
// Yes. This was a real issue.
|
||||
refreshPageFor(`help-text-${ticketId}`, 'staff');
|
||||
Chat.refreshPageFor(`help-text-${ticketId}`, 'staff');
|
||||
},
|
||||
|
||||
list(target, room, user) {
|
||||
|
|
|
|||
|
|
@ -2399,6 +2399,29 @@ export const Chat = new class {
|
|||
return [Math.round(width * ratio), Math.round(height * ratio), true];
|
||||
}
|
||||
|
||||
refreshPageFor(
|
||||
pageid: string,
|
||||
roomid: Room | RoomID,
|
||||
checkPrefix = false,
|
||||
ignoreUsers: ID[] | null = null
|
||||
) {
|
||||
const room = Rooms.get(roomid);
|
||||
if (!room) return false;
|
||||
for (const id in room.users) {
|
||||
if (ignoreUsers?.includes(id as ID)) continue;
|
||||
const u = room.users[id];
|
||||
for (const conn of u.connections) {
|
||||
if (conn.openPages) {
|
||||
for (const page of conn.openPages) {
|
||||
if ((checkPrefix ? page.startsWith(pageid) : page === pageid)) {
|
||||
void this.parse(`/j view-${page}`, room, u, conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies a targetUser that a user was blocked from reaching them due to a setting they have enabled.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user