Skip to content
Snippets Groups Projects
Commit cac4552f authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Nicolas Jager
Browse files

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
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,8 @@ using namespace ViewModel; ...@@ -32,7 +32,8 @@ using namespace ViewModel;
Contact::Contact(String^ name, Contact::Contact(String^ name,
String^ ringID, String^ ringID,
String^ GUID) String^ GUID,
unsigned int unreadmessages)
{ {
name_ = name; name_ = name;
ringID_ = ringID; ringID_ = ringID;
...@@ -68,10 +69,14 @@ Contact::Contact(String^ name, ...@@ -68,10 +69,14 @@ Contact::Contact(String^ name,
} }
} }
}); });
//conversation_ = ref new Conversation();
notificationNewMessage_ = Windows::UI::Xaml::Visibility::Collapsed; 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 */ /* connect to delegate */
ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] () { ContactsViewModel::instance->notifyNewConversationMessage += ref new NotifyNewConversationMessage([&] () {
...@@ -82,6 +87,7 @@ Contact::Contact(String^ name, ...@@ -82,6 +87,7 @@ Contact::Contact(String^ name,
PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages")); PropertyChanged(this, ref new PropertyChangedEventArgs("unreadMessages"));
notificationNewMessage = Windows::UI::Xaml::Visibility::Collapsed; notificationNewMessage = Windows::UI::Xaml::Visibility::Collapsed;
unreadMessages_ = 0; unreadMessages_ = 0;
ContactsViewModel::instance->saveContactsToFile();
} }
}); });
} }
...@@ -91,7 +97,6 @@ Contact::addNotifyNewConversationMessage() ...@@ -91,7 +97,6 @@ Contact::addNotifyNewConversationMessage()
{ {
notificationNewMessage = Windows::UI::Xaml::Visibility::Visible; notificationNewMessage = Windows::UI::Xaml::Visibility::Visible;
unreadMessages_++; unreadMessages_++;
RingDebug::instance->print(Utils::toString(unreadMessages_.ToString()));
} }
void void
...@@ -113,6 +118,7 @@ Contact::ToJsonObject() ...@@ -113,6 +118,7 @@ Contact::ToJsonObject()
contactObject->SetNamedValue(nameKey, JsonValue::CreateStringValue(name_)); contactObject->SetNamedValue(nameKey, JsonValue::CreateStringValue(name_));
contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_)); contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_));
contactObject->SetNamedValue(GUIDKey, JsonValue::CreateStringValue(GUID_)); contactObject->SetNamedValue(GUIDKey, JsonValue::CreateStringValue(GUID_));
contactObject->SetNamedValue(unreadMessagesKey, JsonValue::CreateNumberValue(unreadMessages_));
JsonObject^ jsonObject = ref new JsonObject(); JsonObject^ jsonObject = ref new JsonObject();
jsonObject->SetNamedValue(contactKey, contactObject); jsonObject->SetNamedValue(contactKey, contactObject);
......
...@@ -26,6 +26,7 @@ using namespace Windows::UI::Xaml::Data; ...@@ -26,6 +26,7 @@ using namespace Windows::UI::Xaml::Data;
String^ nameKey = "name"; String^ nameKey = "name";
String^ ringIDKey = "ringid"; String^ ringIDKey = "ringid";
String^ GUIDKey = "guid"; String^ GUIDKey = "guid";
String^ unreadMessagesKey = "unreadmessages";
String^ contactKey = "contact"; String^ contactKey = "contact";
String^ contactListKey = "contactlist"; String^ contactListKey = "contactlist";
...@@ -35,7 +36,7 @@ ref class Conversation; ...@@ -35,7 +36,7 @@ ref class Conversation;
public ref class Contact sealed : public INotifyPropertyChanged public ref class Contact sealed : public INotifyPropertyChanged
{ {
public: public:
Contact(String^ name, String^ ringID, String^ GUID); Contact(String^ name, String^ ringID, String^ GUID, unsigned int unreadmessages);
JsonObject^ ToJsonObject(); JsonObject^ ToJsonObject();
virtual event PropertyChangedEventHandler^ PropertyChanged; virtual event PropertyChangedEventHandler^ PropertyChanged;
......
...@@ -58,8 +58,10 @@ ContactsViewModel::ContactsViewModel() ...@@ -58,8 +58,10 @@ ContactsViewModel::ContactsViewModel()
if (contact->ringID_ == from && isNotSelected) { if (contact->ringID_ == from && isNotSelected) {
// increment contact's unread message count // increment contact's unread message count
contact->addNotifyNewConversationMessage(); contact->addNotifyNewConversationMessage();
// update the xaml for all // update the xaml for all contacts
notifyNewConversationMessage(); notifyNewConversationMessage();
// save to disk
saveContactsToFile();
} }
}); });
...@@ -80,7 +82,7 @@ ContactsViewModel::addNewContact(String^ name, String^ ringId) ...@@ -80,7 +82,7 @@ ContactsViewModel::addNewContact(String^ name, String^ ringId)
{ {
auto trimedName = Utils::Trim(name); auto trimedName = Utils::Trim(name);
if (contactsList_ && !findContactByName(trimedName)) { if (contactsList_ && !findContactByName(trimedName)) {
Contact^ contact = ref new Contact(trimedName, trimedName, nullptr); Contact^ contact = ref new Contact(trimedName, trimedName, nullptr, 0);
contactsList_->Append(contact); contactsList_->Append(contact);
saveContactsToFile(); saveContactsToFile();
return contact; return contact;
...@@ -162,6 +164,7 @@ ContactsViewModel::Destringify(String^ data) ...@@ -162,6 +164,7 @@ ContactsViewModel::Destringify(String^ data)
String^ name; String^ name;
String^ ringid; String^ ringid;
String^ guid; String^ guid;
unsigned int unreadmessages;
JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray()); JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray());
for (unsigned int i = 0; i < contactlist->Size; i++) { for (unsigned int i = 0; i < contactlist->Size; i++) {
...@@ -170,11 +173,12 @@ ContactsViewModel::Destringify(String^ data) ...@@ -170,11 +173,12 @@ ContactsViewModel::Destringify(String^ data)
JsonObject^ jsonContactObject = contact->GetObject(); JsonObject^ jsonContactObject = contact->GetObject();
JsonObject^ contactObject = jsonContactObject->GetNamedObject(contactKey, nullptr); JsonObject^ contactObject = jsonContactObject->GetNamedObject(contactKey, nullptr);
if (contactObject != nullptr) { if (contactObject != nullptr) {
name = contactObject->GetNamedString(nameKey, ""); name = contactObject->GetNamedString(nameKey);
ringid = contactObject->GetNamedString(ringIDKey, ""); ringid = contactObject->GetNamedString(ringIDKey);
guid = contactObject->GetNamedString(GUIDKey, ""); 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));
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment