saner lastSeenAt checking
This commit is contained in:
parent
ef884181e8
commit
d2697477a0
|
@ -102,14 +102,11 @@ async function authMethods (user, args, { models, me }) {
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
me: async (parent, { skipUpdate }, { models, me }) => {
|
me: async (parent, args, { models, me }) => {
|
||||||
if (!me?.id) {
|
if (!me?.id) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipUpdate) {
|
|
||||||
models.user.update({ where: { id: me.id }, data: { lastSeenAt: new Date() } }).catch(console.error)
|
|
||||||
}
|
|
||||||
return await models.user.findUnique({ where: { id: me.id } })
|
return await models.user.findUnique({ where: { id: me.id } })
|
||||||
},
|
},
|
||||||
settings: async (parent, args, { models, me }) => {
|
settings: async (parent, args, { models, me }) => {
|
||||||
|
@ -291,7 +288,14 @@ export default {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
const foundNotes = () => models.user.update({ where: { id: me.id }, data: { foundNotesAt: new Date() } }).catch(console.error)
|
const foundNotes = () =>
|
||||||
|
models.user.update({
|
||||||
|
where: { id: me.id },
|
||||||
|
data: {
|
||||||
|
foundNotesAt: new Date(),
|
||||||
|
lastSeenAt: new Date()
|
||||||
|
}
|
||||||
|
}).catch(console.error)
|
||||||
|
|
||||||
// check if any votes have been cast for them since checkedNotesAt
|
// check if any votes have been cast for them since checkedNotesAt
|
||||||
if (user.noteItemSats) {
|
if (user.noteItemSats) {
|
||||||
|
@ -483,8 +487,14 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// since they don't have notifications, we can update their checkedNotesAt
|
// update checkedNotesAt to prevent rechecking same time period
|
||||||
await models.user.update({ where: { id: me.id }, data: { checkedNotesAt: new Date() } })
|
models.user.update({
|
||||||
|
where: { id: me.id },
|
||||||
|
data: {
|
||||||
|
checkedNotesAt: new Date(),
|
||||||
|
lastSeenAt: new Date()
|
||||||
|
}
|
||||||
|
}).catch(console.error)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
|
|
|
@ -75,10 +75,7 @@ export function getGetServerSideProps (
|
||||||
|
|
||||||
const client = await getSSRApolloClient({ req, res })
|
const client = await getSSRApolloClient({ req, res })
|
||||||
|
|
||||||
const { data: { me } } = await client.query({
|
const { data: { me } } = await client.query({ query: ME })
|
||||||
query: ME,
|
|
||||||
variables: { skipUpdate: true }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (authRequired && !me) {
|
if (authRequired && !me) {
|
||||||
const callback = process.env.PUBLIC_URL + req.url
|
const callback = process.env.PUBLIC_URL + req.url
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { gql } from 'graphql-tag'
|
||||||
|
|
||||||
export default gql`
|
export default gql`
|
||||||
extend type Query {
|
extend type Query {
|
||||||
me(skipUpdate: Boolean): User
|
me: User
|
||||||
settings: User
|
settings: User
|
||||||
user(name: String!): User
|
user(name: String!): User
|
||||||
users: [User!]
|
users: [User!]
|
||||||
|
|
Loading…
Reference in New Issue