fix: Story-Mitteilung oeffnet direkt die Story, nie mehr Code-Namen als Text

Tester-Feedback 04.10. (STORY_MENTION):
- Web: Klick oeffnet die Story als Overlay an der richtigen Stelle
  (initialStoryId) statt ueber das Tierprofil; abgelaufen → Profil.
- App: ganzer Eintrag inkl. Name oeffnet die Story, Viewer springt per
  storyId direkt zur markierten Story.
- Unbekannte Mitteilungstypen zeigen einen neutralen Text statt des
  Code-Namens (der rohe Text kam von einem Geraet mit aelterem App-Stand).
- Keine Markier-Mitteilung an eigene Tiere des Erstellers (petsOfOtherOwners).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-10-04 17:28:15 +02:00
1 parent 53d1382ac0
commit 8aca1bc28e
10 files changed
+120 -20

No files matched your search

+2 -1
View File
@@ -486,7 +486,8 @@
"typeVaccineDue": "💉 Die Impfung „{name}“ ist am {date} fällig – Zeit, einen Termin zu vereinbaren.",
"typeStoryMention": "hat dich in einer Story markiert.",
"typeStoryComment": "hat deine Story kommentiert.",
"typeStoryReaction": "hat deiner Story eine Pfote gegeben."
"typeStoryReaction": "hat deiner Story eine Pfote gegeben.",
"typeUnknown": "hat eine neue Mitteilung für dich."
},
"PhotoPostForm": {
"captionPlaceholder": "Bildunterschrift schreiben…",
+2 -1
View File
@@ -486,7 +486,8 @@
"typeVaccineDue": "💉 The \"{name}\" vaccination is due on {date} – time to book an appointment.",
"typeStoryMention": "tagged you in a story.",
"typeStoryComment": "commented on your story.",
"typeStoryReaction": "gave your story a paw."
"typeStoryReaction": "gave your story a paw.",
"typeUnknown": "has a new notification for you."
},
"PhotoPostForm": {
"captionPlaceholder": "Write a caption…",
+16 -2
View File
@@ -50,7 +50,8 @@ function getNotificationSuffix(item: NotificationItem, t: TFunction): string {
if (selfKey) return t(selfKey);
const actorKey = ACTOR_MESSAGE_KEYS[item.type];
if (actorKey && item.actorPet) return t(actorKey);
return item.type;
// Nie den Code-Namen zeigen (z. B. neuer Typ vom Server, den diese App-Version noch nicht kennt).
return t("notifications.unknown");
}
const SELF_ICONS: Partial<Record<NotificationItem["type"], string>> = {
@@ -79,6 +80,7 @@ function getNotificationRoute(item: NotificationItem): string | null {
petId: item.story.petId,
petName: item.story.pet.name,
petAvatarKey: item.story.pet.avatarKey ?? "",
storyId: item.story.id,
});
return `/story-viewer?${params.toString()}`;
}
@@ -196,7 +198,19 @@ export default function NotificationsScreen() {
<View style={styles.rowText}>
<Text style={styles.bodyText}>
{item.actorPet && (
<Text style={styles.actorName} onPress={() => router.push(`/pets/${item.actorPet!.id}`)}>
<Text
style={styles.actorName}
onPress={() => {
// Bei Story-Mitteilungen führt auch der Name zur Story (nicht zum Profil-Umweg).
const storyRoute = item.story ? getNotificationRoute(item) : null;
if (storyRoute) {
if (!item.read) markRead.mutate({ notificationId: item.id });
router.push(storyRoute);
} else {
router.push(`/pets/${item.actorPet!.id}`);
}
}}
>
{formatPetName(item.actorPet)}{" "}
</Text>
)}
+13 -1
View File
@@ -34,10 +34,12 @@ type Sheet = "comments" | "viewers" | "confirm-delete" | "away" | null;
* die Lösch-Rückfrage offen ist, hält der Timer an.
*/
export default function StoryViewerScreen() {
const { petId, petName, petAvatarKey } = useLocalSearchParams<{
const { petId, petName, petAvatarKey, storyId: initialStoryId } = useLocalSearchParams<{
petId: string;
petName: string;
petAvatarKey?: string;
/** Aus einer Mitteilung: direkt diese Story zeigen statt der ersten. */
storyId?: string;
}>();
const { t } = useTranslation();
const router = useRouter();
@@ -50,6 +52,7 @@ export default function StoryViewerScreen() {
const listQuery = trpc.stories.listActive.queryOptions({ petId, viewerPetId: activePetId ?? undefined });
const { data: stories = [], isSuccess: storiesLoaded } = useQuery(listQuery);
const [index, setIndex] = useState(0);
const jumpedToInitialRef = useRef(false);
const [progress, setProgress] = useState(0);
const [openSheet, setOpenSheet] = useState<Sheet>(null);
const advancedRef = useRef(false);
@@ -190,6 +193,15 @@ export default function StoryViewerScreen() {
return () => cancelAnimationFrame(rafId);
}, [currentStory, isVideo, isPaused, advance]);
// Aus einer Mitteilung geöffnet → einmalig zur genannten Story springen.
useEffect(() => {
if (jumpedToInitialRef.current || !initialStoryId || stories.length === 0) return;
jumpedToInitialRef.current = true;
const target = stories.findIndex((s) => s.id === initialStoryId);
// eslint-disable-next-line react-hooks/set-state-in-effect -- einmaliger Sprung, sobald die Liste da ist
if (target > 0) setIndex(target);
}, [initialStoryId, stories]);
// Keine (laufende) Story mehr, z. B. über eine alte Mitteilung geöffnet → zurück statt schwarzem Bildschirm.
useEffect(() => {
if (storiesLoaded && stories.length === 0) router.back();
+2 -1
View File
@@ -213,7 +213,8 @@
"referralRankUp": "Du hast einen neuen Empfehlungsrang erreicht!",
"storyMention": "hat dich in einer Story markiert.",
"storyComment": "hat deine Story kommentiert.",
"storyReaction": "hat deiner Story eine Pfote gegeben."
"storyReaction": "hat deiner Story eine Pfote gegeben.",
"unknown": "Neue Mitteilung."
},
"pets": {
"empty": "Noch keine Tiere angelegt.",
+2 -1
View File
@@ -213,7 +213,8 @@
"referralRankUp": "You reached a new referral rank!",
"storyMention": "tagged you in a story.",
"storyComment": "commented on your story.",
"storyReaction": "gave your story a paw."
"storyReaction": "gave your story a paw.",
"unknown": "New notification."
},
"pets": {
"empty": "No pets added yet.",
+14 -1
View File
@@ -45,7 +45,7 @@ import {
storyMediaSize,
storyOverlaysSchema,
} from "@/lib/story-overlays";
import { filterMentionablePetIds } from "@/lib/story-mentions";
import { filterMentionablePetIds, petsOfOtherOwners } from "@/lib/story-mentions";
import { isStoryEditorEnabled, setStoryEditorEnabled } from "@/lib/feature-flags";
function createCaller() {
@@ -152,6 +152,19 @@ describe("filterMentionablePetIds — „Wer darf die Follower sehen?“ regelt
});
});
describe("petsOfOtherOwners", () => {
it("skips the creator's own pets when notifying", async () => {
const p = createMockPrisma();
p.pet.findMany.mockResolvedValue([
{ id: "me", ownerId: "owner-1" },
{ id: "my-other-pet", ownerId: "owner-1" },
{ id: "friend", ownerId: "owner-2" },
]);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(await petsOfOtherOwners(p as any, "me", ["my-other-pet", "friend"])).toEqual(["friend"]);
});
});
describe("stories.create with overlays", () => {
it("stores overlays + media size, drops disallowed mentions and notifies only allowed pets", async () => {
const { caller, mockPrisma } = createCaller();
+47 -9
View File
@@ -16,9 +16,12 @@ import type { PostCardPost } from "@/components/feed/PostCard";
import { useLocale, useTranslations } from "next-intl";
import { formatRelativeCompact } from "@/lib/format-relative-time";
import { RankRing } from "@/components/referrals/RankRing";
import { StoryViewer } from "@/components/stories/StoryViewer";
type NotificationType = "FOLLOW" | "REACTION" | "COMMENT" | "MESSAGE" | "BIRTHDAY" | "ADOPTION_DAY" | "MENTION" | "PAW_BACK" | "PET_SUGGESTION" | "REFERRAL_JOINED" | "REFERRAL_RANK_UP" | "VACCINE_DUE" | "STORY_MENTION" | "STORY_COMMENT" | "STORY_REACTION";
const KNOWN_TYPES = new Set<string>(["FOLLOW", "REACTION", "COMMENT", "MESSAGE", "BIRTHDAY", "ADOPTION_DAY", "MENTION", "PAW_BACK", "PET_SUGGESTION", "REFERRAL_JOINED", "REFERRAL_RANK_UP", "VACCINE_DUE", "STORY_MENTION", "STORY_COMMENT", "STORY_REACTION"]);
function notificationIcon(type: NotificationType) {
switch (type) {
case "FOLLOW": return <UserPlus className="h-4 w-4 text-orange-500" />;
@@ -49,7 +52,7 @@ export default function NotificationsPage() {
const locale = useLocale();
const formatRelativeTime = (date: Date | string) => formatRelativeCompact(date, trt);
const { data, isLoading } = useQuery({
const { data, isLoading, dataUpdatedAt } = useQuery({
...trpc.notifications.list.queryOptions({ petId: activePetId ?? "", limit: 30 }),
enabled: !!activePetId,
});
@@ -59,6 +62,9 @@ export default function NotificationsPage() {
// swapped out the notifications page in the background, so closing the
// dialog stranded the user on that profile instead of back on this list.
const [openPostId, setOpenPostId] = useState<string | null>(null);
// Story-Mitteilungen öffnen die Story direkt hier als Overlay (an der richtigen Story),
// statt über das Tierprofil — Tester-Feedback 04.10.
const [openStory, setOpenStory] = useState<{ petId: string; petName: string; petAvatarKey: string | null; storyId: string } | null>(null);
const [selectedPost, setSelectedPost] = useState<PostCardPost | null>(null);
const { data: fetchedPost } = useQuery({
@@ -103,11 +109,12 @@ export default function NotificationsPage() {
return notif.actorPet ? `/pets/${notif.actorPet.id}` : null;
case "REFERRAL_RANK_UP":
return "/einladen";
// Story-Mitteilungen → Tierprofil (dort läuft die Story über den Ring)
// Story-Mitteilungen: läuft die Story noch (oder ist es die eigene, 7 Tage sichtbar),
// öffnet getStoryTarget() sie direkt; sonst bleibt nur das Tierprofil.
case "STORY_MENTION":
case "STORY_COMMENT":
case "STORY_REACTION":
return notif.story ? `/pets/${notif.story.petId}` : null;
return notif.story && !getStoryTarget(notif) ? `/pets/${notif.story.petId}` : null;
case "BIRTHDAY":
case "ADOPTION_DAY":
case "VACCINE_DUE":
@@ -117,6 +124,21 @@ export default function NotificationsPage() {
}
}
function getStoryTarget(notif: (typeof notifications)[number]) {
if (!notif.story) return null;
if (notif.type !== "STORY_MENTION" && notif.type !== "STORY_COMMENT" && notif.type !== "STORY_REACTION") return null;
const isOwnStory = notif.story.petId === notif.recipientPetId;
// Bezugszeit = Ladezeitpunkt der Liste (kein Date.now() im Rendern)
const isRunning = new Date(notif.story.expiresAt).getTime() > dataUpdatedAt;
if (!isRunning && !isOwnStory) return null;
return {
petId: notif.story.petId,
petName: notif.story.pet.name,
petAvatarKey: notif.story.pet.avatarKey,
storyId: notif.story.id,
};
}
// Post-related notifications — opened in-place via PostDetailDialog instead.
function getPostId(notif: (typeof notifications)[number]): string | null {
switch (notif.type) {
@@ -171,17 +193,20 @@ export default function NotificationsPage() {
: null;
const href = getHref(notif);
const postId = getPostId(notif);
const isClickable = !!href || !!postId;
const storyTarget = getStoryTarget(notif);
const isClickable = !!href || !!postId || !!storyTarget;
return (
<li
key={notif.id}
onClick={
href
? () => router.push(href)
: postId
? () => setOpenPostId(postId)
: undefined
storyTarget
? () => setOpenStory(storyTarget)
: href
? () => router.push(href)
: postId
? () => setOpenPostId(postId)
: undefined
}
className={`flex items-start gap-3 p-3 rounded-lg transition-colors ${
!notif.read ? "bg-orange-500/5" : "hover:bg-muted/50"
@@ -248,6 +273,7 @@ export default function NotificationsPage() {
{notif.type === "PET_SUGGESTION" && t("typePetSuggestion")}
{notif.type === "REFERRAL_JOINED" && t("typeReferralJoined")}
{notif.type === "REFERRAL_RANK_UP" && t("typeReferralRankUp")}
{!KNOWN_TYPES.has(notif.type) && t("typeUnknown")}
{notif.type === "STORY_MENTION" && t("typeStoryMention")}
{notif.type === "STORY_COMMENT" && t("typeStoryComment")}
{notif.type === "STORY_REACTION" && t("typeStoryReaction")}
@@ -293,6 +319,18 @@ export default function NotificationsPage() {
onClose={closePostDialog}
onDeleted={closePostDialog}
/>
{openStory && (
<StoryViewer
petId={openStory.petId}
petName={openStory.petName}
petAvatarKey={openStory.petAvatarKey}
initialStoryId={openStory.storyId}
open
onOpenChange={(isOpen) => {
if (!isOpen) setOpenStory(null);
}}
/>
)}
</>
);
}
+3 -2
View File
@@ -5,7 +5,7 @@ import { redis } from "@/lib/redis";
import { fanOutPost } from "@/lib/feed-helpers";
import { MAX_STORY_VIDEO_DURATION_SECS } from "@/lib/story-video-limits";
import { maybeQualifyReferral } from "@/lib/referrals";
import { notifyStoryMentions } from "@/lib/story-mentions";
import { notifyStoryMentions, petsOfOtherOwners } from "@/lib/story-mentions";
/**
* POST /api/webhooks/mux
@@ -130,7 +130,8 @@ export async function POST(req: NextRequest) {
// jetzt ist die Story sichtbar → jetzt benachrichtigen.
if (!overStoryLimit) {
const mentions = await prisma.storyMention.findMany({ where: { storyId: story.id }, select: { petId: true } });
notifyStoryMentions(prisma, story.id, story.petId, mentions.map((m) => m.petId));
const recipients = await petsOfOtherOwners(prisma, story.petId, mentions.map((m) => m.petId));
notifyStoryMentions(prisma, story.id, story.petId, recipients);
}
break;
}
+19 -1
View File
@@ -72,7 +72,25 @@ export async function saveStoryMentions(
data: petIds.map((petId) => ({ storyId, petId })),
skipDuplicates: true,
});
if (sendNotifications) notifyStoryMentions(prisma, storyId, actorPetId, petIds);
if (sendNotifications) notifyStoryMentions(prisma, storyId, actorPetId, await petsOfOtherOwners(prisma, actorPetId, petIds));
}
/** Eigene Tiere des Erstellers markieren ist erlaubt, aber eine Mitteilung an sich selbst ist sinnlos. */
export async function petsOfOtherOwners(
prisma: Pick<PrismaClient, "pet">,
actorPetId: string,
petIds: readonly string[]
): Promise<string[]> {
if (petIds.length === 0) return [];
const pets = await prisma.pet.findMany({
where: { id: { in: [actorPetId, ...petIds] } },
select: { id: true, ownerId: true },
});
const actorOwner = pets.find((p) => p.id === actorPetId)?.ownerId;
return petIds.filter((id) => {
const owner = pets.find((p) => p.id === id)?.ownerId;
return owner !== undefined && owner !== actorOwner;
});
}
/** Fire-and-forget wie notify() selbst — darf das Erstellen der Story nie scheitern lassen. */