From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: alina sireneva <alina@tei.su>
Date: Fri, 17 Jul 2026 00:36:33 +0400
Subject: fix crash when opening a profile whose note was removed server-side

---
 .../java/org/telegram/ui/ProfileActivity.java     | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java
@@ -13567,8 +13567,7 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
                     } else if (position == inu_idRow) {
                         detailCell.setTextAndValue(ProfileHelper.formatId(userId, chatId != 0 ? getMessagesController().getChat(chatId) : null), LocaleController.getString(R.string.InuProfileId), false);
                     } else if (position == noteRow) {
-                        final TLRPC.UserFull userInfo = getMessagesController().getUserFull(userId);
-                        if (userInfo == null) return;
+                        if (userInfo == null || userInfo.note == null) return;
                         TLRPC.TL_textWithEntities note = userInfo.note;
                         CharSequence text;
                         if (!UserConfig.getInstance(currentAccount).isPremium()) {
@@ -16348,8 +16347,8 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
         final ItemOptions o = ItemOptions.makeOptions(this, view);
         o.setScrimViewBackground(listView.getClipBackground(view));
         o.setLongPressSelectionEnabled(false);
-        o.addIf(userInfo != null, R.drawable.msg_copy, getString(R.string.Copy), () -> {
-            if (userInfo == null) return;
+        o.addIf(userInfo != null && userInfo.note != null, R.drawable.msg_copy, getString(R.string.Copy), () -> {
+            if (userInfo == null || userInfo.note == null) return;
             final CharSequence text = MessageObject.formatTextWithEntities(userInfo.note, false);
             AndroidUtilities.addToClipboard(text);
             BulletinFactory.of(ProfileActivity.this)
@@ -16367,11 +16366,15 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
                 .setTitle(getString(R.string.ProfileNotesRemoveTitle))
                 .setMessage(getString(R.string.ProfileNotesRemoveText))
                 .setPositiveButton(getString(R.string.Delete), (di, w) -> {
-                    final TLRPC.UserFull userInfo = getMessagesController().getUserFull(userId);
+                    final TLRPC.UserFull cachedUserInfo = getMessagesController().getUserFull(userId);
+                    if (cachedUserInfo != null) {
+                        cachedUserInfo.flags2 &=~ TLObject.FLAG_22;
+                        cachedUserInfo.note = null;
+                        getMessagesStorage().updateUserInfo(cachedUserInfo, true);
+                    }
                     if (userInfo != null) {
                         userInfo.flags2 &=~ TLObject.FLAG_22;
                         userInfo.note = null;
-                        getMessagesStorage().updateUserInfo(userInfo, true);
                     }
 
                     final TLRPC.TL_updateContactNote req = new TLRPC.TL_updateContactNote();
