fix (backend): broken RSS feed title

This commit is contained in:
naskya 2024-07-02 23:31:28 +09:00
parent e19b7164bd
commit c59d7fcd03
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
3 changed files with 98 additions and 82 deletions

View file

@ -46,7 +46,7 @@ export interface Acct {
host: string | null host: string | null
} }
export function acctToString(acct: Acct): string export declare function acctToString(acct: Acct): string
export interface Ad { export interface Ad {
id: string id: string
@ -194,7 +194,7 @@ export enum ChatIndexEvent {
* * `muted_words` : list of muted keyword lists (each array item is a space-separated keyword list that represents an AND condition) * * `muted_words` : list of muted keyword lists (each array item is a space-separated keyword list that represents an AND condition)
* * `muted_patterns` : list of JavaScript-style (e.g., `/foo/i`) regular expressions * * `muted_patterns` : list of JavaScript-style (e.g., `/foo/i`) regular expressions
*/ */
export function checkWordMute(note: PartialNoteToCheckWordMute, mutedWords: Array<string>, mutedPatterns: Array<string>): Promise<boolean> export declare function checkWordMute(note: PartialNoteToCheckWordMute, mutedWords: Array<string>, mutedPatterns: Array<string>): Promise<boolean>
export interface Clip { export interface Clip {
id: string id: string
@ -263,16 +263,16 @@ export interface Config {
userAgent: string userAgent: string
} }
export function countReactions(reactions: Record<string, number>): Record<string, number> export declare function countReactions(reactions: Record<string, number>): Record<string, number>
export interface Cpu { export interface Cpu {
model: string model: string
cores: number cores: number
} }
export function cpuInfo(): Cpu export declare function cpuInfo(): Cpu
export function cpuUsage(): number export declare function cpuUsage(): number
export const DAY: number export const DAY: number
@ -292,7 +292,7 @@ export interface DecodedReaction {
host: string | null host: string | null
} }
export function decodeReaction(reaction: string): DecodedReaction export declare function decodeReaction(reaction: string): DecodedReaction
export interface DeepLConfig { export interface DeepLConfig {
managed?: boolean managed?: boolean
@ -381,12 +381,12 @@ export interface Emoji {
height: number | null height: number | null
} }
export function extractHost(uri: string): string export declare function extractHost(uri: string): string
export function fetchMeta(): Promise<Meta> export declare function fetchMeta(): Promise<Meta>
/** Fetches and returns the NodeInfo (version 2.0) of a remote server. */ /** Fetches and returns the NodeInfo (version 2.0) of a remote server. */
export function fetchNodeinfo(host: string): Promise<Nodeinfo> export declare function fetchNodeinfo(host: string): Promise<Nodeinfo>
/** /**
* List of file types allowed to be viewed directly in the browser * List of file types allowed to be viewed directly in the browser
@ -427,9 +427,9 @@ export interface FollowRequest {
} }
/** Converts milliseconds to a human readable string. */ /** Converts milliseconds to a human readable string. */
export function formatMilliseconds(milliseconds: number): string export declare function formatMilliseconds(milliseconds: number): string
export function fromMastodonId(mastodonId: string): string | null export declare function fromMastodonId(mastodonId: string): string | null
export interface GalleryLike { export interface GalleryLike {
id: string id: string
@ -452,9 +452,9 @@ export interface GalleryPost {
} }
/** Generates a random string based on [thread_rng] and [Alphanumeric]. */ /** Generates a random string based on [thread_rng] and [Alphanumeric]. */
export function generateSecureRandomString(length: number): string export declare function generateSecureRandomString(length: number): string
export function generateUserToken(): string export declare function generateUserToken(): string
/** /**
* The generated ID results in the form of `[8 chars timestamp] + [cuid2]`. * The generated ID results in the form of `[8 chars timestamp] + [cuid2]`.
@ -464,24 +464,24 @@ export function generateUserToken(): string
* *
* Ref: <https://github.com/paralleldrive/cuid2#parameterized-length> * Ref: <https://github.com/paralleldrive/cuid2#parameterized-length>
*/ */
export function genId(): string export declare function genId(): string
/** Generate an ID using a specific datetime */ /** Generate an ID using a specific datetime */
export function genIdAt(date: Date): string export declare function genIdAt(date: Date): string
export function getFullApAccount(username: string, host?: string | undefined | null): string export declare function getFullApAccount(username: string, host?: string | undefined | null): string
export function getImageSizeFromUrl(url: string): Promise<ImageSize> export declare function getImageSizeFromUrl(url: string): Promise<ImageSize>
export function getNoteSummary(fileIds: Array<string>, text: string | undefined | null, cw: string | undefined | null, hasPoll: boolean): string export declare function getNoteSummary(fileIds: Array<string>, text: string | undefined | null, cw: string | undefined | null, hasPoll: boolean): string
export function getTimestamp(id: string): number export declare function getTimestamp(id: string): number
/** Prints the greeting message and the Firefish version to stdout. */ /** Prints the greeting message and the Firefish version to stdout. */
export function greet(): void export declare function greet(): void
/** Hashes the given password using [argon2] algorithm. */ /** Hashes the given password using [argon2] algorithm. */
export function hashPassword(password: string): string export declare function hashPassword(password: string): string
export interface Hashtag { export interface Hashtag {
id: string id: string
@ -525,7 +525,7 @@ export enum Inbound {
} }
/** Initializes the [tracing] logger. */ /** Initializes the [tracing] logger. */
export function initializeRustLogger(): void export declare function initializeRustLogger(): void
export interface Instance { export interface Instance {
id: string id: string
@ -573,7 +573,7 @@ export interface Instance {
* # } * # }
* ``` * ```
*/ */
export function isAllowedServer(host: string): Promise<boolean> export declare function isAllowedServer(host: string): Promise<boolean>
/** /**
* Checks if a server is blocked. * Checks if a server is blocked.
@ -593,18 +593,18 @@ export function isAllowedServer(host: string): Promise<boolean>
* # } * # }
* ``` * ```
*/ */
export function isBlockedServer(host: string): Promise<boolean> export declare function isBlockedServer(host: string): Promise<boolean>
/** Returns whether the [bcrypt] algorithm is used for the password hash. */ /** Returns whether the [bcrypt] algorithm is used for the password hash. */
export function isOldPasswordAlgorithm(hash: string): boolean export declare function isOldPasswordAlgorithm(hash: string): boolean
export function isQuote(note: Note): boolean export declare function isQuote(note: NoteLikeForIsQuote): boolean
export function isSafeUrl(url: string): boolean export declare function isSafeUrl(url: string): boolean
export function isSameOrigin(uri: string): boolean export declare function isSameOrigin(uri: string): boolean
export function isSelfHost(host?: string | undefined | null): boolean export declare function isSelfHost(host?: string | undefined | null): boolean
/** /**
* Checks if a server is silenced. * Checks if a server is silenced.
@ -624,12 +624,12 @@ export function isSelfHost(host?: string | undefined | null): boolean
* # } * # }
* ``` * ```
*/ */
export function isSilencedServer(host: string): Promise<boolean> export declare function isSilencedServer(host: string): Promise<boolean>
export function isUnicodeEmoji(s: string): boolean export declare function isUnicodeEmoji(s: string): boolean
/** Returns the latest Firefish version. */ /** Returns the latest Firefish version. */
export function latestVersion(): Promise<string> export declare function latestVersion(): Promise<string>
export interface LibreTranslateConfig { export interface LibreTranslateConfig {
managed?: boolean managed?: boolean
@ -637,7 +637,7 @@ export interface LibreTranslateConfig {
apiKey?: string apiKey?: string
} }
export function loadConfig(): Config export declare function loadConfig(): Config
export interface Memory { export interface Memory {
/** Total memory amount in bytes */ /** Total memory amount in bytes */
@ -648,7 +648,7 @@ export interface Memory {
available: number available: number
} }
export function memoryUsage(): Memory export declare function memoryUsage(): Memory
export interface MessagingMessage { export interface MessagingMessage {
id: string id: string
@ -751,7 +751,7 @@ export interface Meta {
antennaLimit: number antennaLimit: number
} }
export function metaToPugArgs(meta: Meta): PugArgs export declare function metaToPugArgs(meta: Meta): PugArgs
export interface Migrations { export interface Migrations {
id: number id: number
@ -807,9 +807,9 @@ export interface Nodeinfo {
metadata: Record<string, any> metadata: Record<string, any>
} }
export function nodeinfo_2_0(): Promise<any> export declare function nodeinfo_2_0(): Promise<any>
export function nodeinfo_2_1(): Promise<any> export declare function nodeinfo_2_1(): Promise<any>
export interface Note { export interface Note {
id: string id: string
@ -871,6 +871,13 @@ export interface NoteFile {
fileId: string fileId: string
} }
export interface NoteLikeForIsQuote {
renoteId: string | null
text: string | null
hasPoll: boolean
fileIds: Array<string>
}
export interface NoteReaction { export interface NoteReaction {
id: string id: string
createdAt: DateTimeWithTimeZone createdAt: DateTimeWithTimeZone
@ -964,7 +971,7 @@ export enum NotificationType {
* assert_eq!(nyaify("I'll take a nap.", Some("en")), "I'll take a nyap."); * assert_eq!(nyaify("I'll take a nap.", Some("en")), "I'll take a nyap.");
* ``` * ```
*/ */
export function nyaify(text: string, lang?: string | undefined | null): string export declare function nyaify(text: string, lang?: string | undefined | null): string
export interface ObjectStorageConfig { export interface ObjectStorageConfig {
managed?: boolean managed?: boolean
@ -1126,23 +1133,23 @@ export enum Protocol {
Zot = 9 Zot = 9
} }
export function publishToBroadcastStream(emoji: PackedEmoji): Promise<void> export declare function publishToBroadcastStream(emoji: PackedEmoji): Promise<void>
export function publishToChannelStream(channelId: string, userId: string): Promise<void> export declare function publishToChannelStream(channelId: string, userId: string): Promise<void>
export function publishToChatIndexStream(userId: string, kind: ChatIndexEvent, object: any): Promise<void> export declare function publishToChatIndexStream(userId: string, kind: ChatIndexEvent, object: any): Promise<void>
export function publishToChatStream(senderUserId: string, receiverUserId: string, kind: ChatEvent, object: any): Promise<void> export declare function publishToChatStream(senderUserId: string, receiverUserId: string, kind: ChatEvent, object: any): Promise<void>
export function publishToDriveFileStream(userId: string, kind: DriveFileEvent, object: any): Promise<void> export declare function publishToDriveFileStream(userId: string, kind: DriveFileEvent, object: any): Promise<void>
export function publishToDriveFolderStream(userId: string, kind: DriveFolderEvent, object: any): Promise<void> export declare function publishToDriveFolderStream(userId: string, kind: DriveFolderEvent, object: any): Promise<void>
export function publishToGroupChatStream(groupId: string, kind: ChatEvent, object: any): Promise<void> export declare function publishToGroupChatStream(groupId: string, kind: ChatEvent, object: any): Promise<void>
export function publishToModerationStream(moderatorId: string, report: AbuseUserReportLike): Promise<void> export declare function publishToModerationStream(moderatorId: string, report: AbuseUserReportLike): Promise<void>
export function publishToNotesStream(note: Note): Promise<void> export declare function publishToNotesStream(note: Note): Promise<void>
export interface PugArgs { export interface PugArgs {
img: string | null img: string | null
@ -1207,7 +1214,7 @@ export enum RelayStatus {
} }
/** Delete all entries in the [attestation_challenge] table created at more than 5 minutes ago */ /** Delete all entries in the [attestation_challenge] table created at more than 5 minutes ago */
export function removeOldAttestationChallenges(): Promise<void> export declare function removeOldAttestationChallenges(): Promise<void>
export interface RenoteMuting { export interface RenoteMuting {
id: string id: string
@ -1224,11 +1231,11 @@ export interface ReplyMuting {
} }
/** Returns `true` if `src` does not contain suspicious characters like `%`. */ /** Returns `true` if `src` does not contain suspicious characters like `%`. */
export function safeForSql(src: string): boolean export declare function safeForSql(src: string): boolean
export const SECOND: number export const SECOND: number
export function sendPushNotification(receiverUserId: string, kind: PushNotificationKind, content: any): Promise<void> export declare function sendPushNotification(receiverUserId: string, kind: PushNotificationKind, content: any): Promise<void>
export interface ServerConfig { export interface ServerConfig {
url: string url: string
@ -1289,7 +1296,7 @@ export interface Services {
} }
/** Prints the server hardware information as the server info log. */ /** Prints the server hardware information as the server info log. */
export function showServerInfo(): void export declare function showServerInfo(): void
export interface Signin { export interface Signin {
id: string id: string
@ -1309,7 +1316,7 @@ export interface Software20 {
} }
/** Escapes `%` and `\` in the given string. */ /** Escapes `%` and `\` in the given string. */
export function sqlLikeEscape(src: string): string export declare function sqlLikeEscape(src: string): string
export interface Storage { export interface Storage {
/** Total storage space in bytes */ /** Total storage space in bytes */
@ -1318,9 +1325,9 @@ export interface Storage {
used: number used: number
} }
export function storageUsage(): Storage | null export declare function storageUsage(): Storage | null
export function stringToAcct(acct: string): Acct export declare function stringToAcct(acct: string): Acct
export interface SwSubscription { export interface SwSubscription {
id: string id: string
@ -1342,21 +1349,21 @@ export interface TlsConfig {
rejectUnauthorized: boolean rejectUnauthorized: boolean
} }
export function toDbReaction(reaction?: string | undefined | null, host?: string | undefined | null): Promise<string> export declare function toDbReaction(reaction?: string | undefined | null, host?: string | undefined | null): Promise<string>
export function toMastodonId(firefishId: string): string | null export declare function toMastodonId(firefishId: string): string | null
export function toPuny(host: string): string export declare function toPuny(host: string): string
export function unwatchNote(watcherId: string, noteId: string): Promise<void> export declare function unwatchNote(watcherId: string, noteId: string): Promise<void>
export function updateAntennaCache(): Promise<void> export declare function updateAntennaCache(): Promise<void>
export function updateAntennasOnNewNote(note: Note, noteAuthor: Acct, noteMutedUsers: Array<string>): Promise<void> export declare function updateAntennasOnNewNote(note: Note, noteAuthor: Acct, noteMutedUsers: Array<string>): Promise<void>
export function updateMetaCache(): Promise<void> export declare function updateMetaCache(): Promise<void>
export function updateNodeinfoCache(): Promise<void> export declare function updateNodeinfoCache(): Promise<void>
/** Usage statistics for this server. */ /** Usage statistics for this server. */
export interface Usage { export interface Usage {
@ -1575,9 +1582,9 @@ export interface UserSecurityKey {
} }
/** Checks whether the given password and hash match. */ /** Checks whether the given password and hash match. */
export function verifyPassword(password: string, hash: string): boolean export declare function verifyPassword(password: string, hash: string): boolean
export function watchNote(watcherId: string, noteAuthorId: string, noteId: string): Promise<void> export declare function watchNote(watcherId: string, noteAuthorId: string, noteId: string): Promise<void>
export interface Webhook { export interface Webhook {
id: string id: string

View file

@ -1,10 +1,12 @@
use crate::model::entity::note; #[macros::export(object, js_name = "NoteLikeForIsQuote")]
pub struct NoteLike {
// for napi export pub renote_id: Option<String>,
// https://github.com/napi-rs/napi-rs/issues/2060 pub text: Option<String>,
type Note = note::Model; pub has_poll: bool,
pub file_ids: Vec<String>,
}
#[macros::export] #[macros::export]
pub fn is_quote(note: Note) -> bool { pub fn is_quote(note: &NoteLike) -> bool {
note.renote_id.is_some() && (note.text.is_some() || note.has_poll || !note.file_ids.is_empty()) note.renote_id.is_some() && (note.text.is_some() || note.has_poll || !note.file_ids.is_empty())
} }

View file

@ -5,6 +5,7 @@ import type { User } from "@/models/entities/user.js";
import type { Note } from "@/models/entities/note.js"; import type { Note } from "@/models/entities/note.js";
import { Notes, DriveFiles, UserProfiles, Users } from "@/models/index.js"; import { Notes, DriveFiles, UserProfiles, Users } from "@/models/index.js";
import getNoteHtml from "@/remote/activitypub/misc/get-note-html.js"; import getNoteHtml from "@/remote/activitypub/misc/get-note-html.js";
import { isQuote, getNoteSummary } from "backend-rs";
/** /**
* If there is this part in the note, it will cause CDATA to be terminated early. * If there is this part in the note, it will cause CDATA to be terminated early.
@ -17,7 +18,7 @@ export default async function (
user: User, user: User,
threadDepth = 5, threadDepth = 5,
history = 20, history = 20,
noteintitle = false, noteintitle = true,
renotes = true, renotes = true,
replies = true, replies = true,
) { ) {
@ -81,20 +82,26 @@ export default async function (
depth -= 1; depth -= 1;
} }
let title = `${author.name} `; let title = `Post by ${author.name}`;
if (note.renoteId) {
title += "renotes";
} else if (note.replyId) {
title += "replies";
} else {
title += "says";
}
if (noteintitle) { if (noteintitle) {
const content = note.cw ?? note.text; if (note.renoteId) {
title = `Boost by ${author.name}`;
} else if (note.replyId) {
title = `Reply by ${author.name}`;
} else {
title = `Post by ${author.name}`;
}
const effectiveNote =
!isQuote(note) && note.renote != null ? note.renote : note;
const content = getNoteSummary(
effectiveNote.fileIds,
effectiveNote.text,
effectiveNote.cw,
effectiveNote.hasPoll,
);
if (content) { if (content) {
title += `: ${content}`; title += `: ${content}`;
} else {
title += "something";
} }
} }