stacker.news/prisma/schema.prisma

557 lines
20 KiB
Plaintext
Raw Normal View History

2023-07-26 16:01:31 +00:00
generator client {
provider = "prisma-client-js"
}
2021-03-25 19:29:24 +00:00
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
2023-06-20 01:26:34 +00:00
model Snl {
id Int @id @default(autoincrement())
live Boolean @default(false)
}
2021-03-25 19:29:24 +00:00
model User {
2023-07-26 16:01:31 +00:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
name String? @unique(map: "users.name_unique") @db.Citext
email String? @unique(map: "users.email_unique")
emailVerified DateTime? @map("email_verified")
image String?
msats BigInt @default(0)
freeComments Int @default(5)
freePosts Int @default(2)
checkedNotesAt DateTime?
pubkey String? @unique(map: "users.pubkey_unique")
tipDefault Int @default(100)
bioId Int?
inviteId String?
tipPopover Boolean @default(false)
upvotePopover Boolean @default(false)
trust Float @default(0)
lastSeenAt DateTime?
stackedMsats BigInt @default(0)
noteAllDescendants Boolean @default(true)
noteDeposits Boolean @default(true)
noteEarning Boolean @default(true)
noteInvites Boolean @default(true)
noteItemSats Boolean @default(true)
noteMentions Boolean @default(true)
lastCheckedJobs DateTime?
noteJobIndicator Boolean @default(true)
photoId Int?
upvoteTrust Float @default(0)
hideInvoiceDesc Boolean @default(false)
wildWestMode Boolean @default(false)
greeterMode Boolean @default(false)
fiatCurrency String @default("USD")
hideFromTopUsers Boolean @default(false)
turboTipping Boolean @default(false)
referrerId Int?
nostrPubkey String?
slashtagId String? @unique(map: "users.slashtagId_unique")
noteCowboyHat Boolean @default(true)
streak Int?
subs String[]
hideCowboyHat Boolean @default(false)
Bookmarks Bookmark[]
Donation Donation[]
Earn Earn[]
2023-07-26 16:01:31 +00:00
invites Invite[] @relation("Invites")
invoices Invoice[]
fwdItems Item[] @relation("FwdItem")
items Item[] @relation("UserItems")
actions ItemAct[]
mentions Mention[]
messages Message[]
PollVote PollVote[]
2023-07-26 16:01:31 +00:00
PushSubscriptions PushSubscription[]
ReferralAct ReferralAct[]
Streak Streak[]
Subscriptions Subscription[]
ThreadSubscriptions ThreadSubscription[]
2023-07-26 16:01:31 +00:00
Upload Upload[] @relation("Uploads")
nostrRelays UserNostrRelay[]
withdrawls Withdrawl[]
2023-07-27 00:18:42 +00:00
bio Item? @relation(fields: [bioId], references: [id])
invite Invite? @relation(fields: [inviteId], references: [id])
photo Upload? @relation(fields: [photoId], references: [id])
referrer User? @relation("referrals", fields: [referrerId], references: [id])
2023-07-26 16:01:31 +00:00
referrees User[] @relation("referrals")
Account Account[]
Session Session[]
2022-08-06 22:03:57 +00:00
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "users.created_at_index")
@@index([inviteId], map: "users.inviteId_index")
@@map("users")
2021-03-25 19:29:24 +00:00
}
2023-02-01 14:44:35 +00:00
model Streak {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2023-02-01 14:44:35 +00:00
startedAt DateTime @db.Date
endedAt DateTime? @db.Date
userId Int
2023-07-26 16:01:31 +00:00
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2023-02-01 14:44:35 +00:00
2023-07-26 16:01:31 +00:00
@@unique([startedAt, userId], map: "Streak.startedAt_userId_unique")
@@index([userId], map: "Streak.userId_index")
2023-02-01 14:44:35 +00:00
}
2023-01-07 00:53:09 +00:00
model NostrRelay {
addr String @id
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2023-01-07 00:53:09 +00:00
users UserNostrRelay[]
}
model UserNostrRelay {
userId Int
nostrRelayAddr String
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
NostrRelay NostrRelay @relation(fields: [nostrRelayAddr], references: [addr], onDelete: Cascade)
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
2023-01-07 00:53:09 +00:00
@@id([userId, nostrRelayAddr])
}
2022-12-08 00:04:02 +00:00
model Donation {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2022-12-08 00:04:02 +00:00
sats Int
userId Int
2023-07-26 16:01:31 +00:00
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2022-12-08 00:04:02 +00:00
}
2022-05-12 18:44:21 +00:00
model Upload {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2022-05-12 18:44:21 +00:00
type String
size Int
width Int?
height Int?
2023-07-26 16:01:31 +00:00
itemId Int? @unique(map: "Upload.itemId_unique")
2022-05-12 18:44:21 +00:00
userId Int
2023-07-26 16:01:31 +00:00
item Item? @relation(fields: [itemId], references: [id])
user User @relation("Uploads", fields: [userId], references: [id], onDelete: Cascade)
User User[]
2022-05-12 18:44:21 +00:00
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "Upload.created_at_index")
@@index([itemId], map: "Upload.itemId_index")
@@index([userId], map: "Upload.userId_index")
}
2022-03-17 20:13:19 +00:00
model Earn {
2023-07-26 16:01:31 +00:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
msats BigInt
userId Int
rank Int?
type EarnType?
typeId Int?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "Earn.created_at_index")
@@index([createdAt, userId], map: "Earn.created_at_userId_index")
@@index([userId], map: "Earn.userId_index")
2022-03-17 20:13:19 +00:00
}
2021-06-27 03:09:39 +00:00
model LnAuth {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
k1 String @unique(map: "LnAuth.k1_unique")
2021-06-27 03:09:39 +00:00
pubkey String?
}
2021-10-28 19:59:53 +00:00
model LnWith {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
k1 String @unique(map: "LnWith.k1_unique")
2021-10-28 19:59:53 +00:00
userId Int
withdrawalId Int?
}
2021-10-12 20:40:30 +00:00
model Invite {
id String @id @default(cuid())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2021-10-12 20:40:30 +00:00
userId Int
gift Int?
limit Int?
revoked Boolean @default(false)
2023-07-26 16:01:31 +00:00
user User @relation("Invites", fields: [userId], references: [id], onDelete: Cascade)
2021-10-12 20:40:30 +00:00
invitees User[]
2022-03-10 19:26:35 +00:00
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "Invite.created_at_index")
@@index([userId], map: "Invite.userId_index")
2021-10-12 20:40:30 +00:00
}
2021-03-25 19:29:24 +00:00
model Message {
id Int @id @default(autoincrement())
text String
userId Int
2023-07-26 16:01:31 +00:00
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2022-02-25 17:34:09 +00:00
}
2023-07-27 00:18:42 +00:00
/// This model contains an expression index which requires additional setup for migrations. Visit https://pris.ly/d/expression-indexes for more info.
2021-03-25 19:29:24 +00:00
model Item {
2023-07-26 16:01:31 +00:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
title String?
text String?
url String?
userId Int
parentId Int?
path Unsupported("ltree")?
pinId Int?
latitude Float?
location String?
longitude Float?
maxBid Int?
maxSalary Int?
minSalary Int?
remote Boolean?
subName String? @db.Citext
statusUpdatedAt DateTime?
status Status @default(ACTIVE)
company String?
fwdUserId Int?
weightedVotes Float @default(0)
boost Int @default(0)
uploadId Int?
pollCost Int?
paidImgLink Boolean @default(false)
commentMsats BigInt @default(0)
lastCommentAt DateTime?
ncomments Int @default(0)
msats BigInt @default(0)
weightedDownVotes Float @default(0)
bio Boolean @default(false)
freebie Boolean @default(false)
deletedAt DateTime?
otsFile Bytes?
otsHash String?
bounty Int?
rootId Int?
bountyPaidTo Int[]
upvotes Int @default(0)
weightedComments Float @default(0)
2023-07-27 00:18:42 +00:00
Bookmark Bookmark[]
2023-07-26 16:01:31 +00:00
fwdUser User? @relation("FwdItem", fields: [fwdUserId], references: [id])
parent Item? @relation("ParentChildren", fields: [parentId], references: [id])
2023-07-27 00:18:42 +00:00
children Item[] @relation("ParentChildren")
2023-07-26 16:01:31 +00:00
pin Pin? @relation(fields: [pinId], references: [id])
root Item? @relation("RootDescendant", fields: [rootId], references: [id])
2023-07-27 00:18:42 +00:00
descendants Item[] @relation("RootDescendant")
2023-07-26 16:01:31 +00:00
sub Sub? @relation(fields: [subName], references: [name])
user User @relation("UserItems", fields: [userId], references: [id], onDelete: Cascade)
actions ItemAct[]
mentions Mention[]
2023-06-20 01:26:34 +00:00
PollOption PollOption[]
PollVote PollVote[]
ThreadSubscription ThreadSubscription[]
2023-07-26 16:01:31 +00:00
upload Upload?
User User[]
2022-08-06 22:03:57 +00:00
2023-07-26 16:01:31 +00:00
@@index([bio], map: "Item.bio_index")
@@index([createdAt], map: "Item.created_at_index")
@@index([freebie], map: "Item.freebie_index")
@@index([maxBid], map: "Item.maxBid_index")
@@index([parentId], map: "Item.parentId_index")
2023-07-27 00:18:42 +00:00
@@index([path], map: "Item.path_index", type: Gist)
@@index([path], map: "Item.path_index0", type: Gist)
2023-07-26 16:01:31 +00:00
@@index([pinId], map: "Item.pinId_index")
@@index([rootId], map: "Item.rootId_index")
@@index([statusUpdatedAt], map: "Item.statusUpdatedAt_index")
@@index([status], map: "Item.status_index")
@@index([subName], map: "Item.subName_index")
@@index([userId], map: "Item.userId_index")
@@index([weightedDownVotes], map: "Item.weightedDownVotes_index")
@@index([weightedVotes], map: "Item.weightedVotes_index")
2021-03-25 19:29:24 +00:00
}
2022-07-30 13:25:46 +00:00
model PollOption {
2023-07-26 16:01:31 +00:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2022-07-30 13:25:46 +00:00
itemId Int
option String
2023-07-26 16:01:31 +00:00
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
PollVote PollVote[]
2022-07-30 13:25:46 +00:00
2023-07-26 16:01:31 +00:00
@@index([itemId], map: "PollOption.itemId_index")
2022-07-30 13:25:46 +00:00
}
model PollVote {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2022-07-30 13:25:46 +00:00
userId Int
itemId Int
pollOptionId Int
2023-07-26 16:01:31 +00:00
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
pollOption PollOption @relation(fields: [pollOptionId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2022-07-30 13:25:46 +00:00
2023-07-26 16:01:31 +00:00
@@unique([itemId, userId], map: "PollVote.itemId_userId_unique")
@@index([pollOptionId], map: "PollVote.pollOptionId_index")
@@index([userId], map: "PollVote.userId_index")
2022-02-17 17:23:43 +00:00
}
model Sub {
2023-07-26 16:01:31 +00:00
name String @id @db.Citext
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
postTypes PostType[]
rankingType RankingType
baseCost Int @default(1)
desc String?
2023-05-01 20:58:30 +00:00
Item Item[]
Subscription Subscription[]
}
model Subscription {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2023-05-01 20:58:30 +00:00
subName String @db.Citext
userId Int
2023-07-26 16:01:31 +00:00
sub Sub @relation(fields: [subName], references: [name], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2022-02-17 17:23:43 +00:00
}
2022-01-07 16:32:31 +00:00
model Pin {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2022-01-07 16:32:31 +00:00
cron String?
timezone String?
position Int
Item Item[]
}
2022-12-19 22:27:52 +00:00
model ReferralAct {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @default(now()) @updatedAt @map("updated_at")
2022-12-19 22:27:52 +00:00
referrerId Int
itemActId Int
msats BigInt
2023-07-26 16:01:31 +00:00
itemAct ItemAct @relation(fields: [itemActId], references: [id], onDelete: Cascade)
referrer User @relation(fields: [referrerId], references: [id], onDelete: Cascade)
2021-09-08 21:15:06 +00:00
}
2021-09-08 21:51:23 +00:00
model ItemAct {
2023-07-26 16:01:31 +00:00
id Int @id(map: "Vote_pkey") @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
2022-12-19 22:27:52 +00:00
msats BigInt
act ItemActType
itemId Int
userId Int
2023-07-26 16:01:31 +00:00
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2022-12-19 22:27:52 +00:00
ReferralAct ReferralAct[]
2021-04-22 22:14:32 +00:00
2023-07-26 16:01:31 +00:00
@@index([act], map: "ItemAct.act_index")
@@index([createdAt], map: "ItemAct.created_at_index")
@@index([createdAt, itemId, act], map: "ItemAct.created_at_itemId_act_index")
@@index([itemId, createdAt, act], map: "ItemAct.itemId_created_at_act_index")
@@index([itemId], map: "ItemAct.itemId_index")
@@index([itemId, userId, act], map: "ItemAct.itemId_userId_act_index")
@@index([userId, createdAt, act], map: "ItemAct.userId_created_at_act_index")
@@index([userId], map: "ItemAct.userId_index")
@@index([itemId], map: "Vote.itemId_index")
@@index([userId], map: "Vote.userId_index")
2021-04-22 22:14:32 +00:00
}
2021-08-18 22:20:33 +00:00
model Mention {
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
2021-08-18 22:20:33 +00:00
itemId Int
userId Int
2023-07-26 16:01:31 +00:00
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2021-08-18 22:20:33 +00:00
2023-07-26 16:01:31 +00:00
@@unique([itemId, userId], map: "Mention.itemId_userId_unique")
@@index([createdAt], map: "Mention.created_at_index")
@@index([itemId], map: "Mention.itemId_index")
@@index([userId], map: "Mention.userId_index")
2021-08-18 22:20:33 +00:00
}
2021-05-11 15:52:50 +00:00
model Invoice {
2023-07-26 16:01:31 +00:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
userId Int
hash String @unique(map: "Invoice.hash_unique")
2021-05-11 15:52:50 +00:00
bolt11 String
expiresAt DateTime
confirmedAt DateTime?
2023-07-26 16:01:31 +00:00
cancelled Boolean @default(false)
2022-11-15 20:51:55 +00:00
msatsRequested BigInt
msatsReceived BigInt?
2023-07-26 16:01:31 +00:00
desc String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2021-05-11 15:52:50 +00:00
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "Invoice.created_at_index")
@@index([userId], map: "Invoice.userId_index")
2021-05-12 23:04:19 +00:00
}
model Withdrawl {
2023-07-26 16:01:31 +00:00
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
userId Int
hash String
2021-05-12 23:04:19 +00:00
bolt11 String
2022-11-15 20:51:55 +00:00
msatsPaying BigInt
msatsPaid BigInt?
msatsFeePaying BigInt
msatsFeePaid BigInt?
2023-07-26 16:01:31 +00:00
status WithdrawlStatus?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2021-05-12 23:04:19 +00:00
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "Withdrawl.created_at_index")
@@index([userId], map: "Withdrawl.userId_index")
2021-05-12 23:04:19 +00:00
}
2021-03-25 19:29:24 +00:00
model Account {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
userId Int @map("user_id")
type String @map("provider_type")
provider String @map("provider_id")
providerAccountId String @map("provider_account_id")
refresh_token String? @map("refresh_token")
access_token String? @map("access_token")
expires_at String? @map("access_token_expires")
token_type String?
scope String?
id_token String?
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
2023-07-26 16:01:31 +00:00
@@index([userId], map: "accounts.user_id_index")
@@map("accounts")
2021-03-25 19:29:24 +00:00
}
model Session {
id Int @id @default(autoincrement())
sessionToken String @unique(map: "sessions.session_token_unique") @map("session_token")
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
userId Int @map("user_id")
2021-03-25 19:29:24 +00:00
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2021-03-25 19:29:24 +00:00
2023-07-26 16:01:31 +00:00
@@map("sessions")
2021-03-25 19:29:24 +00:00
}
model VerificationToken {
2021-03-25 19:29:24 +00:00
id Int @id @default(autoincrement())
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
2021-03-25 19:29:24 +00:00
identifier String
2023-07-26 16:01:31 +00:00
token String @unique(map: "verification_requests.token_unique")
2021-03-25 19:29:24 +00:00
expires DateTime
@@unique([identifier, token])
2023-07-26 16:01:31 +00:00
@@map("verification_requests")
2021-03-25 19:29:24 +00:00
}
model Bookmark {
userId Int
itemId Int
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
2023-02-24 16:35:05 +00:00
@@id([userId, itemId])
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "Bookmark.created_at_index")
}
model ThreadSubscription {
userId Int
itemId Int
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([userId, itemId])
2023-07-26 16:01:31 +00:00
@@index([createdAt], map: "ThreadSubscription.created_at_index")
2023-06-20 01:26:34 +00:00
}
Service worker rework, Web Target Share API & Web Push API (#324) * npm uninstall next-pwa next-pwa was last updated in August 2022. There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482 But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us. It even lead to a bug since pages were cached without our knowledge. So I will go with a different PWA approach. This different approach should do the following: - make it more transparent what the service worker is doing - gives us more control to configure the service worker and thus making it easier * Use workbox-webpack-plugin Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built. (PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature) These default configurations even lead to worse UX since they made invalid assumptions about stacker.news: We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to. Almost every page on SN should be fresh for the best UX. To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there). Therefore, this should be the simplest configuration with a valid precache and cache busting support. In the future, we can try to use prefetching to improve performance of navigation requests. * Add support for Web Share Target API See https://developer.chrome.com/articles/web-share-target/ * Use Web Push API for push notifications I followed this (very good!) guide: https://web.dev/notifications/ * Refactor code related to Web Push * Send push notification to users on events * Merge notifications * Send notification to author of every parent recursively * Remove unused userId param in savePushSubscription As it should be, the user id is retrieved from the authenticated user in the backend. * Resubscribe user if push subscription changed * Update old subscription if oldEndpoint was given * Allow users to unsubscribe * Use LTREE operator instead of recursive query * Always show checkbox for push notifications * Justify checkbox to end * Update title of first push notification * Fix warning from uncontrolled to controlled * Add comment about Notification.requestPermission * Fix timestamp * Catch error on push subscription toggle * Wrap function bodies in try/catch * Use Promise.allSettled * Filter subscriptions by user notification settings * Fix user notification filter * Use skipWaiting --------- Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
model PushSubscription {
2023-07-26 16:01:31 +00:00
id Int @id @default(autoincrement())
Service worker rework, Web Target Share API & Web Push API (#324) * npm uninstall next-pwa next-pwa was last updated in August 2022. There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482 But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us. It even lead to a bug since pages were cached without our knowledge. So I will go with a different PWA approach. This different approach should do the following: - make it more transparent what the service worker is doing - gives us more control to configure the service worker and thus making it easier * Use workbox-webpack-plugin Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built. (PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature) These default configurations even lead to worse UX since they made invalid assumptions about stacker.news: We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to. Almost every page on SN should be fresh for the best UX. To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there). Therefore, this should be the simplest configuration with a valid precache and cache busting support. In the future, we can try to use prefetching to improve performance of navigation requests. * Add support for Web Share Target API See https://developer.chrome.com/articles/web-share-target/ * Use Web Push API for push notifications I followed this (very good!) guide: https://web.dev/notifications/ * Refactor code related to Web Push * Send push notification to users on events * Merge notifications * Send notification to author of every parent recursively * Remove unused userId param in savePushSubscription As it should be, the user id is retrieved from the authenticated user in the backend. * Resubscribe user if push subscription changed * Update old subscription if oldEndpoint was given * Allow users to unsubscribe * Use LTREE operator instead of recursive query * Always show checkbox for push notifications * Justify checkbox to end * Update title of first push notification * Fix warning from uncontrolled to controlled * Add comment about Notification.requestPermission * Fix timestamp * Catch error on push subscription toggle * Wrap function bodies in try/catch * Use Promise.allSettled * Filter subscriptions by user notification settings * Fix user notification filter * Use skipWaiting --------- Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
userId Int
endpoint String
p256dh String
auth String
2023-07-26 16:01:31 +00:00
createdAt DateTime @default(now()) @map("created_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
Service worker rework, Web Target Share API & Web Push API (#324) * npm uninstall next-pwa next-pwa was last updated in August 2022. There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482 But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us. It even lead to a bug since pages were cached without our knowledge. So I will go with a different PWA approach. This different approach should do the following: - make it more transparent what the service worker is doing - gives us more control to configure the service worker and thus making it easier * Use workbox-webpack-plugin Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built. (PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature) These default configurations even lead to worse UX since they made invalid assumptions about stacker.news: We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to. Almost every page on SN should be fresh for the best UX. To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there). Therefore, this should be the simplest configuration with a valid precache and cache busting support. In the future, we can try to use prefetching to improve performance of navigation requests. * Add support for Web Share Target API See https://developer.chrome.com/articles/web-share-target/ * Use Web Push API for push notifications I followed this (very good!) guide: https://web.dev/notifications/ * Refactor code related to Web Push * Send push notification to users on events * Merge notifications * Send notification to author of every parent recursively * Remove unused userId param in savePushSubscription As it should be, the user id is retrieved from the authenticated user in the backend. * Resubscribe user if push subscription changed * Update old subscription if oldEndpoint was given * Allow users to unsubscribe * Use LTREE operator instead of recursive query * Always show checkbox for push notifications * Justify checkbox to end * Update title of first push notification * Fix warning from uncontrolled to controlled * Add comment about Notification.requestPermission * Fix timestamp * Catch error on push subscription toggle * Wrap function bodies in try/catch * Use Promise.allSettled * Filter subscriptions by user notification settings * Fix user notification filter * Use skipWaiting --------- Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
2023-07-26 16:01:31 +00:00
@@index([userId], map: "PushSubscription.userId_index")
}
enum EarnType {
POST
COMMENT
TIP_COMMENT
TIP_POST
}
enum Status {
ACTIVE
STOPPED
NOSATS
}
enum PostType {
LINK
DISCUSSION
JOB
POLL
BOUNTY
}
enum RankingType {
WOT
RECENT
AUCTION
}
enum ItemActType {
VOTE
BOOST
TIP
STREAM
POLL
DONT_LIKE_THIS
FEE
}
enum WithdrawlStatus {
INSUFFICIENT_BALANCE
INVALID_PAYMENT
PATHFINDING_TIMEOUT
ROUTE_NOT_FOUND
CONFIRMED
UNKNOWN_FAILURE
Service worker rework, Web Target Share API & Web Push API (#324) * npm uninstall next-pwa next-pwa was last updated in August 2022. There is also an issue which mentions that next-pwa is abandoned (?): https://github.com/shadowwalker/next-pwa/issues/482 But the main reason for me uninstalling it is that it adds a lot of preconfigured stuff which is not necessary for us. It even lead to a bug since pages were cached without our knowledge. So I will go with a different PWA approach. This different approach should do the following: - make it more transparent what the service worker is doing - gives us more control to configure the service worker and thus making it easier * Use workbox-webpack-plugin Every other plugin (`next-offline`, `next-workbox-webpack-plugin`, `next-with-workbox`, ...) added unnecessary configuration which felt contrary to how PWAs should be built. (PWAs should progressivly enhance the website in small steps, see https://web.dev/learn/pwa/getting-started/#focus-on-a-feature) These default configurations even lead to worse UX since they made invalid assumptions about stacker.news: We _do not_ want to cache our start url and we _do not_ want to cache anything unless explicitly told to. Almost every page on SN should be fresh for the best UX. To achieve this, by default, the service worker falls back to the network (as if the service worker wasn't there). Therefore, this should be the simplest configuration with a valid precache and cache busting support. In the future, we can try to use prefetching to improve performance of navigation requests. * Add support for Web Share Target API See https://developer.chrome.com/articles/web-share-target/ * Use Web Push API for push notifications I followed this (very good!) guide: https://web.dev/notifications/ * Refactor code related to Web Push * Send push notification to users on events * Merge notifications * Send notification to author of every parent recursively * Remove unused userId param in savePushSubscription As it should be, the user id is retrieved from the authenticated user in the backend. * Resubscribe user if push subscription changed * Update old subscription if oldEndpoint was given * Allow users to unsubscribe * Use LTREE operator instead of recursive query * Always show checkbox for push notifications * Justify checkbox to end * Update title of first push notification * Fix warning from uncontrolled to controlled * Add comment about Notification.requestPermission * Fix timestamp * Catch error on push subscription toggle * Wrap function bodies in try/catch * Use Promise.allSettled * Filter subscriptions by user notification settings * Fix user notification filter * Use skipWaiting --------- Co-authored-by: ekzyis <ek@stacker.news>
2023-07-04 19:36:07 +00:00
}