diff --git a/src/persistence/historykeeper.cpp b/src/persistence/historykeeper.cpp index 188a41bbf..6eeb385fd 100644 --- a/src/persistence/historykeeper.cpp +++ b/src/persistence/historykeeper.cpp @@ -529,6 +529,15 @@ QList HistoryKeeper::exportMessagesDeleteFile() return msgs; } + +void HistoryKeeper::removeAvatar(const QString& ownerId) +{ + QSqlQuery query; + query.prepare("UPDATE aliases SET avatar=NULL, av_hash=NULL WHERE user_id = (:id)"); + query.bindValue(":id", ownerId.left(64)); + query.exec(); +} + void HistoryKeeper::saveAvatar(QPixmap& pic, const QString& ownerId) { QByteArray bArray; diff --git a/src/persistence/historykeeper.h b/src/persistence/historykeeper.h index 2ee7c54ac..fd0c99145 100644 --- a/src/persistence/historykeeper.h +++ b/src/persistence/historykeeper.h @@ -78,6 +78,8 @@ public: void saveAvatarHash(const QByteArray& hash, const QString& ownerId); QByteArray getAvatarHash(const QString& ownerId); + void removeAvatar(const QString& ownerId); + private: HistoryKeeper(GenericDdInterface *db_); HistoryKeeper(HistoryKeeper &hk) = delete; diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index afc0f0cc7..f4cd55774 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -184,18 +184,13 @@ void ProfileForm::showProfilePictureContextMenu(const QPoint &point) QPoint pos = profilePicture->mapToGlobal(point); QMenu contextMenu; - QAction *removeAction = contextMenu.addAction(tr("Remove")); + QAction *removeAction = contextMenu.addAction(style()->standardIcon(QStyle::SP_DialogCancelButton), tr("Remove")); QAction *selectedItem = contextMenu.exec(pos); if (selectedItem == removeAction) { QString selfPubKey = Core::getInstance()->getSelfId().publicKey; - if (!QFile::remove(Settings::getInstance().getSettingsDirPath()+"avatars/"+selfPubKey.left(64)+".png")) - { - GUI::showError(tr("Error"), tr("Could not remove avatar.")); - return; - } - + HistoryKeeper::getInstance()->removeAvatar(selfPubKey); Core::getInstance()->setAvatar({}); } }