refactoring conversation context in mobiel app

This commit is contained in:
Roland Osborne 2023-02-13 16:09:31 -08:00
parent 7e03cdcc97
commit eca43835be
4 changed files with 364 additions and 643 deletions

View File

@ -82,12 +82,15 @@ export function useCardContext() {
};
};
const setCardChannelField = (cardId, channelId, field, value) => {
const setCardChannelField = (cardId, channelId, field, value, field2, value2) => {
const card = cards.current.get(cardId);
if (card) {
const channel = card.channels.get(channelId);
if (channel) {
channel[field] = value;
if(field2) {
channel[field2] = value2;
}
card.channels.set(channelId, { ...channel });
cards.current.set(cardId, { ...card });
}
@ -374,7 +377,7 @@ export function useCardContext() {
getTopics: async (cardId, channelId, revision, count, begin, end) => {
const { detail, profile } = cards.current.get(cardId) || {};
const cardToken = `${profile?.guid}.${detail?.token}`;
return await store.actions.getCardChannelTopicItems(guid, cardId, channelId);
return await getContactChannelTopics(profile?.node, cardToken, channelId);
},
getChannelTopic: async (cardId, channelId, topicId) => {
const { detail, profile } = cards.current.get(cardId) || {};
@ -401,6 +404,11 @@ export function useCardContext() {
await store.actions.setCardChannelItemTopicMarker(guid, cardId, channelId, marker);
setCardField(cardId, 'topicMarker', marker);
},
setChannelMarkerAndSync: async (cardId, channelId, marker, revision) => {
const { guid } = access.current;
await store.actions.setCardChannelItemMarkerAndSync(guid, cardId, channelId, marker, revision);
setCardField(cardId, 'topicMarker', marker, 'syncRevision', revision);
},
setCardFlag: async (cardId) => {
const { guid } = acccess.current;
await store.actions.setCardItemBlocked(guid, cardId);
@ -451,15 +459,15 @@ export function useCardContext() {
const { guid } = access.current;
return await store.actions.getCardChannelTopicItems(guid, cardId, channelId);
},
setChannelTopicItem: async (cardId, channelId, topicId, topic) => {
setTopicItem: async (cardId, channelId, topicId, topic) => {
const { guid } = access.current;
return await store.actions.setCardChannelTopicItem(guid, cardId, channelId, topicId, topic);
},
clearChannelTopicItem: async (cardId, channelId, topicId) => {
clearTopicItem: async (cardId, channelId, topicId) => {
const { guid } = access.current;
return await store.actions.clearCardChannelTopicItem(guid, cardId, channelId, topicId);
},
clearChannelTopicItems: async (cardId, channelId) => {
clearTopicItems: async (cardId, channelId) => {
const { guid } = access.current;
return await store.actions.clearCardChannelTopicItems(guid, cardId, channelId);
},

View File

@ -47,9 +47,12 @@ export function useChannelContext() {
}
}
const setChannelField = (channelId, field, value) => {
const setChannelField = (channelId, field, value, field2, value2) => {
const channel = channels.get(channelId) || {};
channel[field] = value;
if (field2) {
channel[field2] = value2;
}
channels.set(channelId, { ...channel });
updateState({ channels: channels.current });
};
@ -223,6 +226,11 @@ export function useChannelContext() {
await store.actions.setChannelItemTopicMarker(guid, channelId, revision);
setChannelField(channelId, 'topicMarker', marker);
},
setMarkerAndSync: async (channelId, marker, revision) => {
const { guid } = access.current;
await store.actions.setChannelItemMarkerAndSync(guid, channelId, revision);
setChannelField(channelId, 'topicMarker', marker, 'syncRevision', revision);
},
setChannelFlag: async (channelId) => {
const { guid } = access.current;
await store.actions.setChannelItemBlocked(guid, channelId);
@ -249,7 +257,7 @@ export function useChannelContext() {
const { server, guid } = access.current;
return await addFlag(server, guid, channelId, topicId);
},
getTopicItems: async (channelId, revision, count, begin, end) => {
getTopicItems: async (channelId) => {
const { guid } = access.current;
return await store.actions.getChannelTopicItems(guid, channelId);
},

File diff suppressed because it is too large Load Diff

View File

@ -159,17 +159,6 @@ export function useStoreContext() {
blocked: values[0].blocked,
};
},
getCardItemView: async (guid, cardId) => {
const values = await getAppValues(db.current, `SELECT revision, detail_revision, profile_revision FROM card_${guid} WHERE card_id=?`, [cardId]);
if (!values.length) {
return null;
}
return {
revision: values[0].revision,
detailRevision: values[0].detail_revision,
profileRevision: values[0].profile_revision,
};
},
getCardItems: async (guid) => {
const values = await getAppValues(db.current, `SELECT card_id, revision, detail_revision, profile_revision, detail, profile, offsync, blocked, notified_view, notified_profile, notified_article, notified_channel FROM card_${guid}`, []);
return values.map(card => ({
@ -215,6 +204,9 @@ export function useStoreContext() {
setChannelItemTopicMarker: async (guid, channelId, marker) => {
await db.current.executeSql(`UPDATE channel_${guid} set topic_marker=? where channel_id=?`, [marker, channelId]);
},
setChannelItemMarkerAndSync: async (guid, channelId, marker, revision) => {
await db.current.executeSql(`UPDATE channel_${guid} set sync_revision=?, topic_marker=? where channel_id=?`, [revision, maker, channelId]);
},
setChannelItemBlocked: async (guid, channelId) => {
await db.current.executeSql(`UPDATE channel_${guid} set blocked=? where channel_id=?`, [1, channelId]);
},
@ -233,17 +225,6 @@ export function useStoreContext() {
setChannelItemUnsealedSummary: async (guid, channelId, revision, unsealed) => {
await db.current.executeSql(`UPDATE channel_${guid} set unsealed_summary=? where topic_revision=? AND channel_id=?`, [encodeObject(unsealed), revision, channelId]);
},
getChannelItemView: async (guid, channelId) => {
const values = await getAppValues(db.current, `SELECT revision, detail_revision, topic_revision FROM channel_${guid} WHERE channel_id=?`, [channelId]);
if (!values.length) {
return null;
}
return {
revision: values[0].revision,
detailRevision: values[0].detail_revision,
topicRevision: values[0].topic_revision,
};
},
getChannelItems: async (guid) => {
const values = await getAppValues(db.current, `SELECT channel_id, read_revision, revision, sync_revision, blocked, detail_revision, topic_revision, topic_marker, detail, unsealed_detail, summary, unsealed_summary FROM channel_${guid}`, []);
return values.map(channel => ({
@ -318,6 +299,9 @@ export function useStoreContext() {
setCardChannelItemTopicMarker: async (guid, cardId, channelId, marker) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set topic_marker=? where card_id=? and channel_id=?`, [marker, cardId, channelId]);
},
setCardChannelItemMakerAndSync: async (guid, cardId, channelId, marker, revision) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set topic_marker=?, sync_revision=? where card_id=? and channel_id=?`, [marker, revision, cardId, channelId]);
},
setCardChannelItemDetail: async (guid, cardId, channelId, revision, detail) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set detail_revision=?, detail=?, unsealed_detail=null where card_id=? and channel_id=?`, [revision, encodeObject(detail), cardId, channelId]);
},
@ -330,17 +314,6 @@ export function useStoreContext() {
setCardChannelItemUnsealedSummary: async (guid, cardId, channelId, revision, unsealed) => {
await db.current.executeSql(`UPDATE card_channel_${guid} set unsealed_summary=? where topic_revision=? AND card_id=? AND channel_id=?`, [encodeObject(unsealed), revision, cardId, channelId]);
},
getCardChannelItemView: async (guid, cardId, channelId) => {
const values = await getAppValues(db.current, `SELECT revision, detail_revision, topic_revision FROM card_channel_${guid} WHERE card_id=? and channel_id=?`, [cardId, channelId]);
if (!values.length) {
return null;
}
return {
revision: values[0].revision,
detailRevision: values[0].detail_revision,
topicRevision: values[0].topic_revision,
};
},
getCardChannelItems: async (guid) => {
const values = await getAppValues(db.current, `SELECT card_id, channel_id, read_revision, sync_revision, revision, blocked, detail_revision, topic_revision, topic_marker, detail, unsealed_detail, summary, unsealed_summary FROM card_channel_${guid}`, []);
return values.map(channel => ({