From ad781e6c819f3e8297a2bfeff95b13ad34c924f9 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Thu, 29 Sep 2022 15:21:18 -0700 Subject: [PATCH] more syncing of topics --- app/mobile/src/context/useCardContext.hook.js | 33 +++++++++++++- .../src/context/useChannelContext.hook.js | 18 +++++++- .../context/useConversationContext.hook.js | 45 ++++++++++++++++--- 3 files changed, 85 insertions(+), 11 deletions(-) diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index b52228fd..3c1ce56e 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -42,6 +42,14 @@ export function useCardContext() { setState((s) => ({ ...s, ...value })) } + const getCard = (cardId) => { + const card = cards.current.get(cardId); + if (!card) { + throw new Error('cared not found'); + } + return card; + } + const setCard = (cardId, card) => { let updated = cards.current.get(cardId); if (updated == null) { @@ -449,18 +457,39 @@ export function useCardContext() { return await store.actions.clearCardChannelTopicItems(guid, cardId, channelId); }, getChannelTopic: async (cardId, channelId, topicId) => { + const { guid } = session.current; + const { detail, profile } = getCard(cardId); + return await getContactChannelTopic(profile.node, detail.token, channelId, topicId); }, - getChannelTopics: async (cardId, channelId) => { + getChannelTopics: async (cardId, channelId, revision) => { + const { guid } = session.current; + const { detail, profile } = getCard(cardId); + return await getContactChannelTopics(profile.node, detail.token, channelId, revision); }, - getChannelTopicAssetUrl: async (cardId, channelId, assetId) => { + getChannelTopicAssetUrl: (cardId, channelId, topicId, assetId) => { + const { guid } = session.current; + const { detail, profile } = getCard(cardId); + return getContactChannelTopicAssetUrl(profile.node, detail.token, channelId, topicId, assetId); }, addChannelTopic: async (cardId, channelId, message, assets) => { + const { guid } = session.current; + const { detail, profile } = getCard(cardId); + return await addChannelTopic(profile.node, detail.token, channelId, message, assets); }, setChannelTopicSubject: async (cardId, channelId, topicId, data) => { + const { guid } = session.current; + const { detail, profile } = getCard(cardId); + return await setContactChannelTopicSubject(profile.node, detail.token, channelId, topicId, data); }, removeChannel: async (cardId, channelId) => { + const { guid } = session.current; + const { detail, profile } = getCard(cardId); + return await removeChannel(profile.node, detail.token, channelId); }, removeChannelTopic: async (cardId, channelId, topicId) => { + const { guid } = session.current; + const { detail, profile } = getCard(cardId); + return await removeChannelTopic(profile.node, detail.token, channelId, topicId); }, } diff --git a/app/mobile/src/context/useChannelContext.hook.js b/app/mobile/src/context/useChannelContext.hook.js index 91dd7c1c..0e4c1db6 100644 --- a/app/mobile/src/context/useChannelContext.hook.js +++ b/app/mobile/src/context/useChannelContext.hook.js @@ -201,18 +201,32 @@ export function useChannelContext() { return await store.actions.clearChannelTopicItems(guid, channelId); }, getTopic: async (channelId, topicId) => { + const { server, appToken } = session.current; + return await getChannelTopic(server, appToken, channelId, topicId); }, - getTopics: async (channelId) => { + getTopics: async (channelId, revision) => { + const { server, appToken } = session.current; + return await getChannelTopics(server, appToken, channelId, revision); }, - getTopicAssetUrl: async (channelId, assetId) => { + getTopicAssetUrl: (channelId, topicId, assetId) => { + const { server, appToken } = session.current; + return getChannelTopicAssetUrl(server, appToken, channelId, topicId, assetId); }, addTopic: async (channelId, message, assets) => { + const { server, appToken } = session.current; + return await addChannelTopic(server, appToken, channelId, message, assets); }, setTopicSubject: async (channelId, topicId, data) => { + const { server, appToken } = session.current; + return await setChannelTopicSubject(server, appToken, channelId, topicId, data); }, remove: async (channelId) => { + const { server, appToken } = session.current; + return await removeChannel(server, appToken, channelId); }, removeTopic: async (channelId, topicId) => { + const { server, appToken } = session.current; + return await removeChannelTopic(server, appToken, channelId, topicId); }, } diff --git a/app/mobile/src/context/useConversationContext.hook.js b/app/mobile/src/context/useConversationContext.hook.js index ad7b81a2..1bd0c243 100644 --- a/app/mobile/src/context/useConversationContext.hook.js +++ b/app/mobile/src/context/useConversationContext.hook.js @@ -52,18 +52,46 @@ export function useConversationContext() { return await channel.actions.clearTopicItem(channelId, topicId); } const getTopic = async (cardId, channelId, topicId) => { + if (cardId) { + return await card.actions.getChannelTopic(cardId, channelId, topicId); + } + return await channel.actions.getTopic(channelId, topicId); } - const getTopics = async (cardId, channelId) => { + const getTopics = async (cardId, channelId, revision) => { + if (cardId) { + return await card.actions.getChannelTopics(cardId, channelId, revision); + } + return await channel.actions.getTopics(channelId, revision) } - const getTopicAssetUrl = async (cardId, channelId, assetId) => { + const getTopicAssetUrl = (cardId, channelId, assetId) => { + if (cardId) { + return card.actions.getChannelTopicAssetUrl(cardId, channelId, topicId, assetId); + } + return channel.actions.getTopicAssetUrl(channelId, assetId); } const addTopic = async (cardId, channelId, message, asssets) => { + if (cardId) { + return await card.actions.addChannelTopic(cardId, channelId, message, assetId); + } + return await channel.actions.addTopic(channelId, message, assetId); } const setTopicSubject = async (cardId, channelId, topicId, data) => { + if (cardId) { + return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, data); + } + return await channel.actions.setTopicSubject(channelId, topicId, data); } - const removeChannel = async (cardId, channelId) => { + const remove = async (cardId, channelId) => { + if (cardId) { + return await card.actions.removeChannel(cardId, channelId); + } + return await channel.actions.remove(channelId); } - const removeChannelTopic = async (cardId, channelId, topicId) => { + const removeTopic = async (cardId, channelId, topicId) => { + if (cardId) { + return await card.actions.removeChannelTopic(cardId, channelId, topicId); + } + return await channel.actions.remvoeTopic(channelId, topicId); } const sync = async () => { @@ -85,10 +113,10 @@ export function useConversationContext() { // set channel topics if (syncRevision.current != item.syncRevision) { if (syncRevision.current) { - const topics = getTopicDeltaItems(cardId, channelId); + const topics = await getTopicDeltaItems(cardId, channelId); } else { - const topics = getTopicItems(cardId, channelId); + const topics = await getTopicItems(cardId, channelId); } if (curView === setView.current) { syncRevision.current = item.syncRevision; @@ -97,7 +125,10 @@ export function useConversationContext() { // sync from server to store if (item.topicRevision !== item.syncRevision) { - console.log("pull latest topics"); + const res = await getTopics(cardId, channelId, item.syncRevision) +res.topics.forEach(topic => { + console.log(topic.data); +}); } // update revision