Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verified contributors #474

Merged
merged 7 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions api/resolvers/user.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import { readFile } from 'fs/promises'
import { join, resolve } from 'path'
import { GraphQLError } from 'graphql'
import { decodeCursor, LIMIT, nextCursorEncoded } from '../../lib/cursor'
import { msatsToSats } from '../../lib/format'
import { bioSchema, emailSchema, settingsSchema, ssValidate, userSchema } from '../../lib/validate'
import { getItem, updateItem, filterClause, createItem } from './item'
import { datePivot } from '../../lib/time'

const contributors = new Set()

const loadContributors = async (set) => {
try {
const fileContent = await readFile(resolve(join(process.cwd(), 'contributors.txt')), 'utf-8')
fileContent.split('\n')
.map(line => line.trim())
.filter(line => !!line)
.forEach(name => set.add(name))
} catch (err) {
console.error('Error loading contributors', err)
}
}

export function within (table, within) {
let interval = ' AND "' + table + '".created_at >= $1 - INTERVAL '
switch (within) {
Expand Down Expand Up @@ -817,6 +833,16 @@ export default {
})

return !!subscription?.commentsSubscribedAt
},
isContributor: async (user, args, { me }) => {
// lazy init contributors only once
if (contributors.size === 0) {
await loadContributors(contributors)
}
if (me?.id === user.id) {
return contributors.has(user.name)
}
return !user.hideIsContributor && contributors.has(user.name)
}
}
}
4 changes: 3 additions & 1 deletion api/typeDefs/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default gql`
noteInvites: Boolean!, noteJobIndicator: Boolean!, noteCowboyHat: Boolean!, hideInvoiceDesc: Boolean!,
hideFromTopUsers: Boolean!, hideCowboyHat: Boolean!, clickToLoadImg: Boolean!,
wildWestMode: Boolean!, greeterMode: Boolean!, nostrPubkey: String, nostrRelays: [String!], hideBookmarks: Boolean!,
noteForwardedSats: Boolean!, hideWalletBalance: Boolean!): User
noteForwardedSats: Boolean!, hideWalletBalance: Boolean!, hideIsContributor: Boolean!): User
setPhoto(photoId: ID!): Int!
upsertBio(bio: String!): User!
setWalkthrough(tipPopover: Boolean, upvotePopover: Boolean): Boolean
Expand Down Expand Up @@ -92,6 +92,8 @@ export default gql`
greeterMode: Boolean!
lastCheckedJobs: String
authMethods: AuthMethods!
isContributor: Boolean!
hideIsContributor: Boolean!
meSubscriptionPosts: Boolean!
meSubscriptionComments: Boolean!
}
Expand Down
1 change: 1 addition & 0 deletions components/user-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function HeaderHeader ({ user }) {
: <span>never</span>}
</small>
<small className='text-muted d-flex-inline'>longest cowboy streak: {user.maxStreak !== null ? user.maxStreak : 'none'}</small>
{user.isContributor && <small className='text-muted'>🧑‍💻✅ verified stacker.news contributor</small>}
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions contributors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
k00b
kr
ekzyis
WeAreAllSatoshi
8 changes: 6 additions & 2 deletions fragments/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const ME = gql`
lastCheckedJobs
hideWelcomeBanner
hideWalletBalance
isContributor
hideIsContributor
}
}`

Expand All @@ -57,6 +59,7 @@ export const SETTINGS_FIELDS = gql`
hideFromTopUsers
hideCowboyHat
hideBookmarks
hideIsContributor
clickToLoadImg
hideWalletBalance
nostrPubkey
Expand Down Expand Up @@ -88,14 +91,14 @@ mutation setSettings($tipDefault: Int!, $turboTipping: Boolean!, $fiatCurrency:
$noteInvites: Boolean!, $noteJobIndicator: Boolean!, $noteCowboyHat: Boolean!, $hideInvoiceDesc: Boolean!,
$hideFromTopUsers: Boolean!, $hideCowboyHat: Boolean!, $clickToLoadImg: Boolean!,
$wildWestMode: Boolean!, $greeterMode: Boolean!, $nostrPubkey: String, $nostrRelays: [String!], $hideBookmarks: Boolean!,
$noteForwardedSats: Boolean!, $hideWalletBalance: Boolean!) {
$noteForwardedSats: Boolean!, $hideWalletBalance: Boolean!, $hideIsContributor: Boolean!) {
setSettings(tipDefault: $tipDefault, turboTipping: $turboTipping, fiatCurrency: $fiatCurrency,
noteItemSats: $noteItemSats, noteEarning: $noteEarning, noteAllDescendants: $noteAllDescendants,
noteMentions: $noteMentions, noteDeposits: $noteDeposits, noteInvites: $noteInvites,
noteJobIndicator: $noteJobIndicator, noteCowboyHat: $noteCowboyHat, hideInvoiceDesc: $hideInvoiceDesc,
hideFromTopUsers: $hideFromTopUsers, hideCowboyHat: $hideCowboyHat, clickToLoadImg: $clickToLoadImg,
wildWestMode: $wildWestMode, greeterMode: $greeterMode, nostrPubkey: $nostrPubkey, nostrRelays: $nostrRelays, hideBookmarks: $hideBookmarks,
noteForwardedSats: $noteForwardedSats, hideWalletBalance: $hideWalletBalance) {
noteForwardedSats: $noteForwardedSats, hideWalletBalance: $hideWalletBalance, hideIsContributor: $hideIsContributor) {
...SettingsFields
}
}
Expand Down Expand Up @@ -150,6 +153,7 @@ export const USER_FIELDS = gql`
stacked
since
photoId
isContributor
meSubscriptionPosts
meSubscriptionComments
}`
Expand Down
3 changes: 2 additions & 1 deletion lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ export const settingsSchema = object({
).max(NOSTR_MAX_RELAY_NUM,
({ max, value }) => `${Math.abs(max - value.length)} too many`),
hideBookmarks: boolean(),
hideWalletBalance: boolean()
hideWalletBalance: boolean(),
hideIsContributor: boolean()
})

const warningMessage = 'If I logout, even accidentally, I will never be able to access my account again'
Expand Down
11 changes: 10 additions & 1 deletion pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useShowModal } from '../components/modal'
import { authErrorMessage } from '../components/login'
import { NostrAuth } from '../components/nostr-auth'
import { useToast } from '../components/toast'
import { useMe } from '../components/me'

export const getServerSideProps = getGetServerSideProps({ query: SETTINGS, authRequired: true })

Expand All @@ -32,6 +33,7 @@ function bech32encode (hexString) {

export default function Settings ({ ssrData }) {
const toaster = useToast()
const me = useMe()
const [setSettings] = useMutation(SET_SETTINGS, {
update (cache, { data: { setSettings } }) {
cache.modify({
Expand Down Expand Up @@ -77,7 +79,8 @@ export default function Settings ({ ssrData }) {
nostrPubkey: settings?.nostrPubkey ? bech32encode(settings.nostrPubkey) : '',
nostrRelays: settings?.nostrRelays?.length ? settings?.nostrRelays : [''],
hideBookmarks: settings?.hideBookmarks,
hideWalletBalance: settings?.hideWalletBalance
hideWalletBalance: settings?.hideWalletBalance,
hideIsContributor: settings?.hideIsContributor
}}
schema={settingsSchema}
onSubmit={async ({ tipDefault, nostrPubkey, nostrRelays, ...values }) => {
Expand Down Expand Up @@ -241,6 +244,12 @@ export default function Settings ({ ssrData }) {
name='clickToLoadImg'
groupClassName='mb-0'
/>
{me.isContributor &&
<Checkbox
label={<>hide that I'm a stacker.news contributor</>}
name='hideIsContributor'
groupClassName='mb-0'
/>}
<Checkbox
label={<>hide my bookmarks from other stackers</>}
name='hideBookmarks'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "users" ADD COLUMN "hideIsContributor" BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ model User {
followers UserSubscription[] @relation("follower")
followees UserSubscription[] @relation("followee")
hideWelcomeBanner Boolean @default(false)
hideIsContributor Boolean @default(false)

@@index([createdAt], map: "users.created_at_index")
@@index([inviteId], map: "users.inviteId_index")
Expand Down