refactor (backend): port publishChannelStream to backend-rs

This commit is contained in:
naskya 2024-04-26 06:16:51 +09:00
parent ba8e044f42
commit 1cfe3bfb73
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
6 changed files with 36 additions and 21 deletions

View file

@ -1149,6 +1149,7 @@ export interface Webhook {
export function initializeRustLogger(): void export function initializeRustLogger(): void
export function watchNote(watcherId: string, noteAuthorId: string, noteId: string): Promise<void> export function watchNote(watcherId: string, noteAuthorId: string, noteId: string): Promise<void>
export function unwatchNote(watcherId: string, noteId: string): Promise<void> export function unwatchNote(watcherId: string, noteId: string): Promise<void>
export function publishToChannelStream(channelId: string, userId: string): void
export enum ChatEvent { export enum ChatEvent {
Message = 'message', Message = 'message',
Read = 'read', Read = 'read',

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, 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.SECOND = SECOND
module.exports.MINUTE = MINUTE module.exports.MINUTE = MINUTE
@ -365,6 +365,7 @@ module.exports.UserProfileMutingnotificationtypesEnum = UserProfileMutingnotific
module.exports.initializeRustLogger = initializeRustLogger module.exports.initializeRustLogger = initializeRustLogger
module.exports.watchNote = watchNote module.exports.watchNote = watchNote
module.exports.unwatchNote = unwatchNote module.exports.unwatchNote = unwatchNote
module.exports.publishToChannelStream = publishToChannelStream
module.exports.ChatEvent = ChatEvent module.exports.ChatEvent = ChatEvent
module.exports.publishToChatStream = publishToChatStream module.exports.publishToChatStream = publishToChatStream
module.exports.publishToModerationStream = publishToModerationStream module.exports.publishToModerationStream = publishToModerationStream

View file

@ -1,4 +1,5 @@
pub mod antenna; pub mod antenna;
pub mod channel;
pub mod chat; pub mod chat;
pub mod moderation; pub mod moderation;

View file

@ -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)),
)
}

View file

@ -14,11 +14,12 @@ import {
} from "@/models/index.js"; } from "@/models/index.js";
import type { AccessToken } from "@/models/entities/access-token.js"; import type { AccessToken } from "@/models/entities/access-token.js";
import type { UserProfile } from "@/models/entities/user-profile.js"; import type { UserProfile } from "@/models/entities/user-profile.js";
import { publishGroupMessagingStream } from "@/services/stream.js";
import { import {
publishChannelStream, publishToChannelStream,
publishGroupMessagingStream, publishToChatStream,
} from "@/services/stream.js"; ChatEvent,
import { publishToChatStream, ChatEvent } from "backend-rs"; } from "backend-rs";
import type { UserGroup } from "@/models/entities/user-group.js"; import type { UserGroup } from "@/models/entities/user-group.js";
import type { Packed } from "@/misc/schema.js"; import type { Packed } from "@/misc/schema.js";
import { readNotification } from "@/server/api/common/read-notification.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) { if (this.user) {
publishChannelStream(channel, "typing", this.user.id); publishToChannelStream(channelId, this.user.id);
} }
} }

View file

@ -5,13 +5,13 @@ import type { UserList } from "@/models/entities/user-list.js";
import type { UserGroup } from "@/models/entities/user-group.js"; import type { UserGroup } from "@/models/entities/user-group.js";
import { config } from "@/config.js"; import { config } from "@/config.js";
// import type { Antenna } from "@/models/entities/antenna.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 { import type {
StreamChannels, StreamChannels,
// AdminStreamTypes, // AdminStreamTypes,
// AntennaStreamTypes, // AntennaStreamTypes,
BroadcastTypes, BroadcastTypes,
ChannelStreamTypes, // ChannelStreamTypes,
DriveStreamTypes, DriveStreamTypes,
GroupMessagingStreamTypes, GroupMessagingStreamTypes,
InternalStreamTypes, InternalStreamTypes,
@ -110,17 +110,18 @@ class Publisher {
}); });
}; };
public publishChannelStream = <K extends keyof ChannelStreamTypes>( /* ported to backend-rs */
channelId: Channel["id"], // public publishChannelStream = <K extends keyof ChannelStreamTypes>(
type: K, // channelId: Channel["id"],
value?: ChannelStreamTypes[K], // type: K,
): void => { // value?: ChannelStreamTypes[K],
this.publish( // ): void => {
`channelStream:${channelId}`, // this.publish(
type, // `channelStream:${channelId}`,
typeof value === "undefined" ? null : value, // type,
); // typeof value === "undefined" ? null : value,
}; // );
// };
public publishUserListStream = <K extends keyof UserListStreamTypes>( public publishUserListStream = <K extends keyof UserListStreamTypes>(
listId: UserList["id"], listId: UserList["id"],
@ -218,7 +219,7 @@ 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;
// export const publishMessagingStream = publisher.publishMessagingStream; // export const publishMessagingStream = publisher.publishMessagingStream;