diff --git a/packages/backend-rs/index.d.ts b/packages/backend-rs/index.d.ts index ace0f4fb52..56f3cfe49e 100644 --- a/packages/backend-rs/index.d.ts +++ b/packages/backend-rs/index.d.ts @@ -1375,16 +1375,10 @@ export enum PushNotificationKind { } export function sendPushNotification(receiverUserId: string, kind: PushNotificationKind, content: any): Promise export function publishToChannelStream(channelId: string, userId: string): Promise -export enum ChatEvent { - Message = 'message', - Read = 'read', - Deleted = 'deleted', - Typing = 'typing' -} export function publishToChatStream(senderUserId: string, receiverUserId: string, kind: ChatEvent, object: any): Promise export enum ChatIndexEvent { - Message = 'message', - Read = 'read' + Message = 0, + Read = 1 } export function publishToChatIndexStream(userId: string, kind: ChatIndexEvent, object: any): Promise export interface PackedEmoji { @@ -1407,6 +1401,12 @@ export interface AbuseUserReportLike { comment: string } export function publishToModerationStream(moderatorId: string, report: AbuseUserReportLike): Promise +export enum ChatEvent { + Message = 0, + Read = 1, + Deleted = 2, + Typing = 3 +} export function getTimestamp(id: string): number /** * The generated ID results in the form of `[8 chars timestamp] + [cuid2]`. diff --git a/packages/backend-rs/index.js b/packages/backend-rs/index.js index 5f16e2febd..b3d84eceaf 100644 --- a/packages/backend-rs/index.js +++ b/packages/backend-rs/index.js @@ -310,7 +310,7 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`) } -const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, fetchMeta, updateMetaCache, metaToPugArgs, loadConfig, stringToAcct, acctToString, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, greet, initializeRustLogger, showServerInfo, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isQuote, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, cpuInfo, cpuUsage, memoryUsage, storageUsage, AntennaSrc, DriveFileUsageHint, MutedNoteReason, NoteVisibility, NotificationType, PageVisibility, PollNoteVisibility, RelayStatus, UserEmojiModPerm, UserProfileFfvisibility, UserProfileMutingNotificationTypes, updateAntennasOnNewNote, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding +const { SECOND, MINUTE, HOUR, DAY, USER_ONLINE_THRESHOLD, USER_ACTIVE_THRESHOLD, FILE_TYPE_BROWSERSAFE, loadEnv, fetchMeta, updateMetaCache, metaToPugArgs, loadConfig, stringToAcct, acctToString, fetchNodeinfo, nodeinfo_2_1, nodeinfo_2_0, Protocol, Inbound, Outbound, greet, initializeRustLogger, showServerInfo, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, isQuote, isSafeUrl, latestVersion, toMastodonId, fromMastodonId, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, cpuInfo, cpuUsage, memoryUsage, storageUsage, AntennaSrc, DriveFileUsageHint, MutedNoteReason, NoteVisibility, NotificationType, PageVisibility, PollNoteVisibility, RelayStatus, UserEmojiModPerm, UserProfileFfvisibility, UserProfileMutingNotificationTypes, updateAntennasOnNewNote, watchNote, unwatchNote, PushNotificationKind, sendPushNotification, publishToChannelStream, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, publishToGroupChatStream, publishToModerationStream, ChatEvent, getTimestamp, genId, genIdAt, generateSecureRandomString, generateUserToken } = nativeBinding module.exports.SECOND = SECOND module.exports.MINUTE = MINUTE @@ -384,13 +384,13 @@ module.exports.unwatchNote = unwatchNote module.exports.PushNotificationKind = PushNotificationKind module.exports.sendPushNotification = sendPushNotification module.exports.publishToChannelStream = publishToChannelStream -module.exports.ChatEvent = ChatEvent module.exports.publishToChatStream = publishToChatStream module.exports.ChatIndexEvent = ChatIndexEvent module.exports.publishToChatIndexStream = publishToChatIndexStream module.exports.publishToBroadcastStream = publishToBroadcastStream module.exports.publishToGroupChatStream = publishToGroupChatStream module.exports.publishToModerationStream = publishToModerationStream +module.exports.ChatEvent = ChatEvent module.exports.getTimestamp = getTimestamp module.exports.genId = genId module.exports.genIdAt = genIdAt diff --git a/packages/backend-rs/src/config/meta.rs b/packages/backend-rs/src/config/meta.rs index 9a81dc870c..cedb6cf0ad 100644 --- a/packages/backend-rs/src/config/meta.rs +++ b/packages/backend-rs/src/config/meta.rs @@ -1,7 +1,6 @@ //! Server information -use crate::database::db_conn; -use crate::model::entity::meta; +use crate::{database::db_conn, model::entity::meta}; use sea_orm::{prelude::*, ActiveValue}; use std::sync::Mutex; diff --git a/packages/backend-rs/src/config/server.rs b/packages/backend-rs/src/config/server.rs index 101c860599..5170b0617e 100644 --- a/packages/backend-rs/src/config/server.rs +++ b/packages/backend-rs/src/config/server.rs @@ -2,8 +2,7 @@ use once_cell::sync::Lazy; use serde::Deserialize; -use std::env; -use std::fs; +use std::{env, fs}; pub const VERSION: &str = macro_rs::read_version_from_package_json!(); diff --git a/packages/backend-rs/src/federation/acct.rs b/packages/backend-rs/src/federation/acct.rs index b7b44356e6..eb49e0e45b 100644 --- a/packages/backend-rs/src/federation/acct.rs +++ b/packages/backend-rs/src/federation/acct.rs @@ -1,5 +1,4 @@ -use std::fmt; -use std::str::FromStr; +use std::{fmt, str::FromStr}; #[cfg_attr(test, derive(Debug, PartialEq))] #[crate::export(object)] diff --git a/packages/backend-rs/src/federation/nodeinfo/fetch.rs b/packages/backend-rs/src/federation/nodeinfo/fetch.rs index 0147830815..9095665334 100644 --- a/packages/backend-rs/src/federation/nodeinfo/fetch.rs +++ b/packages/backend-rs/src/federation/nodeinfo/fetch.rs @@ -2,8 +2,7 @@ //! //! ref: -use crate::federation::nodeinfo::schema::*; -use crate::util::http_client; +use crate::{federation::nodeinfo::schema::*, util::http_client}; use isahc::AsyncReadResponseExt; use serde::Deserialize; diff --git a/packages/backend-rs/src/federation/nodeinfo/generate.rs b/packages/backend-rs/src/federation/nodeinfo/generate.rs index cc2add0fc4..63621e9e92 100644 --- a/packages/backend-rs/src/federation/nodeinfo/generate.rs +++ b/packages/backend-rs/src/federation/nodeinfo/generate.rs @@ -1,10 +1,12 @@ //! NodeInfo generator -use crate::config::{local_server_info, CONFIG}; -use crate::database::{cache, db_conn}; -use crate::federation::nodeinfo::schema::*; -use crate::model::entity::{note, user}; -use sea_orm::{ColumnTrait, DbErr, EntityTrait, PaginatorTrait, QueryFilter}; +use crate::{ + config::{local_server_info, CONFIG}, + database::{cache, db_conn}, + federation::nodeinfo::schema::*, + model::entity::{note, user}, +}; +use sea_orm::prelude::*; use serde_json::json; use std::collections::HashMap; diff --git a/packages/backend-rs/src/misc/get_image_size.rs b/packages/backend-rs/src/misc/get_image_size.rs index 5fc068fbe0..bfe5c4edd3 100644 --- a/packages/backend-rs/src/misc/get_image_size.rs +++ b/packages/backend-rs/src/misc/get_image_size.rs @@ -1,5 +1,4 @@ -use crate::database::cache; -use crate::util::http_client; +use crate::{database::cache, util::http_client}; use image::{io::Reader, ImageError, ImageFormat}; use isahc::ReadResponseExt; use nom_exif::{parse_jpeg_exif, EntryValue, ExifTag}; diff --git a/packages/backend-rs/src/misc/get_note_all_texts.rs b/packages/backend-rs/src/misc/get_note_all_texts.rs index 7dc161665c..0532c48054 100644 --- a/packages/backend-rs/src/misc/get_note_all_texts.rs +++ b/packages/backend-rs/src/misc/get_note_all_texts.rs @@ -1,5 +1,7 @@ -use crate::database::db_conn; -use crate::model::entity::{drive_file, note}; +use crate::{ + database::db_conn, + model::entity::{drive_file, note}, +}; use sea_orm::{prelude::*, QuerySelect}; #[crate::export(object)] diff --git a/packages/backend-rs/src/misc/latest_version.rs b/packages/backend-rs/src/misc/latest_version.rs index 7233814df6..1792adee06 100644 --- a/packages/backend-rs/src/misc/latest_version.rs +++ b/packages/backend-rs/src/misc/latest_version.rs @@ -1,7 +1,6 @@ //! Fetch latest Firefish version from the Firefish repository -use crate::database::cache; -use crate::util::http_client; +use crate::{database::cache, util::http_client}; use isahc::ReadResponseExt; use serde::Deserialize; diff --git a/packages/backend-rs/src/misc/reaction.rs b/packages/backend-rs/src/misc/reaction.rs index 50b679cd53..4f11894ee7 100644 --- a/packages/backend-rs/src/misc/reaction.rs +++ b/packages/backend-rs/src/misc/reaction.rs @@ -1,6 +1,4 @@ -use crate::config::local_server_info; -use crate::database::db_conn; -use crate::model::entity::emoji; +use crate::{config::local_server_info, database::db_conn, model::entity::emoji}; use once_cell::sync::Lazy; use regex::Regex; use sea_orm::prelude::*; diff --git a/packages/backend-rs/src/misc/remove_old_attestation_challenges.rs b/packages/backend-rs/src/misc/remove_old_attestation_challenges.rs index 9102d1ce39..2dc45c02eb 100644 --- a/packages/backend-rs/src/misc/remove_old_attestation_challenges.rs +++ b/packages/backend-rs/src/misc/remove_old_attestation_challenges.rs @@ -1,7 +1,6 @@ // TODO: We want to get rid of this -use crate::database::db_conn; -use crate::model::entity::attestation_challenge; +use crate::{database::db_conn, model::entity::attestation_challenge}; use chrono::{Duration, Utc}; use sea_orm::prelude::*; diff --git a/packages/backend-rs/src/service/antenna/check_hit.rs b/packages/backend-rs/src/service/antenna/check_hit.rs index cf4429212c..0f297ccbb2 100644 --- a/packages/backend-rs/src/service/antenna/check_hit.rs +++ b/packages/backend-rs/src/service/antenna/check_hit.rs @@ -1,7 +1,9 @@ -use crate::config::CONFIG; -use crate::database::{cache, db_conn}; -use crate::federation::acct::Acct; -use crate::model::entity::{antenna, blocking, following, note, sea_orm_active_enums::*}; +use crate::{ + config::CONFIG, + database::{cache, db_conn}, + federation::acct::Acct, + model::entity::{antenna, blocking, following, note, sea_orm_active_enums::*}, +}; use sea_orm::{prelude::*, QuerySelect}; #[derive(thiserror::Error, Debug)] diff --git a/packages/backend-rs/src/service/antenna/process_new_note.rs b/packages/backend-rs/src/service/antenna/process_new_note.rs index a4fdc28848..1af4e93433 100644 --- a/packages/backend-rs/src/service/antenna/process_new_note.rs +++ b/packages/backend-rs/src/service/antenna/process_new_note.rs @@ -1,10 +1,12 @@ -use crate::database::{cache, db_conn, redis_conn, redis_key, RedisConnError}; -use crate::federation::acct::Acct; -use crate::misc::get_note_all_texts::{all_texts, PartialNoteToElaborate}; -use crate::model::entity::{antenna, note}; -use crate::service::antenna::check_hit::{check_hit_antenna, AntennaCheckError}; -use crate::service::stream; -use crate::util::id::{get_timestamp, InvalidIdError}; +use crate::{ + database::{cache, db_conn, redis_conn, redis_key, RedisConnError}, + federation::acct::Acct, + misc::get_note_all_texts::{all_texts, PartialNoteToElaborate}, + model::entity::{antenna, note}, + service::antenna::check_hit::{check_hit_antenna, AntennaCheckError}, + service::stream, + util::id::{get_timestamp, InvalidIdError}, +}; use redis::{streams::StreamMaxlen, AsyncCommands, RedisError}; use sea_orm::prelude::*; diff --git a/packages/backend-rs/src/service/note/watch.rs b/packages/backend-rs/src/service/note/watch.rs index d6496553e3..d63ce00e85 100644 --- a/packages/backend-rs/src/service/note/watch.rs +++ b/packages/backend-rs/src/service/note/watch.rs @@ -1,6 +1,4 @@ -use crate::database::db_conn; -use crate::model::entity::note_watching; -use crate::util::id::gen_id_at; +use crate::{database::db_conn, model::entity::note_watching, util::id::gen_id_at}; use sea_orm::{prelude::*, ActiveValue}; #[crate::export] diff --git a/packages/backend-rs/src/service/push_notification.rs b/packages/backend-rs/src/service/push_notification.rs index b417630194..35c97f86c1 100644 --- a/packages/backend-rs/src/service/push_notification.rs +++ b/packages/backend-rs/src/service/push_notification.rs @@ -1,14 +1,13 @@ -use crate::config::local_server_info; -use crate::database::db_conn; -use crate::misc::get_note_summary::{get_note_summary, PartialNoteToSummarize}; -use crate::model::entity::sw_subscription; -use crate::util::http_client; +use crate::{ + config::local_server_info, + database::db_conn, + misc::get_note_summary::{get_note_summary, PartialNoteToSummarize}, + model::entity::sw_subscription, + util::http_client, +}; use once_cell::sync::OnceCell; use sea_orm::prelude::*; -use web_push::{ - ContentEncoding, IsahcWebPushClient, SubscriptionInfo, SubscriptionKeys, VapidSignatureBuilder, - WebPushClient, WebPushError, WebPushMessageBuilder, -}; +use web_push::*; #[derive(thiserror::Error, Debug)] pub enum Error { diff --git a/packages/backend-rs/src/service/stream.rs b/packages/backend-rs/src/service/stream.rs index 47cff7de1f..a028707d38 100644 --- a/packages/backend-rs/src/service/stream.rs +++ b/packages/backend-rs/src/service/stream.rs @@ -6,8 +6,10 @@ pub mod custom_emoji; pub mod group_chat; pub mod moderation; -use crate::config::CONFIG; -use crate::database::{redis_conn, RedisConnError}; +use crate::{ + config::CONFIG, + database::{redis_conn, RedisConnError}, +}; use redis::{AsyncCommands, RedisError}; pub enum Stream { @@ -50,6 +52,14 @@ pub enum Stream { }, } +#[crate::export] +pub enum ChatEvent { + Message, + Read, + Deleted, + Typing, +} + #[derive(thiserror::Error, Debug)] pub enum Error { #[error("Redis error: {0}")] diff --git a/packages/backend-rs/src/service/stream/antenna.rs b/packages/backend-rs/src/service/stream/antenna.rs index 7210719c93..ddd3dd711a 100644 --- a/packages/backend-rs/src/service/stream/antenna.rs +++ b/packages/backend-rs/src/service/stream/antenna.rs @@ -1,5 +1,7 @@ -use crate::model::entity::note; -use crate::service::stream::{publish_to_stream, Error, Stream}; +use crate::{ + model::entity::note, + service::stream::{publish_to_stream, Error, Stream}, +}; pub async fn publish(antenna_id: String, note: ¬e::Model) -> Result<(), Error> { publish_to_stream( diff --git a/packages/backend-rs/src/service/stream/chat.rs b/packages/backend-rs/src/service/stream/chat.rs index 62701d3976..2f60ff4015 100644 --- a/packages/backend-rs/src/service/stream/chat.rs +++ b/packages/backend-rs/src/service/stream/chat.rs @@ -1,12 +1,4 @@ -use crate::service::stream::{publish_to_stream, Error, Stream}; - -#[crate::export(string_enum = "camelCase")] -pub enum ChatEvent { - Message, - Read, - Deleted, - Typing, -} +use crate::service::stream::{publish_to_stream, ChatEvent, Error, Stream}; // We want to merge `kind` and `object` into a single enum // https://github.com/napi-rs/napi-rs/issues/2036 diff --git a/packages/backend-rs/src/service/stream/chat_index.rs b/packages/backend-rs/src/service/stream/chat_index.rs index 790dd905ea..e686db8149 100644 --- a/packages/backend-rs/src/service/stream/chat_index.rs +++ b/packages/backend-rs/src/service/stream/chat_index.rs @@ -1,6 +1,6 @@ use crate::service::stream::{publish_to_stream, Error, Stream}; -#[crate::export(string_enum = "camelCase")] +#[crate::export] pub enum ChatIndexEvent { Message, Read, diff --git a/packages/backend-rs/src/service/stream/group_chat.rs b/packages/backend-rs/src/service/stream/group_chat.rs index 6cf3c5f671..49ebc299d2 100644 --- a/packages/backend-rs/src/service/stream/group_chat.rs +++ b/packages/backend-rs/src/service/stream/group_chat.rs @@ -1,4 +1,4 @@ -use crate::service::stream::{chat::ChatEvent, publish_to_stream, Error, Stream}; +use crate::service::stream::{publish_to_stream, ChatEvent, Error, Stream}; // We want to merge `kind` and `object` into a single enum // https://github.com/napi-rs/napi-rs/issues/2036