mirror of
https://github.com/balzack/databag.git
synced 2025-02-15 21:19:16 +00:00
more syncing of topics
This commit is contained in:
parent
c6485d5b47
commit
ad781e6c81
@ -42,6 +42,14 @@ export function useCardContext() {
|
|||||||
setState((s) => ({ ...s, ...value }))
|
setState((s) => ({ ...s, ...value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getCard = (cardId) => {
|
||||||
|
const card = cards.current.get(cardId);
|
||||||
|
if (!card) {
|
||||||
|
throw new Error('cared not found');
|
||||||
|
}
|
||||||
|
return card;
|
||||||
|
}
|
||||||
|
|
||||||
const setCard = (cardId, card) => {
|
const setCard = (cardId, card) => {
|
||||||
let updated = cards.current.get(cardId);
|
let updated = cards.current.get(cardId);
|
||||||
if (updated == null) {
|
if (updated == null) {
|
||||||
@ -449,18 +457,39 @@ export function useCardContext() {
|
|||||||
return await store.actions.clearCardChannelTopicItems(guid, cardId, channelId);
|
return await store.actions.clearCardChannelTopicItems(guid, cardId, channelId);
|
||||||
},
|
},
|
||||||
getChannelTopic: async (cardId, channelId, topicId) => {
|
getChannelTopic: async (cardId, channelId, topicId) => {
|
||||||
|
const { guid } = session.current;
|
||||||
|
const { detail, profile } = getCard(cardId);
|
||||||
|
return await getContactChannelTopic(profile.node, detail.token, channelId, topicId);
|
||||||
},
|
},
|
||||||
getChannelTopics: async (cardId, channelId) => {
|
getChannelTopics: async (cardId, channelId, revision) => {
|
||||||
|
const { guid } = session.current;
|
||||||
|
const { detail, profile } = getCard(cardId);
|
||||||
|
return await getContactChannelTopics(profile.node, detail.token, channelId, revision);
|
||||||
},
|
},
|
||||||
getChannelTopicAssetUrl: async (cardId, channelId, assetId) => {
|
getChannelTopicAssetUrl: (cardId, channelId, topicId, assetId) => {
|
||||||
|
const { guid } = session.current;
|
||||||
|
const { detail, profile } = getCard(cardId);
|
||||||
|
return getContactChannelTopicAssetUrl(profile.node, detail.token, channelId, topicId, assetId);
|
||||||
},
|
},
|
||||||
addChannelTopic: async (cardId, channelId, message, assets) => {
|
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);
|
||||||
},
|
},
|
||||||
setChannelTopicSubject: async (cardId, channelId, topicId, data) => {
|
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);
|
||||||
},
|
},
|
||||||
removeChannel: async (cardId, channelId) => {
|
removeChannel: async (cardId, channelId) => {
|
||||||
|
const { guid } = session.current;
|
||||||
|
const { detail, profile } = getCard(cardId);
|
||||||
|
return await removeChannel(profile.node, detail.token, channelId);
|
||||||
},
|
},
|
||||||
removeChannelTopic: async (cardId, channelId, topicId) => {
|
removeChannelTopic: async (cardId, channelId, topicId) => {
|
||||||
|
const { guid } = session.current;
|
||||||
|
const { detail, profile } = getCard(cardId);
|
||||||
|
return await removeChannelTopic(profile.node, detail.token, channelId, topicId);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,18 +201,32 @@ export function useChannelContext() {
|
|||||||
return await store.actions.clearChannelTopicItems(guid, channelId);
|
return await store.actions.clearChannelTopicItems(guid, channelId);
|
||||||
},
|
},
|
||||||
getTopic: async (channelId, topicId) => {
|
getTopic: async (channelId, topicId) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
return await getChannelTopic(server, appToken, channelId, topicId);
|
||||||
},
|
},
|
||||||
getTopics: async (channelId) => {
|
getTopics: async (channelId, revision) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
return await getChannelTopics(server, appToken, channelId, revision);
|
||||||
},
|
},
|
||||||
getTopicAssetUrl: async (channelId, assetId) => {
|
getTopicAssetUrl: (channelId, topicId, assetId) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
return getChannelTopicAssetUrl(server, appToken, channelId, topicId, assetId);
|
||||||
},
|
},
|
||||||
addTopic: async (channelId, message, assets) => {
|
addTopic: async (channelId, message, assets) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
return await addChannelTopic(server, appToken, channelId, message, assets);
|
||||||
},
|
},
|
||||||
setTopicSubject: async (channelId, topicId, data) => {
|
setTopicSubject: async (channelId, topicId, data) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
return await setChannelTopicSubject(server, appToken, channelId, topicId, data);
|
||||||
},
|
},
|
||||||
remove: async (channelId) => {
|
remove: async (channelId) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
return await removeChannel(server, appToken, channelId);
|
||||||
},
|
},
|
||||||
removeTopic: async (channelId, topicId) => {
|
removeTopic: async (channelId, topicId) => {
|
||||||
|
const { server, appToken } = session.current;
|
||||||
|
return await removeChannelTopic(server, appToken, channelId, topicId);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,18 +52,46 @@ export function useConversationContext() {
|
|||||||
return await channel.actions.clearTopicItem(channelId, topicId);
|
return await channel.actions.clearTopicItem(channelId, topicId);
|
||||||
}
|
}
|
||||||
const getTopic = async (cardId, channelId, topicId) => {
|
const getTopic = async (cardId, channelId, topicId) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.getChannelTopic(cardId, channelId, topicId);
|
||||||
|
}
|
||||||
|
return await channel.actions.getTopic(channelId, topicId);
|
||||||
}
|
}
|
||||||
const getTopics = async (cardId, channelId) => {
|
const getTopics = async (cardId, channelId, revision) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.getChannelTopics(cardId, channelId, revision);
|
||||||
|
}
|
||||||
|
return await channel.actions.getTopics(channelId, revision)
|
||||||
}
|
}
|
||||||
const getTopicAssetUrl = async (cardId, channelId, assetId) => {
|
const getTopicAssetUrl = (cardId, channelId, assetId) => {
|
||||||
|
if (cardId) {
|
||||||
|
return card.actions.getChannelTopicAssetUrl(cardId, channelId, topicId, assetId);
|
||||||
|
}
|
||||||
|
return channel.actions.getTopicAssetUrl(channelId, assetId);
|
||||||
}
|
}
|
||||||
const addTopic = async (cardId, channelId, message, asssets) => {
|
const addTopic = async (cardId, channelId, message, asssets) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.addChannelTopic(cardId, channelId, message, assetId);
|
||||||
|
}
|
||||||
|
return await channel.actions.addTopic(channelId, message, assetId);
|
||||||
}
|
}
|
||||||
const setTopicSubject = async (cardId, channelId, topicId, data) => {
|
const setTopicSubject = async (cardId, channelId, topicId, data) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, data);
|
||||||
|
}
|
||||||
|
return await channel.actions.setTopicSubject(channelId, topicId, data);
|
||||||
}
|
}
|
||||||
const removeChannel = async (cardId, channelId) => {
|
const remove = async (cardId, channelId) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.removeChannel(cardId, channelId);
|
||||||
|
}
|
||||||
|
return await channel.actions.remove(channelId);
|
||||||
}
|
}
|
||||||
const removeChannelTopic = async (cardId, channelId, topicId) => {
|
const removeTopic = async (cardId, channelId, topicId) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.removeChannelTopic(cardId, channelId, topicId);
|
||||||
|
}
|
||||||
|
return await channel.actions.remvoeTopic(channelId, topicId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sync = async () => {
|
const sync = async () => {
|
||||||
@ -85,10 +113,10 @@ export function useConversationContext() {
|
|||||||
// set channel topics
|
// set channel topics
|
||||||
if (syncRevision.current != item.syncRevision) {
|
if (syncRevision.current != item.syncRevision) {
|
||||||
if (syncRevision.current) {
|
if (syncRevision.current) {
|
||||||
const topics = getTopicDeltaItems(cardId, channelId);
|
const topics = await getTopicDeltaItems(cardId, channelId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const topics = getTopicItems(cardId, channelId);
|
const topics = await getTopicItems(cardId, channelId);
|
||||||
}
|
}
|
||||||
if (curView === setView.current) {
|
if (curView === setView.current) {
|
||||||
syncRevision.current = item.syncRevision;
|
syncRevision.current = item.syncRevision;
|
||||||
@ -97,7 +125,10 @@ export function useConversationContext() {
|
|||||||
|
|
||||||
// sync from server to store
|
// sync from server to store
|
||||||
if (item.topicRevision !== item.syncRevision) {
|
if (item.topicRevision !== item.syncRevision) {
|
||||||
console.log("pull latest topics");
|
const res = await getTopics(cardId, channelId, item.syncRevision)
|
||||||
|
res.topics.forEach(topic => {
|
||||||
|
console.log(topic.data);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// update revision
|
// update revision
|
||||||
|
Loading…
Reference in New Issue
Block a user