mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
more cleanup of profile context
This commit is contained in:
parent
b6ce11d766
commit
30ac3d7a3f
@ -336,7 +336,7 @@ export function useConversationContext() {
|
||||
contacts.push(card.state.cards.get(item.cardId));
|
||||
}
|
||||
if (item?.detail?.members) {
|
||||
const profileGuid = profile.state.profile.guid;
|
||||
const profileGuid = profile.state.identity.guid;
|
||||
item.detail.members.forEach(guid => {
|
||||
if (profileGuid !== guid) {
|
||||
const contact = getCard(guid);
|
||||
|
@ -8,7 +8,7 @@ import { StoreContext } from 'context/StoreContext';
|
||||
|
||||
export function useProfileContext() {
|
||||
const [state, setState] = useState({
|
||||
profile: {},
|
||||
identity: {},
|
||||
imageUrl: null,
|
||||
});
|
||||
const store = useContext(StoreContext);
|
||||
@ -29,10 +29,11 @@ export function useProfileContext() {
|
||||
try {
|
||||
const revision = curRevision.current;
|
||||
const { server, appToken, guid } = session.current;
|
||||
const profile = await getProfile(server, appToken);
|
||||
await store.actions.setProfile(guid, profile);
|
||||
const identity = await getProfile(server, appToken);
|
||||
const imageUrl = identity.image ? getProfileImageUrl(server, appToken, revision) : null;
|
||||
await store.actions.setProfile(guid, identity);
|
||||
await store.actions.setProfileRevision(guid, revision);
|
||||
updateState({ profile, imageUrl: getProfileImageUrl(server, appToken, revision) });
|
||||
updateState({ identity, imageUrl: getProfileImageUrl(server, appToken, revision) });
|
||||
setRevision.current = revision;
|
||||
}
|
||||
catch(err) {
|
||||
@ -49,9 +50,10 @@ export function useProfileContext() {
|
||||
const actions = {
|
||||
setSession: async (access) => {
|
||||
const { guid, server, appToken } = access;
|
||||
const profile = await store.actions.getProfile(guid);
|
||||
const identity = await store.actions.getProfile(guid);
|
||||
const revision = await store.actions.getProfileRevision(guid);
|
||||
updateState({ profile, imageUrl: getProfileImageUrl(server, appToken, revision) });
|
||||
const imageUrl = identity.image ? getProfileImageUrl(server, appToken, revision) : null;
|
||||
updateState({ identity, imageUrl });
|
||||
setRevision.current = revision;
|
||||
curRevision.current = revision;
|
||||
session.current = access;
|
||||
@ -72,17 +74,10 @@ export function useProfileContext() {
|
||||
const { server, appToken } = session.current;
|
||||
await setProfileImage(server, appToken, image);
|
||||
},
|
||||
getHandle: async (name) => {
|
||||
getHandleStatus: async (name) => {
|
||||
const { server, appToken } = session.current;
|
||||
return await getHandle(server, appToken, name);
|
||||
},
|
||||
getImageUrl: () => {
|
||||
const { server, appToken } = session.current;
|
||||
if (!state.profile.image) {
|
||||
return null;
|
||||
}
|
||||
return getProfileImageUrl(server, appToken, state.profile.revision);
|
||||
},
|
||||
}
|
||||
|
||||
return { state, actions }
|
||||
|
@ -98,7 +98,7 @@ export function useChannels() {
|
||||
const guid = item?.summary?.lastTopic?.guid;
|
||||
if (created && login && login < created) {
|
||||
if (!item.readRevision || item.readRevision < item.revision) {
|
||||
if (profile.state.profile.guid != guid) {
|
||||
if (profile.state.identity.guid != guid) {
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,7 @@ export function useChannels() {
|
||||
if (item?.detail?.members) {
|
||||
|
||||
item.detail.members.forEach(guid => {
|
||||
const profileGuid = profile.state.profile.guid;
|
||||
const profileGuid = profile.state.identity.guid;
|
||||
if (profileGuid !== guid) {
|
||||
contacts.push(getCard(guid));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ export function useTopicItem(item, hosting, remove, sealed, sealKey) {
|
||||
const { guid, dataType, data, status, transform } = detail;
|
||||
|
||||
let name, nameSet, known, logo;
|
||||
const identity = profile.state?.profile;
|
||||
const identity = profile.state?.identity;
|
||||
if (guid === identity.guid) {
|
||||
known = true;
|
||||
if (identity.name) {
|
||||
@ -53,7 +53,7 @@ export function useTopicItem(item, hosting, remove, sealed, sealKey) {
|
||||
else {
|
||||
name = `${identity.handle}@${identity.node}`;
|
||||
}
|
||||
const img = profile.actions.getImageUrl();
|
||||
const img = profile.state.imageUrl;
|
||||
if (img) {
|
||||
logo = img;
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ export function useBlockedMessages() {
|
||||
|
||||
const setItem = (item) => {
|
||||
let name, nameSet
|
||||
if (item.detail.guid === profile.state.profile.guid) {
|
||||
const identity = profile.state.profile;
|
||||
if (item.detail.guid === profile.state.identity.guid) {
|
||||
const identity = profile.state.identity;
|
||||
if (identity.name) {
|
||||
name = identity.name;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ export function useBlockedTopics() {
|
||||
contacts.push(card.state.cards.get(item.cardId));
|
||||
}
|
||||
if (item?.detail?.members) {
|
||||
const profileGuid = profile.state.profile.guid;
|
||||
const profileGuid = profile.state.identity.guid;
|
||||
item.detail.members.forEach(guid => {
|
||||
if (profileGuid !== guid) {
|
||||
const contact = getCard(guid);
|
||||
|
@ -79,7 +79,7 @@ export function useProfileBody() {
|
||||
}, [dimensions]);
|
||||
|
||||
useEffect(() => {
|
||||
const { name, handle, node, location, description, image } = profile.state.profile;
|
||||
const { name, handle, node, location, description, image } = profile.state.identity;
|
||||
const imageSource = image ? profile.state.imageUrl : 'avatar';
|
||||
updateState({ name, handle, node, location, description, imageSource, editHandle: handle,
|
||||
editName: name, editLocation: location, editDescription: description });
|
||||
@ -398,7 +398,7 @@ export function useProfileBody() {
|
||||
updateState({ available: true, checked: true });
|
||||
}
|
||||
else {
|
||||
const available = await profile.actions.getHandle(editHandle);
|
||||
const available = await profile.actions.getHandleStatus(editHandle);
|
||||
updateState({ available, checked: true });
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ export function useProfile() {
|
||||
}, [dimensions]);
|
||||
|
||||
useEffect(() => {
|
||||
const { name, handle, node, location, description, image } = profile.state.profile;
|
||||
const { name, handle, node, location, description, image } = profile.state.identity;
|
||||
const imageSource = image ? profile.state.imageUrl : 'avatar';
|
||||
updateState({ name, handle, node, location, description, imageSource, editHandle: handle,
|
||||
editName: name, editLocation: location, editDescription: description });
|
||||
|
@ -35,7 +35,7 @@ export function useRegistry() {
|
||||
}, [dimensions]);
|
||||
|
||||
useEffect(() => {
|
||||
const server = profile.state.profile.node;
|
||||
const server = profile.state.identity.node;
|
||||
updateState({ server });
|
||||
getAccounts(server, true);
|
||||
}, [profile]);
|
||||
@ -58,7 +58,7 @@ export function useRegistry() {
|
||||
accounts = await getListing(server);
|
||||
}
|
||||
const filtered = accounts.filter(item => {
|
||||
if (item.guid === profile.state.profile.guid) {
|
||||
if (item.guid === profile.state.identity.guid) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { useState, useRef } from 'react';
|
||||
import { getHandle } from 'api/getHandle';
|
||||
import { getProfile } from 'api/getProfile';
|
||||
import { setProfileData } from 'api/setProfileData';
|
||||
import { setProfileImage } from 'api/setProfileImage';
|
||||
@ -19,12 +20,11 @@ export function useProfileContext() {
|
||||
}
|
||||
|
||||
const sync = async () => {
|
||||
if (!syncing.current) {
|
||||
if (setRevision.current !== curRevision.current) {
|
||||
if (!syncing.current && setRevision.current !== curRevision.current) {
|
||||
syncing.current = true;
|
||||
const revision = curRevision.current;
|
||||
|
||||
try {
|
||||
const revision = curRevision.current;
|
||||
const identity = await getProfile(access.current);
|
||||
const imageUrl = identity.image ? getProfileImageUrl(access.current, revision) : null;
|
||||
updateState({ identity, imageUrl });
|
||||
@ -40,7 +40,6 @@ export function useProfileContext() {
|
||||
sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const actions = {
|
||||
setToken: (token) => {
|
||||
@ -62,6 +61,9 @@ export function useProfileContext() {
|
||||
setProfileImage: async (image) => {
|
||||
await setProfileImage(access.current, image);
|
||||
},
|
||||
getHandleStatus: async (name) => {
|
||||
return await getUsername(name, access.current);
|
||||
},
|
||||
}
|
||||
|
||||
return { state, actions }
|
||||
|
Loading…
Reference in New Issue
Block a user