diff --git a/Contact.cpp b/Contact.cpp index 84022c0fba04e673fe57defa521a49dcd79466f2..0b5c93e53b8681191e9c38728a11ee3d09c46815 100644 --- a/Contact.cpp +++ b/Contact.cpp @@ -70,6 +70,9 @@ Contact::Contact(String^ name, } _accountIdAssociated = ""; + _vcardUID = ""; + _avatarImage = ref new String(L"ms-appx:///Assets/TESTS/contactAvatar.png"); + _displayName = ""; } void @@ -89,10 +92,12 @@ Contact::ToJsonObject() { JsonObject^ contactObject = ref new JsonObject(); contactObject->SetNamedValue(nameKey, JsonValue::CreateStringValue(name_)); + contactObject->SetNamedValue(displayNameKey, JsonValue::CreateStringValue(displayName_)); contactObject->SetNamedValue(ringIDKey, JsonValue::CreateStringValue(ringID_)); contactObject->SetNamedValue(GUIDKey, JsonValue::CreateStringValue(GUID_)); contactObject->SetNamedValue(unreadMessagesKey, JsonValue::CreateNumberValue(unreadMessages_)); contactObject->SetNamedValue(accountIdAssociatedKey, JsonValue::CreateStringValue(_accountIdAssociated)); + contactObject->SetNamedValue(vcardUIDKey, JsonValue::CreateStringValue(_vcardUID)); JsonObject^ jsonObject = ref new JsonObject(); jsonObject->SetNamedValue(contactKey, contactObject); diff --git a/Contact.h b/Contact.h index 12620e24c0bea51affd6384e060b8d1d0fb0adf6..4cb7ba328a452039916ae22944becdb0d372fc55 100644 --- a/Contact.h +++ b/Contact.h @@ -27,12 +27,14 @@ using namespace Windows::UI::Xaml::Data; /* strings required by Windows::Data::Json. Defined here on puprose */ String^ nameKey = "name"; +String^ displayNameKey = "displayname"; String^ ringIDKey = "ringid"; String^ GUIDKey = "id"; String^ unreadMessagesKey = "unreadmessages"; String^ contactKey = "contact"; String^ contactListKey = "contactlist"; String^ accountIdAssociatedKey = "accountIdAssociated"; +String^ vcardUIDKey = "vcardUID"; namespace RingClientUWP { @@ -81,6 +83,18 @@ public: NotifyPropertyChanged("_unreadMessages"); } } + property String^ _avatarImage + { + String^ get() + { + return avatarImage_; + } + void set(String^ value) + { + avatarImage_ = value; + NotifyPropertyChanged("_avatarImage"); + } + } property Windows::UI::Xaml::GridLength _contactBarHeight { Windows::UI::Xaml::GridLength get() @@ -94,6 +108,19 @@ public: } } property String^ _accountIdAssociated; + property String^ _vcardUID; + property String^ _displayName + { + String^ get() + { + return displayName_; + } + void set(String^ value) + { + displayName_ = value; + NotifyPropertyChanged("_displayName"); + } + } VCardUtils::VCard^ getVCard(); @@ -112,6 +139,8 @@ private: Conversation^ conversation_; Visibility notificationNewMessage_; unsigned int unreadMessages_; + String^ avatarImage_; + String^ displayName_; Windows::UI::Xaml::GridLength contactBarHeight_ = 0; }; } diff --git a/ContactsViewModel.cpp b/ContactsViewModel.cpp index 3740038c5ecdf0075dd0d0afc50d5b4ee81de230..099004c44ec8692bbee5044787b94310dca08fee 100644 --- a/ContactsViewModel.cpp +++ b/ContactsViewModel.cpp @@ -146,10 +146,12 @@ ContactsViewModel::Destringify(String^ data) { JsonObject^ jsonObject = JsonObject::Parse(data); String^ name; + String^ displayname; String^ ringid; String^ guid; unsigned int unreadmessages; String^ accountIdAssociated; + String^ vcardUID; JsonArray^ contactlist = jsonObject->GetNamedArray(contactListKey, ref new JsonArray()); for (unsigned int i = 0; i < contactlist->Size; i++) { @@ -159,14 +161,23 @@ ContactsViewModel::Destringify(String^ data) JsonObject^ contactObject = jsonContactObject->GetNamedObject(contactKey, nullptr); if (contactObject != nullptr) { name = contactObject->GetNamedString(nameKey); + displayname = contactObject->GetNamedString(displayNameKey); ringid = contactObject->GetNamedString(ringIDKey); guid = contactObject->GetNamedString(GUIDKey); unreadmessages = static_cast<uint16_t>(contactObject->GetNamedNumber(unreadMessagesKey)); accountIdAssociated = contactObject->GetNamedString(accountIdAssociatedKey); - + vcardUID = contactObject->GetNamedString(vcardUIDKey); } auto contact = ref new Contact(name, ringid, guid, unreadmessages); + contact->_displayName = displayname; contact->_accountIdAssociated = accountIdAssociated; + // contact image + contact->_vcardUID = vcardUID; + std::string contactImageFile = RingD::instance->getLocalFolder() + ".vcards\\" + + Utils::toString(contact->_vcardUID) + ".png"; + if (Utils::fileExists(contactImageFile)) { + contact->_avatarImage = Utils::toPlatformString(contactImageFile); + } contactsList_->Append(contact); contactAdded(contact); } @@ -213,3 +224,9 @@ void RingClientUWP::ViewModel::ContactsViewModel::OnincomingMessage(Platform::St } } } + +void +ContactsViewModel::modifyContact(Contact^ contact) +{ + contactDataModified(contact); +} \ No newline at end of file diff --git a/ContactsViewModel.h b/ContactsViewModel.h index bd78b1ef2d8035ac830da01ff06286df4f9f60eb..06464ffc222056091210dd01ccca7a6435307c19 100644 --- a/ContactsViewModel.h +++ b/ContactsViewModel.h @@ -28,6 +28,7 @@ namespace RingClientUWP /* delegates */ delegate void ContactAdded(Contact^); delegate void ContactDeleted(Contact^); +delegate void ContactDataModified(Contact^); namespace ViewModel { public ref class ContactsViewModel sealed @@ -51,6 +52,7 @@ internal: String^ Stringify(); void Destringify(String^ data); void deleteContact(Contact^ contact); + void modifyContact(Contact^ contact); /* properties */ property Vector<Contact^>^ contactsList @@ -64,6 +66,7 @@ internal: /* events */ event ContactAdded^ contactAdded; event ContactDeleted^ contactDeleted; + event ContactDataModified^ contactDataModified; private: ContactsViewModel(); // singleton diff --git a/SmartPanel.xaml b/SmartPanel.xaml index e2e32def9adb87a216e3570622ff9f5288deb6ed..9e8c9498743952bfbac891b50c1b10c51197647d 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -140,7 +140,7 @@ <ColumnDefinition Width="*" MinWidth="200"/> </Grid.ColumnDefinitions> - <Image x:Name="_contactAvatar_" + <Image x:Name="_XcontactAvatar_" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="0" @@ -252,13 +252,17 @@ <ColumnDefinition Width="*" MinWidth="200"/> </Grid.ColumnDefinitions> - <Image x:Name="_contactAvatar_" - VerticalAlignment="Center" - HorizontalAlignment="Center" - Grid.Column="0" - Width="55" - Height="55" - Source="Assets\TESTS\contactAvatar.png"/> + <Ellipse Height="50" + Width="50" + Grid.Column="0" + VerticalAlignment="Center" + HorizontalAlignment="Center" + Margin="5"> + <Ellipse.Fill> + <ImageBrush x:Name="_contactAvatar_" + ImageSource="{x:Bind _contact._avatarImage, Mode=OneWay}"/> + </Ellipse.Fill> + </Ellipse> <!-- visual notifications. --> <Border x:Name="_visualNotificationVideoChat_" Visibility="Collapsed" diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 9b51759a18fcf8f0e61333aa5e38af8e673165d4..4d41fbb97059325c651bc3f09aa4624c11028347 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -80,6 +80,9 @@ SmartPanel::SmartPanel() String^ image_path = localfolder->Path + "\\.profile\\profile_image.png"; auto uri = ref new Windows::Foundation::Uri(image_path); _selectedAccountAvatar_->ImageSource = ref new BitmapImage(uri); + }); + ContactsViewModel::instance->contactDataModified += ref new ContactDataModified([this](Contact^ contact){ + }); AccountsViewModel::instance->updateScrollView += ref new UpdateScrollView([this]() { _accountsListScrollView_->UpdateLayout(); diff --git a/UserPreferences.cpp b/UserPreferences.cpp index 918ffaa4de28a266c84792b2538c92e6c79a74f5..2dd204ad79d9a0f62370c5645d4c6cbbe5c117c1 100644 --- a/UserPreferences.cpp +++ b/UserPreferences.cpp @@ -112,6 +112,8 @@ UserPreferences::saveProfileToVCard() std::basic_ifstream<uint8_t> stream(imageFile, std::ios::in | std::ios::binary); auto eos = std::istreambuf_iterator<uint8_t>(); auto buffer = std::vector<uint8_t>(std::istreambuf_iterator<uint8_t>(stream), eos); + auto accountListItem = ViewModel::AccountListItemsViewModel::instance->_selectedItem; + vcfData[VCardUtils::Property::FN] = accountListItem ? Utils::toString(accountListItem->_account->name_) : "Unknown"; vcfData[VCardUtils::Property::PHOTO] = ring::base64::encode( buffer ); vCard_->setData(vcfData); vCard_->saveToFile(); @@ -122,6 +124,4 @@ UserPreferences::sendVCard(std::string callID) { vCard_->send(callID, (RingD::instance->getLocalFolder() + "\\.vcards\\" + std::to_string(PREF_PROFILE_UID) + ".vcard").c_str()); - /*vCard_->send(callID, - (RingD::instance->getLocalFolder() + "\\.vcards\\" + std::to_string(4796040057761) + ".vcard").c_str());*/ } \ No newline at end of file diff --git a/VCardUtils.cpp b/VCardUtils.cpp index 6499f682126a88a970cc1dd4099b4992838cab84..2a2e83124b006b722c98f26314624c6222565ae9 100644 --- a/VCardUtils.cpp +++ b/VCardUtils.cpp @@ -62,6 +62,12 @@ VCard::receiveChunk(const std::string& args, const std::string& payload) } m_mParts[Property::UID] = _line.substr(4); + while (std::getline(_payload, _line)) { + if (_line.find("FN:") != std::string::npos) + break; + } + m_mParts[Property::FN] = _line.substr(3); + while (std::getline(_payload, _line)) { if (_line.find("PHOTO;") != std::string::npos) break; @@ -76,6 +82,10 @@ VCard::receiveChunk(const std::string& args, const std::string& payload) m_mParts[Property::PHOTO].append(_line); saveToFile(); decodeBase64ToPNGFile(); + if (!m_mParts[Property::FN].empty()) + m_Owner->_displayName = Utils::toPlatformString(m_mParts[Property::FN]); + m_Owner->_vcardUID = Utils::toPlatformString(m_mParts[Property::UID]); + ViewModel::ContactsViewModel::instance->saveContactsToFile(); MSG_("VCARD_COMPLETE"); return VCARD_COMPLETE; } @@ -100,7 +110,7 @@ VCard::send(std::string callID, const char* vCardFile) else vCard = asString(); int total = vCard.size() / chunkSize + (vCard.size() % chunkSize ? 1 : 0); - std::string idkey = Utils::genID(0LL, 9999999999LL); + std::string idkey = Utils::genID(0LL, 99999999LL); while ( vCard.size() ) { std::map<std::string, std::string> chunk; std::stringstream key; @@ -137,7 +147,7 @@ VCard::asString() ret << Property::UID << Symbols::SEPERATOR2 << m_mParts[Property::UID] << Symbols::END_LINE_TOKEN; - ret << Property::FN << Symbols::SEPERATOR2 << "Unknown" + ret << Property::FN << Symbols::SEPERATOR2 << m_mParts[Property::FN] << Symbols::END_LINE_TOKEN; ret << Property::PHOTO << Symbols::SEPERATOR1 << Symbols::PHOTO_ENC @@ -166,7 +176,8 @@ VCard::decodeBase64ToPNGFile() for (auto i : decodedData) file << i; file.close(); - MSG_("Done decodeing and saving VCard Photo to PNG"); + m_Owner->_avatarImage = Utils::toPlatformString(vcardDir + pngFile); + MSG_("Done decoding and saving VCard Photo to PNG"); } } } diff --git a/VCardUtils.h b/VCardUtils.h index b05475b13e05a9ce0f11d864c3decd3c47c685cb..593fd6059c5746d1e4cb38d361de34c40bdb1a65 100644 --- a/VCardUtils.h +++ b/VCardUtils.h @@ -44,7 +44,7 @@ struct Symbols { constexpr static const char* SEPERATOR1 = ";"; constexpr static const char* SEPERATOR2 = ":"; constexpr static const char* PHOTO_ENC = "ENDCODING=BASE64"; - constexpr static const char* PHOTO_TYPE = "TYPE=JPEG"; + constexpr static const char* PHOTO_TYPE = "TYPE=PNG"; }; struct Property {