mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-09 07:09:57 +03:00
Update last seen after the request is finished (#1643)
* Skip locked rows when updating last seen date * run as post-response hook * return correct key * Change it on the frontend instead * Session may not be available * Don't cause a diff
This commit is contained in:
@@ -306,7 +306,7 @@ function ChangePasswordForm({ reqUser }: { reqUser: UserDocument }) {
|
||||
|
||||
function ChangeUsernameForm({ reqUser }: { reqUser: UserDocument }) {
|
||||
const lastUsernameChange = useApiQuery<
|
||||
{ canChange: false; nextAvailableChange: integer | null } | { canChange: true }
|
||||
{ canChange: false; nextChange: integer | null } | { canChange: true }
|
||||
>(`/users/${reqUser.id}/last-username-change`);
|
||||
|
||||
const nameChangeFormik = useFormik({
|
||||
@@ -424,10 +424,7 @@ function ChangeUsernameForm({ reqUser }: { reqUser: UserDocument }) {
|
||||
<Alert variant="danger">
|
||||
You can only change your username every 6 months. Your next username change
|
||||
will be available on{" "}
|
||||
{new Date(
|
||||
lastUsernameChange.data?.nextAvailableChange ?? 0,
|
||||
).toLocaleDateString()}
|
||||
.
|
||||
{new Date(lastUsernameChange.data?.nextChange ?? 0).toLocaleDateString()}.
|
||||
</Alert>
|
||||
)}
|
||||
<Button
|
||||
|
||||
@@ -3,24 +3,24 @@ import type { RequestHandler } from "express";
|
||||
import DB from "#services/pg/db";
|
||||
import { sql } from "kysely";
|
||||
|
||||
export const UpdateLastSeen: RequestHandler = (req, _res, next) => {
|
||||
if (req.session.tachi?.user.id === undefined) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
export const UpdateLastSeen: RequestHandler = (req, res, next) => {
|
||||
res.once("finish", () => {
|
||||
if (req.session?.tachi?.user.id === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.session.tachi.settings.preferences.invisible) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if (req.session.tachi.settings.preferences.invisible) {
|
||||
return;
|
||||
}
|
||||
|
||||
// fire, but we have no reason to await it.
|
||||
void DB.updateTable("account")
|
||||
.set({
|
||||
last_seen: sql`NOW()`,
|
||||
})
|
||||
.where("id", "=", req.session.tachi.user.id)
|
||||
.execute();
|
||||
// fire, but we have no reason to await it.
|
||||
void DB.updateTable("account")
|
||||
.set({
|
||||
last_seen: sql`NOW()`,
|
||||
})
|
||||
.where("id", "=", req.session.tachi.user.id)
|
||||
.execute();
|
||||
});
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user