mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
addTopic to contact channel
This commit is contained in:
parent
6e2801d705
commit
34eceaa533
24
net/web/src/Api/addContactChannelTopic.js
Normal file
24
net/web/src/Api/addContactChannelTopic.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function addContactChannelTopic(token, channelId, message, assets ) {
|
||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics?contact=${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' };
|
||||
let unconfirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/subject?contact=${token}`,
|
||||
{ method: 'PUT', body: JSON.stringify(subject) });
|
||||
checkResponse(unconfirmed);
|
||||
|
||||
let confirmed = await fetchWithTimeout(`/content/channels/${channelId}/topics/${slot.id}/confirmed?contact=${token}`,
|
||||
{ method: 'PUT', body: JSON.stringify('confirmed') });
|
||||
checkResponse(confirmed);
|
||||
|
||||
return;
|
||||
}
|
||||
|
8
net/web/src/Api/getContactChannel.js
Normal file
8
net/web/src/Api/getContactChannel.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getContactChannel(token, channelId) {
|
||||
let channel = await fetchWithTimeout(`/content/channels/${channelId}/detail?contact=${token}`, { method: 'GET' });
|
||||
checkResponse(channel)
|
||||
return await channel.json()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import { getContactProfile, setCardProfile, getCards, getCardImageUrl, getCardPr
|
||||
import { getChannels } from '../Api/getChannels';
|
||||
import { getChannel } from '../Api/getChannel';
|
||||
import { getContactChannels } from '../Api/getContactChannels';
|
||||
import { getContactChannel } from '../Api/getContactChannel';
|
||||
|
||||
async function updateAccount(token, updateData) {
|
||||
let status = await getAccountStatus(token);
|
||||
@ -134,10 +135,24 @@ async function updateCards(token, revision, cardMap, updateData, mergeChannels)
|
||||
|
||||
async function updateContactChannels(token, viewRevision, channelRevision, channelMap) {
|
||||
let channels = await getContactChannels(token, viewRevision, channelRevision);
|
||||
|
||||
for (let channel of channels) {
|
||||
if (channel.data) {
|
||||
channelMap.set(channel.id, channel);
|
||||
let cur = channelMap.get(channel.id);
|
||||
if (cur == null) {
|
||||
cur = { id: channel.id, data: { } }
|
||||
}
|
||||
if (cur.data.detailRevision != channel.data.detailRevision) {
|
||||
if (channel.data.channelDetail != null) {
|
||||
cur.data.channelDetail = channel.data.channelDetail;
|
||||
cur.data.detailRevision = channel.data.detailRevision;
|
||||
}
|
||||
else {
|
||||
let slot = await getContactChannel(token, channel.id);
|
||||
cur.data.channelDetail = slot.data.channelDetail;
|
||||
cur.data.detailRevision = slot.data.detailRevision;
|
||||
}
|
||||
}
|
||||
channelMap.set(channel.id, cur);
|
||||
}
|
||||
else {
|
||||
channelMap.delete(channel.id);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { useContext, useState, useEffect } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { addChannelTopic } from '../../../Api/addChannelTopic';
|
||||
import { addContactChannelTopic } from '../../../Api/addContactChannelTopic';
|
||||
import { AppContext } from '../../../AppContext/AppContext';
|
||||
|
||||
export function useAddTopic() {
|
||||
@ -53,9 +54,14 @@ export function useAddTopic() {
|
||||
if (!state.busy) {
|
||||
updateState({ busy: true });
|
||||
try {
|
||||
if (!contact) {
|
||||
let message = { text: state.messageText, textColor: state.messageColor,
|
||||
textSize: state.messageSize, backgroundColor: state.backgroundColor };
|
||||
if (contact) {
|
||||
let card = app.actions.getCard(contact);
|
||||
let token = contact + '.' + card?.data?.cardDetail?.token;
|
||||
await addContactChannelTopic(token, channel, message, []);
|
||||
}
|
||||
else {
|
||||
await addChannelTopic(app.state.token, channel, message, []);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user