fixing conversation load sequence

This commit is contained in:
Roland Osborne 2023-03-02 11:18:06 -08:00
parent f1df322523
commit c8dec078aa
9 changed files with 91 additions and 78 deletions

View File

@ -567,7 +567,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
@ -639,7 +639,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "c++14";
CLANG_CXX_LANGUAGE_STANDARD = "c++17";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;

View File

@ -1,6 +1,10 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function getContactChannelTopics(server, token, channelId, revision, count, begin, end) {
console.log("GETTING:", revision, count, begin, end);
let rev = ''
if (revision != null) {
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}`,
{ method: 'GET' });
checkResponse(topics)
console.log(topics.headers);
return {
marker: topics.headers.get('topic-marker'),
revision: topics.headers.get('topic-revision'),

View File

@ -411,7 +411,7 @@ export function useCardContext() {
getTopics: async (cardId, channelId, revision, count, begin, end) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
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) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;

View File

@ -28,18 +28,21 @@ export function useConversationContext() {
const conversationId = useRef(null);
const topics = useRef(new Map());
const curSyncRevision = useRef();
const curTopicMarker = useRef();
const updateState = (value) => {
setState((s) => ({ ...s, ...value }))
}
const sync = async () => {
console.log("SYNCING!");
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 ignoreRevision = force.current;
const conversation = conversationId.current;
let curRevision, setRevision, marker;
syncing.current = true;
update.current = false;
@ -50,39 +53,30 @@ console.log("SYNCING!");
reset.current = false;
loaded.current = false;
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) {
const { cardId, channelId } = conversation;
const cardValue = cardId ? card.state.cards.get(cardId) : null;
const channelValue = cardId ? cardValue?.channels.get(channelId) : channel.state.channels.get(channelId);
const { topicRevision } = channelValue || {};
if (channelValue) {
const { topicRevision, syncRevision, topicMarker } = channelValue;
curRevision = topicRevision;
setRevision = syncRevision;
marker = topicMarker;
updateState({ card: cardValue, channel: channelValue });
if (!loaded.current) {
const topicItems = await getTopicItems(cardId, channelId);
for (let topic of topicItems) {
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;
}
else {
updateState({ card: cardValue, channel: channelValue });
}
}
else {
console.log("failed to load conversation");
@ -90,34 +84,37 @@ console.log("SYNCING!");
return;
}
if (ignoreRevision || curRevision !== setRevision) {
try {
if (!marker) {
try {
if (!curTopicMarker.current) {
console.log("FIRST GET");
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, null);
await setTopicDelta(cardId, channelId, delta.topics);
await setMarkerAndSync(cardId, channelId, delta.marker, curRevision);
}
if (loadMore && marker) {
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, null);
await setTopicDelta(cardId, channelId, delta.topics);
await setMarkerAndSync(cardId, channelId, delta.marker, topicRevision);
curTopicMarker.current = delta.marker;
console.log("---", delta);
curSyncRevision.current = topicRevision;
}
if (loadMore && marker) {
console.log("MORE GET");
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, marker);
await setTopicDelta(cardId, channelId, delta.topics);
await setTopicMarker(cardId, channelId, delta.marker);
}
if (ignoreRevision || curRevision !== setRevision) {
const delta = await getTopicDelta(cardId, channelId, null, COUNT, null, curTopicMarker.current);
await setTopicDelta(cardId, channelId, delta.topics);
await setTopicMarker(cardId, channelId, delta.marker);
curTopicMarker.current = delta.marker;
}
if (ignoreRevision || topicRevision !== curSyncRevision.current) {
console.log("UPDATE");
const delta = await getTopicDelta(cardId, channelId, setRevision, null, marker, null);
await setTopicDelta(cardId, channelId, delta.topics);
await setSyncRevision(cardId, channelId, curRevision);
}
}
catch(err) {
console.log(err);
updateState({ offysnc: true });
syncing.current = false;
return
const delta = await getTopicDelta(cardId, channelId, curSyncRevision.currnet, null, curTopicMarker.current, null);
await setTopicDelta(cardId, channelId, delta.topics);
await setSyncRevision(cardId, channelId, topicRevision);
curSyncRevision.current = topicRevision;
}
}
catch(err) {
console.log(err);
updateState({ offysnc: true });
syncing.current = false;
return
}
}
syncing.current = false;
@ -156,11 +153,13 @@ console.log("UPDATE");
const actions = {
setConversation: async (cardId, channelId) => {
console.log(">>> SET");
conversationId.current = { cardId, channelId };
reset.current = true;
await sync();
},
clearConversation: async () => {
console.log(">>> CLEAR");
conversationId.current = null;
reset.current = true;
await sync();
@ -183,6 +182,15 @@ console.log("UPDATE");
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) => {
const { cardId, channelId } = conversationId.current || {};
if (cardId) {
@ -389,16 +397,6 @@ console.log("UPDATE");
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) => {
if (cardId) {
return card.actions.getTopicAssetUrl(cardId, channelId, topicId, assetId);

View File

@ -1,7 +1,7 @@
import { useEffect, useState, useRef, useContext } from 'react';
import SQLite from "react-native-sqlite-storage";
const DATABAG_DB = 'db_v_113.db';
const DATABAG_DB = 'db_v_114.db';
export function useStoreContext() {
const [state, setState] = useState({});

View File

@ -46,16 +46,23 @@ export function Session() {
const [cardId, setCardId] = useState();
const [channelId, setChannelId] = useState();
const openConversation = async (navigation, card, channel) => {
setCardId(card);
setChannelId(channel);
navigation.navigate('conversation');
}
const closeConversation = (navigation) => {
const setConversation = (card, channel) => {
(async () => {
conversation.actions.setConversation(card, channel);
setCardId(card);
setChannelId(channel);
navigation.navigate('conversation');
})();
};
const closeConversation = () => {
console.log("CLOSE CALLED!");
conversation.actions.clearConversation();
setCardId(null);
setChannelId(null);
navigation.popToTop();
}
};
const openDetails = (navigation) => {
navigation.navigate('details');
}
@ -68,7 +75,7 @@ export function Session() {
</ConversationStack.Screen>
<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 name="details" options={{ ...stackParams, headerTitle: (props) => (
@ -147,11 +154,16 @@ export function Session() {
const [channelId, setChannelId] = useState();
const setConversation = (card, channel) => {
setCardId(card);
setChannelId(channel);
setChannel(true);
(async () => {
conversation.actions.setConversation(card, channel);
setCardId(card);
setChannelId(channel);
setChannel(true);
})();
};
const closeConversation = () => {
console.log("CLOSE CALLED!");
conversation.actions.clearConversation();
setCardId(null);
setChannelId(null);
setChannel(false);
@ -193,7 +205,7 @@ export function Session() {
<View style={styles.conversation}>
{ channel && (
<SafeAreaView edges={['top', 'bottom', 'right']}>
<Conversation cardId={cardId} channelId={channelId} closeConversation={closeConversation} openDetails={openDetails} />
<Conversation closeConversation={closeConversation} openDetails={openDetails} />
</SafeAreaView>
)}
{ !channel && (

View File

@ -11,7 +11,7 @@ import { TopicItem } from './topicItem/TopicItem';
export function Conversation({ navigation, cardId, channelId, closeConversation, openDetails }) {
const [ready, setReady] = useState(false);
const [ready, setReady] = useState(true);
const conversation = useContext(ConversationContext);
const { state, actions } = useConversation();
const ref = useRef();
@ -57,13 +57,8 @@ export function Conversation({ navigation, cardId, channelId, closeConversation,
}, [navigation, state.subject]);
useEffect(() => {
(async () => {
setReady(false);
await conversation.actions.setConversation(cardId, channelId);
setReady(true);
})();
return () => { conversation.actions.clearConversation(); };
}, [cardId, channelId]);
return () => { closeConversation(); };
}, []);
return (
<View style={styles.container}>

View File

@ -14,7 +14,6 @@ export const styles = StyleSheet.create({
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
flexGrow: 1,
borderBottomWidth: 1,
borderColor: Colors.divider,
height: 48,

View File

@ -41,6 +41,8 @@ export function useConversation() {
const filtered = sorted.filter(item => !(item.blocked === 1));
updateState({ logo, subject, topics: filtered });
console.log("UPDATE TOPICS", filtered.length);
}, [conversation.state, card.state, profile.state]);