mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
removing delta methods from store
This commit is contained in:
parent
ad781e6c81
commit
40a29e17c3
@ -440,13 +440,9 @@ export function useCardContext() {
|
||||
const { guid } = session.current;
|
||||
return await store.actions.getCardChannelTopicItems(guid, cardId, channelId);
|
||||
},
|
||||
getChannelTopicDeltaItems: async (cardId, channelId, revision) => {
|
||||
setChannelTopicItem: async (cardId, channelId, topicId, topic) => {
|
||||
const { guid } = session.current;
|
||||
return await store.actions.getCardChannelTopicDeltaItems(guid, cardId, channelId, revision);
|
||||
},
|
||||
setChannelTopicItem: async (cardId, channelId, topicId, channelRevision, topic) => {
|
||||
const { guid } = session.current;
|
||||
return await store.actions.setCardChannelTopicItem(guid, cardId, channelId, topicId, channelRevision, topic);
|
||||
return await store.actions.setCardChannelTopicItem(guid, cardId, channelId, topicId, topic);
|
||||
},
|
||||
clearChannelTopicItem: async (cardId, channelId, topicId) => {
|
||||
const { guid } = session.current;
|
||||
@ -457,39 +453,32 @@ 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);
|
||||
return await getContactChannelTopic(profile.node, `${profile.guid}.${detail.token}`, channelId, topicId);
|
||||
},
|
||||
getChannelTopics: async (cardId, channelId, revision) => {
|
||||
const { guid } = session.current;
|
||||
const { detail, profile } = getCard(cardId);
|
||||
return await getContactChannelTopics(profile.node, detail.token, channelId, revision);
|
||||
return await getContactChannelTopics(profile.node, `${profile.guid}.${detail.token}`, channelId, revision);
|
||||
},
|
||||
getChannelTopicAssetUrl: (cardId, channelId, topicId, assetId) => {
|
||||
const { guid } = session.current;
|
||||
const { detail, profile } = getCard(cardId);
|
||||
return getContactChannelTopicAssetUrl(profile.node, detail.token, channelId, topicId, assetId);
|
||||
return getContactChannelTopicAssetUrl(profile.node, `${profile.guid}.${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);
|
||||
return await addChannelTopic(profile.node, `${profile.guid}.${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);
|
||||
return await setContactChannelTopicSubject(profile.node, `${profile.guid}.${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);
|
||||
return await removeChannel(profile.node, `${profile.guid}.${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);
|
||||
return await removeChannelTopic(profile.node, `${profile.guid}.${detail.token}`, channelId, topicId);
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -184,13 +184,9 @@ export function useChannelContext() {
|
||||
const { guid } = session.current;
|
||||
return await store.actions.getChannelTopicItems(guid, channelId);
|
||||
},
|
||||
getTopicDeltaItems: async (channelId, revision) => {
|
||||
setTopicItem: async (channelId, topicId, topic) => {
|
||||
const { guid } = session.current;
|
||||
return await store.actions.getChannelTopicDeltaItems(guid, channelId, revision);
|
||||
},
|
||||
setTopicItem: async (channelId, topicId, channelRevision, topic) => {
|
||||
const { guid } = session.current;
|
||||
return await store.actions.setChannelTopicItem(guid, channelId, topicId, channelRevision, topic);
|
||||
return await store.actions.setChannelTopicItem(guid, channelId, topicId, topic);
|
||||
},
|
||||
clearTopicItem: async (channelId, topicId) => {
|
||||
const { guid } = session.current;
|
||||
|
@ -102,42 +102,47 @@ export function useConversationContext() {
|
||||
if (item && (item.revision !== revision.current || item.syncRevision != syncRevision.current)) {
|
||||
syncing.current = true;
|
||||
|
||||
// set channel details
|
||||
if (detailRevision.current != item.detailRevision) {
|
||||
try {
|
||||
// set channel details
|
||||
if (detailRevision.current != item.detailRevision) {
|
||||
if (curView === setView.current) {
|
||||
setChannel(item);
|
||||
detailRevision.current = item.detailRevision;
|
||||
}
|
||||
}
|
||||
|
||||
// set channel topics
|
||||
if (syncRevision.current != item.syncRevision) {
|
||||
if (syncRevision.current) {
|
||||
const topics = await getTopicDeltaItems(cardId, channelId);
|
||||
}
|
||||
else {
|
||||
const topics = await getTopicItems(cardId, channelId);
|
||||
}
|
||||
if (curView === setView.current) {
|
||||
syncRevision.current = item.syncRevision;
|
||||
}
|
||||
}
|
||||
|
||||
// sync from server to store
|
||||
if (item.topicRevision !== item.syncRevision) {
|
||||
const res = await getTopics(cardId, channelId, item.syncRevision)
|
||||
}
|
||||
|
||||
// update revision
|
||||
if (curView === setView.current) {
|
||||
setChannel(item);
|
||||
detailRevision.current = item.detailRevision;
|
||||
revision.current = item.revision;
|
||||
//TODO set to synced state
|
||||
}
|
||||
}
|
||||
|
||||
// set channel topics
|
||||
if (syncRevision.current != item.syncRevision) {
|
||||
if (syncRevision.current) {
|
||||
const topics = await getTopicDeltaItems(cardId, channelId);
|
||||
}
|
||||
else {
|
||||
const topics = await getTopicItems(cardId, channelId);
|
||||
}
|
||||
if (curView === setView.current) {
|
||||
syncRevision.current = item.syncRevision;
|
||||
}
|
||||
syncing.current = false;
|
||||
sync();
|
||||
}
|
||||
|
||||
// sync from server to store
|
||||
if (item.topicRevision !== item.syncRevision) {
|
||||
const res = await getTopics(cardId, channelId, item.syncRevision)
|
||||
res.topics.forEach(topic => {
|
||||
console.log(topic.data);
|
||||
});
|
||||
catch(err) {
|
||||
console.log(err);
|
||||
syncing.current = false;
|
||||
//TODO set to unsynced state
|
||||
}
|
||||
|
||||
// update revision
|
||||
if (curView === setView.current) {
|
||||
revision.current = item.revision;
|
||||
}
|
||||
|
||||
syncing.current = false;
|
||||
sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { useEffect, useState, useRef, useContext } from 'react';
|
||||
import SQLite from "react-native-sqlite-storage";
|
||||
|
||||
const DATABAG_DB = 'databag_v036.db';
|
||||
const DATABAG_DB = 'databag_v037.db';
|
||||
|
||||
export function useStoreContext() {
|
||||
const [state, setState] = useState({});
|
||||
@ -13,10 +13,10 @@ export function useStoreContext() {
|
||||
|
||||
const initSession = async (guid) => {
|
||||
await db.current.executeSql(`CREATE TABLE IF NOT EXISTS channel_${guid} (channel_id text, revision integer, detail_revision integer, topic_revision integer, sync_revision integer, detail text, summary text, offsync integer, read_revision integer, unique(channel_id))`);
|
||||
await db.current.executeSql(`CREATE TABLE IF NOT EXISTS channel_topic_${guid} (channel_id text, topic_id text, channel_revision integer, revision integer, detail_revision integer, detail text, unique(channel_id, topic_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, blocked integer, unique(card_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, sync_revision integer, detail text, summary text, offsync integer, blocked integer, read_revision 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, channel_revision integer, 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_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 = {
|
||||
@ -230,16 +230,7 @@ export function useStoreContext() {
|
||||
detail: decodeObject(topic.detail),
|
||||
}));
|
||||
},
|
||||
getChannelTopicDeltaItems: async (guid, channelId, revision) => {
|
||||
const values = await getAppValues(db.current, `SELECT topic_id, revision, detail_revision, detail FROM channel_topic_${guid} WHERE channel_id=? AND channel_revision>?`, [channelId, revision]);
|
||||
return values.map(topic => ({
|
||||
topicId: topic.topic_id,
|
||||
revision: topic.revision,
|
||||
detailRevision: topic.detail_revision,
|
||||
detail: decodeObject(topic.detail),
|
||||
}));
|
||||
},
|
||||
setChannelTopicItem: async (guid, channelId, topicId, channelRevision, topic) => {
|
||||
setChannelTopicItem: async (guid, channelId, topicId, topic) => {
|
||||
const { id, revision, data } = channel;
|
||||
await db.current.executeSql(`INSERT OR REPLACE INTO channel_topic_${guid} (channel_id, topic_id, revision, channel_revision, detail_revision, detail) values (?, ?, ?, ?, ?, ?);`, [channelId, id, revision, channelRevision, data.detailRevision, encodeObject(data.topicDetail)]);
|
||||
},
|
||||
@ -311,16 +302,7 @@ export function useStoreContext() {
|
||||
detail: decodeObject(topic.detail),
|
||||
}));
|
||||
},
|
||||
getCardChannelTopicDeltaItems: async (guid, cardId, channelId, revision) => {
|
||||
const values = await getAppValues(db.current, `SELECT topic_id, revision, detail_revision, detail FROM card_channel_topic_${guid} WHERE card_id=? AND channel_id=? AND channel_revision>?`, [cardId, channelId, revision]);
|
||||
return values.map(topic => ({
|
||||
topicId: topic.topic_id,
|
||||
revision: topic.revision,
|
||||
detailRevision: topic.detail_revision,
|
||||
detail: decodeObject(topic.detail),
|
||||
}));
|
||||
},
|
||||
setCardChannelTopicItem: async (guid, cardId, channelId, topicId, channelRevision, topic) => {
|
||||
setCardChannelTopicItem: async (guid, cardId, channelId, topicId, topic) => {
|
||||
const { id, revision, data } = channel;
|
||||
await db.current.executeSql(`INSERT OR REPLACE INTO channel_topic_${guid} (card_id, channel_id, topic_id, revision, channel_revision, detail_revision, detail) values (?, ?, ?, ?, ?, ?, ?);`, [cardId, channelId, id, revision, channelRevision, data.detailRevision, encodeObject(data.topicDetail)]);
|
||||
},
|
||||
|
@ -23,8 +23,6 @@ export function Profile() {
|
||||
|
||||
const { state, actions } = useProfile();
|
||||
|
||||
console.log(state.imageSource);
|
||||
|
||||
const setVisible = async (visible) => {
|
||||
try {
|
||||
await actions.setVisible(visible);
|
||||
|
Loading…
Reference in New Issue
Block a user