@@ -689,7 +689,7 @@ func (a *AppCore) formatProfileAvatarURL(userID, path string) string {
689689}
690690
691691// onProfileUpdate обрабатывает входящее обновление профиля от контакта
692- func (a * AppCore ) onProfileUpdate (senderPubKey , nickname , bio string , avatar []byte ) {
692+ func (a * AppCore ) onProfileUpdate (senderPubKey , nickname , bio string , avatar []byte , senderAddr string ) {
693693 if a .Repo == nil {
694694 return
695695 }
@@ -701,7 +701,25 @@ func (a *AppCore) onProfileUpdate(senderPubKey, nickname, bio string, avatar []b
701701
702702 contact , _ := a .Repo .GetContactByPublicKey (a .Ctx , senderPubKey )
703703 if contact == nil {
704- return
704+ // Try to find by address (important for b32-only contacts discovery)
705+ contact , _ = a .Repo .GetContactByAddress (a .Ctx , senderAddr )
706+ if contact != nil {
707+ oldChatID := contact .ChatID
708+ newChatID := identity .CalculateChatID (a .Identity .Keys .PublicKeyBase64 , senderPubKey )
709+
710+ log .Printf ("[AppCore] Discovered PublicKey via ProfileUpdate for %s (%s). Migrating ChatID: %s -> %s" , contact .Nickname , senderAddr , oldChatID , newChatID )
711+
712+ contact .PublicKey = senderPubKey
713+ contact .ChatID = newChatID
714+ contact .UpdatedAt = time .Now ()
715+
716+ if err := a .Repo .UpdateContactAndMigrateChatID (a .Ctx , contact , oldChatID , newChatID ); err != nil {
717+ log .Printf ("[AppCore] Failed to migrate ChatID via ProfileUpdate for %s: %v" , contact .Nickname , err )
718+ }
719+ } else {
720+ // Not a contact we know, just return
721+ return
722+ }
705723 }
706724
707725 contact .Nickname = nickname
@@ -752,6 +770,14 @@ func (a *AppCore) onProfileRequest(requestorPubKey string) {
752770 }
753771}
754772
773+ // RequestProfile запрашивает обновление профиля у контакта
774+ func (a * AppCore ) RequestProfile (address string ) error {
775+ if a .Messenger == nil {
776+ return fmt .Errorf ("messenger not initialized" )
777+ }
778+ return a .Messenger .SendProfileRequest (address )
779+ }
780+
755781// ─── Обработчики входящих сообщений ─────────────────────────────────────────
756782
757783// OnMessageReceived — обработчик входящих сообщений.
@@ -761,6 +787,7 @@ func (a *AppCore) OnMessageReceived(msg *core.Message, senderPubKey, senderAddr
761787 return
762788 }
763789
790+ msg .SenderAddr = senderAddr
764791 var contact * core.Contact
765792 contact , _ = a .Repo .GetContactByPublicKey (a .Ctx , senderPubKey )
766793 if contact == nil {
0 commit comments