diff --git a/packages/backend-rs/index.d.ts b/packages/backend-rs/index.d.ts index 1f5fa5f55c..59943ca111 100644 --- a/packages/backend-rs/index.d.ts +++ b/packages/backend-rs/index.d.ts @@ -1149,6 +1149,7 @@ export interface Webhook { export function initializeRustLogger(): void export function watchNote(watcherId: string, noteAuthorId: string, noteId: string): Promise export function unwatchNote(watcherId: string, noteId: string): Promise +export function publishToChannelStream(channelId: string, userId: string): void export enum ChatEvent { Message = 'message', Read = 'read', diff --git a/packages/backend-rs/index.js b/packages/backend-rs/index.js index eef6310871..cc7f7903c1 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, loadConfig, stringToAcct, acctToString, addNoteToAntenna, isBlockedServer, isSilencedServer, isAllowedServer, checkWordMute, getFullApAccount, isSelfHost, isSameOrigin, extractHost, toPuny, isUnicodeEmoji, sqlLikeEscape, safeForSql, formatMilliseconds, getImageSizeFromUrl, getNoteSummary, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, AntennaSrcEnum, DriveFileUsageHintEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, initializeRustLogger, watchNote, unwatchNote, ChatEvent, publishToChatStream, publishToModerationStream, 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, toMastodonId, fromMastodonId, fetchMeta, metaToPugArgs, nyaify, hashPassword, verifyPassword, isOldPasswordAlgorithm, decodeReaction, countReactions, toDbReaction, removeOldAttestationChallenges, AntennaSrcEnum, DriveFileUsageHintEnum, MutedNoteReasonEnum, NoteVisibilityEnum, NotificationTypeEnum, PageVisibilityEnum, PollNotevisibilityEnum, RelayStatusEnum, UserEmojimodpermEnum, UserProfileFfvisibilityEnum, UserProfileMutingnotificationtypesEnum, initializeRustLogger, watchNote, unwatchNote, publishToChannelStream, ChatEvent, publishToChatStream, publishToModerationStream, getTimestamp, genId, genIdAt, secureRndstr } = nativeBinding module.exports.SECOND = SECOND module.exports.MINUTE = MINUTE @@ -365,6 +365,7 @@ module.exports.UserProfileMutingnotificationtypesEnum = UserProfileMutingnotific module.exports.initializeRustLogger = initializeRustLogger module.exports.watchNote = watchNote module.exports.unwatchNote = unwatchNote +module.exports.publishToChannelStream = publishToChannelStream module.exports.ChatEvent = ChatEvent module.exports.publishToChatStream = publishToChatStream module.exports.publishToModerationStream = publishToModerationStream diff --git a/packages/backend-rs/src/service/stream.rs b/packages/backend-rs/src/service/stream.rs index 7d61434081..963d11f899 100644 --- a/packages/backend-rs/src/service/stream.rs +++ b/packages/backend-rs/src/service/stream.rs @@ -1,4 +1,5 @@ pub mod antenna; +pub mod channel; pub mod chat; pub mod moderation; diff --git a/packages/backend-rs/src/service/stream/channel.rs b/packages/backend-rs/src/service/stream/channel.rs new file mode 100644 index 0000000000..10a04c5e66 --- /dev/null +++ b/packages/backend-rs/src/service/stream/channel.rs @@ -0,0 +1,10 @@ +use crate::service::stream::{publish_to_stream, Error, Stream}; + +#[crate::export(js_name = "publishToChannelStream")] +pub fn publish(channel_id: String, user_id: String) -> Result<(), Error> { + publish_to_stream( + &Stream::Channel { channel_id }, + Some("typing".to_string()), + Some(format!("\"{}\"", user_id)), + ) +} diff --git a/packages/backend/src/server/api/stream/index.ts b/packages/backend/src/server/api/stream/index.ts index 97337bd7e1..4079573ffb 100644 --- a/packages/backend/src/server/api/stream/index.ts +++ b/packages/backend/src/server/api/stream/index.ts @@ -14,11 +14,12 @@ import { } from "@/models/index.js"; import type { AccessToken } from "@/models/entities/access-token.js"; import type { UserProfile } from "@/models/entities/user-profile.js"; +import { publishGroupMessagingStream } from "@/services/stream.js"; import { - publishChannelStream, - publishGroupMessagingStream, -} from "@/services/stream.js"; -import { publishToChatStream, ChatEvent } from "backend-rs"; + publishToChannelStream, + publishToChatStream, + ChatEvent, +} from "backend-rs"; import type { UserGroup } from "@/models/entities/user-group.js"; import type { Packed } from "@/misc/schema.js"; import { readNotification } from "@/server/api/common/read-notification.js"; @@ -512,9 +513,9 @@ export default class Connection { } } - private typingOnChannel(channel: ChannelModel["id"]) { + private typingOnChannel(channelId: ChannelModel["id"]) { if (this.user) { - publishChannelStream(channel, "typing", this.user.id); + publishToChannelStream(channelId, this.user.id); } } diff --git a/packages/backend/src/services/stream.ts b/packages/backend/src/services/stream.ts index ab56171031..38a15dcfa3 100644 --- a/packages/backend/src/services/stream.ts +++ b/packages/backend/src/services/stream.ts @@ -5,13 +5,13 @@ import type { UserList } from "@/models/entities/user-list.js"; import type { UserGroup } from "@/models/entities/user-group.js"; import { config } from "@/config.js"; // import type { Antenna } from "@/models/entities/antenna.js"; -import type { Channel } from "@/models/entities/channel.js"; +// import type { Channel } from "@/models/entities/channel.js"; import type { StreamChannels, // AdminStreamTypes, // AntennaStreamTypes, BroadcastTypes, - ChannelStreamTypes, + // ChannelStreamTypes, DriveStreamTypes, GroupMessagingStreamTypes, InternalStreamTypes, @@ -110,17 +110,18 @@ class Publisher { }); }; - public publishChannelStream = ( - channelId: Channel["id"], - type: K, - value?: ChannelStreamTypes[K], - ): void => { - this.publish( - `channelStream:${channelId}`, - type, - typeof value === "undefined" ? null : value, - ); - }; + /* ported to backend-rs */ + // public publishChannelStream = ( + // channelId: Channel["id"], + // type: K, + // value?: ChannelStreamTypes[K], + // ): void => { + // this.publish( + // `channelStream:${channelId}`, + // type, + // typeof value === "undefined" ? null : value, + // ); + // }; public publishUserListStream = ( listId: UserList["id"], @@ -218,7 +219,7 @@ export const publishMainStream = publisher.publishMainStream; export const publishDriveStream = publisher.publishDriveStream; export const publishNoteStream = publisher.publishNoteStream; export const publishNotesStream = publisher.publishNotesStream; -export const publishChannelStream = publisher.publishChannelStream; +// export const publishChannelStream = publisher.publishChannelStream; export const publishUserListStream = publisher.publishUserListStream; // export const publishAntennaStream = publisher.publishAntennaStream; // export const publishMessagingStream = publisher.publishMessagingStream;