import { UserModel } from '@server/models/user/user'
import { VideoModel } from '@server/models/video/video'
import { VideoBlacklistModel } from '@server/models/video/video-blacklist'
-import { MPlugin } from '@server/types/models'
+import { MPlugin, MVideo, UserNotificationModelForApi } from '@server/types/models'
import { PeerTubeHelpers } from '@server/types/plugins'
import { VideoBlacklistCreate, VideoStorage } from '@shared/models'
import { addAccountInBlocklist, addServerInBlocklist, removeAccountFromBlocklist, removeServerFromBlocklist } from '../blocklist'
import { ServerConfigManager } from '../server-config-manager'
import { blacklistVideo, unblacklistVideo } from '../video-blacklist'
import { VideoPathManager } from '../video-path-manager'
+import { PeerTubeSocket } from '../peertube-socket'
function buildPluginHelpers (pluginModel: MPlugin, npmName: string): PeerTubeHelpers {
const logger = buildPluginLogger(npmName)
const plugin = buildPluginRelatedHelpers(pluginModel, npmName)
+ const socket = buildSocketHelpers()
+
const user = buildUserHelpers()
return {
moderation,
plugin,
server,
+ socket,
user
}
}
}
}
+function buildSocketHelpers () {
+ return {
+ sendNotification: (userId: number, notification: UserNotificationModelForApi) => {
+ PeerTubeSocket.Instance.sendNotification(userId, notification)
+ },
+ sendVideoLiveNewState: (video: MVideo) => {
+ PeerTubeSocket.Instance.sendVideoLiveNewState(video)
+ }
+ }
+}
+
function buildUserHelpers () {
return {
+ loadById: (id: number) => {
+ return UserModel.loadByIdFull(id)
+ },
+
getAuthUser: (res: express.Response) => {
const user = res.locals.oauth?.token?.User
if (!user) return undefined