Refactor: 优化关注列表和代码逻辑
本次提交主要包含以下更改:
- **关注/粉丝列表逻辑修正**:修复了在 `FollowerListViewModel` 和 `FollowingListViewModel` 中 `followerId` 和 `followingId` 属性赋值错误的问题,确保正确加载关注和粉丝列表。
- **分页大小调整**:将 `BaseFollowModel` 中分页加载的 `pageSize` 从 5 调整为 20,以提高用户体验。
- **个人资料页智能体展示**:
- 在 `AccountProfileV2` 和 `AccountProfileViewModel` 中增加了对用户智能体列表的加载和展示逻辑。
- 修复了 `MyProfileViewModel` 中加载当前用户智能体时 `authorId` 传递错误的问题。
- 优化了 `UserAgentsRow` 和 `UserAgentsViewModel` 的逻辑,确保正确加载和显示用户智能体,并在用户切换时清理旧数据。
- **代码清理**:移除了部分冗余的 `println` 调试信息。
- **Agent创建流程优化**:在 `AddAgentViewModel` 和 `AgentImageCropScreen` 中,确保在已有裁剪图片时直接使用,避免重复裁剪。
This commit is contained in:
@@ -157,9 +157,7 @@ object AgentChatListViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
agentChatList = result?.conversationList?.map { msg: V2TIMConversation ->
|
||||
val conversation = AgentConversation.convertToAgentConversation(msg, context)
|
||||
println("AgentChatList: Conversation ${conversation.nickname} has ${conversation.unreadCount} unread messages")
|
||||
conversation
|
||||
AgentConversation.convertToAgentConversation(msg, context)
|
||||
} ?: emptyList()
|
||||
}
|
||||
|
||||
|
||||
@@ -157,9 +157,7 @@ object FriendChatListViewModel : ViewModel() {
|
||||
} ?: emptyList()
|
||||
|
||||
friendChatList = filteredConversations.map { msg: V2TIMConversation ->
|
||||
val conversation = FriendConversation.convertToFriendConversation(msg, context)
|
||||
println("FriendChatList: Conversation ${conversation.nickname} has ${conversation.unreadCount} unread messages")
|
||||
conversation
|
||||
FriendConversation.convertToFriendConversation(msg, context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,9 +178,7 @@ object GroupChatListViewModel : ViewModel() {
|
||||
} ?: emptyList()
|
||||
|
||||
groupChatList = filteredConversations.map { msg: V2TIMConversation ->
|
||||
val conversation = GroupConversation.convertToGroupConversation(msg, context)
|
||||
println("GroupChatList: Conversation ${conversation.groupName} has ${conversation.unreadCount} unread messages")
|
||||
conversation
|
||||
GroupConversation.convertToGroupConversation(msg, context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,8 @@ object MyProfileViewModel : ViewModel() {
|
||||
profile?.let {
|
||||
try {
|
||||
momentLoader.loadData(extra = MomentLoaderExtraArgs(authorId = it.id))
|
||||
agentLoader.loadData(extra = AgentLoaderExtraArgs(authorId = it.id))
|
||||
// MyProfileViewModel 总是加载当前用户的数据,所以传递null以调用getMyAgent()
|
||||
agentLoader.loadData(extra = AgentLoaderExtraArgs(authorId = null))
|
||||
} catch (e: Exception) {
|
||||
Log.e("MyProfileViewModel", "loadProfile: ", e)
|
||||
}
|
||||
|
||||
@@ -48,17 +48,14 @@ fun UserAgentsRow(
|
||||
onAgentClick: (AgentEntity) -> Unit = {}
|
||||
) {
|
||||
val AppColors = LocalAppTheme.current
|
||||
val viewModel: UserAgentsViewModel = viewModel()
|
||||
val viewModel: UserAgentsViewModel = viewModel(key = "UserAgentsViewModel_${userId ?: "self"}")
|
||||
val isSelf = userId == null
|
||||
|
||||
// 加载用户的智能体数据
|
||||
LaunchedEffect(userId) {
|
||||
// 无论userId是否为null都加载数据
|
||||
// null表示加载当前用户自己的智能体
|
||||
println("UserAgentsRow: LaunchedEffect 触发, userId = $userId, isSelf = $isSelf")
|
||||
println("UserAgentsRow: 准备调用 viewModel.loadUserAgents")
|
||||
viewModel.loadUserAgents(userId)
|
||||
println("UserAgentsRow: 已调用 viewModel.loadUserAgents")
|
||||
}
|
||||
|
||||
// 总是显示智能体区域,即使没有数据也显示标题和状态
|
||||
@@ -78,7 +75,6 @@ fun UserAgentsRow(
|
||||
when {
|
||||
viewModel.isLoading -> {
|
||||
// 显示加载状态
|
||||
println("UserAgentsRow: 显示加载状态")
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -94,7 +90,6 @@ fun UserAgentsRow(
|
||||
}
|
||||
viewModel.error != null -> {
|
||||
// 显示错误状态
|
||||
println("UserAgentsRow: 显示错误状态, error = ${viewModel.error}")
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -110,7 +105,6 @@ fun UserAgentsRow(
|
||||
}
|
||||
viewModel.agents.isEmpty() -> {
|
||||
// 显示空状态
|
||||
println("UserAgentsRow: 显示空状态, agents.size = ${viewModel.agents.size}")
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -126,7 +120,6 @@ fun UserAgentsRow(
|
||||
}
|
||||
else -> {
|
||||
// 显示智能体列表
|
||||
println("UserAgentsRow: 显示智能体列表, agents.size = ${viewModel.agents.size}")
|
||||
LazyRow(
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
|
||||
@@ -28,16 +28,15 @@ class UserAgentsViewModel : ViewModel() {
|
||||
|
||||
fun loadUserAgents(userId: Int?) {
|
||||
viewModelScope.launch {
|
||||
// 先清理之前的数据
|
||||
clearAgents()
|
||||
isLoading = true
|
||||
error = null
|
||||
|
||||
try {
|
||||
println("UserAgentsViewModel: 开始加载智能体数据, userId = $userId")
|
||||
agentLoader.loadData(AgentLoaderExtraArgs(authorId = userId))
|
||||
println("UserAgentsViewModel: 加载完成, agents.size = ${agents.size}")
|
||||
} catch (e: Exception) {
|
||||
error = e.message ?: "加载失败"
|
||||
println("UserAgentsViewModel: 加载失败, error = $error")
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
isLoading = false
|
||||
|
||||
Reference in New Issue
Block a user