Fix mentions for pessimistic actions (#1615)
* Fix mentions for pessimistic actions * (item)mentions should use tx not models --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: k00b <k00b@stacker.news>
This commit is contained in:
parent
5dac2f2ed0
commit
82fead60f1
|
@ -2,11 +2,11 @@ import { USER_ID } from '@/lib/constants'
|
||||||
import { deleteReminders, getDeleteAt, getRemindAt } from '@/lib/item'
|
import { deleteReminders, getDeleteAt, getRemindAt } from '@/lib/item'
|
||||||
import { parseInternalLinks } from '@/lib/url'
|
import { parseInternalLinks } from '@/lib/url'
|
||||||
|
|
||||||
export async function getMentions ({ text }, { me, models }) {
|
export async function getMentions ({ text }, { me, tx }) {
|
||||||
const mentionPattern = /\B@[\w_]+/gi
|
const mentionPattern = /\B@[\w_]+/gi
|
||||||
const names = text.match(mentionPattern)?.map(m => m.slice(1))
|
const names = text.match(mentionPattern)?.map(m => m.slice(1))
|
||||||
if (names?.length > 0) {
|
if (names?.length > 0) {
|
||||||
const users = await models.user.findMany({
|
const users = await tx.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
name: {
|
name: {
|
||||||
in: names
|
in: names
|
||||||
|
@ -21,7 +21,7 @@ export async function getMentions ({ text }, { me, models }) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getItemMentions = async ({ text }, { me, models }) => {
|
export const getItemMentions = async ({ text }, { me, tx }) => {
|
||||||
const linkPattern = new RegExp(`${process.env.NEXT_PUBLIC_URL}/items/\\d+[a-zA-Z0-9/?=]*`, 'gi')
|
const linkPattern = new RegExp(`${process.env.NEXT_PUBLIC_URL}/items/\\d+[a-zA-Z0-9/?=]*`, 'gi')
|
||||||
const refs = text.match(linkPattern)?.map(m => {
|
const refs = text.match(linkPattern)?.map(m => {
|
||||||
try {
|
try {
|
||||||
|
@ -33,7 +33,7 @@ export const getItemMentions = async ({ text }, { me, models }) => {
|
||||||
}).filter(r => !!r)
|
}).filter(r => !!r)
|
||||||
|
|
||||||
if (refs?.length > 0) {
|
if (refs?.length > 0) {
|
||||||
const referee = await models.item.findMany({
|
const referee = await tx.item.findMany({
|
||||||
where: {
|
where: {
|
||||||
id: { in: refs },
|
id: { in: refs },
|
||||||
userId: { not: me?.id || USER_ID.anon }
|
userId: { not: me?.id || USER_ID.anon }
|
||||||
|
|
|
@ -119,11 +119,12 @@ async function performPessimisticAction ({ lndInvoice, dbInvoice, tx, models, ln
|
||||||
const context = {
|
const context = {
|
||||||
tx,
|
tx,
|
||||||
cost: BigInt(lndInvoice.received_mtokens),
|
cost: BigInt(lndInvoice.received_mtokens),
|
||||||
me: dbInvoice.user,
|
me: dbInvoice.user
|
||||||
sybilFeePercent: await paidActions[dbInvoice.actionType].getSybilFeePercent?.()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await paidActions[dbInvoice.actionType].perform(args, context)
|
const sybilFeePercent = await paidActions[dbInvoice.actionType].getSybilFeePercent?.(args, context)
|
||||||
|
|
||||||
|
const result = await paidActions[dbInvoice.actionType].perform(args, { ...context, sybilFeePercent })
|
||||||
await tx.invoice.update({
|
await tx.invoice.update({
|
||||||
where: { id: dbInvoice.id },
|
where: { id: dbInvoice.id },
|
||||||
data: {
|
data: {
|
||||||
|
|
Loading…
Reference in New Issue