feat: Add avatar deletion functionality and update ProfileScreen to handle avatar presence

This commit is contained in:
2026-01-30 03:36:01 +05:00
parent 7691926ef6
commit 5091eb557a
4 changed files with 149 additions and 29 deletions

View File

@@ -167,6 +167,43 @@ class AvatarRepository(
}
}
/**
* Удалить свой аватар
*/
suspend fun deleteMyAvatar() {
withContext(Dispatchers.IO) {
try {
Log.d(TAG, "🗑️ deleteMyAvatar called")
Log.d(TAG, "👤 Current public key: ${currentPublicKey.take(16)}...")
// Получаем все аватары пользователя
val avatars = avatarDao.getAvatarsByPublicKey(currentPublicKey)
// Удаляем файлы
for (avatar in avatars) {
try {
AvatarFileManager.deleteAvatar(context, avatar.avatar)
Log.d(TAG, "✅ Deleted avatar file: ${avatar.avatar}")
} catch (e: Exception) {
Log.w(TAG, "⚠️ Failed to delete avatar file: ${avatar.avatar}", e)
}
}
// Удаляем из БД
avatarDao.deleteAllAvatars(currentPublicKey)
Log.d(TAG, "✅ Avatars deleted from DB")
// Очищаем memory cache
memoryCache.remove(currentPublicKey)
Log.d(TAG, "🎉 Avatar deleted successfully!")
} catch (e: Exception) {
Log.e(TAG, "❌ Failed to delete avatar: ${e.message}", e)
throw e
}
}
}
/**
* Загрузить и расшифровать аватар из файла
*/