Skip to content

Commit e07a496

Browse files
authored
Merge branch 'master' into schedule_posts
2 parents 51f9ab4 + 4620160 commit e07a496

File tree

40 files changed

+867
-314
lines changed

40 files changed

+867
-314
lines changed

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ grpc_proxy=http://tor:7050/
184184

185185
# lnbits
186186
LNBITS_WEB_PORT=5001
187+
LNBITS_WEB_PORT_V1=5002
187188

188189
# CPU shares for each category
189190
CPU_SHARES_IMPORTANT=1024

.github/pull_request_template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ _Was anything unclear during your work on this PR? Anything we should definitely
1010

1111
## Checklist
1212

13-
**Are your changes backwards compatible? Please answer below:**
13+
**Are your changes backward compatible? Please answer below:**
1414

15+
_For example, a change is not backward compatible if you removed a GraphQL field or dropped a database column._
1516

1617
**On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:**
1718

api/paidAction/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ stateDiagram-v2
103103
| donations | x | | x | x | x | | | x | |
104104
| update posts | x | | x | | x | | x | x | |
105105
| update comments | x | | x | | x | | x | x | |
106-
| receive | | x | | | x | x | x | | x |
106+
| receive | | | | | x | x | x | | x |
107107
| buy fee credits | | | x | | x | | | x | |
108108
| invite gift | x | | | | | | x | x | |
109109

api/paidAction/receive.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export async function getCost ({ msats }) {
1616

1717
export async function getInvoiceablePeer (_, { me, models, cost, paymentMethod }) {
1818
if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.P2P && !me?.proxyReceive) return null
19-
if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.DIRECT && !me?.directReceive) return null
19+
20+
// don't fallback to direct if proxy is enabled to always hide stacker's node pubkey
21+
if (paymentMethod === PAID_ACTION_PAYMENT_METHODS.DIRECT && me?.proxyReceive) return null
2022

2123
const wallets = await getInvoiceableWallets(me.id, { models })
2224
if (wallets.length === 0) {
@@ -54,24 +56,6 @@ export async function describe ({ description }, { me, cost, paymentMethod, sybi
5456
return description ?? `SN: ${me?.name ?? ''} receives ${numWithUnits(msatsToSats(cost - fee))}`
5557
}
5658

57-
export async function onPaid ({ invoice }, { tx }) {
58-
if (!invoice) {
59-
throw new Error('invoice is required')
60-
}
61-
62-
// P2P lnurlp does not need to update the user's balance
63-
if (invoice?.invoiceForward) return
64-
65-
await tx.user.update({
66-
where: { id: invoice.userId },
67-
data: {
68-
mcredits: {
69-
increment: invoice.msatsReceived
70-
}
71-
}
72-
})
73-
}
74-
7559
export async function nonCriticalSideEffects ({ invoice }, { models }) {
7660
await notifyDeposit(invoice.userId, invoice)
7761
await models.$executeRaw`

api/paidAction/territoryUnarchive.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,16 @@ export async function perform ({ name, invoiceId, ...data }, { me, cost, tx }) {
7878
}
7979
})
8080

81-
await tx.userSubTrust.createMany({
82-
data: initialTrust({ name: updatedSub.name, userId: updatedSub.userId })
83-
})
81+
const trust = initialTrust({ name: updatedSub.name, userId: updatedSub.userId })
82+
for (const t of trust) {
83+
await tx.userSubTrust.upsert({
84+
where: {
85+
userId_subName: { userId: t.userId, subName: t.subName }
86+
},
87+
update: t,
88+
create: t
89+
})
90+
}
8491

8592
return updatedSub
8693
}

api/resolvers/search.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ export default {
512512
item.searchTitle = e.highlight?.title?.[0] || e.highlight?.['title.exact']?.[0] || item.title
513513

514514
// prefer the exact highlight for text
515-
const searchTextHighlight = [...(e.highlight?.['text.exact'] || []), ...(e.highlight?.text || [])]
516-
item.searchText = searchTextHighlight?.slice(0, 5)?.join(' ... ')
515+
const searchTextHighlight = e.highlight?.['text.exact'] || e.highlight?.text || []
516+
item.searchText = searchTextHighlight?.join(' ... ')
517517

518518
return item
519519
})

api/resolvers/sub.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export default {
127127
subs
128128
}
129129
},
130-
userSubs: async (_parent, { name, cursor, when, by, from, to, limit = LIMIT }, { models }) => {
130+
userSubs: async (_parent, { name, cursor, when, by, from, to, limit = LIMIT }, { models, me }) => {
131131
if (!name) {
132132
throw new GqlInputError('must supply user name')
133133
}
@@ -150,26 +150,56 @@ export default {
150150
}
151151

152152
const subs = await models.$queryRawUnsafe(`
153-
SELECT "Sub".*,
154-
"Sub".created_at as "createdAt",
155-
COALESCE(floor(sum(msats_revenue)/1000), 0) as revenue,
156-
COALESCE(floor(sum(msats_stacked)/1000), 0) as stacked,
157-
COALESCE(floor(sum(msats_spent)/1000), 0) as spent,
158-
COALESCE(sum(posts), 0) as nposts,
159-
COALESCE(sum(comments), 0) as ncomments
160-
FROM ${viewGroup(range, 'sub_stats')}
161-
JOIN "Sub" on "Sub".name = u.sub_name
162-
WHERE "Sub"."userId" = $3
163-
AND "Sub".status = 'ACTIVE'
164-
GROUP BY "Sub".name
165-
ORDER BY ${column} DESC NULLS LAST, "Sub".created_at ASC
166-
OFFSET $4
167-
LIMIT $5`, ...range, user.id, decodedCursor.offset, limit)
153+
SELECT "Sub".*,
154+
"Sub".created_at as "createdAt",
155+
COALESCE(floor(sum(msats_revenue)/1000), 0) as revenue,
156+
COALESCE(floor(sum(msats_stacked)/1000), 0) as stacked,
157+
COALESCE(floor(sum(msats_spent)/1000), 0) as spent,
158+
COALESCE(sum(posts), 0) as nposts,
159+
COALESCE(sum(comments), 0) as ncomments,
160+
ss."userId" IS NOT NULL as "meSubscription",
161+
ms."userId" IS NOT NULL as "meMuteSub"
162+
FROM ${viewGroup(range, 'sub_stats')}
163+
JOIN "Sub" on "Sub".name = u.sub_name
164+
LEFT JOIN "SubSubscription" ss ON ss."subName" = "Sub".name AND ss."userId" IS NOT DISTINCT FROM $4
165+
LEFT JOIN "MuteSub" ms ON ms."subName" = "Sub".name AND ms."userId" IS NOT DISTINCT FROM $4
166+
WHERE "Sub"."userId" = $3
167+
AND "Sub".status = 'ACTIVE'
168+
GROUP BY "Sub".name, ss."userId", ms."userId"
169+
ORDER BY ${column} DESC NULLS LAST, "Sub".created_at ASC
170+
OFFSET $5
171+
LIMIT $6
172+
`, ...range, user.id, me?.id, decodedCursor.offset, limit)
168173

169174
return {
170175
cursor: subs.length === limit ? nextCursorEncoded(decodedCursor, limit) : null,
171176
subs
172177
}
178+
},
179+
mySubscribedSubs: async (parent, { cursor }, { models, me }) => {
180+
if (!me) {
181+
throw new GqlAuthenticationError()
182+
}
183+
184+
const decodedCursor = decodeCursor(cursor)
185+
const subs = await models.$queryRaw`
186+
SELECT "Sub".*,
187+
"MuteSub"."userId" IS NOT NULL as "meMuteSub",
188+
TRUE as "meSubscription"
189+
FROM "SubSubscription"
190+
JOIN "Sub" ON "SubSubscription"."subName" = "Sub".name
191+
LEFT JOIN "MuteSub" ON "MuteSub"."subName" = "Sub".name AND "MuteSub"."userId" = ${me.id}
192+
WHERE "SubSubscription"."userId" = ${me.id}
193+
AND "Sub".status <> 'STOPPED'
194+
ORDER BY "Sub".name ASC
195+
OFFSET ${decodedCursor.offset}
196+
LIMIT ${LIMIT}
197+
`
198+
199+
return {
200+
cursor: subs.length === LIMIT ? nextCursorEncoded(decodedCursor, LIMIT) : null,
201+
subs
202+
}
173203
}
174204
},
175205
Mutation: {

api/resolvers/wallet.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import {
55
import crypto, { timingSafeEqual } from 'crypto'
66
import { decodeCursor, LIMIT, nextCursorEncoded } from '@/lib/cursor'
77
import { SELECT, itemQueryWithMeta } from './item'
8-
import { formatMsats, msatsToSats, msatsToSatsDecimal, satsToMsats } from '@/lib/format'
8+
import { formatMsats, msatsToSats, msatsToSatsDecimal } from '@/lib/format'
99
import {
1010
USER_ID, INVOICE_RETENTION_DAYS,
11-
PAID_ACTION_PAYMENT_METHODS,
1211
WALLET_CREATE_INVOICE_TIMEOUT_MS,
1312
WALLET_RETRY_AFTER_MS,
1413
WALLET_RETRY_BEFORE_MS,
1514
WALLET_MAX_RETRIES
1615
} from '@/lib/constants'
17-
import { amountSchema, validateSchema, withdrawlSchema, lnAddrSchema } from '@/lib/validate'
16+
import { validateSchema, withdrawlSchema, lnAddrSchema } from '@/lib/validate'
1817
import assertGofacYourself from './ofac'
1918
import assertApiKeyNotPermitted from './apiKey'
2019
import { bolt11Tags } from '@/lib/bolt11'
@@ -475,20 +474,6 @@ const resolvers = {
475474
__resolveType: invoiceOrDirect => invoiceOrDirect.__resolveType
476475
},
477476
Mutation: {
478-
createInvoice: async (parent, { amount }, { me, models, lnd, headers }) => {
479-
await validateSchema(amountSchema, { amount })
480-
await assertGofacYourself({ models, headers })
481-
482-
const { invoice, paymentMethod } = await performPaidAction('RECEIVE', {
483-
msats: satsToMsats(amount)
484-
}, { models, lnd, me })
485-
486-
return {
487-
...invoice,
488-
__resolveType:
489-
paymentMethod === PAID_ACTION_PAYMENT_METHODS.DIRECT ? 'Direct' : 'Invoice'
490-
}
491-
},
492477
createWithdrawl: createWithdrawal,
493478
sendToLnAddr,
494479
cancelInvoice: async (parent, { hash, hmac, userCancel }, { me, models, lnd, boss }) => {

api/typeDefs/sub.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default gql`
77
subs: [Sub!]!
88
topSubs(cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Subs
99
userSubs(name: String!, cursor: String, when: String, from: String, to: String, by: String, limit: Limit): Subs
10+
mySubscribedSubs(cursor: String): Subs
1011
subSuggestions(q: String!, limit: Limit): [Sub!]!
1112
}
1213

api/typeDefs/user.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export default gql`
125125
wildWestMode: Boolean!
126126
withdrawMaxFeeDefault: Int!
127127
proxyReceive: Boolean
128-
directReceive: Boolean
129128
receiveCreditsBelowSats: Int!
130129
sendCreditsBelowSats: Int!
131130
}
@@ -209,7 +208,7 @@ export default gql`
209208
vaultKeyHash: String
210209
walletsUpdatedAt: Date
211210
proxyReceive: Boolean
212-
directReceive: Boolean
211+
directReceive: Boolean @deprecated
213212
receiveCreditsBelowSats: Int!
214213
sendCreditsBelowSats: Int!
215214
}

0 commit comments

Comments
 (0)