refactor (backend): port publishChannelStream to backend-rs
This commit is contained in:
parent
ba8e044f42
commit
1cfe3bfb73
6 changed files with 36 additions and 21 deletions
1
packages/backend-rs/index.d.ts
vendored
1
packages/backend-rs/index.d.ts
vendored
|
@ -1149,6 +1149,7 @@ export interface Webhook {
|
|||
export function initializeRustLogger(): void
|
||||
export function watchNote(watcherId: string, noteAuthorId: 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 {
|
||||
Message = 'message',
|
||||
Read = 'read',
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
pub mod antenna;
|
||||
pub mod channel;
|
||||
pub mod chat;
|
||||
pub mod moderation;
|
||||
|
||||
|
|
10
packages/backend-rs/src/service/stream/channel.rs
Normal file
10
packages/backend-rs/src/service/stream/channel.rs
Normal 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)),
|
||||
)
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = <K extends keyof ChannelStreamTypes>(
|
||||
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 = <K extends keyof ChannelStreamTypes>(
|
||||
// channelId: Channel["id"],
|
||||
// type: K,
|
||||
// value?: ChannelStreamTypes[K],
|
||||
// ): void => {
|
||||
// this.publish(
|
||||
// `channelStream:${channelId}`,
|
||||
// type,
|
||||
// typeof value === "undefined" ? null : value,
|
||||
// );
|
||||
// };
|
||||
|
||||
public publishUserListStream = <K extends keyof UserListStreamTypes>(
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue