From a9f66f8e0e09259989323fe94c098c57f11c317d Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Fri, 16 Sep 2022 11:28:54 -0700 Subject: [PATCH] fixed card syncing error --- app/mobile/src/api/getContactChannels.js | 7 +------ app/mobile/src/context/useCardContext.hook.js | 13 +++++++------ app/mobile/src/context/useStoreContext.hook.js | 8 ++++---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/mobile/src/api/getContactChannels.js b/app/mobile/src/api/getContactChannels.js index d4769672..3edd9b1c 100644 --- a/app/mobile/src/api/getContactChannels.js +++ b/app/mobile/src/api/getContactChannels.js @@ -1,11 +1,6 @@ import { checkResponse, fetchWithTimeout } from './fetchUtil'; export async function getContactChannels(server, token, viewRevision, channelRevision) { - let host = ""; - if (server) { - host = `https://${server}`; - } - let param = "?contact=" + token if (viewRevision != null) { param += '&viewRevision=' + viewRevision @@ -13,7 +8,7 @@ export async function getContactChannels(server, token, viewRevision, channelRev if (channelRevision != null) { param += '&channelRevision=' + channelRevision } - let channels = await fetchWithTimeout(`${host}/content/channels${param}`, { method: 'GET' }); + let channels = await fetchWithTimeout(`https://${server}/content/channels${param}`, { method: 'GET' }); checkResponse(channels) return await channels.json() } diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index bf4c43d1..5db18f34 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -4,6 +4,7 @@ import { getCards } from 'api/getCards'; import { getCardProfile } from 'api/getCardProfile'; import { getCardDetail } from 'api/getCardDetail'; +import { getContactChannels } from 'api/getContactChannels'; import { getContactChannelTopics } from 'api/getContactChannelTopics'; import { getContactChannelDetail } from 'api/getContactChannelDetail'; import { getContactChannelSummary } from 'api/getContactChannelSummary'; @@ -60,20 +61,20 @@ export function useCardContext() { } const status = await store.actions.getCardItemStatus(guid, card.id); - const cardServer = status.cardProfile.node; - const cardToken = status.cardDetail.token; + const cardServer = status.profile.node; + const cardToken = status.profile.guid + '.' + status.detail.token; if (status.detail.status === 'connected') { try { const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = card.data; if (status.notifiedView !== notifiedView) { await store.actions.clearCardChannelItems(guid, card.id); - await updateCardChannelItems(guid, card.id, cardServer, cardToken, notifiedView, null); + await updateCardChannelItems(card.id, cardServer, cardToken, notifiedView, null); await store.actions.setCardItemNotifiedChannel(guid, card.id, notifiedChannel); await store.actions.setCardItemNotifiedView(guid, card.id, notifiedView); } else { if (status.notifiedChannel != notifiedChannel) { - await updateCardChannelItems(guid, card.id, cardServer, cardToken, status.notifiedChannel) + await updateCardChannelItems(card.id, cardServer, cardToken, status.notifiedChannel) await store.actions.setCardItemNotifiedChannel(guid, card.id, notifiedView, notifiedChannel); } } @@ -82,12 +83,12 @@ export function useCardContext() { await store.actions.setCardItemNotifiedProfile(guid, card.id, notifiedProfile); } if (status.offsync) { - await store.actions.clearCardItemOffsync(guid, cardId); + await store.actions.clearCardItemOffsync(guid, card.id); } } catch(err) { console.log(err); - await store.actions.setCardItemOffsync(guid, cardId); + await store.actions.setCardItemOffsync(guid, card.id); } } } diff --git a/app/mobile/src/context/useStoreContext.hook.js b/app/mobile/src/context/useStoreContext.hook.js index 529fa478..0589dd95 100644 --- a/app/mobile/src/context/useStoreContext.hook.js +++ b/app/mobile/src/context/useStoreContext.hook.js @@ -1,7 +1,7 @@ import { useEffect, useState, useRef, useContext } from 'react'; import SQLite from "react-native-sqlite-storage"; -const DATABAG_DB = 'databag_v017.db'; +const DATABAG_DB = 'databag_v019.db'; export function useStoreContext() { const [state, setState] = useState({}); @@ -15,8 +15,8 @@ export function useStoreContext() { await db.current.executeSql(`CREATE TABLE IF NOT EXISTS channel_${guid} (channel_id text, revision integer, detail_revision integer, topic_revision integer, detail text, summary text, offsync integer, unique(channel_id))`); await db.current.executeSql(`CREATE TABLE IF NOT EXISTS channel_topic_${guid} (channel_id text, topic_id text, revision integer, detail_revision integer, detail text, unique(channel_id, topic_id))`); await db.current.executeSql(`CREATE TABLE IF NOT EXISTS card_${guid} (card_id text, revision integer, detail_revision integer, profile_revision integer, detail text, profile text, notified_view integer, notified_article integer, notified_profile integer, notified_channel integer, offsync integer, unique(card_id))`); - await db.current.executeSql(`CREATE TABLE IF NOT EXISTS contact_channel_${guid} (card_id text, channel_id text, revision integer, detail_revision integer, topic_revision integer, detail text, summary text, offsync integer, unique(card_id, channel_id))`); - await db.current.executeSql(`CREATE TABLE IF NOT EXISTS contact_channel_topic_${guid} (card_id text, channel_id text, topic_id text, revision integer, detail_revision integer, detail text, unique(card_id, channel_id, topic_id))`); + await db.current.executeSql(`CREATE TABLE IF NOT EXISTS card_channel_${guid} (card_id text, channel_id text, revision integer, detail_revision integer, topic_revision integer, detail text, summary text, offsync integer, unique(card_id, channel_id))`); + await db.current.executeSql(`CREATE TABLE IF NOT EXISTS card_channel_topic_${guid} (card_id text, channel_id text, topic_id text, revision integer, detail_revision integer, detail text, unique(card_id, channel_id, topic_id))`); } const actions = { @@ -241,7 +241,7 @@ export function useStoreContext() { })); }, clearCardChannelItems: async (guid, cardId) => { - await db.current.executeSql(`DELETE FROM card_channel_${guid} WHERE card_id=?`, [cardID]); + await db.current.executeSql(`DELETE FROM card_channel_${guid} WHERE card_id=?`, [cardId]); }, }