databag/app/mobile/src/context/useCardContext.hook.js

554 lines
24 KiB
JavaScript
Raw Normal View History

2022-09-15 08:03:20 +00:00
import { useState, useRef, useContext } from 'react';
import { StoreContext } from 'context/StoreContext';
2022-10-07 05:52:28 +00:00
import { UploadContext } from 'context/UploadContext';
import { addFlag } from 'api/addFlag';
2022-10-25 07:06:39 +00:00
import { getCard } from 'api/getCard';
2022-09-15 18:26:03 +00:00
import { getCards } from 'api/getCards';
import { getCardProfile } from 'api/getCardProfile';
2022-10-23 06:57:44 +00:00
import { setCardProfile } from 'api/setCardProfile';
2022-09-15 18:26:03 +00:00
import { getCardDetail } from 'api/getCardDetail';
2022-10-23 06:57:44 +00:00
import { getContactProfile } from 'api/getContactProfile';
2022-09-16 18:28:54 +00:00
import { getContactChannels } from 'api/getContactChannels';
2022-09-16 06:18:46 +00:00
import { getContactChannelDetail } from 'api/getContactChannelDetail';
import { getContactChannelSummary } from 'api/getContactChannelSummary';
2022-09-20 07:50:53 +00:00
import { getCardImageUrl } from 'api/getCardImageUrl';
2022-09-26 19:14:06 +00:00
import { addCard } from 'api/addCard';
import { removeCard } from 'api/removeCard';
import { setCardConnecting, setCardConnected, setCardConfirmed } from 'api/setCardStatus';
import { getCardOpenMessage } from 'api/getCardOpenMessage';
import { setCardOpenMessage } from 'api/setCardOpenMessage';
import { getCardCloseMessage } from 'api/getCardCloseMessage';
import { setCardCloseMessage } from 'api/setCardCloseMessage';
2022-09-29 18:31:55 +00:00
import { getContactChannelTopic } from 'api/getContactChannelTopic';
import { getContactChannelTopics } from 'api/getContactChannelTopics';
import { getContactChannelTopicAssetUrl } from 'api/getContactChannelTopicAssetUrl';
import { addContactChannelTopic } from 'api/addContactChannelTopic';
import { setContactChannelTopicSubject } from 'api/setContactChannelTopicSubject';
import { removeContactChannel } from 'api/removeContactChannel';
import { removeContactChannelTopic } from 'api/removeContactChannelTopic';
2022-11-14 21:30:58 +00:00
import { getContactChannelNotifications } from 'api/getContactChannelNotifications';
import { setContactChannelNotifications } from 'api/setContactChannelNotifications';
2022-09-15 08:03:20 +00:00
export function useCardContext() {
const [state, setState] = useState({
2023-02-04 18:36:30 +00:00
offsync: false,
2022-09-20 05:39:53 +00:00
cards: new Map(),
viewRevision: null,
2022-09-15 08:03:20 +00:00
});
2022-10-07 05:52:28 +00:00
const upload = useContext(UploadContext);
2023-02-04 18:36:30 +00:00
const access = useRef(null);
2022-09-15 08:03:20 +00:00
const setRevision = useRef(null);
2023-02-04 18:36:30 +00:00
const curRevision = useRef(null);
2022-09-20 05:39:53 +00:00
const cards = useRef(new Map());
2023-02-04 18:36:30 +00:00
const syncing = useRef(false);
const store = useContext(StoreContext);
2022-09-15 08:03:20 +00:00
const updateState = (value) => {
setState((s) => ({ ...s, ...value }))
}
const setCardItem = (card) => {
return {
cardId: card.id,
revision: card.revision,
detailRevision: card.data?.detailRevision,
profileRevision: card.data?.profileRevision,
detail: card.data?.cardDetail,
profile: card.data?.cardProfile,
notifiedView: card.data?.notifiedView,
notifiedProfile: card.data?.notifiedProfile,
notifiedArticle: card.data?.notifiedArticle,
notifiedChannel: card.data?.notifiedChannel,
}
}
const setCardField = (cardId, field, value) => {
2023-09-06 07:00:22 +00:00
const item = cards.current.get(cardId);
if (item?.card) {
item.card[field] = value;
cards.current.set(cardId, { ...item });
updateState({ cards: cards.current });
}
2023-09-06 07:00:22 +00:00
}
2023-02-06 21:46:39 +00:00
const setCardChannelItem = (cardChannel) => {
return {
channelId: cardChannel.id,
revision: cardChannel.revision,
detailRevision: cardChannel.data.detailRevision,
topicRevision: cardChannel.data.topicRevision,
2023-02-08 07:52:38 +00:00
detail: cardChannel.data.channelDetail,
summary: cardChannel.data.channelSummary,
2023-02-06 21:46:39 +00:00
};
};
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 });
2023-02-27 19:32:53 +00:00
updateState({ cards: cards.current });
}
}
};
2023-02-09 18:42:06 +00:00
const resyncCard = async (cardId) => {
if (!syncing.current) {
syncing.current = true;
try {
2023-03-05 06:05:40 +00:00
const { server, token, guid } = access.current || {};
2023-02-06 21:46:39 +00:00
const entry = cards.current.get(cardId);
2023-02-08 07:52:38 +00:00
if (entry?.card?.detail.status === 'connected') {
2023-02-06 21:46:39 +00:00
const card = await getCard(server, token, cardId);
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = card.data || {};
const cardRevision = { view: notifiedView, profile: notifiedProfile, artcile: notifiedArticle, channel: notifiedChannel };
await syncCard(server, token, guid, entry, cardRevision);
2023-05-06 17:30:08 +00:00
await store.actions.clearCardItemOffsync(guid, cardId);
2023-02-06 21:46:39 +00:00
entry.card.offsync = false;
2023-05-06 17:30:08 +00:00
cards.current.set(cardId, entry);
updateState({ cards: cards.current });
}
}
catch(err) {
console.log(err);
}
syncing.current = false;
await sync();
}
}
2022-09-15 08:03:20 +00:00
const sync = async () => {
2023-02-09 18:42:06 +00:00
if (access.current && !syncing.current && setRevision.current !== curRevision.current) {
2022-09-15 08:03:20 +00:00
syncing.current = true;
try {
2023-03-05 06:05:40 +00:00
const { server, token, guid } = access.current || {};
2022-09-15 08:03:20 +00:00
const revision = curRevision.current;
const delta = await getCards(server, token, setRevision.current);
2022-09-15 18:26:03 +00:00
for (let card of delta) {
if (card.data) {
const item = setCardItem(card);
const entry = cards.current.get(card.id) || { channels: new Map() };
if (!entry.card) {
const { cardId, detailRevision, profileRevision } = item;
const entryCard = { cardId, detailRevision, profileRevision };
if (item.detail) {
entryCard.detail = item.detail;
}
else {
entryCard.detail = await getCardDetail(server, token, card.id);
}
if (item.profile) {
entryCard.profile = item.profile;
}
else {
entryCard.profile = await getCardProfile(server, token, card.id);
}
2023-02-24 00:00:49 +00:00
await store.actions.setCardItem(guid, entryCard);
entry.card = entryCard;
cards.current.set(card.id, entry);
}
else {
const { profileRevision, detailRevision } = entry.card;
if (item.profileRevision !== profileRevision) {
if (item.profile) {
entry.card.profile = item.profile;
}
else {
entry.card.profile = await getCardProfile(server, token, card.id);
}
entry.card.profileRevision = item.profileRevision;
await store.actions.setCardItemProfile(guid, card.id, entry.card.profileRevision, entry.card.profile);
}
if (item.detailRevision !== detailRevision) {
if (item.detail) {
entry.card.detail = item.detail;
}
else {
entry.card.detail = await getCardDetail(server, token, card.id);
}
entry.card.detailRevision = item.detailRevision;
await store.actions.setCardItemDetail(guid, card.id, entry.card.detailRevision, entry.card.detail);
}
}
2023-02-08 07:52:38 +00:00
if (entry.card.detail?.status === 'connected' && !entry.card.offsync) {
2023-02-06 21:46:39 +00:00
try {
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = item;
const cardRevision = { view: notifiedView, profile: notifiedProfile, article: notifiedArticle, channel: notifiedChannel };
await syncCard(server, token, guid, entry, cardRevision);
}
catch (err) {
console.log(err);
entry.card.offsync = true;
2023-02-16 18:04:05 +00:00
await store.actions.setCardItemOffsync(guid, card.id);
2023-02-06 21:46:39 +00:00
}
}
cards.current.set(card.id, { ...entry });
}
else {
2023-02-06 21:46:39 +00:00
const entry = cards.current.get(card.id) || { card: {}, channels: new Map() };
const ids = [];
2023-02-06 21:46:39 +00:00
entry.channels.forEach((value, key) => {
ids.push(key);
2023-02-06 21:46:39 +00:00
});
for (let i = 0; i < ids.length; i++) {
await store.actions.clearCardChannelTopicItems(guid, card.id, ids[i]);
}
await store.actions.clearCardChannelItems(guid, card.id);
await store.actions.clearCardItem(guid, card.id);
cards.current.delete(card.id);
}
}
2023-02-06 21:46:39 +00:00
setRevision.current = revision;
await store.actions.setCardRevision(guid, revision);
updateState({ offsync: false, cards: cards.current });
}
catch (err) {
console.log(err);
syncing.current = false;
updateState({ offsync: true });
return;
}
syncing.current = false;
await sync();
}
};
2023-02-06 21:46:39 +00:00
const syncCard = async (server, token, guid, entry, cardRevision) => {
const { detail, profile, cardId } = entry.card;
const { notifiedView, notifiedProfile, notifiedArticle, notifiedChannel } = entry.card;
const cardServer = profile?.node ? profile.node : server;
2023-02-06 21:46:39 +00:00
const cardToken = `${profile?.guid}.${detail?.token}`;
if (entry.card.notifiedProfile !== cardRevision.profile) {
2023-02-08 19:24:56 +00:00
if (entry.card.profileRevision !== cardRevision.profile) {
const message = await getContactProfile(cardServer, cardToken);
await setCardProfile(server, token, cardId, message);
}
2023-02-06 21:46:39 +00:00
entry.card.notifiedProfile = cardRevision.profile;
store.actions.setCardItemNotifiedProfile(guid, cardId, cardRevision.profile);
}
if (entry.card.notifiedView !== cardRevision.view || entry.card.notifiedChannel !== cardRevision.channel) {
const view = cardRevision.view === entry.card.notifiedView ? entry.card.notifiedView : null;
const channel = cardRevision.view === entry.card.notifiedView ? entry.card.notifiedChannel : null;
const delta = await getContactChannels(cardServer, cardToken, view, channel);
for (let channel of delta) {
if (channel.data) {
const channelItem = setCardChannelItem(channel);
const channelEntry = entry.channels.get(channel.id);
if (!channelEntry) {
if (!channelItem.detail) {
channelItem.detail = await getContactChannelDetail(cardServer, cardToken, channel.id);
2023-02-08 07:52:38 +00:00
}
if (!channelItem.summary) {
channelItem.summary = await getContactChannelSummary(cardServer, cardToken, channel.id);
2023-02-08 07:52:38 +00:00
}
await store.actions.setCardChannelItem(guid, cardId, channelItem);
entry.channels.set(channel.id, { ...channelItem });
2022-10-25 07:06:39 +00:00
}
else {
if (channelItem.detailRevision !== channelEntry.detailRevision) {
if (channelItem.detail) {
channelEntry.detail = channelItem.detail;
}
else {
channelEntry.detail = await getContactChannelDetail(cardServer, cardToken, channel.id);
}
channelEntry.unsealedDetail = null;
channelEntry.detailRevision = channelItem.detailRevision;
await store.actions.setCardChannelItemDetail(guid, cardId, channel.id, channelEntry.detailRevision, channelEntry.detail);
2023-02-08 07:52:38 +00:00
}
if (channelItem.topicRevision !== channelEntry.topicRevision) {
if (channelItem.summary) {
channelEntry.summary = channelItem.summary;
}
else {
channelEntry.summary = await getContactChannelSummary(cardServer, cardToken, channel.id);
}
channelEntry.unsealedSummary = null;
channelEntry.topicRevision = channelItem.topicRevision;
await store.actions.setCardChannelItemSummary(guid, cardId, channel.id, channelEntry.topicRevision, channelEntry.summary);
2023-02-08 07:52:38 +00:00
}
entry.channels.set(channel.id, { ...channelEntry });
2022-10-25 07:06:39 +00:00
}
2022-09-16 06:18:46 +00:00
}
else {
2023-02-08 19:24:56 +00:00
await store.actions.clearCardChannelTopicItems(guid, cardId, channel.id);
await store.actions.clearCardChannelItem(guid, cardId, channel.id);
entry.channels.delete(channel.id);
2022-09-16 06:18:46 +00:00
}
}
2023-02-08 19:24:56 +00:00
entry.card.notifiedChannel = cardRevision.channel;
await store.actions.setCardItemNotifiedChannel(guid, cardId, cardRevision.channel);
entry.card.notifiedView = cardRevision.view;
await store.actions.setCardItemNotifiedView(guid, cardId, cardRevision.view);
2022-09-16 06:18:46 +00:00
}
2023-02-06 21:46:39 +00:00
};
2022-09-16 06:18:46 +00:00
2022-09-15 08:03:20 +00:00
const actions = {
setSession: async (session) => {
2023-02-04 18:36:30 +00:00
if (access.current || syncing.current) {
throw new Error('invalid card state');
}
access.current = session;
cards.current = new Map();
const cardItems = await store.actions.getCardItems(session.guid);
for(card of cardItems) {
const entry = { card, channels: new Map() };
const cardChannelItems = await store.actions.getCardChannelItems(session.guid, card.cardId);
for (cardChannel of cardChannelItems) {
entry.channels.set(cardChannel.channelId, cardChannel);
2023-02-04 18:36:30 +00:00
}
cards.current.set(card.cardId, entry);
2023-02-04 18:36:30 +00:00
}
const status = await store.actions.getCardRequestStatus(session.guid);
2023-02-04 18:36:30 +00:00
const revision = await store.actions.getCardRevision(session.guid);
curRevision.current = revision;
setRevision.current = revision;
setState({ offsync: false, viewRevision: status?.revision, cards: cards.current });
2023-02-04 18:36:30 +00:00
},
clearSession: () => {
access.current = null;
},
2023-02-09 18:42:06 +00:00
setRevision: (revision) => {
2023-02-04 18:36:30 +00:00
curRevision.current = revision;
2023-02-09 18:42:06 +00:00
sync();
2023-02-04 18:36:30 +00:00
},
addCard: async (message) => {
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-04 18:36:30 +00:00
return await addCard(server, token, message);
},
removeCard: async (cardId) => {
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-04 18:36:30 +00:00
return await removeCard(server, token, cardId);
},
setCardConnecting: async (cardId) => {
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-04 18:36:30 +00:00
return await setCardConnecting(server, token, cardId);
},
setCardConnected: async (cardId, cardToken, revision) => {
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-04 18:36:30 +00:00
return await setCardConnected(server, token, cardId, cardToken,
revision.viewRevision, revision.articleRevision,
revision.channelRevision, revision.profileRevision);
},
setCardConfirmed: async (cardId) => {
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-04 18:36:30 +00:00
return await setCardConfirmed(server, token, cardId);
},
getCardOpenMessage: async (cardId) => {
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-04 18:36:30 +00:00
return await getCardOpenMessage(server, token, cardId);
},
setCardOpenMessage: async (server, message) => {
return await setCardOpenMessage(server, message);
},
getCardCloseMessage: async (cardId) => {
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-04 18:36:30 +00:00
return await getCardCloseMessage(server, token, cardId);
},
setCardCloseMessage: async (server, message) => {
return await setCardCloseMessage(server, message);
},
getCardImageUrl: (cardId) => {
2023-03-03 05:30:17 +00:00
const { profileRevision } = cards.current.get(cardId)?.card || {};
2023-03-05 06:05:40 +00:00
const { server, token } = access.current || {};
2023-02-24 00:00:49 +00:00
return getCardImageUrl(server, token, cardId, profileRevision);
2023-02-04 18:36:30 +00:00
},
removeChannel: async (cardId, channelId) => {
2023-03-01 21:35:43 +00:00
const { detail, profile } = cards.current.get(cardId)?.card || {};
const cardToken = `${profile?.guid}.${detail?.token}`;
return await removeContactChannel(profile?.node, cardToken, channelId);
},
addTopic: async (cardId, channelId, type, message, files) => {
2023-03-03 05:30:17 +00:00
const { detail, profile } = cards.current.get(cardId)?.card || {};
const cardToken = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current?.server;
if (files?.length > 0) {
2023-03-03 05:30:17 +00:00
const topicId = await addContactChannelTopic(node, cardToken, channelId, null, null, null);
upload.actions.addTopic(node, cardToken, channelId, topicId, files, async (assets) => {
const subject = message(assets);
2023-03-03 05:30:17 +00:00
await setContactChannelTopicSubject(node, cardToken, channelId, topicId, type, subject);
}, async () => {
try {
2023-03-03 05:30:17 +00:00
await removeContactChannelTopic(node, cardToken, channelId, topicId);
}
catch (err) {
console.log(err);
}
}, cardId);
}
else {
const subject = message([]);
2023-03-03 05:30:17 +00:00
await addContactChannelTopic(node, cardToken, channelId, type, subject, []);
}
2023-02-04 18:36:30 +00:00
},
removeTopic: async (cardId, channelId, topicId) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const cardToken = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current.server;
return await removeContactChannelTopic(node, cardToken, channelId, topicId);
2023-02-04 18:36:30 +00:00
},
setTopicSubject: async (cardId, channelId, topicId, type, subject) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const cardToken = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current.server;
return await setContactChannelTopicSubject(node, cardToken, channelId, topicId, type, subject);
2023-02-04 18:36:30 +00:00
},
getTopicAssetUrl: (cardId, channelId, topicId, assetId) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const cardToken = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current.server;
return getContactChannelTopicAssetUrl(node, cardToken, channelId, topicId, assetId);
2023-02-04 18:36:30 +00:00
},
getTopics: async (cardId, channelId, revision, count, begin, end) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const cardToken = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current.server;
return await getContactChannelTopics(node, cardToken, channelId, revision, count, begin, end);
2023-02-04 18:36:30 +00:00
},
getTopic: async (cardId, channelId, topicId) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const cardToken = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current.server;
return await getContactChannelTopic(node, cardToken, channelId, topicId);
2023-02-04 18:36:30 +00:00
},
setContactRevision: async (cardId, revision) => {
2023-09-05 04:37:10 +00:00
const { guid } = access.current || {};
await store.actions.setCardRequestStatus(guid, { revision });
updateState({ viewRevision: revision });
2023-02-04 18:36:30 +00:00
},
setChannelReadRevision: async (cardId, channelId, revision) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelItemReadRevision(guid, cardId, channelId, revision);
setCardChannelField(cardId, channelId, 'readRevision', revision);
2023-02-04 18:36:30 +00:00
},
setChannelSyncRevision: async (cardId, channelId, revision) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelItemSyncRevision(guid, cardId, channelId, revision);
setCardChannelField(cardId, channelId, 'syncRevision', revision);
2023-02-04 18:36:30 +00:00
},
setChannelTopicMarker: async (cardId, channelId, marker) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelItemTopicMarker(guid, cardId, channelId, marker);
setCardChannelField(cardId, channelId, 'topicMarker', marker);
2023-02-04 18:36:30 +00:00
},
setChannelMarkerAndSync: async (cardId, channelId, marker, revision) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelItemMarkerAndSync(guid, cardId, channelId, marker, revision);
setCardChannelField(cardId, channelId, 'topicMarker', marker, 'syncRevision', revision);
},
setCardFlag: async (cardId) => {
2023-09-05 04:37:10 +00:00
const { guid } = access.current || {};
await store.actions.setCardItemBlocked(guid, cardId);
setCardField(cardId, 'blocked', true);
},
clearCardFlag: async (cardId) => {
2023-09-05 04:37:10 +00:00
const { guid } = access.current || {};
await store.actions.clearCardItemBlocked(guid, cardId);
setCardField(cardId, 'blocked', false);
2023-02-04 18:36:30 +00:00
},
setChannelFlag: async (cardId, channelId) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelItemBlocked(guid, cardId, channelId);
setCardChannelField(cardId, channelId, 'blocked', true);
2023-02-04 18:36:30 +00:00
},
clearChannelFlag: async (cardId, channelId) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.clearCardChannelItemBlocked(guid, cardId, channelId);
setCardChannelField(cardId, channelId, 'blocked', false);
2023-02-04 18:36:30 +00:00
},
setTopicFlag: async (cardId, channelId, topicId) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, true);
2023-02-04 18:36:30 +00:00
},
clearTopicFlag: async (cardId, channelId, topicId) => {
const { guid } = access.current || {};
await store.actions.setCardChannelTopicBlocked(guid, cardId, channelId, topicId, false);
2023-02-04 18:36:30 +00:00
},
getFlaggedTopics: async () => {
const { guid } = access.current || {};
return await store.actions.getCardChannelTopicBlocked(guid);
},
addChannelAlert: async (cardId, channelId) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const node = profile?.node ? profile.node : access.current.server;
return await addFlag(node, profile?.guid, channelId);
2023-02-04 18:36:30 +00:00
},
addTopicAlert: async (cardId, channelId, topicId) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const node = profile?.node ? profile.node : access.current.server;
return await addFlag(node, profile?.guid, channelId, topicId);
2023-02-04 18:36:30 +00:00
},
getChannelNotifications: async (cardId, channelId) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const token = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current.server;
return await getContactChannelNotifications(node, token, channelId);
2022-10-18 21:52:13 +00:00
},
setChannelNotifications: async (cardId, channelId, notify) => {
const { detail, profile } = (cards.current.get(cardId) || {}).card;
const token = `${profile?.guid}.${detail?.token}`;
const node = profile?.node ? profile.node : access.current.server;
return await setContactChannelNotifications(node, token, channelId, notify);
2022-10-18 21:52:13 +00:00
},
getTopicItems: async (cardId, channelId) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
2022-09-29 06:30:22 +00:00
return await store.actions.getCardChannelTopicItems(guid, cardId, channelId);
},
getTopicItemsId: async (cardId, channelId) => {
const { guid } = access.current || {};
return await store.actions.getCardChannelTopicItemsId(guid, cardId, channelId);
},
getTopicItemsById: async (cardId, channelId, topics) => {
const { guid } = access.current || {};
return await store.actions.getCardChannelTopicItemsById(guid, cardId, channelId, topics);
},
setTopicItem: async (cardId, channelId, topicId, topic) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
2022-09-29 23:00:48 +00:00
return await store.actions.setCardChannelTopicItem(guid, cardId, channelId, topicId, topic);
2022-09-29 06:30:22 +00:00
},
clearTopicItem: async (cardId, channelId, topicId) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
2022-09-29 06:30:22 +00:00
return await store.actions.clearCardChannelTopicItem(guid, cardId, channelId, topicId);
},
clearTopicItems: async (cardId, channelId) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
2022-09-29 06:30:22 +00:00
return await store.actions.clearCardChannelTopicItems(guid, cardId, channelId);
},
setUnsealedChannelSubject: async (cardId, channelId, revision, unsealed) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelItemUnsealedDetail(guid, cardId, channelId, revision, unsealed);
2023-02-27 19:32:53 +00:00
setCardChannelField(cardId, channelId, 'unsealedDetail', unsealed);
2022-09-29 18:31:55 +00:00
},
setUnsealedChannelSummary: async (cardId, channelId, revision, unsealed) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelItemUnsealedSummary(guid, cardId, channelId, revision, unsealed);
2023-02-27 19:32:53 +00:00
setCardChannelField(cardId, channelId, 'unsealedSummary', unsealed);
2022-11-14 21:30:58 +00:00
},
setUnsealedTopicSubject: async (cardId, channelId, topicId, revision, unsealed) => {
2023-03-05 06:05:40 +00:00
const { guid } = access.current || {};
await store.actions.setCardChannelTopicItemUnsealedDetail(guid, cardId, channelId, topicId, revision, unsealed);
},
resync: async () => {
2023-02-09 18:42:06 +00:00
await sync();
},
resyncCard: async (cardId) => {
await resyncCard(cardId);
2022-10-25 07:06:39 +00:00
},
2022-09-15 08:03:20 +00:00
}
2022-11-14 21:30:58 +00:00
2022-09-15 08:03:20 +00:00
return { state, actions }
}