rudeshark.net/packages/client/src/scripts/get-note-summary.ts

59 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-01-13 05:40:33 +01:00
import * as misskey from "calckey-js";
import { i18n } from "@/i18n";
2021-11-11 18:02:25 +01:00
2018-04-07 19:30:37 +02:00
/**
* 稿
* @param {*} note (packされた)稿
2018-04-07 19:30:37 +02:00
*/
2021-11-11 18:02:25 +01:00
export const getNoteSummary = (note: misskey.entities.Note): string => {
2022-07-28 18:24:43 +02:00
/*
2018-05-28 07:39:46 +02:00
if (note.deletedAt) {
return `(${i18n.ts.deletedNote})`;
2018-05-28 07:39:46 +02:00
}
2022-07-28 18:24:43 +02:00
*/
2018-05-28 07:39:46 +02:00
2023-01-13 05:40:33 +01:00
let summary = "";
2018-04-07 19:30:37 +02:00
// 本文
2018-12-19 19:22:27 +01:00
if (note.cw != null) {
2018-12-17 12:17:21 +01:00
summary += note.cw;
} else {
2023-01-13 05:40:33 +01:00
summary += note.text ? note.text : "";
2018-12-17 12:17:21 +01:00
}
2018-04-07 19:30:37 +02:00
2018-09-05 12:32:46 +02:00
// ファイルが添付されているとき
if ((note.files || []).length !== 0) {
const len = note.files?.length;
2023-06-03 08:55:31 +02:00
summary += ` 📎${len !== 1 ? ` (${len})` : ""}`;
2018-04-07 19:30:37 +02:00
}
// 投票が添付されているとき
if (note.poll) {
summary += " 📊";
2018-04-07 19:30:37 +02:00
}
2022-07-28 18:24:43 +02:00
/*
2018-04-07 19:30:37 +02:00
// 返信のとき
if (note.replyId) {
if (note.reply) {
2021-11-11 18:02:25 +01:00
summary += `\n\nRE: ${getNoteSummary(note.reply)}`;
2018-04-07 19:30:37 +02:00
} else {
summary += '\n\nRE: ...';
2018-04-07 19:30:37 +02:00
}
}
// Renoteのとき
if (note.renoteId) {
if (note.renote) {
2021-11-11 18:02:25 +01:00
summary += `\n\nRN: ${getNoteSummary(note.renote)}`;
2018-04-07 19:30:37 +02:00
} else {
summary += '\n\nRN: ...';
2018-04-07 19:30:37 +02:00
}
}
2022-07-28 18:24:43 +02:00
*/
2018-04-07 19:30:37 +02:00
return summary.trim();
};