Commit cac4552f authored by atraczyk's avatar atraczyk Committed by Nicolas Jager

notifications: store unread messages count to file

- stores and loads unread message notification count to and from
  the contact data file

Change-Id: Idc00f1d964c273f51cec943b0521da2faa1c9666
Tuleap: #983
parent a535ee13
......@@ -32,7 +32,8 @@ using namespace ViewModel;
Contact::Contact(String^ name,
String^ ringID,
String^ GUID)
String^ GUID,
unsigned int unreadmessages)
{
name_ = name;
ringID_ = ringID;
......@@ -68,10 +69,14 @@ Contact::Contact(String^ name,
}
}
});
//conversation_ = ref new Conversation();
notificationNewMessage_ = Windows::UI::Xaml::Visibility::Collapsed;
unreadMessages_ = 0; // not saved on disk yet (TO DO)
unreadMessages_ = unreadmessages; // not saved on disk yet (TO DO)
if(unreadMessages_) {
notificationNewMessage = Windows::UI::Xaml::Visibility::Visible;
PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
}
/* connect to delegate */
ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] () {
......@@ -82,6 +87,7 @@ Contact::Contact(String^ name,
PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
notificationNewMessage = Windows::UI::Xaml::Visibility::Collapsed;
unreadMessages_ = 0;
ContactsViewModel::instance->saveContactsToFile();
}
});
}
......@@ -91,7 +97,6 @@ Contact::addNotifyNewConversationMessage()
{
notificationNewMessage = Windows::UI::Xaml::Visibility::Visible;
unreadMessages_++;
RingDebug::instance->print(Utils::toString(unreadMessages_.ToString()));
}
void
......@@ -113,6 +118,7 @@ Contact::ToJsonObject()
contactObject->SetNamedValue(nameKey, JsonValue::CreateStringValue(name_));
contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_));
contactObject->SetNamedValue(GUIDKey, JsonValue::CreateStringValue(GUID_));
contactObject->SetNamedValue(unreadMessagesKey, JsonValue::CreateNumberValue(unreadMessages_));
JsonObject^ jsonObject = ref new JsonObject();
jsonObject->SetNamedValue(contactKey, contactObject);
......
......@@ -26,6 +26,7 @@ using namespace Windows::UI::Xaml::Data;
String^ nameKey = "name";
String^ ringIDKey = "ringid";
String^ GUIDKey = "guid";
String^ unreadMessagesKey = "unreadmessages";
String^ contactKey = "contact";
String^ contactListKey = "contactlist";
......@@ -35,7 +36,7 @@ ref class Conversation;
public ref class Contact sealed : public INotifyPropertyChanged
{
public:
Contact(String^ name, String^ ringID, String^ GUID);
Contact(String^ name, String^ ringID, String^ GUID, unsigned int unreadmessages);
JsonObject^ ToJsonObject();
virtual event PropertyChangedEventHandler^ PropertyChanged;
......
......@@ -58,8 +58,10 @@ ContactsViewModel::ContactsViewModel()
if (contact->ringID_ == from && isNotSelected) {
// increment contact's unread message count
contact->addNotifyNewConversationMessage();
// update the xaml for all
// update the xaml for all contacts
notifyNewConversationMessage();
// save to disk
saveContactsToFile();
}
});
......@@ -80,7 +82,7 @@ ContactsViewModel::addNewContact(String^ name, String^ ringId)
{
auto trimedName = Utils::Trim(name);
if (contactsList_ && !findContactByName(trimedName)) {
Contact^ contact = ref new Contact(trimedName, trimedName, nullptr);
Contact^ contact = ref new Contact(trimedName, trimedName, nullptr, 0);
contactsList_->Append(contact);
saveContactsToFile();
return contact;
......@@ -158,10 +160,11 @@ ContactsViewModel::Stringify()
void
ContactsViewModel::Destringify(String^ data)
{
JsonObject^ jsonObject = JsonObject::Parse(data);
String^ name;
String^ ringid;
String^ guid;
JsonObject^ jsonObject = JsonObject::Parse(data);
String^ name;
String^ ringid;
String^ guid;
unsigned int unreadmessages;
JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray());
for (unsigned int i = 0; i < contactlist->Size; i++) {
......@@ -170,11 +173,12 @@ ContactsViewModel::Destringify(String^ data)
JsonObject^ jsonContactObject = contact->GetObject();
JsonObject^ contactObject = jsonContactObject->GetNamedObject(contactKey, nullptr);
if (contactObject != nullptr) {
name = contactObject->GetNamedString(nameKey, "");
ringid = contactObject->GetNamedString(ringIDKey, "");
guid = contactObject->GetNamedString(GUIDKey, "");
name = contactObject->GetNamedString(nameKey);
ringid = contactObject->GetNamedString(ringIDKey);
guid = contactObject->GetNamedString(GUIDKey);
unreadmessages = static_cast<uint16_t>(contactObject->GetNamedNumber(unreadMessagesKey));
}
contactsList_->Append(ref new Contact(name, ringid, guid));
contactsList_->Append(ref new Contact(name, ringid, guid, unreadmessages));
}
}
}
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