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:
1 parent
53d1382ac0
commit
8aca1bc28e
10 files changed
+120
-20
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in new issue
Block a user