mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
fixing conversation load sequence
This commit is contained in:
parent
f1df322523
commit
c8dec078aa
@ -567,7 +567,7 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
|
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
@ -639,7 +639,7 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||||
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
|
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
|
||||||
CLANG_CXX_LIBRARY = "libc++";
|
CLANG_CXX_LIBRARY = "libc++";
|
||||||
CLANG_ENABLE_MODULES = YES;
|
CLANG_ENABLE_MODULES = YES;
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
CLANG_ENABLE_OBJC_ARC = YES;
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) {
|
export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) {
|
||||||
|
|
||||||
|
console.log("GETTING:", revision, count, begin, end);
|
||||||
|
|
||||||
|
|
||||||
let rev = ''
|
let rev = ''
|
||||||
if (revision != null) {
|
if (revision != null) {
|
||||||
rev = `&revision=${revision}`
|
rev = `&revision=${revision}`
|
||||||
@ -20,6 +24,9 @@ export async function getContactChannelTopics(server, token, channelId, revision
|
|||||||
let topics = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}${rev}${cnt}${bgn}${edn}`,
|
let topics = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}${rev}${cnt}${bgn}${edn}`,
|
||||||
{ method: 'GET' });
|
{ method: 'GET' });
|
||||||
checkResponse(topics)
|
checkResponse(topics)
|
||||||
|
|
||||||
|
console.log(topics.headers);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
marker: topics.headers.get('topic-marker'),
|
marker: topics.headers.get('topic-marker'),
|
||||||
revision: topics.headers.get('topic-revision'),
|
revision: topics.headers.get('topic-revision'),
|
||||||
|
@ -411,7 +411,7 @@ export function useCardContext() {
|
|||||||
getTopics: async (cardId, channelId, revision, count, begin, end) => {
|
getTopics: async (cardId, channelId, revision, count, begin, end) => {
|
||||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||||
const cardToken = `${profile?.guid}.${detail?.token}`;
|
const cardToken = `${profile?.guid}.${detail?.token}`;
|
||||||
return await getContactChannelTopics(profile?.node, cardToken, channelId);
|
return await getContactChannelTopics(profile?.node, cardToken, channelId, revision, count, begin, end);
|
||||||
},
|
},
|
||||||
getTopic: async (cardId, channelId, topicId) => {
|
getTopic: async (cardId, channelId, topicId) => {
|
||||||
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
const { detail, profile } = (cards.current.get(cardId) || {}).card;
|
||||||
|
@ -28,18 +28,21 @@ export function useConversationContext() {
|
|||||||
const conversationId = useRef(null);
|
const conversationId = useRef(null);
|
||||||
const topics = useRef(new Map());
|
const topics = useRef(new Map());
|
||||||
|
|
||||||
|
const curSyncRevision = useRef();
|
||||||
|
const curTopicMarker = useRef();
|
||||||
|
|
||||||
const updateState = (value) => {
|
const updateState = (value) => {
|
||||||
setState((s) => ({ ...s, ...value }))
|
setState((s) => ({ ...s, ...value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
const sync = async () => {
|
const sync = async () => {
|
||||||
|
|
||||||
console.log("SYNCING!");
|
|
||||||
if (!syncing.current && (reset.current || update.current || force.current || more.current)) {
|
if (!syncing.current && (reset.current || update.current || force.current || more.current)) {
|
||||||
|
|
||||||
|
console.log("SYNCING!", reset.current, update.current, force.current, more.current);
|
||||||
const loadMore = more.current;
|
const loadMore = more.current;
|
||||||
const ignoreRevision = force.current;
|
const ignoreRevision = force.current;
|
||||||
const conversation = conversationId.current;
|
const conversation = conversationId.current;
|
||||||
let curRevision, setRevision, marker;
|
|
||||||
|
|
||||||
syncing.current = true;
|
syncing.current = true;
|
||||||
update.current = false;
|
update.current = false;
|
||||||
@ -50,39 +53,30 @@ console.log("SYNCING!");
|
|||||||
reset.current = false;
|
reset.current = false;
|
||||||
loaded.current = false;
|
loaded.current = false;
|
||||||
topics.current = new Map();
|
topics.current = new Map();
|
||||||
|
|
||||||
let notification;
|
|
||||||
try {
|
|
||||||
notification = await getNotifications();
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateState({ offsync: false, channel: null, card: null, topics: topics.current, notification });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conversation) {
|
if (conversation) {
|
||||||
const { cardId, channelId } = conversation;
|
const { cardId, channelId } = conversation;
|
||||||
const cardValue = cardId ? card.state.cards.get(cardId) : null;
|
const cardValue = cardId ? card.state.cards.get(cardId) : null;
|
||||||
const channelValue = cardId ? cardValue?.channels.get(channelId) : channel.state.channels.get(channelId);
|
const channelValue = cardId ? cardValue?.channels.get(channelId) : channel.state.channels.get(channelId);
|
||||||
|
const { topicRevision } = channelValue || {};
|
||||||
|
|
||||||
if (channelValue) {
|
if (channelValue) {
|
||||||
const { topicRevision, syncRevision, topicMarker } = channelValue;
|
|
||||||
|
|
||||||
curRevision = topicRevision;
|
|
||||||
setRevision = syncRevision;
|
|
||||||
marker = topicMarker;
|
|
||||||
updateState({ card: cardValue, channel: channelValue });
|
|
||||||
|
|
||||||
if (!loaded.current) {
|
if (!loaded.current) {
|
||||||
const topicItems = await getTopicItems(cardId, channelId);
|
const topicItems = await getTopicItems(cardId, channelId);
|
||||||
for (let topic of topicItems) {
|
for (let topic of topicItems) {
|
||||||
topics.current.set(topic.topicId, topic);
|
topics.current.set(topic.topicId, topic);
|
||||||
}
|
}
|
||||||
updateState({ offsync: false, topics: topics.current });
|
updateState({ offsync: false, topics: topics.current, card: cardValue, channel: channelValue });
|
||||||
|
|
||||||
|
const { syncRevision, topicMarker } = channelValue;
|
||||||
|
curSyncRevision.current = syncRevision;
|
||||||
|
curTopicMarker.current = topicMarker;
|
||||||
loaded.current = true;
|
loaded.current = true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
updateState({ card: cardValue, channel: channelValue });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("failed to load conversation");
|
console.log("failed to load conversation");
|
||||||
@ -90,34 +84,37 @@ console.log("SYNCING!");
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ignoreRevision || curRevision !== setRevision) {
|
try {
|
||||||
try {
|
if (!curTopicMarker.current) {
|
||||||
if (!marker) {
|
|
||||||
console.log("FIRST GET");
|
console.log("FIRST GET");
|
||||||
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, null);
|
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, null);
|
||||||
await setTopicDelta(cardId, channelId, delta.topics);
|
await setTopicDelta(cardId, channelId, delta.topics);
|
||||||
await setMarkerAndSync(cardId, channelId, delta.marker, curRevision);
|
await setMarkerAndSync(cardId, channelId, delta.marker, topicRevision);
|
||||||
}
|
curTopicMarker.current = delta.marker;
|
||||||
if (loadMore && marker) {
|
console.log("---", delta);
|
||||||
|
curSyncRevision.current = topicRevision;
|
||||||
|
}
|
||||||
|
if (loadMore && marker) {
|
||||||
console.log("MORE GET");
|
console.log("MORE GET");
|
||||||
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, marker);
|
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, curTopicMarker.current);
|
||||||
await setTopicDelta(cardId, channelId, delta.topics);
|
await setTopicDelta(cardId, channelId, delta.topics);
|
||||||
await setTopicMarker(cardId, channelId, delta.marker);
|
await setTopicMarker(cardId, channelId, delta.marker);
|
||||||
}
|
curTopicMarker.current = delta.marker;
|
||||||
if (ignoreRevision || curRevision !== setRevision) {
|
}
|
||||||
|
if (ignoreRevision || topicRevision !== curSyncRevision.current) {
|
||||||
console.log("UPDATE");
|
console.log("UPDATE");
|
||||||
const delta = await getTopicDelta(cardId, channelId, setRevision, null, marker, null);
|
const delta = await getTopicDelta(cardId, channelId, curSyncRevision.currnet, null, curTopicMarker.current, null);
|
||||||
await setTopicDelta(cardId, channelId, delta.topics);
|
await setTopicDelta(cardId, channelId, delta.topics);
|
||||||
await setSyncRevision(cardId, channelId, curRevision);
|
await setSyncRevision(cardId, channelId, topicRevision);
|
||||||
}
|
curSyncRevision.current = topicRevision;
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
console.log(err);
|
|
||||||
updateState({ offysnc: true });
|
|
||||||
syncing.current = false;
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log(err);
|
||||||
|
updateState({ offysnc: true });
|
||||||
|
syncing.current = false;
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncing.current = false;
|
syncing.current = false;
|
||||||
@ -156,11 +153,13 @@ console.log("UPDATE");
|
|||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
setConversation: async (cardId, channelId) => {
|
setConversation: async (cardId, channelId) => {
|
||||||
|
console.log(">>> SET");
|
||||||
conversationId.current = { cardId, channelId };
|
conversationId.current = { cardId, channelId };
|
||||||
reset.current = true;
|
reset.current = true;
|
||||||
await sync();
|
await sync();
|
||||||
},
|
},
|
||||||
clearConversation: async () => {
|
clearConversation: async () => {
|
||||||
|
console.log(">>> CLEAR");
|
||||||
conversationId.current = null;
|
conversationId.current = null;
|
||||||
reset.current = true;
|
reset.current = true;
|
||||||
await sync();
|
await sync();
|
||||||
@ -183,6 +182,15 @@ console.log("UPDATE");
|
|||||||
await channel.actions.removeChannel(channelId);
|
await channel.actions.removeChannel(channelId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
getNotifications: async () => {
|
||||||
|
const { cardId, channelId } = conversationId.current || {};
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.getChannelNotifications(cardId, channelId);
|
||||||
|
}
|
||||||
|
else if (channelId) {
|
||||||
|
return await channel.actions.getNotifications(channelId);
|
||||||
|
}
|
||||||
|
},
|
||||||
setNotifications: async (notification) => {
|
setNotifications: async (notification) => {
|
||||||
const { cardId, channelId } = conversationId.current || {};
|
const { cardId, channelId } = conversationId.current || {};
|
||||||
if (cardId) {
|
if (cardId) {
|
||||||
@ -389,16 +397,6 @@ console.log("UPDATE");
|
|||||||
return await channel.actions.getTopic(channelId, topicId);
|
return await channel.actions.getTopic(channelId, topicId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const getNotifications = async (notification) => {
|
|
||||||
const { cardId, channelId } = conversationId.current || {};
|
|
||||||
if (cardId) {
|
|
||||||
return await card.actions.getChannelNotifications(cardId, channelId);
|
|
||||||
}
|
|
||||||
else if (channelId) {
|
|
||||||
return await channel.actions.getNotifications(channelId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const getTopicAssetUrl = (cardId, channelId, topicId, assetId) => {
|
const getTopicAssetUrl = (cardId, channelId, topicId, assetId) => {
|
||||||
if (cardId) {
|
if (cardId) {
|
||||||
return card.actions.getTopicAssetUrl(cardId, channelId, topicId, assetId);
|
return card.actions.getTopicAssetUrl(cardId, channelId, topicId, assetId);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useState, useRef, useContext } from 'react';
|
import { useEffect, useState, useRef, useContext } from 'react';
|
||||||
import SQLite from "react-native-sqlite-storage";
|
import SQLite from "react-native-sqlite-storage";
|
||||||
|
|
||||||
const DATABAG_DB = 'db_v_113.db';
|
const DATABAG_DB = 'db_v_114.db';
|
||||||
|
|
||||||
export function useStoreContext() {
|
export function useStoreContext() {
|
||||||
const [state, setState] = useState({});
|
const [state, setState] = useState({});
|
||||||
|
@ -46,16 +46,23 @@ export function Session() {
|
|||||||
const [cardId, setCardId] = useState();
|
const [cardId, setCardId] = useState();
|
||||||
const [channelId, setChannelId] = useState();
|
const [channelId, setChannelId] = useState();
|
||||||
|
|
||||||
const openConversation = async (navigation, card, channel) => {
|
|
||||||
setCardId(card);
|
const setConversation = (card, channel) => {
|
||||||
setChannelId(channel);
|
(async () => {
|
||||||
navigation.navigate('conversation');
|
conversation.actions.setConversation(card, channel);
|
||||||
}
|
setCardId(card);
|
||||||
const closeConversation = (navigation) => {
|
setChannelId(channel);
|
||||||
|
navigation.navigate('conversation');
|
||||||
|
})();
|
||||||
|
};
|
||||||
|
const closeConversation = () => {
|
||||||
|
console.log("CLOSE CALLED!");
|
||||||
|
conversation.actions.clearConversation();
|
||||||
setCardId(null);
|
setCardId(null);
|
||||||
setChannelId(null);
|
setChannelId(null);
|
||||||
navigation.popToTop();
|
navigation.popToTop();
|
||||||
}
|
};
|
||||||
|
|
||||||
const openDetails = (navigation) => {
|
const openDetails = (navigation) => {
|
||||||
navigation.navigate('details');
|
navigation.navigate('details');
|
||||||
}
|
}
|
||||||
@ -68,7 +75,7 @@ export function Session() {
|
|||||||
</ConversationStack.Screen>
|
</ConversationStack.Screen>
|
||||||
|
|
||||||
<ConversationStack.Screen name="conversation" options={stackParams}>
|
<ConversationStack.Screen name="conversation" options={stackParams}>
|
||||||
{(props) => <Conversation navigation={props.navigation} cardId={cardId} channelId={channelId} openDetails={() => openDetails(props.navigation)} closeConversation={closeConversation} /> }
|
{(props) => <Conversation navigation={props.navigation} openDetails={() => openDetails(props.navigation)} closeConversation={closeConversation} /> }
|
||||||
</ConversationStack.Screen>
|
</ConversationStack.Screen>
|
||||||
|
|
||||||
<ConversationStack.Screen name="details" options={{ ...stackParams, headerTitle: (props) => (
|
<ConversationStack.Screen name="details" options={{ ...stackParams, headerTitle: (props) => (
|
||||||
@ -147,11 +154,16 @@ export function Session() {
|
|||||||
const [channelId, setChannelId] = useState();
|
const [channelId, setChannelId] = useState();
|
||||||
|
|
||||||
const setConversation = (card, channel) => {
|
const setConversation = (card, channel) => {
|
||||||
setCardId(card);
|
(async () => {
|
||||||
setChannelId(channel);
|
conversation.actions.setConversation(card, channel);
|
||||||
setChannel(true);
|
setCardId(card);
|
||||||
|
setChannelId(channel);
|
||||||
|
setChannel(true);
|
||||||
|
})();
|
||||||
};
|
};
|
||||||
const closeConversation = () => {
|
const closeConversation = () => {
|
||||||
|
console.log("CLOSE CALLED!");
|
||||||
|
conversation.actions.clearConversation();
|
||||||
setCardId(null);
|
setCardId(null);
|
||||||
setChannelId(null);
|
setChannelId(null);
|
||||||
setChannel(false);
|
setChannel(false);
|
||||||
@ -193,7 +205,7 @@ export function Session() {
|
|||||||
<View style={styles.conversation}>
|
<View style={styles.conversation}>
|
||||||
{ channel && (
|
{ channel && (
|
||||||
<SafeAreaView edges={['top', 'bottom', 'right']}>
|
<SafeAreaView edges={['top', 'bottom', 'right']}>
|
||||||
<Conversation cardId={cardId} channelId={channelId} closeConversation={closeConversation} openDetails={openDetails} />
|
<Conversation closeConversation={closeConversation} openDetails={openDetails} />
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)}
|
)}
|
||||||
{ !channel && (
|
{ !channel && (
|
||||||
|
@ -11,7 +11,7 @@ import { TopicItem } from './topicItem/TopicItem';
|
|||||||
|
|
||||||
export function Conversation({ navigation, cardId, channelId, closeConversation, openDetails }) {
|
export function Conversation({ navigation, cardId, channelId, closeConversation, openDetails }) {
|
||||||
|
|
||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState(true);
|
||||||
const conversation = useContext(ConversationContext);
|
const conversation = useContext(ConversationContext);
|
||||||
const { state, actions } = useConversation();
|
const { state, actions } = useConversation();
|
||||||
const ref = useRef();
|
const ref = useRef();
|
||||||
@ -57,13 +57,8 @@ export function Conversation({ navigation, cardId, channelId, closeConversation,
|
|||||||
}, [navigation, state.subject]);
|
}, [navigation, state.subject]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
return () => { closeConversation(); };
|
||||||
setReady(false);
|
}, []);
|
||||||
await conversation.actions.setConversation(cardId, channelId);
|
|
||||||
setReady(true);
|
|
||||||
})();
|
|
||||||
return () => { conversation.actions.clearConversation(); };
|
|
||||||
}, [cardId, channelId]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
|
@ -14,7 +14,6 @@ export const styles = StyleSheet.create({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
flexGrow: 1,
|
|
||||||
borderBottomWidth: 1,
|
borderBottomWidth: 1,
|
||||||
borderColor: Colors.divider,
|
borderColor: Colors.divider,
|
||||||
height: 48,
|
height: 48,
|
||||||
|
@ -41,6 +41,8 @@ export function useConversation() {
|
|||||||
const filtered = sorted.filter(item => !(item.blocked === 1));
|
const filtered = sorted.filter(item => !(item.blocked === 1));
|
||||||
|
|
||||||
updateState({ logo, subject, topics: filtered });
|
updateState({ logo, subject, topics: filtered });
|
||||||
|
|
||||||
|
console.log("UPDATE TOPICS", filtered.length);
|
||||||
}, [conversation.state, card.state, profile.state]);
|
}, [conversation.state, card.state, profile.state]);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user