Skip to content

Commit edea0e5

Browse files
authored
Merge branch 'master' into bolt12a
2 parents 143d7bc + 4262189 commit edea0e5

File tree

25 files changed

+221
-57
lines changed

25 files changed

+221
-57
lines changed

api/paidAction/inviteGift.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export async function perform ({ id, userId }, { me, cost, tx }) {
2121
where: { id, userId: me.id, revoked: false }
2222
})
2323

24-
if (invite.giftedCount >= invite.limit) {
24+
if (invite.limit && invite.giftedCount >= invite.limit) {
2525
throw new Error('invite limit reached')
2626
}
2727

@@ -45,7 +45,7 @@ export async function perform ({ id, userId }, { me, cost, tx }) {
4545
})
4646

4747
return await tx.invite.update({
48-
where: { id, userId: me.id, giftedCount: { lt: invite.limit }, revoked: false },
48+
where: { id, userId: me.id, revoked: false, ...(invite.limit ? { giftedCount: { lt: invite.limit } } : {}) },
4949
data: {
5050
giftedCount: {
5151
increment: 1

api/paidAction/itemCreate.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ANON_ITEM_SPAM_INTERVAL, ITEM_SPAM_INTERVAL, PAID_ACTION_PAYMENT_METHOD
22
import { notifyItemMention, notifyItemParents, notifyMention, notifyTerritorySubscribers, notifyUserSubscribers } from '@/lib/webPush'
33
import { getItemMentions, getMentions, performBotBehavior } from './lib/item'
44
import { msatsToSats, satsToMsats } from '@/lib/format'
5+
import { GqlInputError } from '@/lib/error'
56

67
export const anonable = true
78

@@ -137,7 +138,15 @@ export async function perform (args, context) {
137138
}
138139
})).bio
139140
} else {
140-
item = await tx.item.create({ data: itemData })
141+
try {
142+
item = await tx.item.create({ data: itemData })
143+
} catch (err) {
144+
if (err.message.includes('violates exclusion constraint \\"Item_unique_time_constraint\\"')) {
145+
const message = `you already submitted this ${itemData.title ? 'post' : 'comment'}`
146+
throw new GqlInputError(message)
147+
}
148+
throw err
149+
}
141150
}
142151

143152
// store a reference to the item in the invoice
@@ -223,7 +232,7 @@ export async function onPaid ({ invoice, id }, context) {
223232
), ancestors AS (
224233
UPDATE "Item"
225234
SET ncomments = "Item".ncomments + 1,
226-
"lastCommentAt" = now(),
235+
"lastCommentAt" = GREATEST("Item"."lastCommentAt", comment.created_at),
227236
"weightedComments" = "Item"."weightedComments" +
228237
CASE WHEN comment."userId" = "Item"."userId" THEN 0 ELSE comment.trust END
229238
FROM comment

api/typeDefs/invite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default gql`
77
}
88
99
extend type Mutation {
10-
createInvite(id: String, gift: Int!, limit: Int, description: String): Invite
10+
createInvite(id: String, gift: Int!, limit: Int!, description: String): Invite
1111
revokeInvite(id: ID!): Invite
1212
}
1313

components/bookmark.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default function BookmarkDropdownItem ({ item: { id, meBookmark } }) {
1717
id: `Item:${id}`,
1818
fields: {
1919
meBookmark: () => bookmarkItem.meBookmark
20-
}
20+
},
21+
optimistic: true
2122
})
2223
}
2324
}

components/comment-edit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ export default function CommentEdit ({ comment, editThreshold, onSuccess, onCanc
1818
text () {
1919
return result.text
2020
}
21-
}
21+
},
22+
optimistic: true
2223
})
2324
}
2425
},

components/delete.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export default function Delete ({ itemId, children, onDelete, type = 'post' }) {
3030
url: () => deleteItem.url,
3131
pollCost: () => deleteItem.pollCost,
3232
deletedAt: () => deleteItem.deletedAt
33-
}
33+
},
34+
optimistic: true
3435
})
3536
}
3637
}

components/dont-link-this.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export function OutlawDropdownItem ({ item }) {
8484
id: `Item:${item.id}`,
8585
fields: {
8686
outlawed: () => true
87-
}
87+
},
88+
optimistic: true
8889
})
8990
}
9091
}

components/item-act.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default function ItemAct ({ onClose, item, act = 'TIP', step, children, a
181181

182182
function modifyActCache (cache, { result, invoice }) {
183183
if (!result) return
184-
const { id, sats, path, act } = result
184+
const { id, sats, act } = result
185185
cache.modify({
186186
id: `Item:${id}`,
187187
fields: {
@@ -209,9 +209,16 @@ function modifyActCache (cache, { result, invoice }) {
209209
}
210210
return existingBoost
211211
}
212-
}
212+
},
213+
optimistic: true
213214
})
215+
}
214216

217+
// doing this onPaid fixes issue #1695 because optimistically updating all ancestors
218+
// conflicts with the writeQuery on navigation from SSR
219+
function updateAncestors (cache, { result, invoice }) {
220+
if (!result) return
221+
const { id, sats, act, path } = result
215222
if (act === 'TIP') {
216223
// update all ancestors
217224
path.split('.').forEach(aId => {
@@ -222,7 +229,8 @@ function modifyActCache (cache, { result, invoice }) {
222229
commentSats (existingCommentSats = 0) {
223230
return existingCommentSats + sats
224231
}
225-
}
232+
},
233+
optimistic: true
226234
})
227235
})
228236
}
@@ -259,6 +267,7 @@ export function useAct ({ query = ACT_MUTATION, ...options } = {}) {
259267
onPaid: (cache, { data }) => {
260268
const response = getPaidActionResult(data)
261269
if (!response) return
270+
updateAncestors(cache, response)
262271
options?.onPaid?.(cache, { data })
263272
}
264273
})

components/nav/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function SignUpButton ({ className = 'py-0', width }) {
227227

228228
return (
229229
<Button
230-
className={classNames('align-items-center ps-2 py-1 pe-3', className)}
230+
className={classNames('align-items-center ps-2 pe-3', className)}
231231
style={{ borderWidth: '2px', width: width || '150px' }}
232232
id='signup'
233233
onClick={() => handleLogin('/signup')}
@@ -359,7 +359,7 @@ export function LoginButtons ({ handleClose }) {
359359
<LoginButton />
360360
</Dropdown.Item>
361361
<Dropdown.Item className='py-1'>
362-
<SignUpButton />
362+
<SignUpButton className='py-1' />
363363
</Dropdown.Item>
364364
<Dropdown.Item className='py-1'>
365365
<SwitchAccountButton handleClose={handleClose} />

components/notifications.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ function getPayerSig (lud18Data) {
344344

345345
function InvoicePaid ({ n }) {
346346
const payerSig = getPayerSig(n.invoice.lud18Data)
347-
let actionString = 'desposited to your account'
347+
let actionString = 'deposited to your account'
348348
let sats = n.earnedSats
349349
if (n.invoice.forwardedSats) {
350350
actionString = 'sent directly to your attached wallet'

0 commit comments

Comments
 (0)