Keep the expedition view in sync with other players and only send alerts players still want
- The expeditions page rereads its view on its own: every 10 seconds while a group is shown, every 20 seconds otherwise, on tab return and at the next recruitment deadline; late responses no longer overwrite a newer action. A failed load offers "Réessayer" and a failed refresh keeps the last view. - The periodic alert pass first departs groups whose recruitment ended, so their return is announced even if nobody visits the site. - Queued alerts are checked again at sending time: a player who opted out or alerts switched off by the administration drop the message for good. - The engraving confirmation sticks to the bottom of its window, the workshop lists commons by spare count, the guild expeditions card shows the Great Void, and stale help texts and comments are fixed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
30413de036
commit
84b0d69b1f
13 changed files with 174 additions and 24 deletions
|
|
@ -407,6 +407,8 @@ export function validateSiteContent(site) {
|
|||
"cards.expeditions.closedText",
|
||||
"cards.expeditions.expired",
|
||||
"cards.expeditions.reload",
|
||||
"cards.expeditions.retry",
|
||||
"cards.expeditions.syncError",
|
||||
"cards.expeditions.reportMeta",
|
||||
"cards.expeditions.running",
|
||||
"cards.expeditions.returned",
|
||||
|
|
|
|||
|
|
@ -948,6 +948,49 @@ test("Discord alerts stay off until a player opts in, then queue group openings
|
|||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM alert_outbox WHERE player_id = ?").get(friend.id).count, 0);
|
||||
});
|
||||
|
||||
// Passage périodique des alertes, sans aucune visite de joueur : un groupe dont l'inscription est échue part, puis son retour est
|
||||
// annoncé. Un message déjà en file n'est envoyé que s'il est encore voulu : désactivé par le joueur ou coupé par l'administration,
|
||||
// il est abandonné, et ne repart pas plus tard.
|
||||
test("periodic alerts settle due groups without any visit and drop messages no longer wanted", async () => {
|
||||
const context = expeditionService();
|
||||
const { clock, service, player, open, rares, database } = context;
|
||||
service.expeditions.alertsAvailable = true;
|
||||
open();
|
||||
const friend = service.upsertPlayer({ discordId: "123456789012345678", displayName: "Friend" });
|
||||
database.db.prepare("UPDATE players SET discord_id = '323456789012345678' WHERE id = ?").run(player.id);
|
||||
service.expeditions.setAlertPreferences(player.id, { groupOpened: false, expeditionReturned: true });
|
||||
service.expeditions.setAlertPreferences(friend.id, { groupOpened: true, expeditionReturned: false });
|
||||
const sent = [];
|
||||
const send = async (discordId, content) => { sent.push({ discordId, content }); };
|
||||
|
||||
// Groupe ouvert : l'ami est prévenu, mais désactive l'alerte avant l'envoi ; le message est abandonné.
|
||||
const view = service.expeditions.getExpeditions(player.id);
|
||||
const group = service.expeditions.createGroup(player.id, groupBody(view, rares[0]), "auto-depart").expeditions.groups[0];
|
||||
service.expeditions.setAlertPreferences(friend.id, { groupOpened: false, expeditionReturned: false });
|
||||
assert.equal(await dispatchAlerts(service.expeditions, send), 0);
|
||||
assert.deepEqual({ ...database.db.prepare("SELECT kind, last_error FROM alert_outbox WHERE player_id = ?").get(friend.id) }, { kind: "group_opened", last_error: "player opted out" });
|
||||
service.expeditions.setAlertPreferences(friend.id, { groupOpened: true, expeditionReturned: false });
|
||||
assert.equal(await dispatchAlerts(service.expeditions, send), 0);
|
||||
|
||||
// Personne ne revient sur le site : l'inscription puis le voyage s'achèvent, le passage fait partir le groupe et annonce son retour.
|
||||
clock.now = group.recruitUntil + 3 * HOUR;
|
||||
assert.equal(await dispatchAlerts(service.expeditions, send), 1);
|
||||
assert.equal(sent[0].discordId, "323456789012345678");
|
||||
assert.match(sent[0].content, /est de retour/);
|
||||
assert.equal(database.db.prepare("SELECT status FROM expeditions WHERE id = ?").get(group.id).status, "running");
|
||||
|
||||
// Coupées par l'administration après la mise en file : le message n'est pas envoyé, ni plus tard une fois les alertes rouvertes.
|
||||
const later = service.expeditions.getExpeditions(player.id);
|
||||
service.expeditions.claim(player.id, later.expeditions[0].id);
|
||||
service.expeditions.createGroup(player.id, groupBody(service.expeditions.getExpeditions(player.id), rares[1]), "second-group");
|
||||
service.expeditions.updateSettings(context.admin.id, { ...service.expeditions.settings, alerts: { enabled: false } });
|
||||
assert.equal(await dispatchAlerts(service.expeditions, send), 0);
|
||||
service.expeditions.updateSettings(context.admin.id, { ...service.expeditions.settings, alerts: { enabled: true } });
|
||||
assert.equal(await dispatchAlerts(service.expeditions, send), 0);
|
||||
assert.equal(sent.length, 1);
|
||||
assert.equal(database.db.prepare("SELECT COUNT(*) AS count FROM alert_outbox WHERE last_error = 'alerts disabled'").get().count, 1);
|
||||
});
|
||||
|
||||
test("the alert sender posts to palico-bot with its key and flags permanent refusals", async () => {
|
||||
const calls = [];
|
||||
const answers = [204, 422, 503];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue