presenting sealed conversation subject in header for webapp

This commit is contained in:
Roland Osborne 2022-12-15 10:41:54 -08:00
parent 6ee1ebef14
commit c44bf282de
5 changed files with 51 additions and 53 deletions

View File

@ -21,6 +21,10 @@ export function useConversationContext() {
enableImage: null, enableImage: null,
enabelAudio: null, enabelAudio: null,
enableVideo: null, enableVideo: null,
sealed: false,
image: null,
logoUrl: null,
logoImg: null,
}); });
const EVENT_OPEN = 1; const EVENT_OPEN = 1;
@ -56,6 +60,10 @@ export function useConversationContext() {
return null; return null;
} }
if (conversation.data.channelDetail.dataType === 'sealed') {
return conversation.data.unsealedChannel?.subject;
}
else {
try { try {
let subject = JSON.parse(conversation.data.channelDetail.data).subject; let subject = JSON.parse(conversation.data.channelDetail.data).subject;
if (subject) { if (subject) {
@ -63,9 +71,11 @@ export function useConversationContext() {
} }
} }
catch (err) { catch (err) {
return null; console.log(err);
} }
} }
return null;
}
const getContacts = (conversation) => { const getContacts = (conversation) => {
if (!conversation) { if (!conversation) {
@ -199,16 +209,37 @@ export function useConversationContext() {
if (curView === view.current) { if (curView === view.current) {
let chan = getChannel(); let chan = getChannel();
let subject = getSubject(chan);
let contacts = getContacts(chan); let contacts = getContacts(chan);
let subject = getSubject(chan);
let members = getMembers(chan); let members = getMembers(chan);
const enableImage = chan?.data?.channelDetail?.enableImage; const enableImage = chan?.data?.channelDetail?.enableImage;
const enableAudio = chan?.data?.channelDetail?.enableAudio; const enableAudio = chan?.data?.channelDetail?.enableAudio;
const enableVideo = chan?.data?.channelDetail?.enableVideo; const enableVideo = chan?.data?.channelDetail?.enableVideo;
const sealed = chan?.data?.channelDetail?.dataType === 'sealed';
let logoUrl = null;
let logoImg = null;
if (!members?.size) {
subject = subject ? subject : "Notes";
logoImg = "solution";
}
else if (members.size > 1) {
subject = subject ? subject : "Group";
logoImg = "appstore";
}
else {
const contact = card.actions.getCardByGuid(members.values().next().value);
subject = subject ? subject : card.actions.getName(contact.id);
logoUrl = card.actions.getImageUrl(contact.id);
}
updateState({ updateState({
init: true, init: true,
error: false, error: false,
sealed,
subject, subject,
logoImg,
logoUrl,
contacts, contacts,
members, members,
enableImage, enableImage,

View File

@ -41,7 +41,7 @@ export function Conversation({ closeConversation, openDetails, cardId, channelId
<div class="header"> <div class="header">
<div class="title"> <div class="title">
<div class="logo"> <div class="logo">
<Logo img={state.image} url={state.logo} width={32} height={32} radius={4} /> <Logo img={state.logoImg} url={state.logoUrl} width={32} height={32} radius={4} />
</div> </div>
<div class="label">{ state.subject }</div> <div class="label">{ state.subject }</div>
{ state.error && state.display === 'small' && ( { state.error && state.display === 'small' && (

View File

@ -104,22 +104,24 @@ export function AddTopic({ cardId, channelId }) {
value={state.messageText} autocapitalize="none" /> value={state.messageText} autocapitalize="none" />
</div> </div>
<div class="buttons"> <div class="buttons">
{ state.enableImage && ( { !state.sealed && state.enableImage && (
<div class="button space" onClick={() => attachImage.current.click()}> <div class="button space" onClick={() => attachImage.current.click()}>
<PictureOutlined /> <PictureOutlined />
</div> </div>
)} )}
{ state.enableVideo && ( { !state.sealed && state.enableVideo && (
<div class="button space" onClick={() => attachVideo.current.click()}> <div class="button space" onClick={() => attachVideo.current.click()}>
<VideoCameraOutlined /> <VideoCameraOutlined />
</div> </div>
)} )}
{ state.enableAudio && ( { !state.sealed && state.enableAudio && (
<div class="button space" onClick={() => attachAudio.current.click()}> <div class="button space" onClick={() => attachAudio.current.click()}>
<SoundOutlined /> <SoundOutlined />
</div> </div>
)} )}
{ !state.sealed && (
<div class="bar space" /> <div class="bar space" />
)}
<div class="button space"> <div class="button space">
<Dropdown overlay={picker} overlayStyle={{ minWidth: 0 }} trigger={['click']} placement="top"> <Dropdown overlay={picker} overlayStyle={{ minWidth: 0 }} trigger={['click']} placement="top">
<FontColorsOutlined /> <FontColorsOutlined />

View File

@ -9,6 +9,7 @@ export function useAddTopic(cardId, channelId) {
enableImage: null, enableImage: null,
enableAudio: null, enableAudio: null,
enableVideo: null, enableVideo: null,
sealed: false,
assets: [], assets: [],
messageText: null, messageText: null,
textColor: '#444444', textColor: '#444444',
@ -49,8 +50,8 @@ export function useAddTopic(cardId, channelId) {
} }
useEffect(() => { useEffect(() => {
const { enableImage, enableAudio, enableVideo } = conversation.state; const { enableImage, enableAudio, enableVideo, sealed } = conversation.state;
updateState({ enableImage, enableAudio, enableVideo }); updateState({ enableImage, enableAudio, enableVideo, sealed });
}, [conversation]); }, [conversation]);
const actions = { const actions = {

View File

@ -10,7 +10,6 @@ export function useConversation(cardId, channelId) {
const [state, setState] = useState({ const [state, setState] = useState({
display: null, display: null,
image: null,
logo: null, logo: null,
subject: null, subject: null,
topics: [], topics: [],
@ -69,41 +68,6 @@ export function useConversation(cardId, channelId) {
updateState({ upload: active, uploadError, uploadPercent }); updateState({ upload: active, uploadError, uploadPercent });
}, [cardId, channelId, upload]); }, [cardId, channelId, upload]);
useEffect(() => {
let chan, image, subject, logo;
if (cardId) {
const cardChan = card.state.cards.get(cardId);
if (cardChan) {
chan = cardChan.channels.get(channelId);
}
}
else {
chan = channel.state.channels.get(channelId);
}
if (chan) {
if (!chan.contacts?.length) {
image = 'solution';
subject = 'Notes';
}
else if (chan.contacts.length > 1) {
image = 'appstore'
subject = 'Group';
}
else {
logo = card.actions.getImageUrl(chan.contacts[0]?.id);
subject = card.actions.getName(chan.contacts[0]?.id);
}
const parsed = JSON.parse(chan.data.channelDetail.data);
if (parsed.subject) {
subject = parsed.subject;
}
}
updateState({ image, subject, logo });
}, [cardId, channelId, card, channel]);
useEffect(() => { useEffect(() => {
updateState({ topics: [] }); updateState({ topics: [] });
conversation.actions.setConversationId(cardId, channelId); conversation.actions.setConversationId(cardId, channelId);
@ -122,8 +86,8 @@ export function useConversation(cardId, channelId) {
} }
return 1; return 1;
}); });
const { error, loadingInit, loadingMore } = conversation.state; const { error, loadingInit, loadingMore, subject, logoUrl, logoImg } = conversation.state;
updateState({ topics, error, loadingInit, loadingMore }); updateState({ topics, error, loadingInit, loadingMore, subject, logoUrl, logoImg });
store.actions.setValue(`${channelId}::${cardId}`, Number(conversation.state.revision)); store.actions.setValue(`${channelId}::${cardId}`, Number(conversation.state.revision));
// eslint-disable-next-line // eslint-disable-next-line
}, [conversation]); }, [conversation]);