Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 1 | /**************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
Nicolas Jager | 58c70b0 | 2016-08-26 09:50:45 -0400 | [diff] [blame] | 4 | * Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> *
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 5 | * *
|
| 6 | * This program is free software; you can redistribute it and/or modify *
|
| 7 | * it under the terms of the GNU General Public License as published by *
|
| 8 | * the Free Software Foundation; either version 3 of the License, or *
|
| 9 | * (at your option) any later version. *
|
| 10 | * *
|
| 11 | * This program is distributed in the hope that it will be useful, *
|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 14 | * GNU General Public License for more details. *
|
| 15 | * *
|
| 16 | * You should have received a copy of the GNU General Public License *
|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 18 | **************************************************************************/
|
| 19 | #include "pch.h"
|
| 20 |
|
| 21 | #include "Contact.h"
|
| 22 |
|
| 23 | using namespace Windows::ApplicationModel::Core;
|
| 24 | using namespace Platform;
|
Nicolas Jager | 2e6ab41 | 2016-08-26 11:12:00 -0400 | [diff] [blame] | 25 | using namespace Windows::Data::Json;
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 26 | using namespace Windows::UI::Core;
|
| 27 |
|
| 28 | using namespace RingClientUWP;
|
Nicolas Jager | 0788e96 | 2016-08-26 15:41:06 -0400 | [diff] [blame^] | 29 | using namespace ViewModel;
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 30 |
|
| 31 | Contact::Contact(String^ name,
|
| 32 | String^ ringID)
|
| 33 | {
|
| 34 | name_ = name;
|
| 35 | ringID_ = ringID;
|
Nicolas Jager | 58c70b0 | 2016-08-26 09:50:45 -0400 | [diff] [blame] | 36 | conversation_ = ref new Conversation();
|
Nicolas Jager | 0788e96 | 2016-08-26 15:41:06 -0400 | [diff] [blame^] | 37 | notificationNewMessage_ = Windows::UI::Xaml::Visibility::Collapsed;
|
| 38 | unreadMessages_ = 0; // not saved on disk yet (TO DO)
|
| 39 |
|
| 40 | /* connect to delegate */
|
| 41 | ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] () {
|
| 42 | notificationNewMessage = Windows::UI::Xaml::Visibility::Visible;
|
| 43 | unreadMessages_++;
|
| 44 | PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
|
| 45 | });
|
| 46 | ContactsViewModel::instance->newContactSelected += ref new RingClientUWP::NewContactSelected([&]() {
|
| 47 | if (ContactsViewModel::instance->selectedContact == this) {
|
| 48 | PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
|
| 49 | notificationNewMessage = Windows::UI::Xaml::Visibility::Collapsed;
|
| 50 | unreadMessages_ = 0;
|
| 51 | }
|
| 52 | });
|
| 53 |
|
| 54 |
|
Nicolas Jager | bff5fbb | 2016-08-18 08:58:56 -0400 | [diff] [blame] | 55 | }
|
| 56 |
|
| 57 | void
|
| 58 | Contact::NotifyPropertyChanged(String^ propertyName)
|
| 59 | {
|
| 60 | CoreApplicationView^ view = CoreApplication::MainView;
|
| 61 | view->CoreWindow->Dispatcher->RunAsync(
|
| 62 | CoreDispatcherPriority::Normal,
|
| 63 | ref new DispatchedHandler([this, propertyName]()
|
| 64 | {
|
| 65 | PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
|
| 66 |
|
| 67 | }));
|
Nicolas Jager | 2e6ab41 | 2016-08-26 11:12:00 -0400 | [diff] [blame] | 68 | }
|
| 69 |
|
| 70 | JsonObject^
|
| 71 | Contact::ToJsonObject()
|
| 72 | {
|
| 73 | JsonObject^ contactObject = ref new JsonObject();
|
| 74 | contactObject->SetNamedValue(nameKey, JsonValue::CreateStringValue(name_));
|
| 75 | contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_));
|
| 76 |
|
| 77 | JsonObject^ jsonObject = ref new JsonObject();
|
| 78 | jsonObject->SetNamedValue(contactKey, contactObject);
|
| 79 |
|
| 80 | return jsonObject;
|
| 81 | }
|