diff --git a/Contact.cpp b/Contact.cpp index 1fb7032402f5c5f2cf9d4f904aed40c6195ba643..b49cbbd59ba7838ec268bf7fbe8c16bf00ec5e93 100644 --- a/Contact.cpp +++ b/Contact.cpp @@ -26,6 +26,7 @@ using namespace Windows::Data::Json; using namespace Windows::UI::Core; using namespace RingClientUWP; +using namespace ViewModel; Contact::Contact(String^ name, String^ ringID) @@ -33,6 +34,24 @@ Contact::Contact(String^ name, name_ = name; ringID_ = ringID; conversation_ = ref new Conversation(); + notificationNewMessage_ = Windows::UI::Xaml::Visibility::Collapsed; + unreadMessages_ = 0; // not saved on disk yet (TO DO) + + /* connect to delegate */ + ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] () { + notificationNewMessage = Windows::UI::Xaml::Visibility::Visible; + unreadMessages_++; + PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages")); + }); + ContactsViewModel::instance->newContactSelected += ref new RingClientUWP::NewContactSelected([&]() { + if (ContactsViewModel::instance->selectedContact == this) { + PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages")); + notificationNewMessage = Windows::UI::Xaml::Visibility::Collapsed; + unreadMessages_ = 0; + } + }); + + } void diff --git a/Contact.h b/Contact.h index eb1ff211ce89633af3d49366c81ce8c0ce1516b7..7e84d87a2fc3db59706e43ca3a46fc5aa0f154e5 100644 --- a/Contact.h +++ b/Contact.h @@ -19,6 +19,7 @@ **************************************************************************/ using namespace Platform; using namespace Windows::Data::Json; +using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Data; /* strings required by Windows::Data::Json. Defined here on puprose */ @@ -36,7 +37,6 @@ public: Contact(String^ name, String^ ringID); JsonObject^ ToJsonObject(); - virtual event PropertyChangedEventHandler^ PropertyChanged; property String^ name_; @@ -48,12 +48,33 @@ public: return conversation_; } } + property Visibility notificationNewMessage + { + Visibility get() + { + return notificationNewMessage_; + } + void set(Visibility visibility) + { + notificationNewMessage_ = visibility; + PropertyChanged(this, ref new PropertyChangedEventArgs("notificationNewMessage")); + } + } + property String^ unreadMessages + { + String^ get() + { + return unreadMessages_.ToString(); + } + } protected: void NotifyPropertyChanged(String^ propertyName); private: Conversation^ conversation_; + Visibility notificationNewMessage_; + unsigned int unreadMessages_; }; } diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index 80799ff8e0b443c970d9763d42e43348e2282952..0aa9aed0a0380924d0fededcc2845727d5b1ff11 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -43,11 +43,17 @@ ContactsViewModel::ContactsViewModel() if (contact == nullptr) contact = addNewContact(from, from); // contact checked inside addNewContact. + bool isNotSelected = (contact != ContactsViewModel::instance->selectedContact) ? true : false; + if (contact == nullptr) { ERR_("contact not handled!"); return; } + screenConversationMessage("" /* accountId not used yet at this stage */, from, payload); + + if (contact->ringID_ == from && isNotSelected) + notifyNewConversationMessage(); }); } diff --git a/ContactsViewModel.h b/ContactsViewModel.h index 29dfec8a467b5de6ca6b59f06122f7791a75f8bb..b4de756ec1d63b85f171f9f2178e833b690ce7fd 100644 --- a/ContactsViewModel.h +++ b/ContactsViewModel.h @@ -25,8 +25,11 @@ using namespace Concurrency; namespace RingClientUWP { +/* delegates */ delegate void NewContactSelected(); delegate void NoContactSelected(); +delegate void ScreenConversationMessage(String^ accountId, String^ from, String^ payload); +delegate void NotifyNewConversationMessage(); namespace ViewModel { public ref class ContactsViewModel sealed @@ -79,6 +82,8 @@ internal: /* events */ event NewContactSelected^ newContactSelected; event NoContactSelected^ noContactSelected; + event ScreenConversationMessage^ screenConversationMessage; + event NotifyNewConversationMessage^ notifyNewConversationMessage; private: ContactsViewModel(); // singleton diff --git a/SmartPanel.xaml b/SmartPanel.xaml index 9e5fb61e4199cb585c1bbbfd3f917e3b3936e7d2..cef2e262c7cc29fbc8ffab9778645c8afdff00e1 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -58,9 +58,9 @@ </Border.RenderTransform> </Border> <Border x:Name="_visualNotificationNewMessage_" - Visibility="Collapsed" + Visibility="{x:Bind notificationNewMessage, Mode=OneWay}" Style="{StaticResource BorderStyle2}"> - <TextBlock Text="0" + <TextBlock Text="{x:Bind unreadMessages, Mode=OneWay}" Style="{StaticResource TextStyle3}"/> <Border.RenderTransform> <TranslateTransform X="-17" Y="-14"/> diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index d9e0dd541f4e4f3e51468330ffe36346139cdfe0..4c340efb85c366ec9f16090eab166a36533fdeb2 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -44,6 +44,11 @@ SmartPanel::SmartPanel() _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; _smartList_->ItemsSource = ContactsViewModel::instance->contactsList; + + /* connect delegate */ + ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&]() { + //_visualNotificationNewMessage_->Vi + }); } void