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

Chelonia in SW #2357

Merged
merged 97 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
9b89d48
Chelonia in SW
corrideat Sep 19, 2024
bce3c5c
Debug
corrideat Sep 22, 2024
4601d99
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Sep 29, 2024
15d5f86
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Oct 4, 2024
2861605
Test fixes
corrideat Oct 6, 2024
80b1385
Fix group-chat-direct-message spec
corrideat Oct 6, 2024
693173f
Fix issue with the no-results slot being (incorrectly) used
corrideat Oct 6, 2024
ba57fb4
Changes supporting failing chat tests
corrideat Oct 7, 2024
13b4357
Fix attachments in SW
corrideat Oct 9, 2024
0a90ec4
Fix Flow fypes
corrideat Oct 13, 2024
22a0f6e
Use atomic for chatroom members
corrideat Oct 13, 2024
e5f8ed2
Chat bugfixes
corrideat Oct 14, 2024
286570a
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Oct 15, 2024
ab7d69d
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Oct 17, 2024
3c78f54
Use session storage for tab logs. Refactor logging to be more generic.
corrideat Oct 17, 2024
c8a4441
Bugfixes and removal of unnecessary selectors
corrideat Oct 17, 2024
17f3e77
SW logs
corrideat Oct 19, 2024
fe4521a
Bugfix for loading preferences (fix event handlers)
corrideat Oct 20, 2024
870d9a6
State for KV events
corrideat Oct 20, 2024
001e813
Serious banner error
corrideat Oct 20, 2024
48db75e
More consistent chelonia / vuex state use
corrideat Oct 20, 2024
d99c1e0
Remove debug logging
corrideat Oct 20, 2024
90460e7
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Oct 21, 2024
279e171
Logs UI
corrideat Oct 23, 2024
933957b
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Oct 23, 2024
ce94156
Lint
corrideat Oct 23, 2024
bdd0f84
Autologout for non-exisiting identity contracts
corrideat Oct 23, 2024
218dd9b
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Oct 24, 2024
aa12e08
Safari workaround
corrideat Oct 24, 2024
fd77e0b
Bugfix
corrideat Oct 24, 2024
18046a7
Bugfixes
corrideat Oct 25, 2024
bbb7277
Logout flow fixes
corrideat Oct 25, 2024
f7bc3d4
Last logged in event
corrideat Oct 25, 2024
b08b48b
Avoid SW logs spam
corrideat Oct 25, 2024
0f55f24
Chatroom position events
corrideat Oct 25, 2024
332e8cb
Feedback
corrideat Oct 27, 2024
6fd370f
WIP
corrideat Oct 28, 2024
fe4e55d
Stability bugfixes
corrideat Nov 2, 2024
ca116a5
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Nov 2, 2024
e4f40bc
Port notifications code
corrideat Nov 3, 2024
74b2dfa
Backend functions for sending
corrideat Nov 3, 2024
a2a0d37
Server push events
corrideat Nov 4, 2024
89329d0
Improvements
corrideat Nov 15, 2024
979218b
Proposals spec selector specificity fix
corrideat Nov 15, 2024
7bdf50c
Add wait to contributions spec
corrideat Nov 15, 2024
e3a6d9a
Push subscription improvements
corrideat Nov 16, 2024
d002c75
Server: persist subscriptions
corrideat Nov 16, 2024
af90f82
Push subscription reporting fixes
corrideat Nov 17, 2024
4b7a25a
Fix to add and join chatroom
corrideat Nov 17, 2024
78c77a7
Notification permissions improvements
corrideat Nov 20, 2024
63caf86
NotificationSettings based on permission
corrideat Nov 21, 2024
dd41be7
Fixes. Bugfix for messageReceivePostEffect
corrideat Nov 22, 2024
e1b55de
Fixes
corrideat Nov 23, 2024
9cee47d
Native notifications logic for display and opening
corrideat Nov 24, 2024
1865646
PWA improvements
corrideat Nov 24, 2024
0654213
Add PWA check to background sound
corrideat Nov 24, 2024
97d4505
Node 18 cypto fixes
corrideat Nov 25, 2024
5dbd05c
Push subscription setup fixes
corrideat Nov 25, 2024
80a6a5e
Document VAPID_EMAIL
corrideat Nov 28, 2024
24535cf
Add notification enabled check to main
corrideat Nov 28, 2024
3e67bee
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Nov 28, 2024
68c6d98
Add comments
corrideat Nov 28, 2024
d065020
Feedback
corrideat Nov 29, 2024
0aed55b
Fixes
corrideat Nov 29, 2024
37ab10b
Feedback
corrideat Nov 29, 2024
a39de0c
Feedback
corrideat Nov 29, 2024
f862f65
Fix pending messages issue
corrideat Nov 30, 2024
ec2d5d7
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Nov 30, 2024
99aa0c0
Fix types. Add contractID to message
corrideat Nov 30, 2024
1b276c8
Cleanup
corrideat Nov 30, 2024
e72dd29
Better PWA detection
corrideat Nov 30, 2024
4af5291
DRY PWA check
corrideat Nov 30, 2024
2734f8b
Simplify visibility check for PWA
corrideat Dec 1, 2024
fd202ea
Lazy init indexedDB + fix types
corrideat Dec 1, 2024
84c4200
Fix query check
corrideat Dec 1, 2024
36cdd68
Notifications error handling
corrideat Dec 1, 2024
c539b02
Fix #2422 (sp: -> shelter:)
corrideat Dec 1, 2024
cff3535
Show native notification if the app isn't focused
corrideat Dec 1, 2024
659930a
Add comment to indexedDB lazy init
corrideat Dec 2, 2024
b4998ff
Feedback & createMessage as object
corrideat Dec 3, 2024
f263fa9
Fixes
corrideat Dec 3, 2024
da6d2f0
Maximum payload size
corrideat Dec 3, 2024
e7fd6b4
Add type to debug log
corrideat Dec 3, 2024
93a6860
Update VAPID cache time
corrideat Dec 3, 2024
cf128a5
Feedback
corrideat Dec 5, 2024
3b30b0e
Cleanup
corrideat Dec 5, 2024
0eee8de
App logs styling
corrideat Dec 5, 2024
9278dc0
Don't set notifications.notificationEnabled if an error occurred
corrideat Dec 5, 2024
3eac14c
Simplify RPC cleanup
corrideat Dec 5, 2024
2119a34
Remove finally(cleanup)
corrideat Dec 5, 2024
269b1a5
Add comments explaining service-worker/setup-push-subscription
corrideat Dec 5, 2024
2f842eb
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Dec 6, 2024
e83ab13
Feedback
corrideat Dec 7, 2024
6817445
Feedback
corrideat Dec 9, 2024
5a762e1
Comments
corrideat Dec 9, 2024
a4e1238
Feedback
corrideat Dec 10, 2024
63023d7
Merge branch 'master' into feature/chelonia-in-service-worker
corrideat Dec 10, 2024
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
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = (grunt) => {
;(function defineApiEnvars () {
const API_PORT = Number.parseInt(grunt.option('port') ?? process.env.API_PORT ?? '8000', 10)

if (Number.isNaN(API_PORT) || API_PORT < 8000 || API_PORT > 65535) {
if (Number.isNaN(API_PORT) || API_PORT < 1024 || API_PORT > 65535) {
throw new RangeError(`Invalid API_PORT value: ${API_PORT}.`)
}
process.env.API_PORT = String(API_PORT)
Expand Down
3 changes: 2 additions & 1 deletion backend/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import path from 'node:path'
import '@sbp/okturtles.data'
import { checkKey, parsePrefixableKey, prefixHandlers } from '~/shared/domains/chelonia/db.js'
import LRU from 'lru-cache'
import { initVapid } from './vapid.js'
import { initZkpp } from './zkppSalt.js'

const Boom = require('@hapi/boom')
Expand Down Expand Up @@ -211,5 +212,5 @@ export default async () => {
}
numNewKeys && console.info(`[chelonia.db] Preloaded ${numNewKeys} new entries`)
}
await initZkpp()
await Promise.all([initVapid(), initZkpp()])
}
74 changes: 68 additions & 6 deletions backend/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
} from '~/shared/pubsub.js'

import type { JSONType, JSONObject } from '~/shared/types.js'
import { postEvent } from './push.js'

const { bold } = require('chalk')
const WebSocket = require('ws')
Expand Down Expand Up @@ -105,7 +106,7 @@ export function createServer (httpServer: Object, options?: Object = {}): Object
server.channels = new Set()
server.customServerEventHandlers = { ...options.serverHandlers }
server.customSocketEventHandlers = { ...options.socketHandlers }
server.messageHandlers = { ...defaultMessageHandlers, ...options.messageHandlers }
server.customMessageHandlers = { ...options.messageHandlers }
server.pingIntervalID = undefined
server.subscribersByChannelID = Object.create(null)
server.pushSubscriptions = Object.create(null)
Expand Down Expand Up @@ -163,11 +164,22 @@ const defaultServerHandlers = {
const url = request.url
const urlSearch = url.includes('?') ? url.slice(url.lastIndexOf('?')) : ''
const debugID = new URLSearchParams(urlSearch).get('debugID') || ''
const send = socket.send.bind(socket)
socket.id = generateSocketID(debugID)
socket.activeSinceLastPing = true
socket.pinged = false
socket.server = server
socket.subscriptions = new Set()
// Sometimes (like when using `createMessage`), we want to send objects that
// are serialized as strings. The `ws` library sends these as binary data,
// whereas the client expects strings. This avoids having to manually
// specify `{ binary: false }` along with calls.
socket.send = function (data) {
if (typeof data === 'object' && typeof data[Symbol.toPrimitive] === 'function') {
return send(data[Symbol.toPrimitive]())
}
return send(data)
}

log.bold(`Socket ${socket.id} connected. Total: ${this.clients.size}`)

Expand Down Expand Up @@ -231,14 +243,16 @@ const defaultSocketEventHandlers = {
}
// The socket can be marked as active since it just received a message.
socket.activeSinceLastPing = true
const handler = server.messageHandlers[msg.type]
const defaultHandler = defaultMessageHandlers[msg.type]
const customHandler = server.customMessageHandlers[msg.type]

if (handler) {
if (defaultHandler || customHandler) {
try {
handler.call(socket, msg)
defaultHandler?.call(socket, msg)
customHandler?.call(socket, msg)
corrideat marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
// Log the error message and stack trace but do not send it to the client.
log.error(error, 'onMesage')
log.error(error, 'onMessage')
server.rejectMessageAndTerminateSocket(msg, socket)
}
} else {
Expand Down Expand Up @@ -322,9 +336,57 @@ const publicMethods = {
) {
const server = this

const msg = typeof message === 'string' ? message : JSON.stringify(message)
let shortMsg
// Utility function to remove `data` (i.e., the GIMessage data) from a
// message. We need this for push notifications, which may have a certain
// maximum size (usually around 4 KiB)
const shortenPayload = () => {
if (!shortMsg && (typeof message === 'object' && message.type === NOTIFICATION_TYPE.ENTRY && message.data)) {
delete message.data
shortMsg = JSON.stringify(message)
}
return shortMsg
}

for (const client of to || server.clients) {
// `client` could be either a WebSocket or a wrapped subscription info
// object
// Duplicate message sending (over both WS and push) is handled on the
// WS logic, for the `close` event (to remove the WS and send over push)
// and for the `STORE_SUBSCRIPTION` WS action.
if (client.endpoint) {
// `client.endpoint` means the client is a subscription info object
// The max length for push notifications in many providers is 4 KiB.
// However, encrypting adds a slight overhead of 17 bytes at the end
// and 86 bytes at the start.
if (msg.length > (4096 - 86 - 17)) {
if (!shortenPayload()) {
console.info('Skipping too large of a payload for', client.id)
taoeffect marked this conversation as resolved.
Show resolved Hide resolved
continue
}
}
postEvent(client, shortMsg || msg).catch(e => {
// If we have an error posting due to too large of a payload and the
// message wasn't already shortened, try again
if (e?.message === 'Payload too large') {
if (shortMsg || !shortenPayload()) {
// The max length for push notifications in many providers is 4 KiB.
console.info('Skipping too large of a payload for', client.id)
return
}
postEvent(client, shortMsg).catch(e => {
console.error(e, 'Error posting push notification')
})
return
}
console.error(e, 'Error posting push notification')
})
continue
}
if (client.readyState === WebSocket.OPEN && client !== except) {
client.send(typeof message === 'string' ? message : JSON.stringify(message))
// In this branch, we're dealing with a WebSocket
client.send(msg)
corrideat marked this conversation as resolved.
Show resolved Hide resolved
}
}
},
Expand Down
Loading