2023-01-12 21:40:33 -07:00
|
|
|
import * as misskey from "calckey-js";
|
|
|
|
import { i18n } from "@/i18n";
|
2021-11-11 10:02:25 -07:00
|
|
|
|
2018-04-07 11:30:37 -06:00
|
|
|
/**
|
|
|
|
* 投稿を表す文字列を取得します。
|
2018-05-05 10:34:48 -06:00
|
|
|
* @param {*} note (packされた)投稿
|
2018-04-07 11:30:37 -06:00
|
|
|
*/
|
2021-11-11 10:02:25 -07:00
|
|
|
export const getNoteSummary = (note: misskey.entities.Note): string => {
|
2022-07-28 10:24:43 -06:00
|
|
|
/*
|
2018-05-27 23:39:46 -06:00
|
|
|
if (note.deletedAt) {
|
2022-01-27 19:39:49 -07:00
|
|
|
return `(${i18n.ts.deletedNote})`;
|
2018-05-27 23:39:46 -06:00
|
|
|
}
|
2022-07-28 10:24:43 -06:00
|
|
|
*/
|
2018-05-27 23:39:46 -06:00
|
|
|
|
2023-01-12 21:40:33 -07:00
|
|
|
let summary = "";
|
2018-04-07 11:30:37 -06:00
|
|
|
|
|
|
|
// 本文
|
2018-12-19 11:22:27 -07:00
|
|
|
if (note.cw != null) {
|
2018-12-17 04:17:21 -07:00
|
|
|
summary += note.cw;
|
|
|
|
} else {
|
2023-01-12 21:40:33 -07:00
|
|
|
summary += note.text ? note.text : "";
|
2018-12-17 04:17:21 -07:00
|
|
|
}
|
2018-04-07 11:30:37 -06:00
|
|
|
|
2018-09-05 04:32:46 -06:00
|
|
|
// ファイルが添付されているとき
|
2022-05-06 23:19:15 -06:00
|
|
|
if ((note.files || []).length !== 0) {
|
2023-01-12 21:40:33 -07:00
|
|
|
summary += ` (${i18n.t("withNFiles", { n: note.files.length })})`;
|
2018-04-07 11:30:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// 投票が添付されているとき
|
|
|
|
if (note.poll) {
|
2022-01-27 19:39:49 -07:00
|
|
|
summary += ` (${i18n.ts.poll})`;
|
2018-04-07 11:30:37 -06:00
|
|
|
}
|
|
|
|
|
2022-07-28 10:24:43 -06:00
|
|
|
/*
|
|
|
|
|
2018-04-07 11:30:37 -06:00
|
|
|
// 返信のとき
|
|
|
|
if (note.replyId) {
|
|
|
|
if (note.reply) {
|
2021-11-11 10:02:25 -07:00
|
|
|
summary += `\n\nRE: ${getNoteSummary(note.reply)}`;
|
2018-04-07 11:30:37 -06:00
|
|
|
} else {
|
2018-11-29 17:34:37 -07:00
|
|
|
summary += '\n\nRE: ...';
|
2018-04-07 11:30:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Renoteのとき
|
|
|
|
if (note.renoteId) {
|
|
|
|
if (note.renote) {
|
2021-11-11 10:02:25 -07:00
|
|
|
summary += `\n\nRN: ${getNoteSummary(note.renote)}`;
|
2018-04-07 11:30:37 -06:00
|
|
|
} else {
|
2018-11-29 17:34:37 -07:00
|
|
|
summary += '\n\nRN: ...';
|
2018-04-07 11:30:37 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 10:24:43 -06:00
|
|
|
*/
|
|
|
|
|
2018-04-07 11:30:37 -06:00
|
|
|
return summary.trim();
|
|
|
|
};
|