Skip to content

Commit

Permalink
Merge pull request #246 from Zekiah-A/main
Browse files Browse the repository at this point in the history
FINAL delete message hotfix, service worker update
  • Loading branch information
Zekiah-A authored Feb 25, 2024
2 parents 77d9666 + e125d7d commit 032e081
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 97 deletions.
14 changes: 10 additions & 4 deletions db-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ export type UserVip = {
}
export type DeletionMessageInfo = {
messageId: number,

reason: string,
moderatorIntId: number
}
export type DeletionInsert = {
moderatorIntId: number,
reason: string,
deletionDate: number
}
export type LiveChatDeletion = {
deletionId: number,
moderatorIntId: number,
Expand Down Expand Up @@ -206,7 +212,7 @@ const createLiveChatDeletions = `
db.exec(createLiveChatDeletions)

/**
* Adds % to object keys in order to make it act as a valid bun SQLite query object
* Adds $ to object keys in order to make it act as a valid bun SQLite query object
*/
function toQueryObject<T extends object>(object: T): T {
// @ts-expect-error Chicanery to keep type inference whilst transforming
Expand Down Expand Up @@ -373,9 +379,9 @@ const internal: DbInternals = {
},
// Messages may or may not be in the DB by the time they are being asked to be deleted due to periodic transactions
deleteLiveChat: function(data) {
const deletionQuery = db.query<LiveChatDeletion, DeletionMessageInfo>(
"INSERT INTO LiveChatDeletions (moderatorIntId, reason, deletionDate) VALUES ($moderatorIntId, $reason, $deletionDate) RETURNING *")
const deletion = deletionQuery.get(toQueryObject(data))
const deletionQuery = db.query<LiveChatDeletion, DeletionInsert>(
"INSERT INTO LiveChatDeletions (moderatorIntId, reason, deletionDate) VALUES ($moderatorIntId, $reason, $deletionDate) RETURNING *")
const deletion = deletionQuery.get(toQueryObject({ moderatorIntId: data.moderatorIntId, reason: data.reason, deletionDate: Date.now() }))
if (deletion == null) return

// If pending to be inserted into DB we can update the record in preflight
Expand Down
Binary file removed images/burdurland.png
Binary file not shown.
24 changes: 13 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -448,14 +448,6 @@
{ url: "https://t.me/rplacelive", banners: { en: "images/telegram-ad.png" } },
{ url: "https://discord.gg/4XnZ9WGux2", banners: { en: "images/discord-ad.png" } },
{ url: "https://arbitrum.life", banners: { en: "https://avatars.githubusercontent.com/u/131141781" } },
{
url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
banners: {
de: "https://media.discordapp.net/attachments/1096547665875046591/1133066712783265883/german.png?width=620&height=310",
tr: "https://media.discordapp.net/attachments/1096547665875046591/1133066713039114281/turkish.png?width=620&height=310",
en: "https://media.discordapp.net/attachments/1096547665875046591/1133066712523231414/english.png?width=620&height=310"
}
}
]

const PUNISHMENT_STATE = {
Expand All @@ -465,6 +457,8 @@
}

const MAX_CHANNEL_MESSAGES = 100

const SW_REVISION = 2
</script>
<script>
if(!("subtle" in (window.crypto || {}))) location.protocol = "https:"
Expand All @@ -486,9 +480,17 @@
}

// Register PWA Service worker
if ("serviceWorker" in navigator)
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("./sw.js")

.then((registration) => {
if (localStorage.sw != SW_REVISION) {
console.log(`Updating service worker from ${localStorage.sw} to revision ${SW_REVISION}`);
registration.update()
localStorage.sw = SW_REVISION
}
})
.catch((error) => console.error(`Service worker failed with ${error}`))
}
const intIdPositions = new Map() // position : intId
const intIdNames = new Map() // intId : name
let account = null
Expand Down Expand Up @@ -1683,7 +1685,7 @@ <h2>Place</h2>
localStorage.placeChat = +placeChat
this.children[0].style.opacity = placeChat ? '1' : '0.6'
">
<img src="images/place-chat.svg" width="60">
<img src="svg/place-chat.svg" width="60">
</place-chat-button>
</div>
</div>
Expand Down
File renamed without changes
204 changes: 122 additions & 82 deletions sw.js
Original file line number Diff line number Diff line change
@@ -1,82 +1,122 @@
// Service worker for PWA installation
self.addEventListener("install", (event) => {
event.waitUntil(
caches
.open("tkv1")
.then((cache) =>
cache.addAll([
"/index.html",
"/style.css",

// Images
"images/account_profile.png",
"images/burdurland.png",
"images/canv.png",
"images/discord.png",
"images/hammer-and-wrench.png",
"images/live.png",
"images/news.png",
"images/patreon.png",
"images/place-chat.svg",
"images/reddit.png",
"images/rplace.png",
"images/rplace2.png",
"images/timelapse.png",
"images/twitter.png",

//Badges
"badges/1000000_pixels_placed.svg",
"badges/100000_pixels_placed.svg",
"badges/1000_pixels_placed.svg",
"badges/100_pixels_placed.svg",
"badges/20000_pixels_placed.svg",
"badges/5000_pixels_placed.svg",
"badges/admin.svg",
"badges/based.svg",
"badges/discord_member.svg",
"badges/ethical_botter.svg",
"badges/gay.svg",
"badges/moderator.svg",
"badges/noob.svg",
"badges/script_kiddie.svg",
"badges/trouble_maker.svg",
"badges/veteran.svg",

// Custom emojis
"custom_emojis/amogus.png",
"custom_emojis/biaoqing.png",
"custom_emojis/deepfriedh.png",
"custom_emojis/edp445.png",
"custom_emojis/fan.png",
"custom_emojis/heavy.png",
"custom_emojis/herkul.png",
"custom_emojis/kaanozdil.png",
"custom_emojis/lowtiergod.png",
"custom_emojis/manly.png",
"custom_emojis/plsaddred.png",
"custom_emojis/rplace.png",
"custom_emojis/rplacediscord.png",
"custom_emojis/sonic.png",
"custom_emojis/transparent.png",
"custom_emojis/trollface.png"
])
)
)
})


self.addEventListener('fetch', (event) => {
// Only catch GET requests.
if (event.request.method !== "GET") return

// Prevent the default, and handle the request ourselves.
event.respondWith(
(async () => {
const cache = await caches.open("tkv1")
const cachedResponse = await cache.match(event.request)

if (cachedResponse) return cachedResponse
return await fetch(event.request)
})()
)
})
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
// Service worker for PWA installation
const CURRENT_CACHES = "tkv2"
self.addEventListener("install", (event) => {
event.waitUntil(
caches.open(CURRENT_CACHES).then((cache) =>
cache.addAll([
"index.html",
"style.css",
"rplace-2022.css",
"rplace-2023.css",

// Images
"images/1984.png",
"images/account_profile.png",
"images/canv.png",
"images/discord-ad.png",
"images/discord.png",
"images/discord-popup.png",
"images/hammer-and-wrench.png",
"images/lamda.png",
"images/live.png",
"images/news.png",
"images/patreon.png",
"images/reddit-login-banner.png",
"images/reddit.png",
"images/rplace2.png",
"images/rplace-loader.gif",
"images/rplace-offline.png",
"images/rplace.png",
"images/snoo-edge.png",
"images/telegram-ad.png",
"images/timelapse.png",
"images/trophy.png",
"images/twitter.png",

// Svg
"svg/place-chat.svg",
"svg/clipboard.svg",
"svg/flag-gb.svg",
"svg/pattern.svg",
"svg/santa-hat.svg",
"svg/pixel-select-2022.svg",
"svg/chat.svg",
"svg/lock.svg",
"svg/moderate-action.svg",
"svg/reply-action.svg",
"svg/report-action.svg",
"svg/player.svg",
"svg/help.svg",
"svg/green-checkmark.svg",
"svg/pixel-select-2023.svg",

//Badges
"badges/1000000_pixels_placed.svg",
"badges/100000_pixels_placed.svg",
"badges/1000_pixels_placed.svg",
"badges/100_pixels_placed.svg",
"badges/20000_pixels_placed.svg",
"badges/5000_pixels_placed.svg",
"badges/admin.svg",
"badges/based.svg",
"badges/discord_member.svg",
"badges/ethical_botter.svg",
"badges/gay.svg",
"badges/moderator.svg",
"badges/noob.svg",
"badges/script_kiddie.svg",
"badges/trouble_maker.svg",
"badges/veteran.svg",

// Custom emojis
"custom_emojis/amogus.png",
"custom_emojis/biaoqing.png",
"custom_emojis/deepfriedh.png",
"custom_emojis/edp445.png",
"custom_emojis/fan.png",
"custom_emojis/heavy.png",
"custom_emojis/herkul.png",
"custom_emojis/kaanozdil.png",
"custom_emojis/lowtiergod.png",
"custom_emojis/manly.png",
"custom_emojis/plsaddred.png",
"custom_emojis/rplace.png",
"custom_emojis/rplacediscord.png",
"custom_emojis/sonic.png",
"custom_emojis/transparent.png",
"custom_emojis/trollface.png",

// Fonts
"fonts/RedditMono-Bold.woff2",
"fonts/RedditSans-Bold.woff2",
"fonts/RedditSans-Regular.woff2",

// Sounds
"sounds/cooldown-start.mp3",
"sounds/invalid.mp3",
"sounds/cooldown-end.mp3",
"sounds/highlight.mp3",
"sounds/select-colour.mp3",
"sounds/close-palette.mp3",
])
)
)
})

self.addEventListener("fetch", (event) => {
// Only catch GET requests.
if (event.request.method !== "GET") return

// Prevent the default, and handle the request ourselves.
event.respondWith(
(async () => {
const cache = await caches.open(CURRENT_CACHES)
const cachedResponse = await cache.match(event.request)

if (cachedResponse) return cachedResponse
return await fetch(event.request)
})()
)
})

0 comments on commit 032e081

Please sign in to comment.