- Admin „Vermisst“ (/p/[secret]/lost): alle Meldungen mit Status, Ort/Zeit, Reichweite (benachrichtigte Tiere), freigegebenen Kontaktwegen; Moderatoren schließen vergessene Meldungen (ohne Entwarnung) oder löschen Missbrauch, beides im Audit-Log (CLOSE_/DELETE_LOST_REPORT) - App: eigener Vermisst-Bildschirm /lost/[petId] mit Foto, Merkmalen, Kontakt (Anrufen, E-Mail, Nachricht in PawFeed), Fotos und Teilen — Profil-Banner und Push-Tipp auf PET_LOST führen dorthin statt in den Browser - lostReports.byPet + gemeinsamer Lader loadLostReportView für App und öffentliche Seite Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.2 KiB
TypeScript
83 lines
3.2 KiB
TypeScript
/**
|
|
* Wohin führt eine Mitteilung? Eine Regel für die Mitteilungsliste und für das
|
|
* Antippen einer Push-Mitteilung (Tester-Wunsch 04.10.: „Benachrichtigung bringt
|
|
* dich auf kürzestem Weg dorthin, wo es wichtig ist“).
|
|
*
|
|
* Push-Daten kommen von src/lib/notify.ts (Server): type, petId (Empfänger),
|
|
* actorPetId, postId, storyId, conversationId — fehlende Felder als "".
|
|
*/
|
|
export type NotificationTarget = {
|
|
type: string;
|
|
/** Empfänger-Tier (eigenes Tier) */
|
|
recipientPetId?: string | null;
|
|
actorPetId?: string | null;
|
|
postId?: string | null;
|
|
conversationId?: string | null;
|
|
storyId?: string | null;
|
|
/** Tier, dem die Story gehört — aus der Liste bekannt, beim Push hergeleitet */
|
|
storyPetId?: string | null;
|
|
storyPetName?: string | null;
|
|
storyPetAvatarKey?: string | null;
|
|
/** Ablauf der Story, falls bekannt (Liste); beim Push unbekannt → Viewer prüft selbst */
|
|
storyExpiresAt?: string | Date | null;
|
|
};
|
|
|
|
const STORY_TYPES = new Set(["STORY_MENTION", "STORY_COMMENT", "STORY_REACTION"]);
|
|
|
|
export function notificationRoute(target: NotificationTarget, now: number): string | null {
|
|
const { type, recipientPetId, actorPetId, postId, conversationId } = target;
|
|
|
|
if (STORY_TYPES.has(type) && target.storyId) {
|
|
// Markierung: Story gehört dem markierenden Tier; Kommentar/Pfote: der eigenen.
|
|
const storyPetId = target.storyPetId || (type === "STORY_MENTION" ? actorPetId : recipientPetId);
|
|
if (!storyPetId) return null;
|
|
const isOwnStory = storyPetId === recipientPetId;
|
|
const expired = target.storyExpiresAt ? new Date(target.storyExpiresAt).getTime() <= now : false;
|
|
if (expired && !isOwnStory) return `/pets/${storyPetId}`;
|
|
const params = new URLSearchParams({ petId: storyPetId, storyId: target.storyId });
|
|
if (target.storyPetName) params.set("petName", target.storyPetName);
|
|
if (target.storyPetAvatarKey) params.set("petAvatarKey", target.storyPetAvatarKey);
|
|
return `/story-viewer?${params.toString()}`;
|
|
}
|
|
|
|
switch (type) {
|
|
case "MESSAGE":
|
|
return conversationId ? `/messages/${conversationId}` : "/messages";
|
|
case "REACTION":
|
|
case "COMMENT":
|
|
case "MENTION":
|
|
case "PAW_BACK":
|
|
return postId ? `/posts/${postId}/comments` : null;
|
|
case "FOLLOW":
|
|
case "PET_SUGGESTION":
|
|
case "REFERRAL_JOINED":
|
|
case "PET_DECEASED":
|
|
case "PET_FOUND":
|
|
return actorPetId ? `/pets/${actorPetId}` : null;
|
|
case "PET_LOST":
|
|
return actorPetId ? `/lost/${actorPetId}` : null;
|
|
case "REFERRAL_RANK_UP":
|
|
return "/invite";
|
|
case "BIRTHDAY":
|
|
case "ADOPTION_DAY":
|
|
case "VACCINE_DUE":
|
|
return recipientPetId ? `/pets/${recipientPetId}/health` : null;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** Push-Daten (alles Strings, leer = fehlt) → Ziel. */
|
|
export function targetFromPushData(data: Record<string, unknown> | null | undefined): NotificationTarget | null {
|
|
if (!data || typeof data.type !== "string") return null;
|
|
const str = (key: string) => (typeof data[key] === "string" && data[key] ? (data[key] as string) : null);
|
|
return {
|
|
type: data.type,
|
|
recipientPetId: str("petId"),
|
|
actorPetId: str("actorPetId"),
|
|
postId: str("postId"),
|
|
storyId: str("storyId"),
|
|
conversationId: str("conversationId"),
|
|
};
|
|
}
|