open existing dm thread if exists

This commit is contained in:
Roland Osborne 2023-04-05 22:59:44 -07:00
parent 843a22c17b
commit 8d8b6c32e0
2 changed files with 14 additions and 2 deletions

View File

@ -45,10 +45,10 @@ export function CardItem({ item, tooltip, resync, open, call, message }) {
)}
{ item.status === 'connected' && (
<ComOptions>
<Tooltip className="option" placement="left" title="start a new topic">
<Tooltip className="option" placement="left" title="message contact">
<MessageOutlined onClick={onMessage} />
</Tooltip>
<Tooltip className="option" placement="left" title="start a call">
<Tooltip className="option" placement="left" title="call contact">
<PhoneOutlined onClick={onCall} />
</Tooltip>
</ComOptions>

View File

@ -119,6 +119,18 @@ export function useCards() {
await card.actions.resyncCard(cardId);
},
message: async (cardId) => {
let channelId = null;
channel.state.channels.forEach((entry, id) => {
const cards = entry?.data?.channelDetail?.contacts?.cards || [];
const subject = entry?.data?.channelDetail?.data || '';
const type = entry?.data?.channelDetail?.dataType || '';
if (cards.length === 1 && cards[0] === cardId && type === 'superbasic' && subject === '{"subject":null}') {
channelId = entry.id;
}
});
if (channelId != null) {
return channelId;
}
const conversation = await channel.actions.addChannel('superbasic', { subject: null }, [ cardId ]);
return conversation.id;
},