mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Add ping support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
FinishKeyRequestAction,
|
||||
ForceSyncAction,
|
||||
MarkTaskPendingAction,
|
||||
PingAction,
|
||||
ReplyToKeyRequestAction,
|
||||
RemoveInstalledAppsAction,
|
||||
SendKeyRequestAction,
|
||||
@@ -41,6 +42,7 @@ import { dispatchAddUsedTimeVersion2 } from './addusedtime2'
|
||||
import { dispatchFinishKeyRequestAction } from './finishkeyrequest'
|
||||
import { dispatchForceSyncAction } from './forcesync'
|
||||
import { dispatchMarkTaskPendingAction } from './marktaskpendingaction'
|
||||
import { dispatchPingAction } from './ping'
|
||||
import { dispatchReplyToKeyRequestAction } from './replytokeyrequest'
|
||||
import { dispatchSendKeyRequestAction } from './sendkeyrequest'
|
||||
import { dispatchSignOutAtDevice } from './signoutatdevice'
|
||||
@@ -67,6 +69,8 @@ export const dispatchAppLogicAction = async ({ action, deviceId, cache, eventHan
|
||||
await dispatchForceSyncAction({ deviceId, action, cache })
|
||||
} else if (action instanceof MarkTaskPendingAction) {
|
||||
await dispatchMarkTaskPendingAction({ deviceId, action, cache })
|
||||
} else if (action instanceof PingAction) {
|
||||
await dispatchPingAction({ deviceId, action, cache })
|
||||
} else if (action instanceof ReplyToKeyRequestAction) {
|
||||
await dispatchReplyToKeyRequestAction({ deviceId, action, cache, eventHandler })
|
||||
} else if (action instanceof RemoveInstalledAppsAction) {
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { PingAction } from '../../../../action'
|
||||
import { types as pingTypes } from '../../../../database/ping'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchPingAction ({ action, cache, deviceId }: {
|
||||
deviceId: string
|
||||
action: PingAction
|
||||
cache: Cache
|
||||
}) {
|
||||
// handle insertion
|
||||
if (action.event === 'ping' || action.event === 'pong') {
|
||||
let type
|
||||
|
||||
if (action.event === 'ping') type = pingTypes.ping
|
||||
else if (action.event === 'pong') type = pingTypes.pong
|
||||
else throw new Error()
|
||||
|
||||
// delete any previous ping/pong
|
||||
await cache.database.ping.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: action.deviceId,
|
||||
senderDeviceId: deviceId,
|
||||
type: type
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
// insert
|
||||
await cache.database.ping.create({
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: action.deviceId,
|
||||
senderDeviceId: deviceId,
|
||||
type,
|
||||
token: action.token
|
||||
}, {
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
// notify
|
||||
cache.incrementTargetedTriggeredSyncLevel(action.deviceId, 2)
|
||||
}
|
||||
|
||||
// handle deleting
|
||||
if (action.event === 'pong' || action.event === 'clear') {
|
||||
await cache.database.ping.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
receiverDeviceId: deviceId,
|
||||
senderDeviceId: action.deviceId,
|
||||
token: action.token
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user