mark conversation update only after login timestamp

This commit is contained in:
Roland Osborne 2022-07-21 13:14:37 -07:00
parent 31fd45890a
commit b00d84b05c
5 changed files with 74 additions and 30 deletions

View File

@ -681,7 +681,7 @@ paths:
content: content:
application/json: application/json:
schema: schema:
type: string $ref: '#/components/schemas/LoginAccess'
'401': '401':
description: invalid token description: invalid token
'406': '406':
@ -3227,6 +3227,18 @@ components:
appToken: appToken:
type: string type: string
LoginAccess {
type: object
required:
- appToken
- created
properties:
appToken:
type: string
created:
type: integer
format: int64
Revision: Revision:
type: object type: object
required: required:

View File

@ -53,6 +53,11 @@ func AddAccountApp(w http.ResponseWriter, r *http.Request) {
return return
} }
WriteResponse(w, account.Guid + "." + access) login := LoginAccess {
AppToken: account.Guid + "." + access,
Created: app.Created,
}
WriteResponse(w, login)
} }

View File

@ -322,6 +322,13 @@ type IdList struct {
Ids []string `json:"ids"` Ids []string `json:"ids"`
} }
type LoginAccess struct {
AppToken string `json:"appToken"`
Created int64 `json:"created"`
}
type NodeConfig struct { type NodeConfig struct {
Domain string `json:"domain"` Domain string `json:"domain"`

View File

@ -57,6 +57,14 @@ export function useChannels() {
}; };
const setUpdated = (chan) => { const setUpdated = (chan) => {
const login = store.state['login:timestamp'];
const update = chan?.data?.channelSummary?.lastTopic?.created;
if (!update || (login && update < login)) {
chan.updated = false;
return;
}
let key = `${chan.id}::${chan.cardId}` let key = `${chan.id}::${chan.cardId}`
if (store.state[key] && store.state[key] == chan.revision) { if (store.state[key] && store.state[key] == chan.revision) {
chan.updated = false; chan.updated = false;

View File

@ -14,34 +14,6 @@ import { ChannelContext } from './ChannelContext';
import { StoreContext } from './StoreContext'; import { StoreContext } from './StoreContext';
import { UploadContext } from './UploadContext'; import { UploadContext } from './UploadContext';
async function appCreate(username, password, token, updateState, setWebsocket) {
await addAccount(username, password, token);
let access = await setLogin(username, password)
updateState({ token: access, access: 'user' });
setWebsocket(access)
localStorage.setItem("session", JSON.stringify({ token: access, access: 'user' }));
}
async function appLogin(username, password, updateState, setWebsocket) {
let access = await setLogin(username, password)
updateState({ token: access, access: 'user' });
setWebsocket(access)
localStorage.setItem("session", JSON.stringify({ token: access, access: 'user' }));
}
async function appAccess(token, updateState, setWebsocket) {
let access = await setAccountAccess(token)
updateState({ token: access, access: 'user' });
setWebsocket(access)
localStorage.setItem("session", JSON.stringify({ token: access, access: 'user' }));
}
function appLogout(updateState, clearWebsocket) {
updateState({ token: null, access: null });
clearWebsocket()
localStorage.removeItem("session");
}
export function useAppContext() { export function useAppContext() {
const [state, setState] = useState(null); const [state, setState] = useState(null);
const [appRevision, setAppRevision] = useState(); const [appRevision, setAppRevision] = useState();
@ -97,6 +69,46 @@ export function useAppContext() {
} }
} }
const appCreate = async (username, password, token) => {
await addAccount(username, password, token);
let access = await setLogin(username, password)
updateState({ token: access.appToken, access: 'user' });
storeContext.actions.setValue('login:timestamp', access.created);
setWebsocket(access.appToken)
localStorage.setItem("session", JSON.stringify({
token: access.appToken,
access: 'user',
timestamp: access.created,
}));
return access.created;
}
const appLogin = async (username, password) => {
let access = await setLogin(username, password)
updateState({ token: access.appToken, access: 'user' });
storeContext.actions.setValue('login:timestamp', access.created);
setWebsocket(access.appToken)
localStorage.setItem("session", JSON.stringify({
token: access.appToken,
access: 'user',
timestamp: access.created,
}));
return access.created;
}
const appAccess = async (token) => {
let access = await setAccountAccess(token)
updateState({ token: access, access: 'user' });
setWebsocket(access)
localStorage.setItem("session", JSON.stringify({ token: access, access: 'user' }));
}
function appLogout(updateState) {
updateState({ token: null, access: null });
clearWebsocket()
localStorage.removeItem("session");
}
const accessActions = { const accessActions = {
access: async (token) => { access: async (token) => {
await appAccess(token, updateState, setWebsocket) await appAccess(token, updateState, setWebsocket)