Thread viewer for Bluesky
1import { sameDay } from '../utils.js';
2import { Post } from '../models/posts.js';
3import { settings } from '../models/settings.svelte.js';
4
5export class PostPresenter {
6
7 /**
8 * Contexts:
9 * - thread - a post in the thread tree
10 * - parent - parent reference above the thread root
11 * - quote - a quote embed
12 * - quotes - a post on the quotes page
13 * - feed - a post on the hashtag feed page
14 */
15
16 post: Post;
17 placement: PostPlacement;
18
19 constructor(post: Post, placement: PostPlacement) {
20 this.post = post;
21 this.placement = placement;
22 }
23
24 get timeFormatForTimestamp(): Intl.DateTimeFormatOptions {
25 if (this.placement == 'quotes' || this.placement == 'feed') {
26 return { weekday: 'short', day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric' };
27 } else if (this.post.isPageRoot || this.placement != 'thread') {
28 return { day: 'numeric', month: 'short', year: 'numeric', hour: 'numeric', minute: 'numeric' };
29 } else if (this.post.pageRoot && !sameDay(this.post.createdAt, this.post.pageRoot.createdAt)) {
30 return { day: 'numeric', month: 'short', hour: 'numeric', minute: 'numeric' };
31 } else {
32 return { hour: 'numeric', minute: 'numeric' };
33 }
34 }
35
36 get formattedTimestamp() {
37 let timeFormat = this.timeFormatForTimestamp;
38 return this.post.createdAt.toLocaleString(settings.dateLocale, timeFormat);
39 }
40}