diff --git a/app/mobile/src/api/getListingMessage.js b/app/mobile/src/api/getListingMessage.js index 1bd9eba4..aebad94b 100644 --- a/app/mobile/src/api/getListingMessage.js +++ b/app/mobile/src/api/getListingMessage.js @@ -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(); } diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index 9f9b2e41..06699208 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -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 || {}; diff --git a/app/mobile/src/context/useProfileContext.hook.js b/app/mobile/src/context/useProfileContext.hook.js index c59ba68a..42f564d0 100644 --- a/app/mobile/src/context/useProfileContext.hook.js +++ b/app/mobile/src/context/useProfileContext.hook.js @@ -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; diff --git a/app/mobile/src/session/Session.jsx b/app/mobile/src/session/Session.jsx index 7f201907..883d48fc 100644 --- a/app/mobile/src/session/Session.jsx +++ b/app/mobile/src/session/Session.jsx @@ -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( diff --git a/app/mobile/src/session/cards/useCards.hook.js b/app/mobile/src/session/cards/useCards.hook.js index 934a913f..4aab679f 100644 --- a/app/mobile/src/session/cards/useCards.hook.js +++ b/app/mobile/src/session/cards/useCards.hook.js @@ -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}`); }, }; diff --git a/app/mobile/src/session/contact/Contact.jsx b/app/mobile/src/session/contact/Contact.jsx index 8321fa87..8532b89d 100644 --- a/app/mobile/src/session/contact/Contact.jsx +++ b/app/mobile/src/session/contact/Contact.jsx @@ -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 ( - { `${contact?.handle}@${contact?.node}` } + { handle } ) } diff --git a/app/mobile/src/session/contact/useContact.hook.js b/app/mobile/src/session/contact/useContact.hook.js index ccd89d8a..5d789597 100644 --- a/app/mobile/src/session/contact/useContact.hook.js +++ b/app/mobile/src/session/contact/useContact.hook.js @@ -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) { diff --git a/app/mobile/src/session/profile/Profile.jsx b/app/mobile/src/session/profile/Profile.jsx index 93cc2397..613b3f10 100644 --- a/app/mobile/src/session/profile/Profile.jsx +++ b/app/mobile/src/session/profile/Profile.jsx @@ -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 ( - { `${state.handle}@${state.node}` } + { handle } ) } diff --git a/app/mobile/src/session/registry/Registry.jsx b/app/mobile/src/session/registry/Registry.jsx index 11631989..5f6b8346 100644 --- a/app/mobile/src/session/registry/Registry.jsx +++ b/app/mobile/src/session/registry/Registry.jsx @@ -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 ( diff --git a/app/mobile/src/session/registry/registryItem/RegistryItem.jsx b/app/mobile/src/session/registry/registryItem/RegistryItem.jsx index 77a58489..07f8cb9b 100644 --- a/app/mobile/src/session/registry/registryItem/RegistryItem.jsx +++ b/app/mobile/src/session/registry/registryItem/RegistryItem.jsx @@ -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 }) { { item.name } - { `${item.handle}@${item.node}` } + { handle } )} diff --git a/app/mobile/src/session/registry/useRegistry.hook.js b/app/mobile/src/session/registry/useRegistry.hook.js index 47215acb..664e219c 100644 --- a/app/mobile/src/session/registry/useRegistry.hook.js +++ b/app/mobile/src/session/registry/useRegistry.hook.js @@ -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 = {}; diff --git a/app/mobile/src/session/useSession.hook.js b/app/mobile/src/session/useSession.hook.js index 4f0687a1..222c57e9 100644 --- a/app/mobile/src/session/useSession.hook.js +++ b/app/mobile/src/session/useSession.hook.js @@ -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 }); } } });