FoundKey/packages/backend/src/misc/get-note-summary.ts
Johann150 ab22a1afa0
Some checks failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/test Pipeline failed
more compact notifications
Don't show the entire renoted note in notifications and some other places.

Changelog: Changed
2024-03-19 19:09:34 +01:00

42 lines
797 B
TypeScript

import { Packed } from './schema.js';
/**
* 投稿を表す文字列を取得します。
* @param {*} note (packされた)投稿
*/
export const getNoteSummary = (note: Packed<'Note'>): string => {
if (note.deletedAt) {
return '(❌⛔)';
}
let summary = '';
// 本文
if (note.cw != null) {
summary += note.cw;
} else {
summary += note.text ? note.text : '';
}
// ファイルが添付されているとき
if ((note.files || []).length !== 0) {
summary += ` (📎${note.files!.length})`;
}
// 投票が添付されているとき
if (note.poll) {
summary += ' (📊)';
}
// 返信のとき
if (note.replyId) {
if (note.reply) {
summary += `\n\nRE: ${getNoteSummary(note.reply)}`;
} else {
summary += '\n\nRE: ...';
}
}
return summary.trim();
};