@@ -460,13 +469,22 @@ export function StoryViewer({
{/* Gitea #29 — paw + comment buttons, bottom right */}
{activePetId && (
-
+ {currentStory.isExpired ? (
+
+
+
+
+ {currentStory.reactionCount > 0 && {currentStory.reactionCount}}
+
+ ) : (
+
+ )}
,
diff --git a/src/trpc/routers/stories.ts b/src/trpc/routers/stories.ts
index d6292d9..f16a61d 100644
--- a/src/trpc/routers/stories.ts
+++ b/src/trpc/routers/stories.ts
@@ -8,7 +8,15 @@ import {
ALLOWED_CONTENT_TYPES,
MAX_FILE_SIZE,
} from "@/lib/supabase-storage";
-import { deleteStoryWithMedia } from "@/lib/story-cleanup";
+import { STORY_RETENTION_DAYS, deleteStoryWithMedia } from "@/lib/story-cleanup";
+
+const DAY_MS = 24 * 60 * 60 * 1000;
+
+/** Besitzt der aufrufende Owner dieses Tier? Für die 7-Tage-Ansicht des Erstellers. */
+async function isOwnPet(prisma: PrismaClient, petId: string, userId: string): Promise
{
+ const pet = await prisma.pet.findUnique({ where: { id: petId }, select: { ownerId: true } });
+ return pet?.ownerId === userId;
+}
import { randomUUID } from "crypto";
import { petIdentitySelect } from "@/repositories/pet-repository";
import { assertPetOwnership } from "@/lib/assert-pet-ownership";
@@ -220,12 +228,20 @@ export const storiesRouter = router({
* With the optional viewerPetId, each story also carries reactedByViewer so
* the paw button can start filled — optional so older app builds that only
* send { petId } keep working unchanged (reactedByViewer is then false).
+ *
+ * 7-Tage-Ansicht: Der Owner des Tiers bekommt zusätzlich seine abgelaufenen
+ * Storys der letzten STORY_RETENTION_DAYS (isExpired: true) — alle anderen
+ * sehen weiterhin nur die aktiven 24 Stunden.
*/
listActive: protectedProcedure
.input(z.object({ petId: z.string().min(1), viewerPetId: z.string().min(1).optional() }))
.query(async ({ ctx, input }) => {
+ const now = new Date();
+ const ownerView = await isOwnPet(ctx.prisma, input.petId, ctx.userId);
const stories = await ctx.prisma.story.findMany({
- where: { petId: input.petId, expiresAt: { gt: new Date() } },
+ where: ownerView
+ ? { petId: input.petId, createdAt: { gte: new Date(now.getTime() - STORY_RETENTION_DAYS * DAY_MS) } }
+ : { petId: input.petId, expiresAt: { gt: now } },
include: {
musicTrack: true,
...(input.viewerPetId
@@ -238,6 +254,7 @@ export const storiesRouter = router({
return stories.map(({ reactions, ...story }: (typeof stories)[number] & { reactions?: { petId: string }[] }) => ({
...story,
reactedByViewer: (reactions?.length ?? 0) > 0,
+ isExpired: story.expiresAt <= now,
}));
}),
@@ -249,16 +266,34 @@ export const storiesRouter = router({
* viewerPetId is optional — without it allSeen is always false.
*/
hasActiveStory: protectedProcedure
- .input(z.object({ petId: z.string().min(1), viewerPetId: z.string().optional() }))
+ .input(
+ z.object({
+ petId: z.string().min(1),
+ viewerPetId: z.string().optional(),
+ // Nur die Story-Leiste setzt das: eigene, schon abgelaufene Storys der
+ // letzten 7 Tage ergeben einen grauen Ring (expiredOnly). Überall sonst
+ // (Profilbilder im Feed usw.) bleibt es beim 24-Stunden-Verhalten.
+ includeOwnRecent: z.boolean().optional(),
+ })
+ )
.query(async ({ ctx, input }) => {
+ const now = new Date();
const activeStories = await ctx.prisma.story.findMany({
- where: { petId: input.petId, expiresAt: { gt: new Date() } },
+ where: { petId: input.petId, expiresAt: { gt: now } },
select: { id: true },
});
- if (activeStories.length === 0) return { hasStory: false, allSeen: false };
+ if (activeStories.length === 0) {
+ if (input.includeOwnRecent && (await isOwnPet(ctx.prisma, input.petId, ctx.userId))) {
+ const recent = await ctx.prisma.story.count({
+ where: { petId: input.petId, createdAt: { gte: new Date(now.getTime() - STORY_RETENTION_DAYS * DAY_MS) } },
+ });
+ if (recent > 0) return { hasStory: true, allSeen: true, expiredOnly: true };
+ }
+ return { hasStory: false, allSeen: false, expiredOnly: false };
+ }
- if (!input.viewerPetId) return { hasStory: true, allSeen: false };
+ if (!input.viewerPetId) return { hasStory: true, allSeen: false, expiredOnly: false };
const viewedCount = await ctx.prisma.storyView.count({
where: {
@@ -267,7 +302,7 @@ export const storiesRouter = router({
},
});
- return { hasStory: true, allSeen: viewedCount >= activeStories.length };
+ return { hasStory: true, allSeen: viewedCount >= activeStories.length, expiredOnly: false };
}),
/**