Commit 0788e96d authored by Nicolas Jager's avatar Nicolas Jager

text message : add visual new message notification

- adds a red buble with the number of unread messages.

Change-Id: I8c40df3e0421fba02444e5092a8975ce27ce989c
Tuleap: #961
parent 6e30ad83
......@@ -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
......
......@@ -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_;
};
}
......
......@@ -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();
});
}
......
......@@ -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
......
......@@ -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"/>
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment