Skip to content

Commit 2dc40f1

Browse files
authored
Merge pull request #220 from deholic/feature/timeline-banner-contrast
fix: 미스키 스레드/북마크 로딩 및 마크업 정리
2 parents c10cf0e + 018847c commit 2dc40f1

4 files changed

Lines changed: 60 additions & 2 deletions

File tree

src/infra/MisskeyHttpClient.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,30 @@ export class MisskeyHttpClient implements MastodonApi {
316316
return data.map((item) => mapMisskeyStatusWithInstance(item, account.instanceUrl));
317317
}
318318

319+
async fetchBookmarks(account: Account, limit: number = 20, maxId?: string): Promise<Status[]> {
320+
const response = await fetch(`${normalizeInstanceUrl(account.instanceUrl)}/api/i/favorites`, {
321+
method: "POST",
322+
headers: {
323+
"Content-Type": "application/json"
324+
},
325+
body: JSON.stringify(
326+
buildBody(account, {
327+
limit,
328+
untilId: maxId
329+
})
330+
)
331+
});
332+
if (!response.ok) {
333+
throw new Error("북마크를 불러오지 못했습니다.");
334+
}
335+
const data = (await response.json()) as unknown[];
336+
return data.map((item) => {
337+
const typed = item && typeof item === "object" ? (item as Record<string, unknown>) : null;
338+
const note = typed && typed.note ? typed.note : item;
339+
return mapMisskeyStatusWithInstance(note, account.instanceUrl);
340+
});
341+
}
342+
319343
async uploadMedia(account: Account, file: File): Promise<string> {
320344
const formData = new FormData();
321345
formData.append("i", account.accessToken);
@@ -338,6 +362,10 @@ export class MisskeyHttpClient implements MastodonApi {
338362
return id;
339363
}
340364

365+
async fetchThreadContext(account: Account, statusId: string): Promise<ThreadContext> {
366+
return this.fetchConversation(account, statusId);
367+
}
368+
341369
async fetchConversation(account: Account, noteId: string): Promise<ThreadContext> {
342370
const response = await fetch(`${normalizeInstanceUrl(account.instanceUrl)}/api/notes/conversation`, {
343371
method: "POST",
@@ -432,6 +460,16 @@ export class MisskeyHttpClient implements MastodonApi {
432460
return this.fetchNote(account, statusId);
433461
}
434462

463+
async bookmark(account: Account, statusId: string): Promise<Status> {
464+
await this.postSimple(account, "/api/notes/favorites/create", { noteId: statusId });
465+
return this.fetchNote(account, statusId);
466+
}
467+
468+
async unbookmark(account: Account, statusId: string): Promise<Status> {
469+
await this.postSimple(account, "/api/notes/favorites/delete", { noteId: statusId });
470+
return this.fetchNote(account, statusId);
471+
}
472+
435473
async unfavourite(account: Account, statusId: string): Promise<Status> {
436474
try {
437475
await this.postSimple(account, "/api/notes/reactions/delete", { noteId: statusId });
@@ -454,6 +492,19 @@ export class MisskeyHttpClient implements MastodonApi {
454492
return this.fetchNote(account, statusId);
455493
}
456494

495+
async fetchNoteState(
496+
account: Account,
497+
noteId: string
498+
): Promise<{ isFavourited: boolean; isReblogged: boolean; bookmarked: boolean }> {
499+
const note = await this.fetchNoteRaw(account, noteId);
500+
const isFavorited = Boolean(note.isFavorited ?? false);
501+
return {
502+
isFavourited: isFavorited,
503+
isReblogged: Boolean(note.myRenoteId),
504+
bookmarked: isFavorited
505+
};
506+
}
507+
457508
async reblog(account: Account, statusId: string): Promise<Status> {
458509
await this.postSimple(account, "/api/notes/create", { renoteId: statusId });
459510
return this.fetchNote(account, statusId);

src/infra/UnifiedApiClient.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,11 @@ export class UnifiedApiClient implements MastodonApi {
125125
async fetchThreadContext(account: Account, statusId: string): Promise<ThreadContext> {
126126
return this.getClient(account).fetchThreadContext(account, statusId);
127127
}
128+
129+
fetchNoteState(
130+
account: Account,
131+
noteId: string
132+
): Promise<{ isFavourited: boolean; isReblogged: boolean; bookmarked: boolean }> {
133+
return this.getClient(account).fetchNoteState(account, noteId);
134+
}
128135
}

src/infra/misskeyMapper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export const mapMisskeyStatusWithInstance = (raw: unknown, instanceUrl?: string)
460460
reactions,
461461
reblogged,
462462
favourited,
463-
bookmarked: false,
463+
bookmarked: Boolean(value.isFavorited ?? false),
464464
inReplyToId: value.replyId ? String(value.replyId) : null,
465465
mentions,
466466
mediaAttachments,

src/ui/components/TimelineItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ export const TimelineItem = ({
14591459
) : null}
14601460
{showContent ? (
14611461
<>
1462-
<p className="status-text">{displayStatus.content ? contentParts : "(내용 없음)"}</p>
1462+
<div className="status-text">{displayStatus.content ? contentParts : "(내용 없음)"}</div>
14631463
{previewCard ? (
14641464
<a
14651465
className={`link-preview${previewCard.image ? "" : " no-image"}`}

0 commit comments

Comments
 (0)