From a535ee133b4801990c88baf8394919de49b9abb9 Mon Sep 17 00:00:00 2001 From: atraczyk <andreastraczyk@gmail.com> Date: Wed, 31 Aug 2016 17:36:05 -0400 Subject: [PATCH] notifications(fix): notify only the contact that the message applies to - prevents the ContactViewModel's connected delegate that updates upon text message reception, from incrementing all contact's unread message count Change-Id: Ief09bfd077cf1e28ecc23a2df1cc68b4eddf3bbd Tuleap: #982 --- Contact.cpp | 10 +- Contact.h | 1 + ContactsViewModel.cpp | 6 +- SmartPanel.xaml.cpp | 389 +++++++++++++++++++++--------------------- 4 files changed, 206 insertions(+), 200 deletions(-) diff --git a/Contact.cpp b/Contact.cpp index d714ad0..cf24c9c 100644 --- a/Contact.cpp +++ b/Contact.cpp @@ -75,8 +75,6 @@ Contact::Contact(String^ name, /* 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([&]() { @@ -88,6 +86,14 @@ Contact::Contact(String^ name, }); } +void +Contact::addNotifyNewConversationMessage() +{ + notificationNewMessage = Windows::UI::Xaml::Visibility::Visible; + unreadMessages_++; + RingDebug::instance->print(Utils::toString(unreadMessages_.ToString())); +} + void Contact::NotifyPropertyChanged(String^ propertyName) { diff --git a/Contact.h b/Contact.h index a7ec25a..fc8fdae 100644 --- a/Contact.h +++ b/Contact.h @@ -75,6 +75,7 @@ internal: void saveConversationToFile(); String^ StringifyConversation(); void DestringifyConversation(String^ data); + void addNotifyNewConversationMessage(); protected: void NotifyPropertyChanged(String^ propertyName); diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index 0d48109..d42a84b 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -55,8 +55,12 @@ ContactsViewModel::ContactsViewModel() /* save contacts conversation to disk */ contact->saveConversationToFile(); - if (contact->ringID_ == from && isNotSelected) + if (contact->ringID_ == from && isNotSelected) { + // increment contact's unread message count + contact->addNotifyNewConversationMessage(); + // update the xaml for all notifyNewConversationMessage(); + } }); } diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 4c340ef..690183d 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -1,197 +1,192 @@ -/*************************************************************************** - * Copyright (C) 2016 by Savoir-faire Linux * - * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * - * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> * - * * - * 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 * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see <http://www.gnu.org/licenses/>. * - **************************************************************************/ -#include "pch.h" - -#include "SmartPanel.xaml.h" - -using namespace Platform; - -using namespace RingClientUWP; -using namespace RingClientUWP::Views; -using namespace RingClientUWP::ViewModel; -using namespace Windows::Media::Capture; -using namespace Windows::UI::Xaml; -using namespace Windows::Storage; -using namespace Windows::UI::Xaml::Media::Imaging; -using namespace Windows::UI::Xaml::Shapes; -using namespace Windows::UI::Xaml::Media; -using namespace Concurrency; -using namespace Windows::Foundation; - -SmartPanel::SmartPanel() -{ - InitializeComponent(); - - Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) { - _accountsList_->SelectedIndex = index; - }); - - _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; - _smartList_->ItemsSource = ContactsViewModel::instance->contactsList; - - /* connect delegate */ - ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&]() { - //_visualNotificationNewMessage_->Vi - }); -} - -void -RingClientUWP::Views::SmartPanel::updatePageContent() -{ - auto account = AccountsViewModel::instance->selectedAccount; - if (!account) - return; - - Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex; - Configuration::UserPreferences::instance->save(); - _selectedAccountName_->Text = account->name_; -} - -void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) -{ - _shareMenuButton_->IsChecked = false; - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - -void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) -{ - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - -void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) -{ - _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - -void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) -{ - _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - -void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) -{ - if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { - _rowRingTxtBx_->Height = 40; - _selectedAccountAvatar_->Height = 80; - _selectedAccountAvatarColumn_->Width = 90; - _selectedAccountRow_->Height = 90; - } - else { - _rowRingTxtBx_->Height = 0; - _selectedAccountAvatar_->Height = 50; - _selectedAccountAvatarColumn_->Width = 60; - _selectedAccountRow_->Height = 60; - } - - _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; - _settingsTBtn_->IsChecked = false; - _accountsMenuButton_->IsChecked = false; - _shareMenuButton_->IsChecked = false; -} - -void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; - _accountsMenuButton_->IsChecked = false; -} - -void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; -} - - -void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; - _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; -} - - -void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - -} - - -void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - -} - - -void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) -{ - CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI(); - cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png; - cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); - - - create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) - { - if (photo != nullptr) { - // maybe it would be possible to move some logics to the style sheet - auto brush = ref new ImageBrush(); - - auto circle = ref new Ellipse(); - circle->Height = 80; // TODO : use some global constant when ready - circle->Width = 80; - auto path = photo->Path; - auto uri = ref new Windows::Foundation::Uri(path); - auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); - bitmapImage->UriSource = uri; - - brush->ImageSource = bitmapImage; - circle->Fill = brush; - _avatarWebcamCaptureBtn_->Content = circle; - } - }); - -} - - -void -SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) -{ - auto listbox = safe_cast<ListBox^>(sender); - auto contact = safe_cast<Contact^>(listbox->SelectedItem); - ContactsViewModel::instance->selectedContact = contact; -} - -void -SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) -{ - auto listbox = safe_cast<ListBox^>(sender); - auto account = safe_cast<Account^>(listbox->SelectedItem); - AccountsViewModel::instance->selectedAccount = account; - updatePageContent(); -} - -void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) -{ - /* add contact, test purpose but will be reused later in some way */ - if (e->Key == Windows::System::VirtualKey::Enter && _ringTxtBx_->Text != "") { - ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text); - _ringTxtBx_->Text = ""; - } -} +/*************************************************************************** + * Copyright (C) 2016 by Savoir-faire Linux * + * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> * + * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> * + * * + * 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 * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + **************************************************************************/ +#include "pch.h" + +#include "SmartPanel.xaml.h" + +using namespace Platform; + +using namespace RingClientUWP; +using namespace RingClientUWP::Views; +using namespace RingClientUWP::ViewModel; +using namespace Windows::Media::Capture; +using namespace Windows::UI::Xaml; +using namespace Windows::Storage; +using namespace Windows::UI::Xaml::Media::Imaging; +using namespace Windows::UI::Xaml::Shapes; +using namespace Windows::UI::Xaml::Media; +using namespace Concurrency; +using namespace Windows::Foundation; + +SmartPanel::SmartPanel() +{ + InitializeComponent(); + + Configuration::UserPreferences::instance->selectIndex += ref new SelectIndex([this](int index) { + _accountsList_->SelectedIndex = index; + }); + + _accountsList_->ItemsSource = AccountsViewModel::instance->accountsList; + _smartList_->ItemsSource = ContactsViewModel::instance->contactsList; +} + +void +RingClientUWP::Views::SmartPanel::updatePageContent() +{ + auto account = AccountsViewModel::instance->selectedAccount; + if (!account) + return; + + Configuration::UserPreferences::instance->PREF_ACCOUNT_INDEX = _accountsList_->SelectedIndex; + Configuration::UserPreferences::instance->save(); + _selectedAccountName_->Text = account->name_; +} + +void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Checked(Object^ sender, RoutedEventArgs^ e) +{ + _shareMenuButton_->IsChecked = false; + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + +void RingClientUWP::Views::SmartPanel::_accountsMenuButton__Unchecked(Object^ sender, RoutedEventArgs^ e) +{ + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + +void RingClientUWP::Views::SmartPanel::_settings__Checked(Object^ sender, RoutedEventArgs^ e) +{ + _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _settings_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + +void RingClientUWP::Views::SmartPanel::_settings__Unchecked(Object^ sender, RoutedEventArgs^ e) +{ + _settings_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _smartGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + +void RingClientUWP::Views::SmartPanel::setMode(RingClientUWP::Views::SmartPanel::Mode mode) +{ + if (mode == RingClientUWP::Views::SmartPanel::Mode::Normal) { + _rowRingTxtBx_->Height = 40; + _selectedAccountAvatar_->Height = 80; + _selectedAccountAvatarColumn_->Width = 90; + _selectedAccountRow_->Height = 90; + } + else { + _rowRingTxtBx_->Height = 0; + _selectedAccountAvatar_->Height = 50; + _selectedAccountAvatarColumn_->Width = 60; + _selectedAccountRow_->Height = 60; + } + + _selectedAccountAvatar_->Width = _selectedAccountAvatar_->Height; + _settingsTBtn_->IsChecked = false; + _accountsMenuButton_->IsChecked = false; + _shareMenuButton_->IsChecked = false; +} + +void RingClientUWP::Views::SmartPanel::_shareMenuButton__Checked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; + _accountsMenuButton_->IsChecked = false; +} + +void RingClientUWP::Views::SmartPanel::_shareMenuButton__Unchecked(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _shareMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; +} + + +void RingClientUWP::Views::SmartPanel::_addAccountBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + _accountsMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + _accountCreationMenuGrid_->Visibility = Windows::UI::Xaml::Visibility::Visible; +} + + +void RingClientUWP::Views::SmartPanel::_createAccountYes__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + +} + + +void RingClientUWP::Views::SmartPanel::_createAccountNo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + +} + + +void RingClientUWP::Views::SmartPanel::_avatarWebcamCaptureBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + CameraCaptureUI^ cameraCaptureUI = ref new CameraCaptureUI(); + cameraCaptureUI->PhotoSettings->Format = CameraCaptureUIPhotoFormat::Png; + cameraCaptureUI->PhotoSettings->CroppedSizeInPixels = Size(100, 100); + + + create_task(cameraCaptureUI->CaptureFileAsync(CameraCaptureUIMode::Photo)).then([this](StorageFile^ photo) + { + if (photo != nullptr) { + // maybe it would be possible to move some logics to the style sheet + auto brush = ref new ImageBrush(); + + auto circle = ref new Ellipse(); + circle->Height = 80; // TODO : use some global constant when ready + circle->Width = 80; + auto path = photo->Path; + auto uri = ref new Windows::Foundation::Uri(path); + auto bitmapImage = ref new Windows::UI::Xaml::Media::Imaging::BitmapImage(); + bitmapImage->UriSource = uri; + + brush->ImageSource = bitmapImage; + circle->Fill = brush; + _avatarWebcamCaptureBtn_->Content = circle; + } + }); + +} + + +void +SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) +{ + auto listbox = safe_cast<ListBox^>(sender); + auto contact = safe_cast<Contact^>(listbox->SelectedItem); + ContactsViewModel::instance->selectedContact = contact; +} + +void +SmartPanel::_accountList__SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e) +{ + auto listbox = safe_cast<ListBox^>(sender); + auto account = safe_cast<Account^>(listbox->SelectedItem); + AccountsViewModel::instance->selectedAccount = account; + updatePageContent(); +} + +void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) +{ + /* add contact, test purpose but will be reused later in some way */ + if (e->Key == Windows::System::VirtualKey::Enter && _ringTxtBx_->Text != "") { + ContactsViewModel::instance->addNewContact(_ringTxtBx_->Text, _ringTxtBx_->Text); + _ringTxtBx_->Text = ""; + } +} -- GitLab