diff --git a/MessageTextPage.xaml.cpp b/MessageTextPage.xaml.cpp index 3def2afedfb1707aa93cc9709c2ab3dd28785146..b1143bb352cbf41f93afc35c4c223cd2f6c172bc 100644 --- a/MessageTextPage.xaml.cpp +++ b/MessageTextPage.xaml.cpp @@ -93,4 +93,6 @@ RingClientUWP::Views::MessageTextPage::sendMessage() if (!contact || txt->IsEmpty()) return; + RingD::instance->sendAccountTextMessage(txt); + } diff --git a/RingD.cpp b/RingD.cpp index f63215326644af2eb4ddb9a1ba910ec8bfe9f619..6da67297dc4024e60a6712e13da2e8e189ed85bf 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -35,6 +35,7 @@ using namespace Windows::UI::Core; using namespace RingClientUWP; using namespace RingClientUWP::Utils; +using namespace RingClientUWP::ViewModel; void debugOutputWrapper(const std::string& str) @@ -63,6 +64,37 @@ RingClientUWP::RingD::reloadAccountList() Configuration::UserPreferences::instance->load(); } +/* nb: send message during conversation not chat video message */ +void RingClientUWP::RingD::sendAccountTextMessage(String^ message) +{ + /* account id */ + auto accountId = AccountsViewModel::instance->selectedAccount->accountID_; + std::wstring accountId2(accountId->Begin()); + std::string accountId3(accountId2.begin(), accountId2.end()); + + /* recipient */ + auto contact = ContactsViewModel::instance->selectedContact; + auto toRingId = contact->ringID_; + std::wstring toRingId2(toRingId->Begin()); + std::string toRingId3(toRingId2.begin(), toRingId2.end()); + + /* payload(s) */ + std::wstring message2(message->Begin()); + std::string message3(message2.begin(), message2.end()); + std::map<std::string, std::string> payloads; + payloads["text/plain"] = message3; + + /* daemon */ + auto sent = DRing::sendAccountTextMessage(accountId3, toRingId3, payloads); + + /* conversation */ + if (sent) { + contact->_conversation->addMessage(""/* date not yet used*/, MSG_FROM_ME, message); + } else { + WNG_("message not sent, see daemon outputs"); + } +} + void RingClientUWP::RingD::startDaemon() { @@ -131,7 +163,7 @@ RingClientUWP::RingD::startDaemon() DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]() { CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, - ref new DispatchedHandler([=]() { + ref new DispatchedHandler([=]() { reloadAccountList(); })); }) @@ -171,7 +203,7 @@ RingClientUWP::RingD::startDaemon() } else { CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal, - ref new DispatchedHandler([=]() { + ref new DispatchedHandler([=]() { reloadAccountList(); })); } diff --git a/RingD.h b/RingD.h index 2ee79086ad957082b1ad6f91be3784846b1ad326..366ea2efd024070971009d2e509922e1e361a640 100644 --- a/RingD.h +++ b/RingD.h @@ -55,6 +55,7 @@ internal: /* functions */ void startDaemon(); void reloadAccountList(); + void sendAccountTextMessage(String^ message); /* TODO : move members */ bool hasConfig;