From 97cfaaa38ad32d310675fba6e4656101416ac19a Mon Sep 17 00:00:00 2001 From: balzack Date: Sat, 22 Oct 2022 23:57:44 -0700 Subject: [PATCH] syncing contact profile --- app/mobile/ios/Databag.xcodeproj/project.pbxproj | 4 ++-- app/mobile/src/api/getContactProfile.js | 9 ++------- app/mobile/src/api/setCardProfile.js | 4 ++-- app/mobile/src/context/useAppContext.hook.js | 2 -- app/mobile/src/context/useCardContext.hook.js | 11 +++++++---- .../session/conversation/topicItem/TopicItem.jsx | 5 ++--- .../conversation/topicItem/useTopicItem.hook.js | 14 +++++++++----- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/mobile/ios/Databag.xcodeproj/project.pbxproj b/app/mobile/ios/Databag.xcodeproj/project.pbxproj index 47948aab..5687f2d3 100644 --- a/app/mobile/ios/Databag.xcodeproj/project.pbxproj +++ b/app/mobile/ios/Databag.xcodeproj/project.pbxproj @@ -310,7 +310,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 16; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = 3P65PQ7SUR; ENABLE_BITCODE = NO; GCC_PREPROCESSOR_DEFINITIONS = ( @@ -348,7 +348,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CLANG_ENABLE_MODULES = YES; - CURRENT_PROJECT_VERSION = 16; + CURRENT_PROJECT_VERSION = 17; DEVELOPMENT_TEAM = 3P65PQ7SUR; INFOPLIST_FILE = Databag/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Databag; diff --git a/app/mobile/src/api/getContactProfile.js b/app/mobile/src/api/getContactProfile.js index 2d9577d9..b1badc62 100644 --- a/app/mobile/src/api/getContactProfile.js +++ b/app/mobile/src/api/getContactProfile.js @@ -1,12 +1,7 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; -export async function getContactProfile(server, guid, token) { - let host = ""; - if (server) { - host = `https://${server}`; - } - - let profile = await fetchWithTimeout(`${host}/profile/message?contact=${guid}.${token}`, { method: 'GET', }); +export async function getContactProfile(server, token) { + let profile = await fetchWithTimeout(`https://${server}/profile/message?contact=${token}`, { method: 'GET', }); checkResponse(profile); return await profile.json() } diff --git a/app/mobile/src/api/setCardProfile.js b/app/mobile/src/api/setCardProfile.js index 7c6a2215..17f5e303 100644 --- a/app/mobile/src/api/setCardProfile.js +++ b/app/mobile/src/api/setCardProfile.js @@ -1,7 +1,7 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; -export async function setCardProfile(token, cardId, message) { - let profile = await fetchWithTimeout(`/contact/cards/${cardId}/profile?agent=${token}`, { method: 'PUT', body: JSON.stringify(message) }); +export async function setCardProfile(server, token, cardId, message) { + let profile = await fetchWithTimeout(`https://${server}/contact/cards/${cardId}/profile?agent=${token}`, { method: 'PUT', body: JSON.stringify(message) }); checkResponse(profile); return await profile.json() } diff --git a/app/mobile/src/context/useAppContext.hook.js b/app/mobile/src/context/useAppContext.hook.js index 0d1cc4c9..04a9d8b2 100644 --- a/app/mobile/src/context/useAppContext.hook.js +++ b/app/mobile/src/context/useAppContext.hook.js @@ -72,14 +72,12 @@ export function useAppContext() { }, access: async (server, token) => { const access = await setAccountAccess(server, token); -console.log("ACCESS", access); await store.actions.setSession({ ...access, server}); await setSession({ ...access, server }); }, login: async (username, password) => { const acc = username.split('@'); const access = await setLogin(acc[0], acc[1], password) -console.log("ACCESS2", access); await store.actions.setSession({ ...access, server: acc[1]}); await setSession({ ...access, server: acc[1] }); }, diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index 6c165486..6ff98401 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -3,8 +3,10 @@ import { StoreContext } from 'context/StoreContext'; import { UploadContext } from 'context/UploadContext'; import { getCards } from 'api/getCards'; import { getCardProfile } from 'api/getCardProfile'; +import { setCardProfile } from 'api/setCardProfile'; import { getCardDetail } from 'api/getCardDetail'; +import { getContactProfile } from 'api/getContactProfile'; import { getContactChannels } from 'api/getContactChannels'; import { getContactChannelDetail } from 'api/getContactChannelDetail'; import { getContactChannelSummary } from 'api/getContactChannelSummary'; @@ -80,7 +82,7 @@ export function useCardContext() { cards.current.set(cardId, card); } } - const setCardProfile = (cardId, profile, revision) => { + const setCardIdentity = (cardId, profile, revision) => { let card = cards.current.get(cardId); if (card) { card.profile = profile; @@ -245,7 +247,7 @@ export function useCardContext() { if (view.profileRevision != profileRevision) { const profile = await getCardProfile(server, appToken, card.id); await store.actions.setCardItemProfile(guid, card.id, profileRevision, profile); - setCardProfile(card.id, profile, profileRevision); + setCardIdentity(card.id, profile, profileRevision); } await store.actions.setCardItemRevision(guid, card.id, card.revision); setCardRevision(card.id, card.revision); @@ -271,8 +273,9 @@ export function useCardContext() { await store.actions.setCardItemNotifiedChannel(guid, card.id, notifiedChannel); } } - if (status.notifiedProflile != notifiedProfile) { - // TODO update contact profile if different + if (status.notifiedProfile != notifiedProfile) { + const message = await getContactProfile(cardServer, cardToken); + await setCardProfile(server, appToken, card.id, message); await store.actions.setCardItemNotifiedProfile(guid, card.id, notifiedProfile); } if (status.offsync) { diff --git a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx index 03b76b77..e96fda0f 100644 --- a/app/mobile/src/session/conversation/topicItem/TopicItem.jsx +++ b/app/mobile/src/session/conversation/topicItem/TopicItem.jsx @@ -2,7 +2,6 @@ import { KeyboardAvoidingView, FlatList, View, Text, TextInput, Modal, Image, Al import { TouchableOpacity } from 'react-native-gesture-handler'; import { useTopicItem } from './useTopicItem.hook'; import { styles } from './TopicItem.styled'; -import { Logo } from 'utils/Logo'; import Colors from 'constants/Colors'; import { VideoThumb } from './videoThumb/VideoThumb'; import { AudioThumb } from './audioThumb/AudioThumb'; @@ -115,7 +114,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update, block { !state.logo && ( )} - { state.name } + { state.name } { state.timestamp } { state.status === 'confirmed' && ( @@ -139,7 +138,7 @@ export function TopicItem({ item, focused, focus, hosting, remove, update, block )} { state.message && ( - { state.message } + { state.message } )} )} diff --git a/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js b/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js index 7b563ea4..4f03442b 100644 --- a/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js +++ b/app/mobile/src/session/conversation/topicItem/useTopicItem.hook.js @@ -9,6 +9,7 @@ export function useTopicItem(item, hosting, remove) { const [state, setState] = useState({ name: null, + nameSet: null, known: null, logo: null, timestamp: null, @@ -40,7 +41,7 @@ export function useTopicItem(item, hosting, remove) { const { topicId, detail } = item; const { guid, data, status, transform } = detail; - let name, known, logo; + let name, nameSet, known, logo; const identity = profile.state?.profile; if (guid === identity.guid) { known = true; @@ -65,21 +66,24 @@ export function useTopicItem(item, hosting, remove) { logo = card.actions.getCardLogo(contact.cardId, contact.profileRevision); } else { - logo = 'avatar'; + logo = null; } known = true; if (contact.profile.name) { name = contact.profile.name; + nameSet = true; } else { - name = `${contact.handle}@${contact.node}`; + name = `${contact.profile.handle}@${contact.profile.node}`; + nameSet = false; } } else { name = "unknown"; + nameSet = false; known = false; - logo = 'avatar'; + logo = null; } } @@ -124,7 +128,7 @@ export function useTopicItem(item, hosting, remove) { const editable = detail.guid === identity.guid && parsed; const deletable = editable || hosting; - updateState({ logo, name, known, message, fontSize, fontColor, timestamp, transform, status, assets, deletable, editable, editData: parsed, editMessage: message }); + updateState({ logo, name, nameSet, known, message, fontSize, fontColor, timestamp, transform, status, assets, deletable, editable, editData: parsed, editMessage: message }); }, [card, item]); const actions = {