Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 64 additions & 6 deletions src/infra/MisskeyHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,59 @@ const mapMisskeyEmojis = (data: unknown): CustomEmoji[] => {
};

export class MisskeyHttpClient implements MastodonApi {
private async fetchNoteChildren(
account: Account,
noteId: string,
limit: number
): Promise<Status[]> {
const response = await fetch(`${normalizeInstanceUrl(account.instanceUrl)}/api/notes/children`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(buildBody(account, { noteId, limit }))
});
if (!response.ok) {
throw new Error("답글을 불러오지 못했습니다.");
}
const data = (await response.json()) as unknown[];
return data
.map((item) => mapMisskeyStatusWithInstance(item, account.instanceUrl))
.filter((status): status is Status => status !== null);
}

private async fetchDescendants(
account: Account,
noteId: string,
maxNotes: number,
maxDepth: number
): Promise<Status[]> {
const queue: Array<{ id: string; depth: number }> = [{ id: noteId, depth: 0 }];
const seen = new Set<string>([noteId]);
const result: Status[] = [];

while (queue.length > 0 && result.length < maxNotes) {
const current = queue.shift();
if (!current || current.depth >= maxDepth) {
continue;
}
const children = await this.fetchNoteChildren(account, current.id, 100);
for (const child of children) {
if (seen.has(child.id)) {
continue;
}
seen.add(child.id);
result.push(child);
if (result.length >= maxNotes) {
break;
}
queue.push({ id: child.id, depth: current.depth + 1 });
}
}

return result.sort((a, b) => a.createdAt.localeCompare(b.createdAt));
}

async verifyAccount(
account: Account
): Promise<{ accountName: string; handle: string; avatarUrl: string | null }> {
Expand Down Expand Up @@ -195,14 +248,19 @@ export class MisskeyHttpClient implements MastodonApi {
// 미스키는 시간순으로 정렬된 전체 대화를 반환
const conversation = data
.map((item) => mapMisskeyStatusWithInstance(item, account.instanceUrl))
.filter((status): status is Status => status !== null);
.filter((status): status is Status => status !== null)
.sort((a, b) => a.createdAt.localeCompare(b.createdAt));

// 전체 대화에서 현재 노트를 찾아서 ancestors/descendants로 분리
const currentIndex = conversation.findIndex(status => status.id === noteId);
const ancestors = currentIndex > 0 ? conversation.slice(0, currentIndex) : [];
const descendants = currentIndex >= 0 && currentIndex < conversation.length - 1
? conversation.slice(currentIndex + 1)
: [];
const currentIndex = conversation.findIndex((status) => status.id === noteId);
const ancestors =
currentIndex === -1 ? conversation : currentIndex > 0 ? conversation.slice(0, currentIndex) : [];
let descendants: Status[] = [];
try {
descendants = await this.fetchDescendants(account, noteId, 200, 6);
} catch (error) {
console.error("후손 스레드 로딩 실패:", error);
}

return {
ancestors,
Expand Down
4 changes: 4 additions & 0 deletions src/ui/styles/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
--shadow-timeline-column: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 12px 24px rgba(0, 0, 0, 0.35);
--color-status-bg: #171512;
--color-status-border: #302822;
--color-thread-bg: var(--color-status-bg);
--color-thread-border: var(--color-status-border);
--color-status-header: #c4b6a6;
--color-status-meta: #c4b6a6;
--color-status-time: #c4b6a6;
Expand Down Expand Up @@ -492,6 +494,8 @@
--shadow-timeline-column: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 12px 24px rgba(0, 0, 0, 0.35);
--color-status-bg: #171512;
--color-status-border: #302822;
--color-thread-bg: var(--color-status-bg);
--color-thread-border: var(--color-status-border);
--color-status-header: #c4b6a6;
--color-status-meta: #c4b6a6;
--color-status-time: #c4b6a6;
Expand Down
Loading