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 { parseInternalLinks } from '@/lib/url'
 | 
			
		||||
 | 
			
		||||
export async function getMentions ({ text }, { me, models }) {
 | 
			
		||||
export async function getMentions ({ text }, { me, tx }) {
 | 
			
		||||
  const mentionPattern = /\B@[\w_]+/gi
 | 
			
		||||
  const names = text.match(mentionPattern)?.map(m => m.slice(1))
 | 
			
		||||
  if (names?.length > 0) {
 | 
			
		||||
    const users = await models.user.findMany({
 | 
			
		||||
    const users = await tx.user.findMany({
 | 
			
		||||
      where: {
 | 
			
		||||
        name: {
 | 
			
		||||
          in: names
 | 
			
		||||
@ -21,7 +21,7 @@ export async function getMentions ({ text }, { me, models }) {
 | 
			
		||||
  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 refs = text.match(linkPattern)?.map(m => {
 | 
			
		||||
    try {
 | 
			
		||||
@ -33,7 +33,7 @@ export const getItemMentions = async ({ text }, { me, models }) => {
 | 
			
		||||
  }).filter(r => !!r)
 | 
			
		||||
 | 
			
		||||
  if (refs?.length > 0) {
 | 
			
		||||
    const referee = await models.item.findMany({
 | 
			
		||||
    const referee = await tx.item.findMany({
 | 
			
		||||
      where: {
 | 
			
		||||
        id: { in: refs },
 | 
			
		||||
        userId: { not: me?.id || USER_ID.anon }
 | 
			
		||||
 | 
			
		||||
@ -119,11 +119,12 @@ async function performPessimisticAction ({ lndInvoice, dbInvoice, tx, models, ln
 | 
			
		||||
  const context = {
 | 
			
		||||
    tx,
 | 
			
		||||
    cost: BigInt(lndInvoice.received_mtokens),
 | 
			
		||||
    me: dbInvoice.user,
 | 
			
		||||
    sybilFeePercent: await paidActions[dbInvoice.actionType].getSybilFeePercent?.()
 | 
			
		||||
    me: dbInvoice.user
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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({
 | 
			
		||||
    where: { id: dbInvoice.id },
 | 
			
		||||
    data: {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user