mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
Fix websocket to websockets global variable references to support ng
This commit is contained in:
parent
7b7e7b9bb7
commit
1f0c1d5033
@ -89,11 +89,15 @@ export default async (payload = {}, req) => {
|
|||||||
|
|
||||||
// broadcast post to all users
|
// broadcast post to all users
|
||||||
if (visibility === "public") {
|
if (visibility === "public") {
|
||||||
global.websocket.senders.toTopic("realtime:feed", "post:new", result[0])
|
global.websockets.senders.toTopic(
|
||||||
|
"realtime:feed",
|
||||||
|
"post:new",
|
||||||
|
result[0],
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (visibility === "private") {
|
if (visibility === "private") {
|
||||||
const userSockets = await global.websocket.find.clientsByUserId(
|
const userSockets = await global.websockets.find.clientsByUserId(
|
||||||
post.user_id,
|
post.user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ export default async (payload = {}) => {
|
|||||||
|
|
||||||
// broadcast post to all users
|
// broadcast post to all users
|
||||||
if (post.visibility === "public") {
|
if (post.visibility === "public") {
|
||||||
global.websocket.senders.toTopic(
|
global.websockets.senders.toTopic(
|
||||||
"realtime:feed",
|
"realtime:feed",
|
||||||
"post:delete",
|
"post:delete",
|
||||||
post_id,
|
post_id,
|
||||||
@ -50,7 +50,7 @@ export default async (payload = {}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (post.visibility === "private") {
|
if (post.visibility === "private") {
|
||||||
const userSockets = await global.websocket.find.clientsByUserId(
|
const userSockets = await global.websockets.find.clientsByUserId(
|
||||||
post.user_id,
|
post.user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@ export default async (payload = {}) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await VotePoll.deleteOne({
|
await VotePoll.deleteOne({
|
||||||
_id: vote._id
|
_id: vote._id,
|
||||||
})
|
})
|
||||||
|
|
||||||
global.websocket.io.of("/").emit(`post.poll.vote.deleted`, vote)
|
global.websockets.io.of("/").emit(`post.poll.vote.deleted`, vote)
|
||||||
|
|
||||||
return vote
|
return vote
|
||||||
}
|
}
|
@ -37,7 +37,7 @@ export default async (post_id, update) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (post.visibility === "public") {
|
if (post.visibility === "public") {
|
||||||
global.websocket.senders.toTopic(
|
global.websockets.senders.toTopic(
|
||||||
"realtime:feed",
|
"realtime:feed",
|
||||||
`post:update`,
|
`post:update`,
|
||||||
result[0],
|
result[0],
|
||||||
@ -45,7 +45,7 @@ export default async (post_id, update) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (post.visibility === "private") {
|
if (post.visibility === "private") {
|
||||||
const userSockets = await global.websocket.find.clientsByUserId(
|
const userSockets = await global.websockets.find.clientsByUserId(
|
||||||
post.user_id,
|
post.user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ export default async (payload = {}) => {
|
|||||||
post = (await stage({ posts: post, for_user_id: payload.user_id }))[0]
|
post = (await stage({ posts: post, for_user_id: payload.user_id }))[0]
|
||||||
|
|
||||||
if (post.visibility === "public") {
|
if (post.visibility === "public") {
|
||||||
global.websocket.senders.toTopic("realtime:feed", `post:update`, post)
|
global.websockets.senders.toTopic("realtime:feed", `post:update`, post)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
0
packages/server/services/posts/log.txt
Normal file
0
packages/server/services/posts/log.txt
Normal file
@ -1,5 +1,5 @@
|
|||||||
//import { Server } from "../../../../linebridge/server/src"
|
import { Server } from "../../../../linebridge/server/src"
|
||||||
import { Server } from "linebridge"
|
//import { Server } from "linebridge"
|
||||||
|
|
||||||
import DbManager from "@shared-classes/DbManager"
|
import DbManager from "@shared-classes/DbManager"
|
||||||
import RedisClient from "@shared-classes/RedisClient"
|
import RedisClient from "@shared-classes/RedisClient"
|
||||||
@ -10,10 +10,11 @@ import SharedMiddlewares from "@shared-middlewares"
|
|||||||
|
|
||||||
export default class API extends Server {
|
export default class API extends Server {
|
||||||
static refName = "posts"
|
static refName = "posts"
|
||||||
static useEngine = "hyper-express-ng"
|
//static useEngine = "hyper-express-ng"
|
||||||
static enableWebsockets = true
|
static websockets = true
|
||||||
|
static listenPort = process.env.HTTP_LISTEN_PORT ?? 3001
|
||||||
static listen_port = process.env.HTTP_LISTEN_PORT ?? 3001
|
// static useMiddlewares = ["logs"]
|
||||||
|
static bypassCors = true
|
||||||
|
|
||||||
middlewares = {
|
middlewares = {
|
||||||
...SharedMiddlewares,
|
...SharedMiddlewares,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withOptionalAuthentication"],
|
useMiddlewares: ["withOptionalAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
const result = await Posts.data({
|
const result = await Posts.data({
|
||||||
post_id: req.params.post_id,
|
post_id: req.params.post_id,
|
||||||
@ -9,5 +9,5 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,7 +1,8 @@
|
|||||||
import PostClass from "@classes/posts"
|
import PostClass from "@classes/posts"
|
||||||
import { Post } from "@db_models"
|
import { Post } from "@db_models"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
// check if post is owned or if is admin
|
// check if post is owned or if is admin
|
||||||
const post = await Post.findById(req.params.post_id).catch(() => {
|
const post = await Post.findById(req.params.post_id).catch(() => {
|
||||||
@ -21,7 +22,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await PostClass.delete({
|
return await PostClass.delete({
|
||||||
post_id: req.params.post_id
|
post_id: req.params.post_id,
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,13 +1,13 @@
|
|||||||
import PostClass from "@classes/posts"
|
import PostClass from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withOptionalAuthentication"],
|
useMiddlewares: ["withOptionalAuthentication"],
|
||||||
fn: async (req) => {
|
fn: async (req) => {
|
||||||
return await PostClass.replies({
|
return await PostClass.replies({
|
||||||
post_id: req.params.post_id,
|
post_id: req.params.post_id,
|
||||||
for_user_id: req.auth?.session.user_id,
|
for_user_id: req.auth?.session.user_id,
|
||||||
trim: req.query.trim,
|
trim: req.query.trim,
|
||||||
limit: req.query.limit
|
limit: req.query.limit,
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
const result = await Posts.toggleLike({
|
const result = await Posts.toggleLike({
|
||||||
post_id: req.params.post_id,
|
post_id: req.params.post_id,
|
||||||
@ -10,5 +10,5 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
const result = await Posts.toggleSave({
|
const result = await Posts.toggleSave({
|
||||||
post_id: req.params.post_id,
|
post_id: req.params.post_id,
|
||||||
@ -10,5 +10,5 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ const MaxStringsLengths = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req) => {
|
fn: async (req) => {
|
||||||
let update = {}
|
let update = {}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req) => {
|
fn: async (req) => {
|
||||||
const result = await Posts.deleteVotePoll({
|
const result = await Posts.deleteVotePoll({
|
||||||
user_id: req.auth.session.user_id,
|
user_id: req.auth.session.user_id,
|
||||||
@ -10,5 +10,5 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req) => {
|
fn: async (req) => {
|
||||||
const result = await Posts.votePoll({
|
const result = await Posts.votePoll({
|
||||||
user_id: req.auth.session.user_id,
|
user_id: req.auth.session.user_id,
|
||||||
@ -10,5 +10,5 @@ export default {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withOptionalAuthentication"],
|
useMiddlewares: ["withOptionalAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
const payload = {
|
const payload = {
|
||||||
limit: req.query?.limit,
|
limit: req.query?.limit,
|
||||||
@ -15,5 +15,5 @@ export default {
|
|||||||
const result = await Posts.globalTimeline(payload)
|
const result = await Posts.globalTimeline(payload)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withOptionalAuthentication"],
|
useMiddlewares: ["withOptionalAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
const payload = {
|
const payload = {
|
||||||
limit: req.query?.limit,
|
limit: req.query?.limit,
|
||||||
@ -15,5 +15,5 @@ export default {
|
|||||||
const result = await Posts.timeline(payload)
|
const result = await Posts.timeline(payload)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req) => {
|
fn: async (req) => {
|
||||||
return await Posts.getLiked({
|
return await Posts.getLiked({
|
||||||
trim: req.query.trim,
|
trim: req.query.trim,
|
||||||
limit: req.query.limit,
|
limit: req.query.limit,
|
||||||
user_id: req.auth.session.user_id
|
user_id: req.auth.session.user_id,
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
const result = await Posts.create(
|
const result = await Posts.create(
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withAuthentication"],
|
useMiddlewares: ["withAuthentication"],
|
||||||
fn: async (req) => {
|
fn: async (req) => {
|
||||||
return await Posts.getSaved({
|
return await Posts.getSaved({
|
||||||
trim: req.query.trim,
|
trim: req.query.trim,
|
||||||
limit: req.query.limit,
|
limit: req.query.limit,
|
||||||
user_id: req.auth.session.user_id
|
user_id: req.auth.session.user_id,
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ import { Post } from "@db_models"
|
|||||||
import stage from "@classes/posts/methods/stage"
|
import stage from "@classes/posts/methods/stage"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withOptionalAuthentication"],
|
useMiddlewares: ["withOptionalAuthentication"],
|
||||||
fn: async (req) => {
|
fn: async (req) => {
|
||||||
const { limit, trim } = req.query
|
const { limit, trim } = req.query
|
||||||
|
|
||||||
|
@ -12,34 +12,34 @@ export default async (req) => {
|
|||||||
{
|
{
|
||||||
$match: {
|
$match: {
|
||||||
message: { $regex: /#/gi },
|
message: { $regex: /#/gi },
|
||||||
created_at: { $gte: startDate }
|
created_at: { $gte: startDate },
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
hashtags: {
|
hashtags: {
|
||||||
$regexFindAll: {
|
$regexFindAll: {
|
||||||
input: "$message",
|
input: "$message",
|
||||||
regex: /#[a-zA-Z0-9_]+/g
|
regex: /#[a-zA-Z0-9_]+/g,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{ $unwind: "$hashtags" },
|
{ $unwind: "$hashtags" },
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
hashtag: { $substr: ["$hashtags.match", 1, -1] }
|
hashtag: { $substr: ["$hashtags.match", 1, -1] },
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: "$hashtag",
|
_id: "$hashtag",
|
||||||
count: { $sum: 1 }
|
count: { $sum: 1 },
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
{ $sort: { count: -1 } },
|
{ $sort: { count: -1 } },
|
||||||
{ $limit: maxHashtags }
|
{ $limit: maxHashtags },
|
||||||
])
|
])
|
||||||
|
|
||||||
return trendings.map(({ _id, count }) => ({ hashtag: _id, count }));
|
return trendings.map(({ _id, count }) => ({ hashtag: _id, count }))
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import Posts from "@classes/posts"
|
import Posts from "@classes/posts"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
middlewares: ["withOptionalAuthentication"],
|
useMiddlewares: ["withOptionalAuthentication"],
|
||||||
fn: async (req, res) => {
|
fn: async (req, res) => {
|
||||||
return await Posts.fromUserId({
|
return await Posts.fromUserId({
|
||||||
skip: req.query.skip,
|
skip: req.query.skip,
|
||||||
@ -9,5 +9,5 @@ export default {
|
|||||||
user_id: req.params.user_id,
|
user_id: req.params.user_id,
|
||||||
for_user_id: req.auth?.session?.user_id,
|
for_user_id: req.auth?.session?.user_id,
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user