blob: b49cbbd59ba7838ec268bf7fbe8c16bf00ec5e93 [file] [log] [blame]
Nicolas Jagerbff5fbb2016-08-18 08:58:56 -04001/**************************************************************************
2* Copyright (C) 2016 by Savoir-faire Linux *
3* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
Nicolas Jager58c70b02016-08-26 09:50:45 -04004* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> *
Nicolas Jagerbff5fbb2016-08-18 08:58:56 -04005* *
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
23using namespace Windows::ApplicationModel::Core;
24using namespace Platform;
Nicolas Jager2e6ab412016-08-26 11:12:00 -040025using namespace Windows::Data::Json;
Nicolas Jagerbff5fbb2016-08-18 08:58:56 -040026using namespace Windows::UI::Core;
27
28using namespace RingClientUWP;
Nicolas Jager0788e962016-08-26 15:41:06 -040029using namespace ViewModel;
Nicolas Jagerbff5fbb2016-08-18 08:58:56 -040030
31Contact::Contact(String^ name,
32 String^ ringID)
33{
34 name_ = name;
35 ringID_ = ringID;
Nicolas Jager58c70b02016-08-26 09:50:45 -040036 conversation_ = ref new Conversation();
Nicolas Jager0788e962016-08-26 15:41:06 -040037 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 Jagerbff5fbb2016-08-18 08:58:56 -040055}
56
57void
58Contact::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 Jager2e6ab412016-08-26 11:12:00 -040068}
69
70JsonObject^
71Contact::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}