mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
fixed card syncing error
This commit is contained in:
parent
16c2385f2d
commit
a9f66f8e0e
@ -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()
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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]);
|
||||
},
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user