From 655df54fffe65a6d2d57210be96481b931958bb9 Mon Sep 17 00:00:00 2001 From: Nicolas Jager <nicolas.jager@savoirfairelinux.com> Date: Wed, 31 Aug 2016 10:24:47 -0400 Subject: [PATCH] text message : send message - send the message to the contact during a conversation. - add the message to the conversation. Change-Id: Ia93d48feed1fa712f5757df8013fad90bd5853e8 --- MessageTextPage.xaml.cpp | 2 ++ RingD.cpp | 36 ++++++++++++++++++++++++++++++++++-- RingD.h | 1 + 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/MessageTextPage.xaml.cpp b/MessageTextPage.xaml.cpp index 3def2af..b1143bb 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 f632153..6da6729 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 2ee7908..366ea2e 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; -- GitLab