diff --git a/linphone-desktop/src/components/contact/VcardModel.cpp b/linphone-desktop/src/components/contact/VcardModel.cpp index d6eedbdec..4028a9fb8 100644 --- a/linphone-desktop/src/components/contact/VcardModel.cpp +++ b/linphone-desktop/src/components/contact/VcardModel.cpp @@ -58,14 +58,13 @@ inline shared_ptr findBelCardValue (const list > &list, const Q return nullptr; } +inline bool isLinphoneDesktopPhoto (const shared_ptr &photo) { + return !photo->getValue().compare(0, sizeof(VCARD_SCHEME) - 1, VCARD_SCHEME); +} + inline shared_ptr findBelcardPhoto (const shared_ptr &belcard) { const list > &photos = belcard->getPhotos(); - auto it = find_if( - photos.cbegin(), photos.cend(), [](const shared_ptr &photo) { - return !photo->getValue().compare(0, sizeof(VCARD_SCHEME) - 1, VCARD_SCHEME); - } - ); - + auto it = find_if(photos.cbegin(), photos.cend(), isLinphoneDesktopPhoto); if (it != photos.cend()) return *it; @@ -73,17 +72,22 @@ inline shared_ptr findBelcardPhoto (const shared_ptr &belcard) { - shared_ptr oldPhoto = findBelcardPhoto(belcard); - if (oldPhoto) { + list > photos; + for (const auto photo : belcard->getPhotos()) { + if (isLinphoneDesktopPhoto(photo)) + photos.push_back(photo); + } + + for (const auto photo : photos) { QString imagePath( ::Utils::linphoneStringToQString( - Paths::getAvatarsDirPath() + oldPhoto->getValue().substr(sizeof(VCARD_SCHEME) - 1) + Paths::getAvatarsDirPath() + photo->getValue().substr(sizeof(VCARD_SCHEME) - 1) ) ); if (!QFile::remove(imagePath)) qWarning() << QStringLiteral("Unable to remove `%1`.").arg(imagePath); - belcard->removePhoto(oldPhoto); + belcard->removePhoto(photo); } }