Revert "refactor (backend): port publishNotesStream to backend-rs"

This reverts commit 5382dc5da8.

It turns out this sends an inccorect time info to the stream
since JavaScript's Date object doesn't have timezone info

I'll revisit this in the future
This commit is contained in:
naskya 2024-05-08 06:06:31 +09:00
parent 907578e8f8
commit cda31d3dc7
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
6 changed files with 12 additions and 23 deletions

View file

@ -1292,7 +1292,6 @@ export interface AbuseUserReportLike {
comment: string comment: string
} }
export function publishToModerationStream(moderatorId: string, report: AbuseUserReportLike): void export function publishToModerationStream(moderatorId: string, report: AbuseUserReportLike): void
export function publishToNotesStream(note: Note): void
export function getTimestamp(id: string): number export function getTimestamp(id: string): number
/** /**
* The generated ID results in the form of `[8 chars timestamp] + [cuid2]`. * The generated ID results in the form of `[8 chars timestamp] + [cuid2]`.

View file

@ -310,7 +310,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`) throw new Error(`Failed to load native binding`)
} }
const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, loadConfig, stringToAcct, acctToString, addNoteToAntenna, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, AntennaSrcEnum, DriveFileUsageHintEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, initializeRustLogger, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, watchNote, unwatchNote, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, publishToNotesStream, getTimestamp, genId, genIdAt, secureRndstr } = nativeBinding const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, loadConfig, stringToAcct, acctToString, addNoteToAntenna, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, AntennaSrcEnum, DriveFileUsageHintEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, initializeRustLogger, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, watchNote, unwatchNote, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, getTimestamp, genId, genIdAt, secureRndstr } = nativeBinding
module.exports.SECOND = SECOND module.exports.SECOND = SECOND
module.exports.MINUTE = MINUTE module.exports.MINUTE = MINUTE
@ -381,7 +381,6 @@ module.exports.publishToChatIndexStream = publishToChatIndexStream
module.exports.publishToBroadcastStream = publishToBroadcastStream module.exports.publishToBroadcastStream = publishToBroadcastStream
module.exports.publishToGroupChatStream = publishToGroupChatStream module.exports.publishToGroupChatStream = publishToGroupChatStream
module.exports.publishToModerationStream = publishToModerationStream module.exports.publishToModerationStream = publishToModerationStream
module.exports.publishToNotesStream = publishToNotesStream
module.exports.getTimestamp = getTimestamp module.exports.getTimestamp = getTimestamp
module.exports.genId = genId module.exports.genId = genId
module.exports.genIdAt = genIdAt module.exports.genIdAt = genIdAt

View file

@ -5,7 +5,6 @@ pub mod chat_index;
pub mod custom_emoji; pub mod custom_emoji;
pub mod group_chat; pub mod group_chat;
pub mod moderation; pub mod moderation;
pub mod new_note;
use crate::config::CONFIG; use crate::config::CONFIG;
use crate::database::redis_conn; use crate::database::redis_conn;
@ -26,7 +25,7 @@ pub enum Stream {
#[strum(to_string = "noteStream:{note_id}")] #[strum(to_string = "noteStream:{note_id}")]
Note { note_id: String }, Note { note_id: String },
#[strum(serialize = "notesStream")] #[strum(serialize = "notesStream")]
NewNote, Notes,
#[strum(to_string = "userListStream:{list_id}")] #[strum(to_string = "userListStream:{list_id}")]
UserList { list_id: String }, UserList { list_id: String },
#[strum(to_string = "mainStream:{user_id}")] #[strum(to_string = "mainStream:{user_id}")]

View file

@ -1,10 +0,0 @@
use crate::model::entity::note;
use crate::service::stream::{publish_to_stream, Error, Stream};
// for napi export (https://github.com/napi-rs/napi-rs/issues/2060)
type Note = note::Model;
#[crate::export(js_name = "publishToNotesStream")]
pub fn publish(note: &Note) -> Result<(), Error> {
publish_to_stream(&Stream::NewNote, None, Some(serde_json::to_string(note)?))
}

View file

@ -1,5 +1,9 @@
import * as mfm from "mfm-js"; import * as mfm from "mfm-js";
import { publishMainStream, publishNoteStream } from "@/services/stream.js"; import {
publishMainStream,
publishNotesStream,
publishNoteStream,
} from "@/services/stream.js";
import DeliverManager from "@/remote/activitypub/deliver-manager.js"; import DeliverManager from "@/remote/activitypub/deliver-manager.js";
import renderNote from "@/remote/activitypub/renderer/note.js"; import renderNote from "@/remote/activitypub/renderer/note.js";
import renderCreate from "@/remote/activitypub/renderer/create.js"; import renderCreate from "@/remote/activitypub/renderer/create.js";
@ -45,7 +49,6 @@ import {
genId, genId,
genIdAt, genIdAt,
isSilencedServer, isSilencedServer,
publishToNotesStream,
} from "backend-rs"; } from "backend-rs";
import { countSameRenotes } from "@/misc/count-same-renotes.js"; import { countSameRenotes } from "@/misc/count-same-renotes.js";
import { deliverToRelays, getCachedRelays } from "../relay.js"; import { deliverToRelays, getCachedRelays } from "../relay.js";
@ -508,7 +511,7 @@ export default async (
30, 30,
); );
} }
publishToNotesStream(toRustObject(noteToPublish)); publishNotesStream(noteToPublish);
} }
} finally { } finally {
await lock.release(); await lock.release();

View file

@ -193,10 +193,9 @@ class Publisher {
// ); // );
// }; // };
/* ported to backend-rs */ public publishNotesStream = (note: Note): void => {
// public publishNotesStream = (note: Note): void => { this.publish("notesStream", null, note);
// this.publish("notesStream", null, note); };
// };
/* ported to backend-rs */ /* ported to backend-rs */
// public publishAdminStream = <K extends keyof AdminStreamTypes>( // public publishAdminStream = <K extends keyof AdminStreamTypes>(
@ -222,7 +221,7 @@ export const publishUserEvent = publisher.publishUserEvent;
export const publishMainStream = publisher.publishMainStream; export const publishMainStream = publisher.publishMainStream;
export const publishDriveStream = publisher.publishDriveStream; export const publishDriveStream = publisher.publishDriveStream;
export const publishNoteStream = publisher.publishNoteStream; export const publishNoteStream = publisher.publishNoteStream;
// export const publishNotesStream = publisher.publishNotesStream; export const publishNotesStream = publisher.publishNotesStream;
// export const publishChannelStream = publisher.publishChannelStream; // export const publishChannelStream = publisher.publishChannelStream;
export const publishUserListStream = publisher.publishUserListStream; export const publishUserListStream = publisher.publishUserListStream;
// export const publishAntennaStream = publisher.publishAntennaStream; // export const publishAntennaStream = publisher.publishAntennaStream;