summaryrefslogtreecommitdiff
path: root/packages/frontend/src/utility/getNoteUrls.ts
blob: c92e3a868b8a245729114e2736b9a41a525e8153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */

import * as config from '@@/js/config.js';
import type * as Misskey from 'misskey-js';

export function getNoteUrls(note: Misskey.entities.Note): string[] {
	const urls: string[] = [
		// Any note
		`${config.webUrl}/notes/${note.id}`,
	];

	// Remote note
	if (note.url) urls.push(note.url);
	if (note.uri) urls.push(note.uri);

	if (note.reply) {
		// Any Reply
		urls.push(`${config.webUrl}/notes/${note.reply.id}`);
		// Remote Reply
		if (note.reply.url) urls.push(note.reply.url);
		if (note.reply.uri) urls.push(note.reply.uri);
	}

	if (note.renote) {
		// Any Renote
		urls.push(`${config.webUrl}/notes/${note.renote.id}`);
		// Remote Renote
		if (note.renote.url) urls.push(note.renote.url);
		if (note.renote.uri) urls.push(note.renote.uri);
	}

	if (note.renote?.renote) {
		// Any Quote
		urls.push(`${config.webUrl}/notes/${note.renote.renote.id}`);
		// Remote Quote
		if (note.renote.renote.url) urls.push(note.renote.renote.url);
		if (note.renote.renote.uri) urls.push(note.renote.renote.uri);
	}

	return urls;
}