mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2026-01-18 19:01:29 +00:00
Implement mention of all users – first approach
This commit is contained in:
parent
e465e59afe
commit
4e21afb8ff
@ -1,15 +1,42 @@
|
||||
import cheerio from 'cheerio'
|
||||
|
||||
export default (content?) => {
|
||||
const queryAllUserIds = async (context) => {
|
||||
const allUserIdCypher = `
|
||||
MATCH (user: User)
|
||||
// blocked users are not filtered out
|
||||
RETURN user {.id}
|
||||
`
|
||||
const session = context.driver.session()
|
||||
const writeTxResultPromise = session.readTransaction(async (transaction) => {
|
||||
const transactionResponse = await transaction.run(allUserIdCypher, {})
|
||||
return transactionResponse.records.map((record) => record.get('user').id)
|
||||
})
|
||||
try {
|
||||
const ids = await writeTxResultPromise
|
||||
return ids
|
||||
} catch (error) {
|
||||
throw new Error(error)
|
||||
} finally {
|
||||
session.close()
|
||||
}
|
||||
}
|
||||
|
||||
export default async (context, content?) => {
|
||||
if (!content) return []
|
||||
console.log('extractMentionedUsers – content: ', content)
|
||||
const $ = cheerio.load(content)
|
||||
const userIds = $('a.mention[data-mention-id]')
|
||||
let userIds = $('a.mention[data-mention-id]')
|
||||
.map((_, el) => {
|
||||
return $(el).attr('data-mention-id')
|
||||
})
|
||||
.get()
|
||||
return userIds
|
||||
.map((id) => id.trim())
|
||||
.filter((id) => !!id)
|
||||
.filter((id, index, allIds) => allIds.indexOf(id) === index)
|
||||
console.log('extractMentionedUsers – userIds: ', userIds)
|
||||
if (userIds.find((id) => id === 'all')) {
|
||||
userIds = await queryAllUserIds(context)
|
||||
console.log('extractMentionedUsers – all userIds: ', userIds)
|
||||
}
|
||||
return userIds
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ const handleRemoveUserFromGroup = async (resolve, root, args, context, resolveIn
|
||||
}
|
||||
|
||||
const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo) => {
|
||||
const idsOfUsers = extractMentionedUsers(args.content)
|
||||
const idsOfUsers = await extractMentionedUsers(context, args.content)
|
||||
const post = await resolve(root, args, context, resolveInfo)
|
||||
if (post) {
|
||||
await publishNotifications(context, [
|
||||
@ -108,7 +108,7 @@ const handleContentDataOfPost = async (resolve, root, args, context, resolveInfo
|
||||
|
||||
const handleContentDataOfComment = async (resolve, root, args, context, resolveInfo) => {
|
||||
const { content } = args
|
||||
let idsOfUsers = extractMentionedUsers(content)
|
||||
let idsOfUsers = await extractMentionedUsers(context, content)
|
||||
const comment = await resolve(root, args, context, resolveInfo)
|
||||
const [postAuthor] = await postAuthorOfComment(comment.id, { context })
|
||||
idsOfUsers = idsOfUsers.filter((id) => id !== postAuthor.id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user