mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
displaying conversation topics
This commit is contained in:
parent
e2e115b80d
commit
f01dab52b6
@ -2472,7 +2472,7 @@ paths:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Subject'
|
||||
|
||||
/content/channels/{channelId}/topics/{topicId}:
|
||||
/content/channels/{channelId}/topics/{topicId}/detail:
|
||||
get:
|
||||
tags:
|
||||
- content
|
||||
@ -2508,6 +2508,8 @@ paths:
|
||||
description: account disabled
|
||||
'500':
|
||||
description: internal server error
|
||||
|
||||
/content/channels/{channelId}/topics/{topicId}:
|
||||
delete:
|
||||
tags:
|
||||
- content
|
||||
|
@ -25,7 +25,7 @@ func GetChannelTopics(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
var response []*Topic
|
||||
response := []*Topic{}
|
||||
if revisionSet {
|
||||
var slots []store.TopicSlot
|
||||
if err := store.DB.Preload("Topic").Where("channel_id = ? AND revision > ?", channelSlot.Channel.ID, revision).Find(&slots).Error; err != nil {
|
||||
|
@ -555,7 +555,7 @@ var routes = Routes{
|
||||
Route{
|
||||
"GetChannelTopic",
|
||||
strings.ToUpper("Get"),
|
||||
"/content/channels/{channelId}/topics/{topicId}",
|
||||
"/content/channels/{channelId}/topics/{topicId}/detail",
|
||||
GetChannelTopic,
|
||||
},
|
||||
|
||||
|
9
net/web/src/Api/getChannelTopic.js
Normal file
9
net/web/src/Api/getChannelTopic.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getChannelTopic(token, channelId, topicId) {
|
||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics/${topicId}/detail?agent=${token}`,
|
||||
{ method: 'GET' });
|
||||
checkResponse(topic)
|
||||
return await topic.json()
|
||||
}
|
||||
|
13
net/web/src/Api/getChannelTopics.js
Normal file
13
net/web/src/Api/getChannelTopics.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getChannelTopics(token, channelId, revision) {
|
||||
let rev = ''
|
||||
if (revision != null) {
|
||||
rev = `&revision=${revision}`
|
||||
}
|
||||
let topics = await fetchWithTimeout(`/content/channels/${channelId}/topics?agent=${token}${rev}`,
|
||||
{ method: 'GET' });
|
||||
checkResponse(topics)
|
||||
return await topics.json()
|
||||
}
|
||||
|
9
net/web/src/Api/getContactChannelTopic.js
Normal file
9
net/web/src/Api/getContactChannelTopic.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getContactChannelTopic(token, channelId, topicId) {
|
||||
let topic = await fetchWithTimeout(`/content/channels/${channelId}/topics/${topicId}/detail?contact=${token}`,
|
||||
{ method: 'GET' });
|
||||
checkResponse(topic)
|
||||
return await topic.json()
|
||||
}
|
||||
|
13
net/web/src/Api/getContactChannelTopics.js
Normal file
13
net/web/src/Api/getContactChannelTopics.js
Normal file
@ -0,0 +1,13 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function getContactChannelTopics(token, channelId, revision) {
|
||||
let rev = ''
|
||||
if (revision != null) {
|
||||
rev = `&revision=${revision}`
|
||||
}
|
||||
let topics = await fetchWithTimeout(`/content/channels/${channelId}/topics?contact=${token}${rev}`,
|
||||
{ method: 'GET' });
|
||||
checkResponse(topics)
|
||||
return await topics.json()
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ async function updateChannels(token, revision, channelMap, mergeChannels) {
|
||||
cur.data.detailRevision = slot.data.detailRevision;
|
||||
}
|
||||
}
|
||||
cur.data.topicRevision = channel.data.topicRevision;
|
||||
cur.revision = channel.revision;
|
||||
channelMap.set(channel.id, cur);
|
||||
}
|
||||
else {
|
||||
@ -152,6 +154,8 @@ async function updateContactChannels(token, viewRevision, channelRevision, chann
|
||||
cur.data.detailRevision = slot.data.detailRevision;
|
||||
}
|
||||
}
|
||||
cur.data.topicRevision = channel.data.topicRevision;
|
||||
cur.revision = channel.revision;
|
||||
channelMap.set(channel.id, cur);
|
||||
}
|
||||
else {
|
||||
@ -280,6 +284,7 @@ export function useAppContext() {
|
||||
getCardImageUrl: (cardId, revision) => getCardImageUrl(state.token, cardId, revision),
|
||||
getCardByGuid: getCardByGuid,
|
||||
getCard: (id) => cards.current.get(id),
|
||||
getChannel: (id) => channels.current.get(id),
|
||||
getConnectedCards: getConnectedCards,
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ export function useContact() {
|
||||
|
||||
useEffect(() => {
|
||||
if (app?.state?.access === 'user') {
|
||||
let card = app.actions.getCard(guid);
|
||||
let card = app.actions.getCardByGuid(guid);
|
||||
if (card) {
|
||||
let profile = card.data.cardProfile;
|
||||
updateState({ cardId: card.id });
|
||||
|
@ -17,8 +17,8 @@ export function Conversation() {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setScrollIndex(998);
|
||||
})
|
||||
setScrollIndex(state.topics.length);
|
||||
}, [state])
|
||||
|
||||
const renderRow = ({ index, isScrolling, key, parent, style }) => {
|
||||
|
||||
@ -33,7 +33,7 @@ export function Conversation() {
|
||||
{({ measure, registerChild }) => (
|
||||
// 'style' attribute required to position cell (within parent List)
|
||||
<div class="noselect" ref={registerChild} style={style}>
|
||||
TEST MESSAGE!!!
|
||||
{ state.topics[index].data.topicDetail.data }
|
||||
</div>
|
||||
)}
|
||||
</CellMeasurer>
|
||||
@ -56,7 +56,7 @@ export function Conversation() {
|
||||
deferredMeasurementCache={cache}
|
||||
rowHeight={cache.rowHeight}
|
||||
rowRenderer={renderRow}
|
||||
rowCount={999}
|
||||
rowCount={state.topics.length}
|
||||
overscanRowCount={16}
|
||||
scrollToIndex={scrollIndex}
|
||||
/>
|
||||
|
@ -1,16 +1,21 @@
|
||||
import { useContext, useState, useEffect } from 'react';
|
||||
import { useContext, useState, useEffect, useRef } from 'react';
|
||||
import { AppContext } from '../../AppContext/AppContext';
|
||||
import { useNavigate, useLocation, useParams } from "react-router-dom";
|
||||
import { getChannelTopics } from '../../Api/getChannelTopics';
|
||||
import { getChannelTopic } from '../../Api/getChannelTopic';
|
||||
import { getContactChannelTopics } from '../../Api/getContactChannelTopics';
|
||||
import { getContactChannelTopic } from '../../Api/getContactChannelTopic';
|
||||
|
||||
export function useConversation() {
|
||||
|
||||
const [state, setState] = useState({
|
||||
topics: [],
|
||||
});
|
||||
|
||||
const data = useLocation();
|
||||
const { contact, channel } = useParams();
|
||||
const { card, channel } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const app = useContext(AppContext);
|
||||
const topics = useRef(new Map());
|
||||
|
||||
const updateState = (value) => {
|
||||
setState((s) => ({ ...s, ...value }));
|
||||
@ -22,5 +27,89 @@ export function useConversation() {
|
||||
},
|
||||
};
|
||||
|
||||
const updateConversation = async () => {
|
||||
if (card) {
|
||||
if(app?.actions?.getCard) {
|
||||
let contact = app.actions.getCard(card);
|
||||
let conversation = contact.channels.get(channel);
|
||||
if (conversation?.revision != state.revision) {
|
||||
let token = contact.data.cardProfile.guid + "." + contact.data.cardDetail.token;
|
||||
let slots = await getContactChannelTopics(token, channel, state.revision);
|
||||
|
||||
for (let topic of slots) {
|
||||
if (topic.data == null) {
|
||||
topics.current.delete(topic.id);
|
||||
}
|
||||
else {
|
||||
let cur = topics.current.get(topic.id);
|
||||
if (cur == null) {
|
||||
cur = { id: topic.id, data: {} };
|
||||
}
|
||||
if (topic.data.detailRevision != cur.data.detailRevision) {
|
||||
if(topic.data.topicDetail != null) {
|
||||
cur.data.topicDetail = topic.data.topicDetail;
|
||||
cur.data.detailRevision = topic.data.detailRevision;
|
||||
}
|
||||
else {
|
||||
let slot = await getContactChannelTopic(token, channel, topic.id);
|
||||
cur.data.topicDetail = slot.data.topicDetail;
|
||||
cur.data.detailRevision = slot.data.detailRevision;
|
||||
}
|
||||
}
|
||||
cur.revision = topic.revision;
|
||||
topics.current.set(topic.id, cur);
|
||||
}
|
||||
}
|
||||
|
||||
updateState({
|
||||
topics: Array.from(topics.current.values()),
|
||||
revision: conversation.Revision,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(app?.actions?.getChannel) {
|
||||
let conversation = app.actions.getChannel(channel);
|
||||
if (conversation?.revision != state.revision) {
|
||||
let slots = await getChannelTopics(app.state.token, channel, state.revision);
|
||||
|
||||
for (let topic of slots) {
|
||||
if (topic.data == null) {
|
||||
topics.current.delete(topic.id);
|
||||
}
|
||||
else {
|
||||
let cur = topics.current.get(topic.id);
|
||||
if (cur == null) {
|
||||
cur = { id: topic.id, data: {} };
|
||||
}
|
||||
if (topic.data.detailRevision != cur.data.detailRevision) {
|
||||
if(topic.data.topicDetail != null) {
|
||||
cur.data.topicDetail = topic.data.topicDetail;
|
||||
cur.data.detailRevision = topic.data.detailRevision;
|
||||
}
|
||||
else {
|
||||
let slot = await getChannelTopic(app.state.token, channel, topic.id);
|
||||
cur.data.topicDetail = slot.data.topicDetail;
|
||||
cur.data.detailRevision = slot.data.detailRevision;
|
||||
}
|
||||
}
|
||||
cur.revision = topic.revision;
|
||||
topics.current.set(topic.id, cur);
|
||||
}
|
||||
}
|
||||
updateState({
|
||||
topics: Array.from(topics.current.values()),
|
||||
revision: conversation.revision
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
updateConversation();
|
||||
}, [app]);
|
||||
|
||||
return { state, actions };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user