mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
- Introduces a new Music Library system for managing favorites (tracks, playlists, releases), replacing the previous TrackLike model. - Completely revamps the Studio TV profile page, adding live statistics, stream configuration, restream management, and media URL display. - Enhances the media player with a custom seekbar and improved audio playback logic for MPD and non-MPD sources. - Lays foundational groundwork for chat encryption with new models and APIs. - Refactors critical UI components like PlaylistView and PagePanel. - Standardizes monorepo development scripts to use npm. - Updates comty.js submodule and adds various new UI components.
38 lines
865 B
JavaScript
38 lines
865 B
JavaScript
import { ChatMessage } from "@db_models"
|
|
|
|
export default async (socket, payload, engine) => {
|
|
if (!socket.userData) {
|
|
throw new OperationError(401, "Unauthorized")
|
|
}
|
|
|
|
const created_at = new Date().getTime()
|
|
|
|
const [from_user_id, to_user_id] = [socket.userData._id, payload.to_user_id]
|
|
|
|
const wsMessageObj = {
|
|
...payload,
|
|
created_at: created_at,
|
|
user: socket.userData,
|
|
_id: `msg:${from_user_id}:${created_at}`,
|
|
}
|
|
|
|
const doc = await ChatMessage.create({
|
|
type: "user",
|
|
from_user_id: from_user_id,
|
|
to_user_id: to_user_id,
|
|
content: payload.content,
|
|
encrypted: !!payload.encrypted,
|
|
created_at: created_at,
|
|
})
|
|
|
|
socket.emit("chat:receive:message", wsMessageObj)
|
|
|
|
const targetSocket = await engine.find.socketByUserId(payload.to_user_id)
|
|
|
|
if (targetSocket) {
|
|
await targetSocket.emit("chat:receive:message", wsMessageObj)
|
|
}
|
|
|
|
return doc
|
|
}
|