monkeeShark/packages/frontend/src/scripts/get-note-summary.ts

61 lines
1.2 KiB
TypeScript
Raw Normal View History

/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as Misskey from 'misskey-js';
2023-09-19 07:37:43 +00:00
import { i18n } from '@/i18n.js';
2021-11-11 17:02:25 +00:00
2018-04-07 17:30:37 +00:00
/**
* 稿
* @param {*} note (packされた)稿
2018-04-07 17:30:37 +00:00
*/
export const getNoteSummary = (note: Misskey.entities.Note): string => {
2018-05-28 05:39:46 +00:00
if (note.deletedAt) {
return `(${i18n.ts.deletedNote})`;
2018-05-28 05:39:46 +00:00
}
2018-04-28 23:51:17 +00:00
if (note.isHidden) {
return `(${i18n.ts.invisibleNote})`;
2018-04-28 23:51:17 +00:00
}
2018-04-07 17:30:37 +00:00
let summary = '';
// 本文
2018-12-19 18:22:27 +00:00
if (note.cw != null) {
2018-12-17 11:17:21 +00:00
summary += note.cw;
} else {
summary += note.text ? note.text : '';
}
2018-04-07 17:30:37 +00:00
2018-09-05 10:32:46 +00:00
// ファイルが添付されているとき
if ((note.files || []).length !== 0) {
2021-11-11 17:02:25 +00:00
summary += ` (${i18n.t('withNFiles', { n: note.files.length })})`;
2018-04-07 17:30:37 +00:00
}
// 投票が添付されているとき
if (note.poll) {
summary += ` (${i18n.ts.poll})`;
2018-04-07 17:30:37 +00:00
}
// 返信のとき
if (note.replyId) {
if (note.reply) {
2021-11-11 17:02:25 +00:00
summary += `\n\nRE: ${getNoteSummary(note.reply)}`;
2018-04-07 17:30:37 +00:00
} else {
summary += '\n\nRE: ...';
2018-04-07 17:30:37 +00:00
}
}
// Renoteのとき
if (note.renoteId) {
if (note.renote) {
2021-11-11 17:02:25 +00:00
summary += `\n\nRN: ${getNoteSummary(note.renote)}`;
2018-04-07 17:30:37 +00:00
} else {
summary += '\n\nRN: ...';
2018-04-07 17:30:37 +00:00
}
}
return summary.trim();
};