databag/net/web/src/api/addContactChannelTopic.js

25 lines
1003 B
JavaScript
Raw Normal View History

2022-04-15 04:07:11 +00:00
import { checkResponse, fetchWithTimeout } from './fetchUtil';
2022-04-25 17:29:22 +00:00
export async function addContactChannelTopic(server, token, channelId, message, assets ) {
let topic = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics?contact=${token}`,
2022-04-15 04:07:11 +00:00
{ 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' };
2022-04-25 17:29:22 +00:00
let unconfirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
2022-04-15 04:07:11 +00:00
{ method: 'PUT', body: JSON.stringify(subject) });
checkResponse(unconfirmed);
2022-04-25 17:29:22 +00:00
let confirmed = await fetchWithTimeout(`https://${server}/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
2022-04-15 04:07:11 +00:00
{ method: 'PUT', body: JSON.stringify('confirmed') });
checkResponse(confirmed);
return;
}