mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
optimize add topic for message only
This commit is contained in:
parent
8cf1d2f24b
commit
91621b8a58
@ -19,7 +19,7 @@ export function Home() {
|
||||
navigate('/admin')
|
||||
}
|
||||
}
|
||||
}, [])
|
||||
}, [app])
|
||||
|
||||
return <></>
|
||||
}
|
||||
|
@ -1,16 +1,25 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function addChannelTopic(token, channelId, message, assets ) {
|
||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`,
|
||||
{ method: 'POST', body: JSON.stringify({}) });
|
||||
checkResponse(topic);
|
||||
let slot = await topic.json();
|
||||
|
||||
// add each asset
|
||||
|
||||
let subject = { data: JSON.stringify(message, (key, value) => {
|
||||
if (value !== null) return value
|
||||
}), datatype: 'superbasictopic' };
|
||||
|
||||
if (assets == null || assets.length == 0) {
|
||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}&confirm=true`,
|
||||
{ method: 'POST', body: JSON.stringify(subject) });
|
||||
checkResponse(topic);
|
||||
}
|
||||
else {
|
||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}`,
|
||||
{ method: 'POST', body: JSON.stringify({}) });
|
||||
checkResponse(topic);
|
||||
|
||||
let slot = await topic.json();
|
||||
|
||||
// add each asset
|
||||
|
||||
let unconfirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/subject?agent=${token}`,
|
||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||
checkResponse(unconfirmed);
|
||||
@ -18,7 +27,6 @@ export async function addChannelTopic(token, channelId, message, assets ) {
|
||||
let confirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/confirmed?agent=${token}`,
|
||||
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||
checkResponse(confirmed);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,17 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function addContactChannelTopic(server, token, channelId, message, assets ) {
|
||||
|
||||
let subject = { data: JSON.stringify(message, (key, value) => {
|
||||
if (value !== null) return value
|
||||
}), datatype: 'superbasictopic' };
|
||||
|
||||
if (assets == null || assets.length == 0) {
|
||||
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}&confirm=true`,
|
||||
{ method: 'POST', body: JSON.stringify(subject) });
|
||||
checkResponse(topic);
|
||||
}
|
||||
else {
|
||||
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
|
||||
{ method: 'POST', body: JSON.stringify({}) });
|
||||
checkResponse(topic);
|
||||
@ -8,9 +19,6 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
||||
|
||||
// add each asset
|
||||
|
||||
let subject = { data: JSON.stringify(message, (key, value) => {
|
||||
if (value !== null) return value
|
||||
}), datatype: 'superbasictopic' };
|
||||
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
|
||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||
checkResponse(unconfirmed);
|
||||
@ -18,7 +26,6 @@ export async function addContactChannelTopic(server, token, channelId, message,
|
||||
let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
|
||||
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||
checkResponse(confirmed);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,8 +163,8 @@ export function useAppContext() {
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (!state) {
|
||||
return {}
|
||||
if (state == null) {
|
||||
return {};
|
||||
}
|
||||
if (state.access === 'user') {
|
||||
return { state, actions: userActions }
|
||||
|
Loading…
Reference in New Issue
Block a user