From 9a11487059f69d91b2827929082daae8dab6d314 Mon Sep 17 00:00:00 2001 From: roxy Date: Sat, 23 May 2026 23:58:50 +0800 Subject: [PATCH] =?UTF-8?q?cp=E5=BB=B6=E5=90=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/services/auth/user_profile_manager.dart | 82 ++++++++++++++++++--- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/lib/services/auth/user_profile_manager.dart b/lib/services/auth/user_profile_manager.dart index 62c2928..8f1f2bf 100644 --- a/lib/services/auth/user_profile_manager.dart +++ b/lib/services/auth/user_profile_manager.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:yumi/app_localizations.dart'; @@ -170,19 +172,20 @@ class SocialChatUserProfileManager extends ChangeNotifier { final loadedProfile = await SCAccountRepository().loadUserInfo( normalizedUserId, ); - var mergedProfile = await _withCurrentVipLevel( - loadedProfile, - normalizedUserId, - ); - mergedProfile = await _withCpCabinProfiles( - mergedProfile, - normalizedUserId, - ); if (requestSerial != _userInfoRequestSerial) { return; } - userProfile = mergedProfile; + userProfile = loadedProfile; userProfileLoadError = null; + isUserProfileLoading = false; + notifyListeners(); + unawaited( + _hydrateUserInfoById( + profile: loadedProfile, + userId: normalizedUserId, + requestSerial: requestSerial, + ), + ); } catch (error, stackTrace) { if (requestSerial != _userInfoRequestSerial) { return; @@ -196,7 +199,7 @@ class SocialChatUserProfileManager extends ChangeNotifier { stackTrace: stackTrace, ); } finally { - if (requestSerial == _userInfoRequestSerial) { + if (requestSerial == _userInfoRequestSerial && isUserProfileLoading) { isUserProfileLoading = false; notifyListeners(); } @@ -234,12 +237,20 @@ class SocialChatUserProfileManager extends ChangeNotifier { normalizedRoomId, normalizedUserId, ); - card = await _withCurrentVipLevelForCard(card, normalizedUserId); if (requestSerial != _userCardRequestSerial) { return; } userCardInfo = card; userCardLoadError = null; + isUserCardLoading = false; + notifyListeners(); + unawaited( + _hydrateRoomUserCard( + card: card, + userId: normalizedUserId, + requestSerial: requestSerial, + ), + ); } catch (error, stackTrace) { if (requestSerial != _userCardRequestSerial) { return; @@ -253,13 +264,60 @@ class SocialChatUserProfileManager extends ChangeNotifier { stackTrace: stackTrace, ); } finally { - if (requestSerial == _userCardRequestSerial) { + if (requestSerial == _userCardRequestSerial && isUserCardLoading) { isUserCardLoading = false; notifyListeners(); } } } + Future _hydrateUserInfoById({ + required SocialChatUserProfile profile, + required String userId, + required int requestSerial, + }) async { + try { + var mergedProfile = await _withCurrentVipLevel(profile, userId); + mergedProfile = await _withCpCabinProfiles(mergedProfile, userId); + if (requestSerial != _userInfoRequestSerial) { + return; + } + userProfile = mergedProfile; + userProfileLoadError = null; + notifyListeners(); + } catch (error, stackTrace) { + _debugProfileLoadFailure( + scope: 'detailHydrate', + userId: userId, + error: error, + stackTrace: stackTrace, + ); + } + } + + Future _hydrateRoomUserCard({ + required RoomUserCardRes? card, + required String userId, + required int requestSerial, + }) async { + try { + final hydratedCard = await _withCurrentVipLevelForCard(card, userId); + if (requestSerial != _userCardRequestSerial || hydratedCard == null) { + return; + } + userCardInfo = hydratedCard; + userCardLoadError = null; + notifyListeners(); + } catch (error, stackTrace) { + _debugProfileLoadFailure( + scope: 'roomCardHydrate', + userId: userId, + error: error, + stackTrace: stackTrace, + ); + } + } + void clearRoomUserCard() { _userCardRequestSerial++; userCardInfo = null;