From 32de8dab4ff0815362016bcb65f7c20900fd6944 Mon Sep 17 00:00:00 2001 From: balzack Date: Mon, 16 Dec 2024 22:27:27 -0800 Subject: [PATCH] open dm thead from contacts --- app/client/web/src/contacts/Contacts.tsx | 8 +- .../web/src/contacts/useContacts.hook.ts | 6 - app/client/web/src/content/Content.tsx | 22 +- app/client/web/src/content/useContent.hook.ts | 20 + .../web/src/conversation/Conversation.tsx | 34 +- app/client/web/src/session/Session.tsx | 22 +- app/client/web/yarn.lock | 13378 +++++++++------- 7 files changed, 8105 insertions(+), 5385 deletions(-) diff --git a/app/client/web/src/contacts/Contacts.tsx b/app/client/web/src/contacts/Contacts.tsx index 30a18ae6..d05ecb6c 100644 --- a/app/client/web/src/contacts/Contacts.tsx +++ b/app/client/web/src/contacts/Contacts.tsx @@ -37,18 +37,18 @@ function Action({ icon, color, strings, select }: { icon: ReactNode; color: stri ) } -export function Contacts({ openRegistry, openContact }: { openRegistry: () => void; openContact: (params: ProfileParams) => void }) { +export function Contacts({ openRegistry, openContact, textContact, callContact }: { openRegistry: ()=>void; openContact: (params: ProfileParams)=>void, textContact: (cardId: string)=>void, callContact: (cardId: string)=>void }) { const { state, actions } = useContacts() const cards = state.filtered.map((card, idx) => { const getOptions = () => { const status = card.offsync ? 'offsync' : card.status if (status === 'connected') { - const call = + const phone = const text = return [ - actions.call(card.cardId)} strings={state.strings} />, - actions.text(card.cardId)} strings={state.strings} />, + callContact(card.cardId)} strings={state.strings} />, + textContact(card.cardId)} strings={state.strings} />, ] } else if (status === 'offsync') { const resync = diff --git a/app/client/web/src/contacts/useContacts.hook.ts b/app/client/web/src/contacts/useContacts.hook.ts index f862e6b7..acce10e3 100644 --- a/app/client/web/src/contacts/useContacts.hook.ts +++ b/app/client/web/src/contacts/useContacts.hook.ts @@ -70,12 +70,6 @@ export function useContacts() { setFilter: (filter: string) => { updateState({ filter }) }, - call: async (cardId: string) => { - console.log('call', cardId) - }, - text: async (cardId: string) => { - console.log('text', cardId) - }, cancel: async (cardId: string) => { const contact = app.state.session?.getContact() await contact.disconnectCard(cardId) diff --git a/app/client/web/src/content/Content.tsx b/app/client/web/src/content/Content.tsx index 11eb32b9..fda3361f 100644 --- a/app/client/web/src/content/Content.tsx +++ b/app/client/web/src/content/Content.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react' +import React, { useState, useEffect } from 'react' import { useContent } from './useContent.hook' import { Modal, Text, Switch, TextInput, Button } from '@mantine/core' import { IconSearch, IconMessagePlus, IconLabel } from '@tabler/icons-react' @@ -7,7 +7,7 @@ import { Channel } from '../channel/Channel' import { Card } from '../card/Card' import { modals } from '@mantine/modals' -export function Content() { +export function Content({ textCard }: { textCard: { cardId: null|string }}) { const { state, actions } = useContent() const [add, setAdd] = useState(false) const [adding, setAdding] = useState(false) @@ -16,6 +16,18 @@ export function Content() { const [added, setAdded] = useState([] as string[]) const cards = state.sealSet && sealed ? state.sealable : state.connected + const openTopic = async (cardId: string) => { + setAdding(true); + try { + const id = await actions.openTopic(cardId); + actions.setFocus(null, id); + } catch (err) { + console.log(err); + showError(); + } + setAdding(false); + } + const addTopic = async () => { setAdding(true) try { @@ -87,6 +99,12 @@ export function Content() { ) }) + useEffect(() => { + if (textCard.cardId) { + openTopic(textCard.cardId); + } + }, [textCard]); + return (
diff --git a/app/client/web/src/content/useContent.hook.ts b/app/client/web/src/content/useContent.hook.ts index 7286406c..e5c4acdb 100644 --- a/app/client/web/src/content/useContent.hook.ts +++ b/app/client/web/src/content/useContent.hook.ts @@ -242,6 +242,26 @@ export function useContent() { setFocus: (cardId: string | null, channelId: string) => { app.actions.setFocus(cardId, channelId) }, + openTopic: async (cardId: string) => { + const content = app.state.session.getContent() + const card = state.cards.find(card => card.cardId === cardId) + if (!card) { + throw new Error('contact not found'); + } + const sealable = card.sealable && state.sealSet; + const thread = state.sorted.find(channel => { + const { sealed, cardId, members} = channel; + if (sealed === sealable && cardId == null && members.length === 1 && members[0].guid === card.guid) { + return true; + } + return false; + }); + if (thread) { + return thread.channelId; + } + const topic = await content.addChannel(sealable, sealable ? 'sealed' : 'superbasic', {}, [cardId]); + return topic.id; + }, addTopic: async (sealed: boolean, subject: string, contacts: string[]) => { const content = app.state.session.getContent() if (sealed) { diff --git a/app/client/web/src/conversation/Conversation.tsx b/app/client/web/src/conversation/Conversation.tsx index 8f305629..9f3f8b6d 100644 --- a/app/client/web/src/conversation/Conversation.tsx +++ b/app/client/web/src/conversation/Conversation.tsx @@ -216,20 +216,28 @@ export function Conversation() {
{ media }
-