mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
preparing to sync topics
This commit is contained in:
parent
a65c8c1ccd
commit
c6485d5b47
@ -1,9 +1,9 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function addChannel(token, cards, subject, description ) {
|
export async function addChannel(server, token, cards, subject, description ) {
|
||||||
let data = { subject, description };
|
let data = { subject, description };
|
||||||
let params = { dataType: 'superbasic', data: JSON.stringify(data), groups: [], cards };
|
let params = { dataType: 'superbasic', data: JSON.stringify(data), groups: [], cards };
|
||||||
let channel = await fetchWithTimeout(`/content/channels?agent=${token}`, { method: 'POST', body: JSON.stringify(params)} );
|
let channel = await fetchWithTimeout(`https://${server}/content/channels?agent=${token}`, { method: 'POST', body: JSON.stringify(params)} );
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
return await channel.json();
|
return await channel.json();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function addChannelTopic(token, channelId, message, assets ): string {
|
export async function addChannelTopic(server, token, channelId, message, assets ): string {
|
||||||
|
|
||||||
if (message == null && (assets == null || assets.length === 0)) {
|
if (message == null && (assets == null || assets.length === 0)) {
|
||||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`,
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}`,
|
||||||
{ method: 'POST', body: JSON.stringify({}) });
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
@ -14,7 +14,7 @@ export async function addChannelTopic(token, channelId, message, assets ): strin
|
|||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
|
|
||||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}&confirm=true`,
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}&confirm=true`,
|
||||||
{ method: 'POST', body: JSON.stringify(subject) });
|
{ method: 'POST', body: JSON.stringify(subject) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
@ -22,7 +22,7 @@ export async function addChannelTopic(token, channelId, message, assets ): strin
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`,
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}`,
|
||||||
{ method: 'POST', body: JSON.stringify({}) });
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
@ -34,7 +34,7 @@ export async function addChannelTopic(token, channelId, message, assets ): strin
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.image);
|
formData.append('asset', asset.image);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
|
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
|
||||||
let topicAsset = await fetch(`/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData });
|
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData });
|
||||||
checkResponse(topicAsset);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -49,7 +49,7 @@ export async function addChannelTopic(token, channelId, message, assets ): strin
|
|||||||
formData.append('asset', asset.video);
|
formData.append('asset', asset.video);
|
||||||
let thumb = 'vthumb;video;' + asset.position;
|
let thumb = 'vthumb;video;' + asset.position;
|
||||||
let transform = encodeURIComponent(JSON.stringify(["vlq;video", "vhd;video", thumb]));
|
let transform = encodeURIComponent(JSON.stringify(["vlq;video", "vhd;video", thumb]));
|
||||||
let topicAsset = await fetch(`/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData });
|
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData });
|
||||||
checkResponse(topicAsset);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -64,7 +64,7 @@ export async function addChannelTopic(token, channelId, message, assets ): strin
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.audio);
|
formData.append('asset', asset.audio);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
|
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
|
||||||
let topicAsset = await fetch(`/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData });
|
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&agent=${token}`, { method: 'POST', body: formData });
|
||||||
checkResponse(topicAsset);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -80,11 +80,11 @@ export async function addChannelTopic(token, channelId, message, assets ): strin
|
|||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
|
|
||||||
let unconfirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`,
|
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`,
|
||||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
checkResponse(unconfirmed);
|
checkResponse(unconfirmed);
|
||||||
|
|
||||||
let confirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`,
|
let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`,
|
||||||
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||||
checkResponse(confirmed);
|
checkResponse(confirmed);
|
||||||
return slot.id;
|
return slot.id;
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function addContactChannelTopic(server, token, channelId, message, assets ) {
|
export async function addContactChannelTopic(server, token, channelId, message, assets ) {
|
||||||
let host = "";
|
|
||||||
if (server) {
|
|
||||||
host = `https://${server}`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message == null && (assets == null || assets.length === 0)) {
|
if (message == null && (assets == null || assets.length === 0)) {
|
||||||
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics?contact=${token}`,
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
|
||||||
{ method: 'POST', body: JSON.stringify({}) });
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
@ -18,14 +13,14 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
|
|
||||||
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics?contact=${token}&confirm=true`,
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`,
|
||||||
{ method: 'POST', body: JSON.stringify(subject) });
|
{ method: 'POST', body: JSON.stringify(subject) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
return slot.id;
|
return slot.id;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics?contact=${token}`,
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
|
||||||
{ method: 'POST', body: JSON.stringify({}) });
|
{ method: 'POST', body: JSON.stringify({}) });
|
||||||
checkResponse(topic);
|
checkResponse(topic);
|
||||||
let slot = await topic.json();
|
let slot = await topic.json();
|
||||||
@ -37,7 +32,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.image);
|
formData.append('asset', asset.image);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
|
let transform = encodeURIComponent(JSON.stringify(["ithumb;photo", "icopy;photo"]));
|
||||||
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
|
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
|
||||||
checkResponse(topicAsset);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -52,7 +47,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
formData.append('asset', asset.video);
|
formData.append('asset', asset.video);
|
||||||
let thumb = "vthumb;video;" + asset.position
|
let thumb = "vthumb;video;" + asset.position
|
||||||
let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb]));
|
let transform = encodeURIComponent(JSON.stringify(["vhd;video", "vlq;video", thumb]));
|
||||||
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
|
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
|
||||||
checkResponse(topicAsset);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -67,7 +62,7 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('asset', asset.audio);
|
formData.append('asset', asset.audio);
|
||||||
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
|
let transform = encodeURIComponent(JSON.stringify(["acopy;audio"]));
|
||||||
let topicAsset = await fetch(`${host}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
|
let topicAsset = await fetch(`https://${server}/content/channels/${channelId}/topics/${slot.id}/assets?transforms=${transform}&contact=${token}`, { method: 'POST', body: formData });
|
||||||
checkResponse(topicAsset);
|
checkResponse(topicAsset);
|
||||||
let assetEntry = await topicAsset.json();
|
let assetEntry = await topicAsset.json();
|
||||||
message.assets.push({
|
message.assets.push({
|
||||||
@ -83,11 +78,11 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
|||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
|
|
||||||
let unconfirmed = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
|
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
|
||||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
checkResponse(unconfirmed);
|
checkResponse(unconfirmed);
|
||||||
|
|
||||||
let confirmed = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
|
let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
|
||||||
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||||
checkResponse(confirmed);
|
checkResponse(confirmed);
|
||||||
return slot.id;
|
return slot.id;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function clearChannelCard(token, channelId, cardId ) {
|
export async function clearChannelCard(server, token, channelId, cardId ) {
|
||||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'DELETE'});
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/cards/${cardId}?agent=${token}`, {method: 'DELETE'});
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
return await channel.json();
|
return await channel.json();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getChannelTopic(token, channelId, topicId) {
|
export async function getChannelTopic(server, token, channelId, topicId) {
|
||||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`,
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`,
|
||||||
{ method: 'GET' });
|
{ method: 'GET' });
|
||||||
checkResponse(topic)
|
checkResponse(topic)
|
||||||
return await topic.json()
|
return await topic.json()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export function getChannelTopicAssetUrl(token, channelId, topicId, assetId) {
|
export function getChannelTopicAssetUrl(server, token, channelId, topicId, assetId) {
|
||||||
return `/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?agent=${token}`
|
return `https://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?agent=${token}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getChannelTopics(token, channelId, revision, count, begin, end) {
|
export async function getChannelTopics(server, token, channelId, revision, count, begin, end) {
|
||||||
let rev = ''
|
let rev = ''
|
||||||
if (revision != null) {
|
if (revision != null) {
|
||||||
rev = `&revision=${revision}`
|
rev = `&revision=${revision}`
|
||||||
@ -17,7 +17,7 @@ export async function getChannelTopics(token, channelId, revision, count, begin,
|
|||||||
if (end != null) {
|
if (end != null) {
|
||||||
edn = `&end=${end}`
|
edn = `&end=${end}`
|
||||||
}
|
}
|
||||||
let topics = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}${rev}${cnt}${bgn}${edn}`,
|
let topics = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?agent=${token}${rev}${cnt}${bgn}${edn}`,
|
||||||
{ method: 'GET' });
|
{ method: 'GET' });
|
||||||
checkResponse(topics)
|
checkResponse(topics)
|
||||||
return {
|
return {
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function getContactChannelTopic(server, token, channelId, topicId) {
|
export async function getContactChannelTopic(server, token, channelId, topicId) {
|
||||||
let host = "";
|
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`,
|
||||||
if (server) {
|
|
||||||
host = `https://${server}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let topic = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`,
|
|
||||||
{ method: 'GET' });
|
{ method: 'GET' });
|
||||||
checkResponse(topic)
|
checkResponse(topic)
|
||||||
return await topic.json()
|
return await topic.json()
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
export function getContactChannelTopicAssetUrl(server, token, channelId, topicId, assetId) {
|
export function getContactChannelTopicAssetUrl(server, token, channelId, topicId, assetId) {
|
||||||
let host = "";
|
return `https://${server}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?contact=${token}`
|
||||||
if (server) {
|
|
||||||
host = `https://${server}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${host}/content/channels/${channelId}/topics/${topicId}/assets/${assetId}?contact=${token}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
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) {
|
||||||
let host = "";
|
|
||||||
if (server) {
|
|
||||||
host = `https://${server}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let rev = ''
|
let rev = ''
|
||||||
if (revision != null) {
|
if (revision != null) {
|
||||||
rev = `&revision=${revision}`
|
rev = `&revision=${revision}`
|
||||||
@ -22,7 +17,7 @@ export async function getContactChannelTopics(server, token, channelId, revision
|
|||||||
if (end != null) {
|
if (end != null) {
|
||||||
edn = `&end=${end}`
|
edn = `&end=${end}`
|
||||||
}
|
}
|
||||||
let topics = await fetchWithTimeout(`${host}/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)
|
||||||
return {
|
return {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function removeChannel(token, channelId) {
|
export async function removeChannel(server, token, channelId) {
|
||||||
|
|
||||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}?agent=${token}`,
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}?agent=${token}`,
|
||||||
{ method: 'DELETE' });
|
{ method: 'DELETE' });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function removeChannelTopic(token, channelId, topicId) {
|
export async function removeChannelTopic(server, token, channelId, topicId) {
|
||||||
|
|
||||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}/topics/${topicId}?agent=${token}`,
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}?agent=${token}`,
|
||||||
{ method: 'DELETE' });
|
{ method: 'DELETE' });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function removeContactChannel(server, token, channelId) {
|
export async function removeContactChannel(server, token, channelId) {
|
||||||
let host = "";
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}?contact=${token}`,
|
||||||
if (server) {
|
|
||||||
host = `https://${server}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let channel = await fetchWithTimeout(`${host}/content/channels/${channelId}?contact=${token}`,
|
|
||||||
{ method: 'DELETE' });
|
{ method: 'DELETE' });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function removeContactChannelTopic(server, token, channelId, topicId) {
|
export async function removeContactChannelTopic(server, token, channelId, topicId) {
|
||||||
let host = "";
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}?contact=${token}`,
|
||||||
if (server) {
|
|
||||||
host = `https://${server}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let channel = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${topicId}?contact=${token}`,
|
|
||||||
{ method: 'DELETE' });
|
{ method: 'DELETE' });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setChannelSubject(token, channelId, subject ) {
|
export async function setChannelSubject(server, token, channelId, subject ) {
|
||||||
let data = { subject };
|
let data = { subject };
|
||||||
let params = { dataType: 'superbasic', data: JSON.stringify(data) };
|
let params = { dataType: 'superbasic', data: JSON.stringify(data) };
|
||||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} );
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/subject?agent=${token}`, { method: 'PUT', body: JSON.stringify(params)} );
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
return await channel.json();
|
return await channel.json();
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setChannelTopicSubject(token, channelId, topicId, data) {
|
export async function setChannelTopicSubject(server, token, channelId, topicId, data) {
|
||||||
let subject = { data: JSON.stringify(data, (key, value) => {
|
let subject = { data: JSON.stringify(data, (key, value) => {
|
||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
|
|
||||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}/topics/${topicId}/subject?agent=${token}&confirm=true`,
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/subject?agent=${token}&confirm=true`,
|
||||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||||
|
|
||||||
export async function setContactChannelTopicSubject(server, token, channelId, topicId, data) {
|
export async function setContactChannelTopicSubject(server, token, channelId, topicId, data) {
|
||||||
let host = "";
|
|
||||||
if (server) {
|
|
||||||
host = `https://${server}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let subject = { data: JSON.stringify(data, (key, value) => {
|
let subject = { data: JSON.stringify(data, (key, value) => {
|
||||||
if (value !== null) return value
|
if (value !== null) return value
|
||||||
}), datatype: 'superbasictopic' };
|
}), datatype: 'superbasictopic' };
|
||||||
|
|
||||||
let channel = await fetchWithTimeout(`${host}/content/channels/${channelId}/topics/${topicId}/subject?contact=${token}&confirm=true`,
|
let channel = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${topicId}/subject?contact=${token}&confirm=true`,
|
||||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||||
checkResponse(channel);
|
checkResponse(channel);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import { getCardProfile } from 'api/getCardProfile';
|
|||||||
import { getCardDetail } from 'api/getCardDetail';
|
import { getCardDetail } from 'api/getCardDetail';
|
||||||
|
|
||||||
import { getContactChannels } from 'api/getContactChannels';
|
import { getContactChannels } from 'api/getContactChannels';
|
||||||
import { getContactChannelTopics } from 'api/getContactChannelTopics';
|
|
||||||
import { getContactChannelDetail } from 'api/getContactChannelDetail';
|
import { getContactChannelDetail } from 'api/getContactChannelDetail';
|
||||||
import { getContactChannelSummary } from 'api/getContactChannelSummary';
|
import { getContactChannelSummary } from 'api/getContactChannelSummary';
|
||||||
import { getCardImageUrl } from 'api/getCardImageUrl';
|
import { getCardImageUrl } from 'api/getCardImageUrl';
|
||||||
@ -18,6 +17,14 @@ import { setCardOpenMessage } from 'api/setCardOpenMessage';
|
|||||||
import { getCardCloseMessage } from 'api/getCardCloseMessage';
|
import { getCardCloseMessage } from 'api/getCardCloseMessage';
|
||||||
import { setCardCloseMessage } from 'api/setCardCloseMessage';
|
import { setCardCloseMessage } from 'api/setCardCloseMessage';
|
||||||
|
|
||||||
|
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';
|
||||||
|
|
||||||
export function useCardContext() {
|
export function useCardContext() {
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
cards: new Map(),
|
cards: new Map(),
|
||||||
@ -162,6 +169,17 @@ export function useCardContext() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const setCardChannelSyncRevision = (cardId, channelId, revision) => {
|
||||||
|
let card = cards.current.get(cardId);
|
||||||
|
if (card) {
|
||||||
|
let channel = card.channels.get(channelId);
|
||||||
|
if (channel) {
|
||||||
|
channel.syncRevision = revision;
|
||||||
|
card.channels.set(channelId, channel);
|
||||||
|
cards.current.set(cardId, card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
const clearCardChannel = (cardId, channelId) => {
|
const clearCardChannel = (cardId, channelId) => {
|
||||||
let card = cards.current.get(cardId);
|
let card = cards.current.get(cardId);
|
||||||
if (card) {
|
if (card) {
|
||||||
@ -404,34 +422,46 @@ export function useCardContext() {
|
|||||||
await store.actions.clearCardItemBlocked(guid, cardId);
|
await store.actions.clearCardItemBlocked(guid, cardId);
|
||||||
updateState({ cards: cards.current });
|
updateState({ cards: cards.current });
|
||||||
},
|
},
|
||||||
getSyncRevision: async (cardId, channelId) => {
|
|
||||||
const { guid } = session.current;
|
|
||||||
return await store.actions.getCardChannelItemSyncRevision(guid, cardId, channelId);
|
|
||||||
},
|
|
||||||
setSyncRevision: async (cardId, channelId, revision) => {
|
setSyncRevision: async (cardId, channelId, revision) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.setCardChannelItemSyncRevision(guid, cardId, channelId, revision);
|
await store.actions.setCardChannelItemSyncRevision(guid, cardId, channelId, revision);
|
||||||
|
setCardChannelSyncRevision(cardId, channelId, revision);
|
||||||
|
updateState({ cards: cards.current });
|
||||||
},
|
},
|
||||||
getTopicItems: async (cardId, channelId) => {
|
getChannelTopicItems: async (cardId, channelId) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.getCardChannelTopicItems(guid, cardId, channelId);
|
return await store.actions.getCardChannelTopicItems(guid, cardId, channelId);
|
||||||
},
|
},
|
||||||
getTopicDeltaItems: async (cardId, channelId, revision) => {
|
getChannelTopicDeltaItems: async (cardId, channelId, revision) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.getCardChannelTopicDeltaItems(guid, cardId, channelId, revision);
|
return await store.actions.getCardChannelTopicDeltaItems(guid, cardId, channelId, revision);
|
||||||
},
|
},
|
||||||
setTopicItem: async (cardId, channelId, topicId, channelRevision, topic) => {
|
setChannelTopicItem: async (cardId, channelId, topicId, channelRevision, topic) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.setCardChannelTopicItem(guid, cardId, channelId, topicId, channelRevision, topic);
|
return await store.actions.setCardChannelTopicItem(guid, cardId, channelId, topicId, channelRevision, topic);
|
||||||
},
|
},
|
||||||
clearTopicItem: async (cardId, channelId, topicId) => {
|
clearChannelTopicItem: async (cardId, channelId, topicId) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.clearCardChannelTopicItem(guid, cardId, channelId, topicId);
|
return await store.actions.clearCardChannelTopicItem(guid, cardId, channelId, topicId);
|
||||||
},
|
},
|
||||||
clearTopicItems: async (cardId, channelId) => {
|
clearChannelTopicItems: async (cardId, channelId) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.clearCardChannelTopicItems(guid, cardId, channelId);
|
return await store.actions.clearCardChannelTopicItems(guid, cardId, channelId);
|
||||||
},
|
},
|
||||||
|
getChannelTopic: async (cardId, channelId, topicId) => {
|
||||||
|
},
|
||||||
|
getChannelTopics: async (cardId, channelId) => {
|
||||||
|
},
|
||||||
|
getChannelTopicAssetUrl: async (cardId, channelId, assetId) => {
|
||||||
|
},
|
||||||
|
addChannelTopic: async (cardId, channelId, message, assets) => {
|
||||||
|
},
|
||||||
|
setChannelTopicSubject: async (cardId, channelId, topicId, data) => {
|
||||||
|
},
|
||||||
|
removeChannel: async (cardId, channelId) => {
|
||||||
|
},
|
||||||
|
removeChannelTopic: async (cardId, channelId, topicId) => {
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return { state, actions }
|
return { state, actions }
|
||||||
|
@ -3,6 +3,17 @@ import { StoreContext } from 'context/StoreContext';
|
|||||||
import { getChannels } from 'api/getChannels';
|
import { getChannels } from 'api/getChannels';
|
||||||
import { getChannelDetail } from 'api/getChannelDetail';
|
import { getChannelDetail } from 'api/getChannelDetail';
|
||||||
import { getChannelSummary } from 'api/getChannelSummary';
|
import { getChannelSummary } from 'api/getChannelSummary';
|
||||||
|
import { addChannel } from 'api/addChannel';
|
||||||
|
import { removeChannel } from 'api/removeChannel';
|
||||||
|
import { removeChannelTopic } from 'api/removeChannelTopic';
|
||||||
|
import { setChannelTopicSubject } from 'api/setChannelTopicSubject';
|
||||||
|
import { addChannelTopic } from 'api/addChannelTopic';
|
||||||
|
import { getChannelTopics } from 'api/getChannelTopics';
|
||||||
|
import { getChannelTopic } from 'api/getChannelTopic';
|
||||||
|
import { getChannelTopicAssetUrl } from 'api/getChannelTopicAssetUrl';
|
||||||
|
import { setChannelSubject } from 'api/setChannelSubject';
|
||||||
|
import { setChannelCard } from 'api/setChannelCard';
|
||||||
|
import { clearChannelCard } from 'api/clearChannelCard';
|
||||||
|
|
||||||
export function useChannelContext() {
|
export function useChannelContext() {
|
||||||
const [state, setState] = useState({
|
const [state, setState] = useState({
|
||||||
@ -63,6 +74,13 @@ export function useChannelContext() {
|
|||||||
channels.current.set(channelId, channel);
|
channels.current.set(channelId, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const setChannelSyncRevision = (channelId, revision) => {
|
||||||
|
let channel = channels.current.get(channelId);
|
||||||
|
if (channel) {
|
||||||
|
channel.syncRevision = revision;
|
||||||
|
channels.current.set(channelId, channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const sync = async () => {
|
const sync = async () => {
|
||||||
|
|
||||||
@ -156,13 +174,11 @@ export function useChannelContext() {
|
|||||||
setChannelReadRevision(channelId, rev);
|
setChannelReadRevision(channelId, rev);
|
||||||
updateState({ channels: channels.current });
|
updateState({ channels: channels.current });
|
||||||
},
|
},
|
||||||
getSyncRevision: async (channelId) => {
|
|
||||||
const { guid } = session.current;
|
|
||||||
return await store.actions.getChannelItemSyncRevision(guid, channelId);
|
|
||||||
},
|
|
||||||
setSyncRevision: async (channelId, revision) => {
|
setSyncRevision: async (channelId, revision) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.setChannelItemSyncRevision(guid, channelId, revision);
|
await store.actions.setChannelItemSyncRevision(guid, channelId, revision);
|
||||||
|
setChannelSyncRevision(channelId, revision);
|
||||||
|
updateState({ channels: channels.current });
|
||||||
},
|
},
|
||||||
getTopicItems: async (channelId) => {
|
getTopicItems: async (channelId) => {
|
||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
@ -184,7 +200,20 @@ export function useChannelContext() {
|
|||||||
const { guid } = session.current;
|
const { guid } = session.current;
|
||||||
return await store.actions.clearChannelTopicItems(guid, channelId);
|
return await store.actions.clearChannelTopicItems(guid, channelId);
|
||||||
},
|
},
|
||||||
|
getTopic: async (channelId, topicId) => {
|
||||||
|
},
|
||||||
|
getTopics: async (channelId) => {
|
||||||
|
},
|
||||||
|
getTopicAssetUrl: async (channelId, assetId) => {
|
||||||
|
},
|
||||||
|
addTopic: async (channelId, message, assets) => {
|
||||||
|
},
|
||||||
|
setTopicSubject: async (channelId, topicId, data) => {
|
||||||
|
},
|
||||||
|
remove: async (channelId) => {
|
||||||
|
},
|
||||||
|
removeTopic: async (channelId, topicId) => {
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return { state, actions }
|
return { state, actions }
|
||||||
|
@ -17,29 +17,97 @@ export function useConversationContext() {
|
|||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
const topics = useRef(new Map());
|
const topics = useRef(new Map());
|
||||||
const revision = useRef(0);
|
const revision = useRef(0);
|
||||||
|
const detailRevision = useRef(0);
|
||||||
|
const syncRevision = useRef(0);
|
||||||
const syncing = useRef(false);
|
const syncing = useRef(false);
|
||||||
const cardId = useRef(null);
|
const conversationId = useRef(null);
|
||||||
const channelId = useRef(null);
|
|
||||||
const setView = useRef(0);
|
const setView = useRef(0);
|
||||||
|
|
||||||
const updateState = (value) => {
|
const updateState = (value) => {
|
||||||
setState((s) => ({ ...s, ...value }))
|
setState((s) => ({ ...s, ...value }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getTopicItems = async (cardId, channelId) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.getChannelTopicItems(cardId, channelId);
|
||||||
|
}
|
||||||
|
return await channel.actions.getTopicItems(channelId);
|
||||||
|
}
|
||||||
|
const getTopicDeltaItems = async (cardId, channelId, revision) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.getChannelTopicDeltaItems(cardId, channelId, revision);
|
||||||
|
}
|
||||||
|
return await channel.actions.getTopicDeltaItems(channelId, revision);
|
||||||
|
}
|
||||||
|
const setTopicItem = async (cardId, channelId, revision, topic) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.setChannelTopicItem(cardId, channelId, revision, topic);
|
||||||
|
}
|
||||||
|
return await channel.actions.setTopicItem(channelId, revision, topic);
|
||||||
|
}
|
||||||
|
const clearTopicItem = async (cardId, channelId, topicId) => {
|
||||||
|
if (cardId) {
|
||||||
|
return await card.actions.clearChannelTopicItem(cardId, channelId, topicId);
|
||||||
|
}
|
||||||
|
return await channel.actions.clearTopicItem(channelId, topicId);
|
||||||
|
}
|
||||||
|
const getTopic = async (cardId, channelId, topicId) => {
|
||||||
|
}
|
||||||
|
const getTopics = async (cardId, channelId) => {
|
||||||
|
}
|
||||||
|
const getTopicAssetUrl = async (cardId, channelId, assetId) => {
|
||||||
|
}
|
||||||
|
const addTopic = async (cardId, channelId, message, asssets) => {
|
||||||
|
}
|
||||||
|
const setTopicSubject = async (cardId, channelId, topicId, data) => {
|
||||||
|
}
|
||||||
|
const removeChannel = async (cardId, channelId) => {
|
||||||
|
}
|
||||||
|
const removeChannelTopic = async (cardId, channelId, topicId) => {
|
||||||
|
}
|
||||||
|
|
||||||
const sync = async () => {
|
const sync = async () => {
|
||||||
const curView = setView.current;
|
const curView = setView.current;
|
||||||
const item = getChannel(cardId.current, channelId.current);
|
if (!syncing.current && conversationId.current) {
|
||||||
if (!syncing.current && item?.revision !== revision.current) {
|
const { cardId, channelId } = conversationId.current;
|
||||||
syncing.current = true;
|
const item = getChannel(cardId, channelId);
|
||||||
|
if (item && (item.revision !== revision.current || item.syncRevision != syncRevision.current)) {
|
||||||
|
syncing.current = true;
|
||||||
|
|
||||||
// stuff
|
// set channel details
|
||||||
setChannel(item);
|
if (detailRevision.current != item.detailRevision) {
|
||||||
|
if (curView === setView.current) {
|
||||||
|
setChannel(item);
|
||||||
|
detailRevision.current = item.detailRevision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (curView === setView.current) {
|
// set channel topics
|
||||||
revision.current = item?.revision;
|
if (syncRevision.current != item.syncRevision) {
|
||||||
|
if (syncRevision.current) {
|
||||||
|
const topics = getTopicDeltaItems(cardId, channelId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const topics = getTopicItems(cardId, channelId);
|
||||||
|
}
|
||||||
|
if (curView === setView.current) {
|
||||||
|
syncRevision.current = item.syncRevision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sync from server to store
|
||||||
|
if (item.topicRevision !== item.syncRevision) {
|
||||||
|
console.log("pull latest topics");
|
||||||
|
}
|
||||||
|
|
||||||
|
// update revision
|
||||||
|
if (curView === setView.current) {
|
||||||
|
revision.current = item.revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
syncing.current = false;
|
||||||
|
sync();
|
||||||
}
|
}
|
||||||
syncing.current = false;
|
|
||||||
sync();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,12 +202,20 @@ export function useConversationContext() {
|
|||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
setChannel: (channel) => {
|
setChannel: (channel) => {
|
||||||
if (channel.cardId !== cardId.current || channel.channelId !== channelId.current) {
|
if (channel == null) {
|
||||||
setView.current++;
|
setView.current++;
|
||||||
revision.current = 0;
|
conversationId.current = null;
|
||||||
|
updateState({ subject: null, logo: null, contacts: [], topics: [] });
|
||||||
|
}
|
||||||
|
else if (channel.cardId !== conversationId.current?.cardId || channel.channelId !== conversationId.current?.channelId) {
|
||||||
|
setView.current++;
|
||||||
|
conversationId.current = channel;
|
||||||
|
updateState({ subject: null, logo: null, contacts: [], topics: [] });
|
||||||
|
|
||||||
|
revision.current = null;
|
||||||
|
detailRevision.current = null;
|
||||||
|
syncRevision.current = null;
|
||||||
topics.current = new Map();
|
topics.current = new Map();
|
||||||
channelId.current = channel.channelId;
|
|
||||||
cardId.current = channel.cardId;
|
|
||||||
sync();
|
sync();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -186,9 +186,6 @@ export function useStoreContext() {
|
|||||||
setChannelItemReadRevision: async (guid, channelId, revision) => {
|
setChannelItemReadRevision: async (guid, channelId, revision) => {
|
||||||
await db.current.executeSql(`UPDATE channel_${guid} set read_revision=? where channel_id=?`, [revision, channelId]);
|
await db.current.executeSql(`UPDATE channel_${guid} set read_revision=? where channel_id=?`, [revision, channelId]);
|
||||||
},
|
},
|
||||||
getChannelItemSyncRevision: async (guid, cardId, channelId) => {
|
|
||||||
return getValue(`SELECT sync_revision as value FROM channel_${guid} where channel_id=?`, [channelId]);
|
|
||||||
},
|
|
||||||
setChannelItemSyncRevision: async (guid, channelId, revision) => {
|
setChannelItemSyncRevision: async (guid, channelId, revision) => {
|
||||||
await db.current.executeSql(`UPDATE channel_${guid} set sync_revision=? where channel_id=?`, [revision, channelId]);
|
await db.current.executeSql(`UPDATE channel_${guid} set sync_revision=? where channel_id=?`, [revision, channelId]);
|
||||||
},
|
},
|
||||||
@ -210,13 +207,14 @@ export function useStoreContext() {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
getChannelItems: async (guid) => {
|
getChannelItems: async (guid) => {
|
||||||
const values = await getAppValues(db.current, `SELECT channel_id, read_revision, revision, detail_revision, topic_revision, detail, summary FROM channel_${guid}`, []);
|
const values = await getAppValues(db.current, `SELECT channel_id, read_revision, revision, sync_revision, detail_revision, topic_revision, detail, summary FROM channel_${guid}`, []);
|
||||||
return values.map(channel => ({
|
return values.map(channel => ({
|
||||||
channelId: channel.channel_id,
|
channelId: channel.channel_id,
|
||||||
revision: channel.revision,
|
revision: channel.revision,
|
||||||
readRevision: channel.read_revision,
|
readRevision: channel.read_revision,
|
||||||
detailRevision: channel.detail_revision,
|
detailRevision: channel.detail_revision,
|
||||||
topicRevision: channel.topic_revision,
|
topicRevision: channel.topic_revision,
|
||||||
|
syncRevsion: channel.sync_revision,
|
||||||
detail: decodeObject(channel.detail),
|
detail: decodeObject(channel.detail),
|
||||||
summary: decodeObject(channel.summary),
|
summary: decodeObject(channel.summary),
|
||||||
}));
|
}));
|
||||||
@ -265,9 +263,6 @@ export function useStoreContext() {
|
|||||||
setCardChannelItemReadRevision: async (guid, cardId, channelId, revision) => {
|
setCardChannelItemReadRevision: async (guid, cardId, channelId, revision) => {
|
||||||
await db.current.executeSql(`UPDATE card_channel_${guid} set read_revision=? where card_id=? and channel_id=?`, [revision, cardId, channelId]);
|
await db.current.executeSql(`UPDATE card_channel_${guid} set read_revision=? where card_id=? and channel_id=?`, [revision, cardId, channelId]);
|
||||||
},
|
},
|
||||||
getCardChannelItemSyncRevision: async (guid, cardId, channelId) => {
|
|
||||||
return getValue(`SELECT sync_revision as value FROM card_channel_${guid} where card_id=? and channel_id=?`, [cardId, channelId]);
|
|
||||||
},
|
|
||||||
setCardChannelItemSyncRevision: async (guid, cardId, channelId, revision) => {
|
setCardChannelItemSyncRevision: async (guid, cardId, channelId, revision) => {
|
||||||
await db.current.executeSql(`UPDATE card_channel_${guid} set sync_revision=? where card_id=? and channel_id=?`, [revision, cardId, channelId]);
|
await db.current.executeSql(`UPDATE card_channel_${guid} set sync_revision=? where card_id=? and channel_id=?`, [revision, cardId, channelId]);
|
||||||
},
|
},
|
||||||
@ -289,7 +284,7 @@ export function useStoreContext() {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
getCardChannelItems: async (guid) => {
|
getCardChannelItems: async (guid) => {
|
||||||
const values = await getAppValues(db.current, `SELECT card_id, channel_id, read_revision, revision, blocked, detail_revision, topic_revision, detail, summary FROM card_channel_${guid}`, []);
|
const values = await getAppValues(db.current, `SELECT card_id, channel_id, read_revision, sync_revision, revision, blocked, detail_revision, topic_revision, detail, summary FROM card_channel_${guid}`, []);
|
||||||
return values.map(channel => ({
|
return values.map(channel => ({
|
||||||
cardId: channel.card_id,
|
cardId: channel.card_id,
|
||||||
channelId: channel.channel_id,
|
channelId: channel.channel_id,
|
||||||
@ -297,6 +292,7 @@ export function useStoreContext() {
|
|||||||
readRevision: channel.read_revision,
|
readRevision: channel.read_revision,
|
||||||
detailRevision: channel.detail_revision,
|
detailRevision: channel.detail_revision,
|
||||||
topicRevision: channel.topic_revision,
|
topicRevision: channel.topic_revision,
|
||||||
|
syncRevision: channel.sync_revision,
|
||||||
detail: decodeObject(channel.detail),
|
detail: decodeObject(channel.detail),
|
||||||
summary: decodeObject(channel.summary),
|
summary: decodeObject(channel.summary),
|
||||||
blocked: channel.blocked,
|
blocked: channel.blocked,
|
||||||
@ -388,11 +384,4 @@ async function getAppValues(sql: SQLite.SQLiteDatabase, query: string, params) {
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getValue(sql: SQLite.SQLiteDatabase, query: string, params) {
|
|
||||||
const res = await sql.executeSql(query, params);
|
|
||||||
if (hasResult(res)) {
|
|
||||||
return res[0].rows.item(0).value
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { View, TouchableOpacity, Text } from 'react-native';
|
import { View, TouchableOpacity, Text } from 'react-native';
|
||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect, useContext } from 'react';
|
||||||
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
|
import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context';
|
||||||
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
||||||
import { createDrawerNavigator } from '@react-navigation/drawer';
|
import { createDrawerNavigator } from '@react-navigation/drawer';
|
||||||
@ -21,6 +21,7 @@ import { Welcome } from './welcome/Welcome';
|
|||||||
import { ChannelsTitle, ChannelsBody, Channels } from './channels/Channels';
|
import { ChannelsTitle, ChannelsBody, Channels } from './channels/Channels';
|
||||||
import { useChannels } from './channels/useChannels.hook';
|
import { useChannels } from './channels/useChannels.hook';
|
||||||
import { CommonActions } from '@react-navigation/native';
|
import { CommonActions } from '@react-navigation/native';
|
||||||
|
import { ConversationContext } from 'context/ConversationContext';
|
||||||
|
|
||||||
const ConversationStack = createStackNavigator();
|
const ConversationStack = createStackNavigator();
|
||||||
const ProfileStack = createStackNavigator();
|
const ProfileStack = createStackNavigator();
|
||||||
@ -77,6 +78,11 @@ export function Session() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const channels = useChannels();
|
const channels = useChannels();
|
||||||
|
const conversation = useContext(ConversationContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
conversation.actions.setChannel(selected);
|
||||||
|
}, [selected]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConversationStack.Navigator screenOptions={({ route }) => ({ headerShown: true, headerTintColor: Colors.primary })}>
|
<ConversationStack.Navigator screenOptions={({ route }) => ({ headerShown: true, headerTintColor: Colors.primary })}>
|
||||||
|
@ -15,10 +15,6 @@ export function useConversation(cardId, channelId) {
|
|||||||
setState((s) => ({ ...s, ...value }));
|
setState((s) => ({ ...s, ...value }));
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
conversation.actions.setChannel({ cardId, channelId });
|
|
||||||
}, [cardId, channelId]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { topics, subject, logo } = conversation.state;
|
const { topics, subject, logo } = conversation.state;
|
||||||
updateState({ topics, subject, logo });
|
updateState({ topics, subject, logo });
|
||||||
|
Loading…
Reference in New Issue
Block a user