Hide standard_donate megaphone after getting a badge

Co-authored-by: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2026-02-18 11:20:52 -06:00
committed by GitHub
parent de264cc019
commit 28f12dbe39
2 changed files with 29 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ export async function runMegaphoneCheck(): Promise<void> {
}
const megaphones = await DataReader.getAllMegaphones();
const shownIds: Set<RemoteMegaphoneId> = new Set();
log.info(
`runMegaphoneCheck: Checking ${megaphones.length} locally saved megaphones`
@@ -61,7 +62,10 @@ export async function runMegaphoneCheck(): Promise<void> {
for (const megaphone of megaphones) {
try {
// eslint-disable-next-line no-await-in-loop
await processMegaphone(megaphone);
const result = await processMegaphone(megaphone);
if (result === 'shown') {
shownIds.add(megaphone.id);
}
} catch (error) {
log.error(
`runMegaphoneCheck: Error processing ${megaphone.id}`,
@@ -69,6 +73,17 @@ export async function runMegaphoneCheck(): Promise<void> {
);
}
}
// Hide megaphones which are visible but should no longer be shown
// Example: standard_donate, then you donated on primary and got a badge
const { visibleMegaphones } = window.reduxStore.getState().megaphones;
for (const visibleMegaphone of visibleMegaphones) {
const { id } = visibleMegaphone;
if (!shownIds.has(id)) {
log.info(`runMegaphoneCheck: Hiding ${id}`);
window.reduxActions.megaphones.removeVisibleMegaphone(id);
}
}
} finally {
clearTimeoutIfNecessary(nextCheckTimeout);
nextCheckTimeout = safeSetTimeout(() => {
@@ -131,13 +146,15 @@ export async function deleteMegaphoneAndRemoveFromRedux(
// Private
async function processMegaphone(megaphone: RemoteMegaphoneType): Promise<void> {
async function processMegaphone(
megaphone: RemoteMegaphoneType
): Promise<'shown' | 'not-shown'> {
const { id } = megaphone;
if (isMegaphoneDeletable(megaphone)) {
log.info(`processMegaphone: Deleting ${id}`);
await deleteMegaphoneAndRemoveFromRedux(id);
return;
return 'not-shown';
}
if (isMegaphoneShowable(megaphone)) {
@@ -153,7 +170,10 @@ async function processMegaphone(megaphone: RemoteMegaphoneType): Promise<void> {
log.info(`processMegaphone: Showing ${id}`);
window.reduxActions.megaphones.addVisibleMegaphone(megaphone);
return 'shown';
}
return 'not-shown';
}
export function isMegaphoneDeletable(megaphone: RemoteMegaphoneType): boolean {

View File

@@ -56,6 +56,7 @@ import {
import { ProfileDecryptError } from '../types/errors.std.js';
import { signalProtocolStore } from '../SignalProtocolStore.preload.js';
import { itemStorage } from '../textsecure/Storage.preload.js';
import { runMegaphoneCheck } from './megaphone.preload.js';
const log = createLogger('profiles');
@@ -765,6 +766,11 @@ async function doGetProfile(
: {}),
})),
});
// Refresh visible megaphones, since badges may affect conditionals
if (isMe(c.attributes)) {
drop(runMegaphoneCheck());
}
} else {
c.set({ badges: undefined });
}