stacker.news/fragments/users.js

378 lines
7.5 KiB
JavaScript
Raw Normal View History

2021-09-24 21:28:21 +00:00
import { gql } from '@apollo/client'
2023-07-26 00:45:35 +00:00
import { COMMENTS, COMMENTS_ITEM_EXT_FIELDS } from './comments'
import { ITEM_FIELDS, ITEM_FULL_FIELDS } from './items'
import { SUB_FULL_FIELDS } from './subs'
2021-09-24 21:28:21 +00:00
export const STREAK_FIELDS = gql`
2024-10-24 20:30:56 +00:00
fragment StreakFields on User {
optional {
streak
gunStreak
horseStreak
}
}
`
2021-11-28 17:29:17 +00:00
export const ME = gql`
${STREAK_FIELDS}
{
me {
id
name
bioId
photoId
privates {
autoDropBolt11s
diagnostics
noReferralLinks
fiatCurrency
autoWithdrawMaxFeePercent
2024-10-19 14:21:50 +00:00
autoWithdrawMaxFeeTotal
autoWithdrawThreshold
withdrawMaxFeeDefault
satsFilter
hideFromTopUsers
hideWalletBalance
hideWelcomeBanner
imgproxyOnly
showImagesAndVideos
nostrCrossposting
sats
tipDefault
tipRandom
tipRandomMin
tipRandomMax
tipPopover
turboTipping
zapUndos
upvotePopover
wildWestMode
disableFreebies
2024-10-24 20:30:56 +00:00
vaultKeyHash
walletsUpdatedAt
proxyReceive
2023-11-10 01:05:35 +00:00
}
optional {
isContributor
stacked
}
...StreakFields
}
}`
2023-11-10 01:05:35 +00:00
export const SETTINGS_FIELDS = gql`
fragment SettingsFields on User {
privates {
tipDefault
tipRandom
tipRandomMin
tipRandomMax
2022-12-09 19:25:38 +00:00
turboTipping
zapUndos
fiatCurrency
withdrawMaxFeeDefault
noteItemSats
noteEarning
noteAllDescendants
noteMentions
noteItemMentions
noteDeposits
2024-03-25 20:20:11 +00:00
noteWithdrawals
noteInvites
noteJobIndicator
2023-02-01 14:44:35 +00:00
noteCowboyHat
noteForwardedSats
2022-08-30 21:50:47 +00:00
hideInvoiceDesc
autoDropBolt11s
2022-12-01 21:31:04 +00:00
hideFromTopUsers
2023-05-01 21:49:47 +00:00
hideCowboyHat
2023-11-10 01:05:35 +00:00
hideBookmarks
hideGithub
hideNostr
hideTwitter
2023-11-10 01:05:35 +00:00
hideIsContributor
imgproxyOnly
showImagesAndVideos
2023-11-10 01:05:35 +00:00
hideWalletBalance
diagnostics
noReferralLinks
2023-11-10 01:05:35 +00:00
nostrPubkey
nostrCrossposting
nostrRelays
2022-09-21 19:57:36 +00:00
wildWestMode
satsFilter
disableFreebies
nsfwMode
2023-11-10 01:05:35 +00:00
authMethods {
lightning
nostr
github
twitter
email
apiKey
2023-11-10 01:05:35 +00:00
}
apiKeyEnabled
proxyReceive
2022-06-02 22:55:23 +00:00
}
}`
export const SETTINGS = gql`
${SETTINGS_FIELDS}
query Settings {
settings {
...SettingsFields
}
}`
2022-06-02 22:55:23 +00:00
export const SET_SETTINGS = gql`
${SETTINGS_FIELDS}
mutation setSettings($settings: SettingsInput!) {
setSettings(settings: $settings) {
...SettingsFields
}
}`
export const DELETE_WALLET = gql`
mutation removeWallet {
removeWallet
}`
2024-01-07 17:00:24 +00:00
export const NAME_QUERY = gql`
2022-04-19 18:32:39 +00:00
query nameAvailable($name: String!) {
nameAvailable(name: $name)
}`
2022-04-19 18:32:39 +00:00
export const NAME_MUTATION = gql`
2022-04-19 18:32:39 +00:00
mutation setName($name: String!) {
setName(name: $name)
}
`
export const WELCOME_BANNER_MUTATION = gql`
mutation hideWelcomeBanner {
hideWelcomeBanner
}
`
export const USER_SUGGESTIONS = gql`
2023-11-22 16:30:43 +00:00
query userSuggestions($q: String!, $limit: Limit) {
2023-11-21 20:49:39 +00:00
userSuggestions(q: $q, limit: $limit) {
name
}
}`
export const USER_SEARCH = gql`
${STREAK_FIELDS}
2023-11-22 16:30:43 +00:00
query searchUsers($q: String!, $limit: Limit, $similarity: Float) {
2022-10-25 17:13:06 +00:00
searchUsers(q: $q, limit: $limit, similarity: $similarity) {
Allow zapping, posting and commenting without funds or an account (#336) * Add anon zaps * Add anon comments and posts (link, discussion, poll) * Use payment hash instead of invoice id as proof of payment Our invoice IDs can be enumerated. So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself. Random payment hashes prevent this. Also, since we delete invoices after use, using database IDs as proof of payments are not suitable. If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs. * Allow pay per invoice for stackers The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice" * Fix onSuccess called twice For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice. This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice. * Keep invoice modal open if focus is lost * Skip anon user during trust calculation * Add error handling * Skip 'invoice not found' errors * Remove duplicate insufficient funds handling * Fix insufficient funds error detection * Fix invoice amount for comments * Allow pay per invoice for bounty and job posts * Also strike on payment after short press * Fix unexpected token 'export' * Fix eslint * Remove unused id param * Fix comment copy-paste error * Rename to useInvoiceable * Fix unexpected token 'export' * Fix onConfirmation called at every render * Add invoice HMAC This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN. Only the user which created the invoice knows the HMAC and thus can use the invoice hash. * make anon posting less hidden, add anon info button explainer * Fix anon users can't zap other anon users * Always show repeat and contacts on action error * Keep track of modal stack * give anon an icon * add generic date pivot helper * make anon user's invoices expire in 5 minutes * fix forgotten find and replace * use datePivot more places * add sat amounts to invoices * reduce anon invoice expiration to 3 minutes * don't abbreviate * Fix [object Object] as error message Any errors thrown here are already objects of shape { message: string } * Fix empty invoice creation attempts I stumbled across this while checking if anons can edit their items. I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error: Variable "$amount" of required type "Int!" was not provided. I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now. * anon func mods, e.g. inv limits * anon tips should be denormalized * remove redundant meTotalSats * correct overlay zap text for anon * exclude anon from trust graph before algo runs * remove balance limit on anon * give anon a bio and remove cowboy hat/top stackers; * make anon hat appear on profile * concat hash and hmac and call it a token * Fix localStorage cleared because error were swallowed * fix qr layout shift * restyle fund error modal * Catch invoice errors in fund error modal * invoice check backoff * anon info typo * make invoice expiration times have saner defaults * add comma to anon info * use builtin copy input label --------- Co-authored-by: ekzyis <ek@stacker.news> Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
id
2022-08-26 22:20:09 +00:00
name
2022-10-25 17:13:06 +00:00
photoId
ncomments
nposts
2023-11-10 01:05:35 +00:00
optional {
stacked
spent
referrals
}
...StreakFields
2022-08-26 22:20:09 +00:00
}
}`
2021-09-24 21:28:21 +00:00
export const USER_FIELDS = gql`
${STREAK_FIELDS}
2021-09-24 21:28:21 +00:00
fragment UserFields on User {
id
name
since
2022-05-16 20:51:22 +00:00
photoId
2023-11-10 01:05:35 +00:00
nitems
nterritories
meSubscriptionPosts
meSubscriptionComments
2023-09-28 20:02:25 +00:00
meMute
2023-11-10 01:05:35 +00:00
optional {
stacked
maxStreak
isContributor
githubId
nostrAuthPubkey
twitterId
2023-11-10 01:05:35 +00:00
}
...StreakFields
2021-09-24 21:28:21 +00:00
}`
2021-09-30 15:46:58 +00:00
export const MY_SUBSCRIBED_USERS = gql`
${STREAK_FIELDS}
query MySubscribedUsers($cursor: String) {
mySubscribedUsers(cursor: $cursor) {
users {
id
name
photoId
meSubscriptionPosts
meSubscriptionComments
meMute
...StreakFields
}
cursor
}
}
`
export const MY_MUTED_USERS = gql`
${STREAK_FIELDS}
query MyMutedUsers($cursor: String) {
myMutedUsers(cursor: $cursor) {
users {
id
name
photoId
meSubscriptionPosts
meSubscriptionComments
meMute
...StreakFields
}
cursor
}
}
`
2021-12-17 00:39:19 +00:00
export const TOP_USERS = gql`
${STREAK_FIELDS}
2023-11-22 16:30:43 +00:00
query TopUsers($cursor: String, $when: String, $from: String, $to: String, $by: String, ) {
topUsers(cursor: $cursor, when: $when, from: $from, to: $to, by: $by) {
2021-12-17 00:39:19 +00:00
users {
Allow zapping, posting and commenting without funds or an account (#336) * Add anon zaps * Add anon comments and posts (link, discussion, poll) * Use payment hash instead of invoice id as proof of payment Our invoice IDs can be enumerated. So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself. Random payment hashes prevent this. Also, since we delete invoices after use, using database IDs as proof of payments are not suitable. If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs. * Allow pay per invoice for stackers The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice" * Fix onSuccess called twice For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice. This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice. * Keep invoice modal open if focus is lost * Skip anon user during trust calculation * Add error handling * Skip 'invoice not found' errors * Remove duplicate insufficient funds handling * Fix insufficient funds error detection * Fix invoice amount for comments * Allow pay per invoice for bounty and job posts * Also strike on payment after short press * Fix unexpected token 'export' * Fix eslint * Remove unused id param * Fix comment copy-paste error * Rename to useInvoiceable * Fix unexpected token 'export' * Fix onConfirmation called at every render * Add invoice HMAC This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN. Only the user which created the invoice knows the HMAC and thus can use the invoice hash. * make anon posting less hidden, add anon info button explainer * Fix anon users can't zap other anon users * Always show repeat and contacts on action error * Keep track of modal stack * give anon an icon * add generic date pivot helper * make anon user's invoices expire in 5 minutes * fix forgotten find and replace * use datePivot more places * add sat amounts to invoices * reduce anon invoice expiration to 3 minutes * don't abbreviate * Fix [object Object] as error message Any errors thrown here are already objects of shape { message: string } * Fix empty invoice creation attempts I stumbled across this while checking if anons can edit their items. I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error: Variable "$amount" of required type "Int!" was not provided. I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now. * anon func mods, e.g. inv limits * anon tips should be denormalized * remove redundant meTotalSats * correct overlay zap text for anon * exclude anon from trust graph before algo runs * remove balance limit on anon * give anon a bio and remove cowboy hat/top stackers; * make anon hat appear on profile * concat hash and hmac and call it a token * Fix localStorage cleared because error were swallowed * fix qr layout shift * restyle fund error modal * Catch invoice errors in fund error modal * invoice check backoff * anon info typo * make invoice expiration times have saner defaults * add comma to anon info * use builtin copy input label --------- Co-authored-by: ekzyis <ek@stacker.news> Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
id
2021-12-17 00:39:19 +00:00
name
2022-10-25 21:35:32 +00:00
photoId
ncomments(when: $when, from: $from, to: $to)
nposts(when: $when, from: $from, to: $to)
2023-11-10 01:05:35 +00:00
optional {
stacked(when: $when, from: $from, to: $to)
spent(when: $when, from: $from, to: $to)
referrals(when: $when, from: $from, to: $to)
}
...StreakFields
2021-12-17 00:39:19 +00:00
}
cursor
}
}
`
2023-02-09 18:41:28 +00:00
export const TOP_COWBOYS = gql`
${STREAK_FIELDS}
2023-02-09 18:41:28 +00:00
query TopCowboys($cursor: String) {
topCowboys(cursor: $cursor) {
users {
Allow zapping, posting and commenting without funds or an account (#336) * Add anon zaps * Add anon comments and posts (link, discussion, poll) * Use payment hash instead of invoice id as proof of payment Our invoice IDs can be enumerated. So there is a - even though very rare - chance that an attacker could find a paid invoice which is not used yet and use it for himself. Random payment hashes prevent this. Also, since we delete invoices after use, using database IDs as proof of payments are not suitable. If a user tells us an invoice ID after we deleted it, we can no longer tell if the invoice was paid or not since the LN node only knows about payment hashes but nothing about the database IDs. * Allow pay per invoice for stackers The modal which pops up if the stacker does not have enough sats now has two options: "fund wallet" and "pay invoice" * Fix onSuccess called twice For some reason, when calling `showModal`, `useMemo` in modal.js and the code for the modal component (here: <Invoice>) is called twice. This leads to the `onSuccess` callback being called twice and one failing since the first one deletes the invoice. * Keep invoice modal open if focus is lost * Skip anon user during trust calculation * Add error handling * Skip 'invoice not found' errors * Remove duplicate insufficient funds handling * Fix insufficient funds error detection * Fix invoice amount for comments * Allow pay per invoice for bounty and job posts * Also strike on payment after short press * Fix unexpected token 'export' * Fix eslint * Remove unused id param * Fix comment copy-paste error * Rename to useInvoiceable * Fix unexpected token 'export' * Fix onConfirmation called at every render * Add invoice HMAC This prevents entities which know the invoice hash (like all LN nodes on the payment path) from using the invoice hash on SN. Only the user which created the invoice knows the HMAC and thus can use the invoice hash. * make anon posting less hidden, add anon info button explainer * Fix anon users can't zap other anon users * Always show repeat and contacts on action error * Keep track of modal stack * give anon an icon * add generic date pivot helper * make anon user's invoices expire in 5 minutes * fix forgotten find and replace * use datePivot more places * add sat amounts to invoices * reduce anon invoice expiration to 3 minutes * don't abbreviate * Fix [object Object] as error message Any errors thrown here are already objects of shape { message: string } * Fix empty invoice creation attempts I stumbled across this while checking if anons can edit their items. I monkey patched the code to make it possible (so they can see the 'edit' button) and tried to edit an item but I got this error: Variable "$amount" of required type "Int!" was not provided. I fixed this even though this function should never be called without an amount anyway. It will return a sane error in that case now. * anon func mods, e.g. inv limits * anon tips should be denormalized * remove redundant meTotalSats * correct overlay zap text for anon * exclude anon from trust graph before algo runs * remove balance limit on anon * give anon a bio and remove cowboy hat/top stackers; * make anon hat appear on profile * concat hash and hmac and call it a token * Fix localStorage cleared because error were swallowed * fix qr layout shift * restyle fund error modal * Catch invoice errors in fund error modal * invoice check backoff * anon info typo * make invoice expiration times have saner defaults * add comma to anon info * use builtin copy input label --------- Co-authored-by: ekzyis <ek@stacker.news> Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2023-08-11 23:50:57 +00:00
id
2023-02-09 18:41:28 +00:00
name
photoId
ncomments(when: "forever")
nposts(when: "forever")
2023-11-10 01:05:35 +00:00
optional {
stacked(when: "forever")
spent(when: "forever")
referrals(when: "forever")
}
...StreakFields
2023-02-09 18:41:28 +00:00
}
cursor
}
}
`
2021-10-26 20:49:37 +00:00
export const USER_FULL = gql`
2021-09-30 15:46:58 +00:00
${USER_FIELDS}
2023-07-26 00:45:35 +00:00
${ITEM_FULL_FIELDS}
${COMMENTS}
query User($name: String!, $sort: String) {
2021-10-26 20:49:37 +00:00
user(name: $name) {
2021-09-30 15:46:58 +00:00
...UserFields
bio {
2023-07-26 00:45:35 +00:00
...ItemFullFields
comments(sort: $sort) {
...CommentsRecursive
}
2021-09-30 15:46:58 +00:00
}
}
}`
2021-10-26 20:49:37 +00:00
2023-08-31 00:03:05 +00:00
export const USER = gql`
${USER_FIELDS}
Account Switching (#644) * WIP: Account switching * Fix empty USER query ANON_USER_ID was undefined and thus the query for @anon had no variables. * Apply multiAuthMiddleware in /api/graphql * Fix 'you must be logged in' query error on switch to anon * Add smart 'switch account' button "smart" means that it only shows if there are accounts to which one can switch * Fix multiAuth not set in backend * Comment fixes, minor changes * Use fw-bold instead of 'selected' * Close dropdown and offcanvas Inside a dropdown, we can rely on autoClose but need to wrap the buttons with <Dropdown.Item> for that to work. For the offcanvas, we need to pass down handleClose. * Use button to add account * Some pages require hard reload on account switch * Reinit settings form on account switch * Also don't refetch WalletHistory * Formatting * Use width: fit-content for standalone SignUpButton * Remove unused className * Use fw-bold and text-underline on selected * Fix inconsistent padding of login buttons * Fix duplicate redirect from /settings on anon switch * Never throw during refetch * Throw errors which extend GraphQLError * Only use meAnonSats if logged out * Use reactive variable for meAnonSats The previous commit broke the UI update after anon zaps because we actually updated item.meSats in the cache and not item.meAnonSats. Updating item.meAnonSats was not possible because it's a local field. For that, one needs to use reactive variables. We do this now and thus also don't need the useEffect hack in item-info.js anymore. * Switch to new user * Fix missing cleanup during logout If we logged in but never switched to any other account, the 'multi_auth.user-id' cookie was not set. This meant that during logout, the other 'multi_auth.*' cookies were not deleted. This broke the account switch modal. This is fixed by setting the 'multi_auth.user-id' cookie on login. Additionally, we now cleanup if cookie pointer OR session is set (instead of only if both are set). * Fix comments in middleware * Remove unnecessary effect dependencies setState is stable and thus only noise in effect dependencies * Show but disable unavailable auth methods * make signup button consistent with others * Always reload page on switch * refine account switch styling * logout barrier --------- Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com> Co-authored-by: k00b <k00b@stacker.news>
2024-09-12 18:05:11 +00:00
query User($id: ID, $name: String) {
user(id: $id, name: $name) {
2023-08-31 00:03:05 +00:00
...UserFields
}
}`
export const USER_WITH_ITEMS = gql`
2021-10-26 20:49:37 +00:00
${USER_FIELDS}
${ITEM_FIELDS}
${COMMENTS_ITEM_EXT_FIELDS}
2023-11-22 16:30:43 +00:00
query UserWithItems($name: String!, $sub: String, $cursor: String, $type: String, $when: String, $from: String, $to: String, $by: String, $limit: Limit, $includeComments: Boolean = false) {
2021-10-26 20:49:37 +00:00
user(name: $name) {
...UserFields
}
items(sub: $sub, sort: "user", cursor: $cursor, type: $type, name: $name, when: $when, from: $from, to: $to, by: $by, limit: $limit) {
2021-10-26 20:49:37 +00:00
cursor
items {
...ItemFields
...CommentItemExtFields @include(if: $includeComments)
2021-10-26 20:49:37 +00:00
}
}
}`
export const USER_WITH_SUBS = gql`
${USER_FIELDS}
${SUB_FULL_FIELDS}
query UserWithSubs($name: String!, $cursor: String, $type: String, $when: String, $from: String, $to: String, $by: String) {
user(name: $name) {
...UserFields
}
userSubs(name: $name, cursor: $cursor) {
cursor
subs {
...SubFullFields
ncomments(when: "forever")
nposts(when: "forever")
optional {
stacked(when: "forever")
spent(when: "forever")
revenue(when: "forever")
}
}
}
}`
export const USER_STATS = gql`
query UserStats($when: String, $from: String, $to: String) {
userStatsActions(when: $when, from: $from, to: $to) {
time
data {
name
value
}
}
userStatsIncomingSats(when: $when, from: $from, to: $to) {
time
data {
name
value
}
}
userStatsOutgoingSats(when: $when, from: $from, to: $to) {
time
data {
name
value
}
}
}`