Compare commits
No commits in common. "7c294478fb50f198c09359f7a5716cf4262f0fed" and "2dd96f4b83ea4448ca3393e842a5dbcab658ec40" have entirely different histories.
7c294478fb
...
2dd96f4b83
@ -58,8 +58,8 @@ export default async function performPaidAction (actionType, args, context) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('fee credit action failed', e)
|
console.error('fee credit action failed', e)
|
||||||
|
|
||||||
// if we fail with fee credits, but not because of insufficient funds, bail
|
// if we fail to do the action with fee credits, but the cost is 0, we should bail
|
||||||
if (!e.message.includes('\\"users\\" violates check constraint \\"msats_positive\\"')) {
|
if (context.cost === 0n) {
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,29 +6,13 @@ import { gql, useMutation, useQuery, useLazyQuery } from '@apollo/client'
|
|||||||
import { SETTINGS } from '@/fragments/users'
|
import { SETTINGS } from '@/fragments/users'
|
||||||
import { ITEM_FULL_FIELDS, POLL_FIELDS } from '@/fragments/items'
|
import { ITEM_FULL_FIELDS, POLL_FIELDS } from '@/fragments/items'
|
||||||
|
|
||||||
function itemToContent (item, { includeTitle = true } = {}) {
|
async function discussionToEvent (item) {
|
||||||
let content = includeTitle ? item.title : ''
|
|
||||||
|
|
||||||
if (item.url) {
|
|
||||||
content += `\n${item.url}`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.text) {
|
|
||||||
content += `\n\n${item.text}`
|
|
||||||
}
|
|
||||||
|
|
||||||
content += `\n\noriginally posted at https://stacker.news/items/${item.id}`
|
|
||||||
|
|
||||||
return content.trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
function discussionToEvent (item) {
|
|
||||||
const createdAt = Math.floor(Date.now() / 1000)
|
const createdAt = Math.floor(Date.now() / 1000)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
created_at: createdAt,
|
created_at: createdAt,
|
||||||
kind: 30023,
|
kind: 30023,
|
||||||
content: itemToContent(item, { includeTitle: false }),
|
content: item.text,
|
||||||
tags: [
|
tags: [
|
||||||
['d', item.id.toString()],
|
['d', item.id.toString()],
|
||||||
['title', item.title],
|
['title', item.title],
|
||||||
@ -37,18 +21,25 @@ function discussionToEvent (item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function linkToEvent (item) {
|
async function linkToEvent (item) {
|
||||||
const createdAt = Math.floor(Date.now() / 1000)
|
const createdAt = Math.floor(Date.now() / 1000)
|
||||||
|
|
||||||
|
let contentField
|
||||||
|
if (item.text) {
|
||||||
|
contentField = `${item.title}\n${item.url}\n\n${item.text}`
|
||||||
|
} else {
|
||||||
|
contentField = `${item.title}\n${item.url}`
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
created_at: createdAt,
|
created_at: createdAt,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
content: itemToContent(item),
|
content: contentField,
|
||||||
tags: []
|
tags: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pollToEvent (item) {
|
async function pollToEvent (item) {
|
||||||
const createdAt = Math.floor(Date.now() / 1000)
|
const createdAt = Math.floor(Date.now() / 1000)
|
||||||
|
|
||||||
const expiresAt = createdAt + 86400
|
const expiresAt = createdAt + 86400
|
||||||
@ -56,20 +47,20 @@ function pollToEvent (item) {
|
|||||||
return {
|
return {
|
||||||
created_at: createdAt,
|
created_at: createdAt,
|
||||||
kind: 1,
|
kind: 1,
|
||||||
content: itemToContent(item),
|
content: item.text,
|
||||||
tags: [
|
tags: [
|
||||||
['poll', 'single', expiresAt.toString(), item.title, ...item.poll.options.map(op => op?.option.toString())]
|
['poll', 'single', expiresAt.toString(), item.title, ...item.poll.options.map(op => op?.option.toString())]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function bountyToEvent (item) {
|
async function bountyToEvent (item) {
|
||||||
const createdAt = Math.floor(Date.now() / 1000)
|
const createdAt = Math.floor(Date.now() / 1000)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
created_at: createdAt,
|
created_at: createdAt,
|
||||||
kind: 30402,
|
kind: 30402,
|
||||||
content: itemToContent(item),
|
content: item.text,
|
||||||
tags: [
|
tags: [
|
||||||
['d', item.id.toString()],
|
['d', item.id.toString()],
|
||||||
['title', item.title],
|
['title', item.title],
|
||||||
@ -167,15 +158,16 @@ export default function useCrossposter () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const itemType = determineItemType(item)
|
const itemType = determineItemType(item)
|
||||||
|
|
||||||
switch (itemType) {
|
switch (itemType) {
|
||||||
case 'discussion':
|
case 'discussion':
|
||||||
return discussionToEvent(item)
|
return await discussionToEvent(item)
|
||||||
case 'link':
|
case 'link':
|
||||||
return linkToEvent(item)
|
return await linkToEvent(item)
|
||||||
case 'bounty':
|
case 'bounty':
|
||||||
return bountyToEvent(item)
|
return await bountyToEvent(item)
|
||||||
case 'poll':
|
case 'poll':
|
||||||
return pollToEvent(item)
|
return await pollToEvent(item)
|
||||||
default:
|
default:
|
||||||
return crosspostError('Unknown item type')
|
return crosspostError('Unknown item type')
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user