refactor (backend): port publishGroupMessagingStream to backend-rs
This commit is contained in:
parent
d880601d56
commit
38cd4bafde
9 changed files with 54 additions and 39 deletions
1
packages/backend-rs/index.d.ts
vendored
1
packages/backend-rs/index.d.ts
vendored
|
@ -1174,6 +1174,7 @@ export interface PackedEmoji {
|
||||||
height: number | null
|
height: number | null
|
||||||
}
|
}
|
||||||
export function publishToBroadcastStream(emoji: PackedEmoji): void
|
export function publishToBroadcastStream(emoji: PackedEmoji): void
|
||||||
|
export function publishToGroupChatStream(groupId: string, kind: ChatEvent, object: any): void
|
||||||
export interface AbuseUserReportLike {
|
export interface AbuseUserReportLike {
|
||||||
id: string
|
id: string
|
||||||
targetUserId: string
|
targetUserId: string
|
||||||
|
|
|
@ -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, publishToChannelStream, ChatEvent, publishToChatStream, ChatIndexEvent, publishToChatIndexStream, publishToBroadcastStream, 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, 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
|
||||||
|
@ -371,6 +371,7 @@ module.exports.publishToChatStream = publishToChatStream
|
||||||
module.exports.ChatIndexEvent = ChatIndexEvent
|
module.exports.ChatIndexEvent = ChatIndexEvent
|
||||||
module.exports.publishToChatIndexStream = publishToChatIndexStream
|
module.exports.publishToChatIndexStream = publishToChatIndexStream
|
||||||
module.exports.publishToBroadcastStream = publishToBroadcastStream
|
module.exports.publishToBroadcastStream = publishToBroadcastStream
|
||||||
|
module.exports.publishToGroupChatStream = publishToGroupChatStream
|
||||||
module.exports.publishToModerationStream = publishToModerationStream
|
module.exports.publishToModerationStream = publishToModerationStream
|
||||||
module.exports.getTimestamp = getTimestamp
|
module.exports.getTimestamp = getTimestamp
|
||||||
module.exports.genId = genId
|
module.exports.genId = genId
|
||||||
|
|
|
@ -3,6 +3,7 @@ pub mod channel;
|
||||||
pub mod chat;
|
pub mod chat;
|
||||||
pub mod chat_index;
|
pub mod chat_index;
|
||||||
pub mod custom_emoji;
|
pub mod custom_emoji;
|
||||||
|
pub mod group_chat;
|
||||||
pub mod moderation;
|
pub mod moderation;
|
||||||
|
|
||||||
use crate::config::CONFIG;
|
use crate::config::CONFIG;
|
||||||
|
|
13
packages/backend-rs/src/service/stream/group_chat.rs
Normal file
13
packages/backend-rs/src/service/stream/group_chat.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
use crate::service::stream::{chat::ChatEvent, publish_to_stream, Error, Stream};
|
||||||
|
|
||||||
|
// We want to merge `kind` and `object` into a single enum
|
||||||
|
// https://github.com/napi-rs/napi-rs/issues/2036
|
||||||
|
|
||||||
|
#[crate::export(js_name = "publishToGroupChatStream")]
|
||||||
|
pub fn publish(group_id: String, kind: ChatEvent, object: &serde_json::Value) -> Result<(), Error> {
|
||||||
|
publish_to_stream(
|
||||||
|
&Stream::GroupChat { group_id },
|
||||||
|
Some(kind.to_string()),
|
||||||
|
Some(serde_json::to_string(object)?),
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,9 +1,7 @@
|
||||||
import {
|
import { publishMainStream } from "@/services/stream.js";
|
||||||
publishMainStream,
|
|
||||||
publishGroupMessagingStream,
|
|
||||||
} from "@/services/stream.js";
|
|
||||||
import {
|
import {
|
||||||
publishToChatStream,
|
publishToChatStream,
|
||||||
|
publishToGroupChatStream,
|
||||||
publishToChatIndexStream,
|
publishToChatIndexStream,
|
||||||
ChatEvent,
|
ChatEvent,
|
||||||
ChatIndexEvent,
|
ChatIndexEvent,
|
||||||
|
@ -130,9 +128,9 @@ export async function readGroupMessagingMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publish event
|
// Publish event
|
||||||
publishGroupMessagingStream(groupId, "read", {
|
publishToGroupChatStream(groupId, ChatEvent.Read, {
|
||||||
ids: reads,
|
ids: reads,
|
||||||
userId: userId,
|
userId,
|
||||||
});
|
});
|
||||||
publishToChatIndexStream(userId, ChatIndexEvent.Read, reads);
|
publishToChatIndexStream(userId, ChatIndexEvent.Read, reads);
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ 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 {
|
||||||
publishToChannelStream,
|
publishToChannelStream,
|
||||||
publishToChatStream,
|
publishToChatStream,
|
||||||
|
publishToGroupChatStream,
|
||||||
ChatEvent,
|
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";
|
||||||
|
@ -531,8 +531,8 @@ export default class Connection {
|
||||||
ChatEvent.Typing,
|
ChatEvent.Typing,
|
||||||
this.user.id,
|
this.user.id,
|
||||||
);
|
);
|
||||||
} else if (param.group) {
|
} else if (param.group != null) {
|
||||||
publishGroupMessagingStream(param.group, "typing", this.user.id);
|
publishToGroupChatStream(param.group, ChatEvent.Typing, this.user.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,14 @@ import {
|
||||||
import {
|
import {
|
||||||
genId,
|
genId,
|
||||||
publishToChatStream,
|
publishToChatStream,
|
||||||
|
publishToGroupChatStream,
|
||||||
publishToChatIndexStream,
|
publishToChatIndexStream,
|
||||||
toPuny,
|
toPuny,
|
||||||
ChatEvent,
|
ChatEvent,
|
||||||
ChatIndexEvent,
|
ChatIndexEvent,
|
||||||
} from "backend-rs";
|
} from "backend-rs";
|
||||||
import type { MessagingMessage } from "@/models/entities/messaging-message.js";
|
import type { MessagingMessage } from "@/models/entities/messaging-message.js";
|
||||||
import {
|
import { publishMainStream } from "@/services/stream.js";
|
||||||
publishMainStream,
|
|
||||||
publishGroupMessagingStream,
|
|
||||||
} from "@/services/stream.js";
|
|
||||||
import { pushNotification } from "@/services/push-notification.js";
|
import { pushNotification } from "@/services/push-notification.js";
|
||||||
import { Not } from "typeorm";
|
import { Not } from "typeorm";
|
||||||
import type { Note } from "@/models/entities/note.js";
|
import type { Note } from "@/models/entities/note.js";
|
||||||
|
@ -86,11 +84,11 @@ export async function createMessage(
|
||||||
);
|
);
|
||||||
publishMainStream(recipientUser.id, "messagingMessage", messageObj);
|
publishMainStream(recipientUser.id, "messagingMessage", messageObj);
|
||||||
}
|
}
|
||||||
} else if (recipientGroup) {
|
} else if (recipientGroup != null) {
|
||||||
// グループのストリーム
|
// group's stream
|
||||||
publishGroupMessagingStream(recipientGroup.id, "message", messageObj);
|
publishToGroupChatStream(recipientGroup.id, ChatEvent.Message, messageObj);
|
||||||
|
|
||||||
// メンバーのストリーム
|
// member's stream
|
||||||
const joinings = await UserGroupJoinings.findBy({
|
const joinings = await UserGroupJoinings.findBy({
|
||||||
userGroupId: recipientGroup.id,
|
userGroupId: recipientGroup.id,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import { config } from "@/config.js";
|
import { config } from "@/config.js";
|
||||||
import { MessagingMessages, Users } from "@/models/index.js";
|
import { MessagingMessages, Users } from "@/models/index.js";
|
||||||
import type { MessagingMessage } from "@/models/entities/messaging-message.js";
|
import type { MessagingMessage } from "@/models/entities/messaging-message.js";
|
||||||
import { publishGroupMessagingStream } from "@/services/stream.js";
|
import {
|
||||||
import { publishToChatStream, ChatEvent } from "backend-rs";
|
publishToChatStream,
|
||||||
|
publishToGroupChatStream,
|
||||||
|
ChatEvent,
|
||||||
|
} from "backend-rs";
|
||||||
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
import { renderActivity } from "@/remote/activitypub/renderer/index.js";
|
||||||
import renderDelete from "@/remote/activitypub/renderer/delete.js";
|
import renderDelete from "@/remote/activitypub/renderer/delete.js";
|
||||||
import renderTombstone from "@/remote/activitypub/renderer/tombstone.js";
|
import renderTombstone from "@/remote/activitypub/renderer/tombstone.js";
|
||||||
|
@ -42,7 +45,7 @@ async function postDeleteMessage(message: MessagingMessage) {
|
||||||
);
|
);
|
||||||
deliver(user, activity, recipient.inbox);
|
deliver(user, activity, recipient.inbox);
|
||||||
}
|
}
|
||||||
} else if (message.groupId) {
|
} else if (message.groupId != null) {
|
||||||
publishGroupMessagingStream(message.groupId, "deleted", message.id);
|
publishToGroupChatStream(message.groupId, ChatEvent.Deleted, message.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { redisClient } from "@/db/redis.js";
|
||||||
import type { User } from "@/models/entities/user.js";
|
import type { User } from "@/models/entities/user.js";
|
||||||
import type { Note } from "@/models/entities/note.js";
|
import type { Note } from "@/models/entities/note.js";
|
||||||
import type { UserList } from "@/models/entities/user-list.js";
|
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";
|
||||||
|
@ -13,7 +13,7 @@ import type {
|
||||||
// BroadcastTypes,
|
// BroadcastTypes,
|
||||||
// ChannelStreamTypes,
|
// ChannelStreamTypes,
|
||||||
DriveStreamTypes,
|
DriveStreamTypes,
|
||||||
GroupMessagingStreamTypes,
|
// GroupMessagingStreamTypes,
|
||||||
InternalStreamTypes,
|
InternalStreamTypes,
|
||||||
MainStreamTypes,
|
MainStreamTypes,
|
||||||
// MessagingIndexStreamTypes,
|
// MessagingIndexStreamTypes,
|
||||||
|
@ -163,19 +163,20 @@ class Publisher {
|
||||||
// );
|
// );
|
||||||
// };
|
// };
|
||||||
|
|
||||||
public publishGroupMessagingStream = <
|
/* ported to backend-rs */
|
||||||
K extends keyof GroupMessagingStreamTypes,
|
// public publishGroupMessagingStream = <
|
||||||
>(
|
// K extends keyof GroupMessagingStreamTypes,
|
||||||
groupId: UserGroup["id"],
|
// >(
|
||||||
type: K,
|
// groupId: UserGroup["id"],
|
||||||
value?: GroupMessagingStreamTypes[K],
|
// type: K,
|
||||||
): void => {
|
// value?: GroupMessagingStreamTypes[K],
|
||||||
this.publish(
|
// ): void => {
|
||||||
`messagingStream:${groupId}`,
|
// this.publish(
|
||||||
type,
|
// `messagingStream:${groupId}`,
|
||||||
typeof value === "undefined" ? null : value,
|
// type,
|
||||||
);
|
// typeof value === "undefined" ? null : value,
|
||||||
};
|
// );
|
||||||
|
// };
|
||||||
|
|
||||||
/* ported to backend-rs */
|
/* ported to backend-rs */
|
||||||
// public publishMessagingIndexStream = <
|
// public publishMessagingIndexStream = <
|
||||||
|
@ -225,7 +226,6 @@ export const publishNotesStream = publisher.publishNotesStream;
|
||||||
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;
|
||||||
export const publishGroupMessagingStream =
|
// export const publishGroupMessagingStream = publisher.publishGroupMessagingStream;
|
||||||
publisher.publishGroupMessagingStream;
|
|
||||||
// export const publishMessagingIndexStream = publisher.publishMessagingIndexStream;
|
// export const publishMessagingIndexStream = publisher.publishMessagingIndexStream;
|
||||||
// export const publishAdminStream = publisher.publishAdminStream;
|
// export const publishAdminStream = publisher.publishAdminStream;
|
||||||
|
|
Loading…
Reference in a new issue