Skip to content
Snippets Groups Projects
Commit 6e30ad83 authored by Nicolas Jager's avatar Nicolas Jager
Browse files

text message : add new contact to contacts list when

a message arrived from a new contact.

Change-Id: I82545d852c7d880e2ee1fd5bc479765091b6a830
Tuleap: #941
parent b724d332
No related branches found
No related tags found
No related merge requests found
...@@ -16,12 +16,16 @@ ...@@ -16,12 +16,16 @@
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/ **************************************************************************/
#include "pch.h" #include "pch.h"
#include "ContactsViewModel.h" #include "ContactsViewModel.h"
using namespace Windows::ApplicationModel::Core;
using namespace Windows::Data::Json; using namespace Windows::Data::Json;
using namespace Windows::Storage; using namespace Windows::Storage;
using namespace Windows::Storage::Streams;
using namespace Windows::UI::Core;
using namespace RingClientUWP; using namespace RingClientUWP;
using namespace ViewModel; using namespace ViewModel;
...@@ -30,6 +34,22 @@ ContactsViewModel::ContactsViewModel() ...@@ -30,6 +34,22 @@ ContactsViewModel::ContactsViewModel()
{ {
contactsList_ = ref new Vector<Contact^>(); contactsList_ = ref new Vector<Contact^>();
openContactsFromFile(); openContactsFromFile();
/* connect delegates. */
RingD::instance->incomingAccountMessage += ref new IncomingAccountMessage([&](String^ accountId,
String^ from, String^ payload) {
auto contact = findContactByName(from);
if (contact == nullptr)
contact = addNewContact(from, from); // contact checked inside addNewContact.
if (contact == nullptr) {
ERR_("contact not handled!");
return;
}
});
} }
Contact^ Contact^
...@@ -46,7 +66,7 @@ Contact^ ...@@ -46,7 +66,7 @@ Contact^
ContactsViewModel::addNewContact(String^ name, String^ ringId) ContactsViewModel::addNewContact(String^ name, String^ ringId)
{ {
if (contactsList_ && !findContactByName(name)) { if (contactsList_ && !findContactByName(name)) {
Contact^ contact = ref new Contact(name, ringId); Contact^ contact = ref new Contact(name, name);
contactsList_->Append(contact); contactsList_->Append(contact);
saveContactsToFile(); saveContactsToFile();
return contact; return contact;
......
/*************************************************************************** /**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux * * Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> * * Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> *
...@@ -105,7 +105,7 @@ RingClientUWP::RingD::startDaemon() ...@@ -105,7 +105,7 @@ RingClientUWP::RingD::startDaemon()
stateChange(callId2, state2, code); stateChange(callId2, state2, code);
}), }),
DRing::exportable_callback<DRing::ConfigurationSignal::IncomingAccountMessage>([this]( DRing::exportable_callback<DRing::ConfigurationSignal::IncomingAccountMessage>([&](
const std::string& accountId, const std::string& accountId,
const std::string& from, const std::string& from,
const std::map<std::string, std::string>& payloads) const std::map<std::string, std::string>& payloads)
...@@ -114,9 +114,17 @@ RingClientUWP::RingD::startDaemon() ...@@ -114,9 +114,17 @@ RingClientUWP::RingD::startDaemon()
MSG_("accountId = " + accountId); MSG_("accountId = " + accountId);
MSG_("from = " + from); MSG_("from = " + from);
auto accountId2 = toPlatformString(accountId);
auto from2 = toPlatformString(from);
for (auto i : payloads) { for (auto i : payloads) {
MSG_("payload = " + i.second); MSG_("payload = " + i.second);
auto payload = Utils::toPlatformString(i.second); auto payload = Utils::toPlatformString(i.second);
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::Low, ref new DispatchedHandler([=]()
{
incomingAccountMessage(accountId2, from2, payload);
}));
} }
}), }),
DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]() DRing::exportable_callback<DRing::ConfigurationSignal::AccountsChanged>([this]()
......
/*************************************************************************** /**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux * * Copyright (C) 2016 by Savoir-faire Linux *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> *
* * * *
* This program is free software; you can redistribute it and/or modify * * This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by * * it under the terms of the GNU General Public License as published by *
...@@ -15,7 +16,6 @@ ...@@ -15,7 +16,6 @@
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/ **************************************************************************/
#pragma once
using namespace concurrency; using namespace concurrency;
...@@ -25,6 +25,8 @@ namespace RingClientUWP ...@@ -25,6 +25,8 @@ namespace RingClientUWP
/* delegate */ /* delegate */
delegate void IncomingCall(String^ accountId, String^ callId, String^ from); delegate void IncomingCall(String^ accountId, String^ callId, String^ from);
delegate void StateChange(String^ callId, String^ state, int code); delegate void StateChange(String^ callId, String^ state, int code);
delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload);
public ref class RingD sealed public ref class RingD sealed
{ {
...@@ -61,6 +63,7 @@ internal: ...@@ -61,6 +63,7 @@ internal:
/* events */ /* events */
event IncomingCall^ incomingCall; event IncomingCall^ incomingCall;
event StateChange^ stateChange; event StateChange^ stateChange;
event IncomingAccountMessage^ incomingAccountMessage;
private: private:
/* sub classes */ /* sub classes */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment