mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
supporting installations with unset federated host
This commit is contained in:
parent
6b6d756515
commit
170dce9173
@ -1,12 +1,7 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getListingMessage(server, guid) {
|
||||
let host = "";
|
||||
if (server) {
|
||||
host = `https://${server}`;
|
||||
}
|
||||
|
||||
let listing = await fetchWithTimeout(`${host}/account/listing/${guid}/message`, { method: 'GET' });
|
||||
let listing = await fetchWithTimeout(`https://${server}/account/listing/${guid}/message`, { method: 'GET' });
|
||||
checkResponse(listing);
|
||||
return await listing.json();
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ export function useCardContext() {
|
||||
|
||||
const { detail, profile, cardId } = entry.card;
|
||||
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = entry.card;
|
||||
const cardServer = profile?.node;
|
||||
const cardServer = profile?.node ? profile.node : server;
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
|
||||
if (entry.card.notifiedProfile !== cardRevision.profile) {
|
||||
@ -373,7 +373,7 @@ export function useCardContext() {
|
||||
addTopic: async (cardId, channelId, type, message, files) => {
|
||||
const { detail, profile } = cards.current.get(cardId)?.card || {};
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
const node = profile?.node;
|
||||
const node = profile?.node ? profile.node : access.current?.server;
|
||||
if (files?.length > 0) {
|
||||
const topicId = await addContactChannelTopic(node, cardToken, channelId, null, null, null);
|
||||
upload.actions.addTopic(node, cardToken, channelId, topicId, files, async (assets) => {
|
||||
@ -396,27 +396,32 @@ export function useCardContext() {
|
||||
removeTopic: async (cardId, channelId, topicId) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
return await removeContactChannelTopic(profile?.node, cardToken, channelId, topicId);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await removeContactChannelTopic(node, cardToken, channelId, topicId);
|
||||
},
|
||||
setTopicSubject: async (cardId, channelId, topicId, type, subject) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
return await setContactChannelTopicSubject(profile?.node, cardToken, channelId, topicId, type, subject);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await setContactChannelTopicSubject(node, cardToken, channelId, topicId, type, subject);
|
||||
},
|
||||
getTopicAssetUrl: (cardId, channelId, topicId, assetId) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
return getContactChannelTopicAssetUrl(profile?.node, cardToken, channelId, topicId, assetId);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return getContactChannelTopicAssetUrl(node, cardToken, channelId, topicId, assetId);
|
||||
},
|
||||
getTopics: async (cardId, channelId, revision, count, begin, end) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
return await getContactChannelTopics(profile?.node, cardToken, channelId, revision, count, begin, end);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await getContactChannelTopics(node, cardToken, channelId, revision, count, begin, end);
|
||||
},
|
||||
getTopic: async (cardId, channelId, topicId) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||
return await getContactChannelTopic(profile?.node, cardToken, channelId, topicId);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await getContactChannelTopic(node, cardToken, channelId, topicId);
|
||||
},
|
||||
setContactRevision: async (cardId, revision) => {
|
||||
const { guid } = acccess.current || {};
|
||||
@ -473,21 +478,25 @@ export function useCardContext() {
|
||||
},
|
||||
addChannelAlert: async (cardId, channelId) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
return await addFlag(profile?.node, profile?.guid, channelId);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await addFlag(node, profile?.guid, channelId);
|
||||
},
|
||||
addTopicAlert: async (cardId, channelId, topicId) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
return await addFlag(profile?.node, profile?.guid, channelId, topicId);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await addFlag(node, profile?.guid, channelId, topicId);
|
||||
},
|
||||
getChannelNotifications: async (cardId, channelId) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
const token = `${profile?.guid}.${detail?.token}`;
|
||||
return await getContactChannelNotifications(profile?.node, token, channelId);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await getContactChannelNotifications(node, token, channelId);
|
||||
},
|
||||
setChannelNotifications: async (cardId, channelId, notify) => {
|
||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||
const token = `${profile?.guid}.${detail?.token}`;
|
||||
return await setContactChannelNotifications(profile?.node, token, channelId, notify);
|
||||
const node = profile?.node ? profile.node : access.current.server;
|
||||
return await setContactChannelNotifications(node, token, channelId, notify);
|
||||
},
|
||||
getTopicItems: async (cardId, channelId) => {
|
||||
const { guid } = access.current || {};
|
||||
|
@ -10,6 +10,7 @@ export function useProfileContext() {
|
||||
const [state, setState] = useState({
|
||||
offsync: false,
|
||||
identity: {},
|
||||
server: null,
|
||||
imageUrl: null,
|
||||
});
|
||||
const store = useContext(StoreContext);
|
||||
@ -55,7 +56,7 @@ export function useProfileContext() {
|
||||
const identity = await store.actions.getProfile(guid);
|
||||
const revision = await store.actions.getProfileRevision(guid);
|
||||
const imageUrl = identity?.image ? getProfileImageUrl(server, token, revision) : null;
|
||||
updateState({ offsync: false, identity, imageUrl });
|
||||
updateState({ offsync: false, identity, imageUrl, server });
|
||||
setRevision.current = revision;
|
||||
curRevision.current = revision;
|
||||
access.current = session;
|
||||
|
@ -129,7 +129,7 @@ function ContactStackScreen({ addChannel }) {
|
||||
navigation.navigate('contact')
|
||||
}
|
||||
const openRegistry = (navigation) => {
|
||||
setServer(profile.state.identity.node);
|
||||
setServer(profile.state.server);
|
||||
setHandle(null);
|
||||
setSearch(false);
|
||||
navigation.navigate('registry');
|
||||
@ -352,7 +352,7 @@ export function Session({ sharing, clearSharing }) {
|
||||
for (let i = 0; i < state.ringing.length; i++) {
|
||||
const call = state.ringing[i];
|
||||
const { img, cardId, callId, name, handle, contactNode } = call || {};
|
||||
const label = name ? name : `${handle}@${contactNode}`;
|
||||
const label = name ? name : contactNode ? `${handle}@${contactNode}` : handle;
|
||||
const key = `${cardId}:${callId}`
|
||||
incoming.push(
|
||||
<View key={key} style={styles.ringEntry}>
|
||||
|
@ -2,6 +2,7 @@ import { useState, useEffect, useRef, useContext } from 'react';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
import { RingContext } from 'context/RingContext';
|
||||
import { AccountContext } from 'context/AccountContext';
|
||||
import { ProfileContext } from 'context/ProfileContext';
|
||||
|
||||
export function useCards(filter, sort) {
|
||||
|
||||
@ -10,6 +11,7 @@ export function useCards(filter, sort) {
|
||||
enableIce: false,
|
||||
});
|
||||
|
||||
const profile = useContext(ProfileContext);
|
||||
const account = useContext(AccountContext);
|
||||
const card = useContext(CardContext);
|
||||
const ring = useContext(RingContext);
|
||||
@ -97,7 +99,8 @@ export function useCards(filter, sort) {
|
||||
const actions = {
|
||||
call: async (card) => {
|
||||
const { cardId, guid, node, token } = card || {};
|
||||
await ring.actions.call(cardId, node, `${guid}.${token}`);
|
||||
const server = node ? node : profile.state.server;
|
||||
await ring.actions.call(cardId, server, `${guid}.${token}`);
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -6,8 +6,9 @@ import { Logo } from 'utils/Logo';
|
||||
import { Colors } from 'constants/Colors';
|
||||
|
||||
export function ContactHeader({ contact }) {
|
||||
const handle = contact?.node ? `${contact?.handle}@${contact?.node}` : contact?.handle;
|
||||
return (
|
||||
<Text style={styles.headerText}>{ `${contact?.handle}@${contact?.node}` }</Text>
|
||||
<Text style={styles.headerText}>{ handle }</Text>
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { useState, useEffect, useRef, useContext } from 'react';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
import { ProfileContext } from 'context/ProfileContext';
|
||||
import { getListingMessage } from 'api/getListingMessage';
|
||||
import { getListingImageUrl } from 'api/getListingImageUrl';
|
||||
import { addFlag } from 'api/addFlag';
|
||||
@ -22,6 +23,7 @@ export function useContact(contact) {
|
||||
});
|
||||
|
||||
const card = useContext(CardContext);
|
||||
const profile = useContext(ProfileContext);
|
||||
|
||||
const updateState = (value) => {
|
||||
setState((s) => ({ ...s, ...value }));
|
||||
@ -29,18 +31,21 @@ export function useContact(contact) {
|
||||
|
||||
useEffect(() => {
|
||||
const contactCard = getCardByGuid(card.state.cards, contact?.guid);
|
||||
const { server } = profile.state;
|
||||
if (contactCard) {
|
||||
const { offsync, profile, detail, cardId } = contactCard.card;
|
||||
const { name, handle, node, location, description, guid, imageSet, revision } = profile;
|
||||
const host = node ? node : server;
|
||||
const logo = imageSet ? card.actions.getCardImageUrl(cardId) : 'avatar';
|
||||
updateState({ offsync, name, handle, node, location, description, logo, cardId, guid, status: detail.status });
|
||||
updateState({ offsync, name, handle, node: server, location, description, logo, cardId, guid, status: detail.status });
|
||||
}
|
||||
else {
|
||||
const { guid, handle, node, name, location, description, imageSet } = contact || {};
|
||||
const logo = imageSet ? getListingImageUrl(node, guid) : 'avatar';
|
||||
updateState({ guid, handle, node, name, location, description, logo, offsync: false, status: null });
|
||||
}
|
||||
}, [contact, card.state]);
|
||||
const host = node ? node : server;
|
||||
const logo = imageSet ? getListingImageUrl(server, guid) : 'avatar';
|
||||
updateState({ guid, handle, node: host, name, location, description, logo, offsync: false, status: null });
|
||||
}
|
||||
}, [contact, card.state, profile.state]);
|
||||
|
||||
const applyAction = async (action) => {
|
||||
if (!state.busy) {
|
||||
|
@ -12,9 +12,10 @@ import { BlockedMessages } from './blockedMessages/BlockedMessages';
|
||||
|
||||
export function ProfileHeader() {
|
||||
const { state, actions } = useProfile();
|
||||
const handle = state.node ? `${state.handle}@${state.node}` : state.handle;
|
||||
|
||||
return (
|
||||
<Text style={styles.headerText}>{ `${state.handle}@${state.node}` }</Text>
|
||||
<Text style={styles.headerText}>{ handle }</Text>
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ export function Registry({ closeRegistry, openContact }) {
|
||||
useEffect(() => {
|
||||
setSearch(false);
|
||||
setHandle(null);
|
||||
setServer(profile.state.identity?.node);
|
||||
setServer(profile.state.server);
|
||||
}, [profile.state]);
|
||||
|
||||
return (
|
||||
|
@ -6,6 +6,7 @@ import { useRegistryItem } from './useRegistryItem.hook';
|
||||
export function RegistryItem({ item, openContact }) {
|
||||
|
||||
const { state, actions } = useRegistryItem(item);
|
||||
const handle = item.node ? `${item.handle}i@${item.node}` : item.handle;
|
||||
|
||||
const select = () => {
|
||||
const { guid, name, handle, node, location, description, imageSet } = item;
|
||||
@ -20,7 +21,7 @@ export function RegistryItem({ item, openContact }) {
|
||||
<Logo src={item.logo} width={32} height={32} radius={6} />
|
||||
<View style={styles.detail}>
|
||||
<Text style={styles.name} numberOfLines={1} ellipsizeMode={'tail'}>{ item.name }</Text>
|
||||
<Text style={styles.handle} numberOfLines={1} ellipsizeMode={'tail'}>{ `${item.handle}@${item.node}` }</Text>
|
||||
<Text style={styles.handle} numberOfLines={1} ellipsizeMode={'tail'}>{ handle }</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
|
@ -45,8 +45,9 @@ export function useRegistry(search, handle, server) {
|
||||
|
||||
const setAccountItem = (item) => {
|
||||
const { guid, name, handle, node, location, description, imageSet } = item;
|
||||
const logo = imageSet ? getListingImageUrl(node, guid) : 'avatar';
|
||||
return { guid, name, handle, node, location, description, guid, imageSet, logo };
|
||||
const server = node ? node : profile.state.server;
|
||||
const logo = imageSet ? getListingImageUrl(server, guid) : 'avatar';
|
||||
return { guid, name, handle, server, location, description, guid, imageSet, logo };
|
||||
};
|
||||
|
||||
const actions = {};
|
||||
|
@ -6,6 +6,7 @@ import { StoreContext } from 'context/StoreContext';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
import { ChannelContext } from 'context/ChannelContext';
|
||||
import { RingContext } from 'context/RingContext';
|
||||
import { ProfileContext } from 'context/ProfileContext';
|
||||
|
||||
export function useSession() {
|
||||
|
||||
@ -30,6 +31,7 @@ export function useSession() {
|
||||
const ring = useContext(RingContext);
|
||||
const channel = useContext(ChannelContext);
|
||||
const card = useContext(CardContext);
|
||||
const profile = useContext(ProfileContext);
|
||||
const store = useContext(StoreContext);
|
||||
const dimensions = useWindowDimensions();
|
||||
const navigate = useNavigate();
|
||||
@ -50,8 +52,9 @@ export function useSession() {
|
||||
const { imageSet, name, handle, node, guid } = contact.card?.profile || {};
|
||||
const { token } = contact.card?.detail || {};
|
||||
const contactToken = `${guid}.${token}`;
|
||||
const server = node ? node : profile.state.server;
|
||||
const img = imageSet ? card.actions.getCardImageUrl(cardId) : null;
|
||||
ringing.push({ cardId, img, name, handle, contactNode: node, callId, contactToken, calleeToken, iceUrl, iceUsername, icePassword });
|
||||
ringing.push({ cardId, img, name, handle, contactNode: server, callId, contactToken, calleeToken, iceUrl, iceUsername, icePassword });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user