Skip to content

Conversation

graycreate
Copy link
Member

Summary

  • Fixes issue Splash Screen #4: App crashes when non-logged-in users click Ignore or Report buttons
  • Added login status checks for all user actions in FeedDetail view
  • Prevents force unwrapping of nil values that caused crashes

Changes Made

  • Added AccountState.hasSignIn() checks before executing user actions
  • Replaced force unwrapping (!) with safe guard statements
  • Shows login prompt when unauthenticated users try to perform actions
  • Added graceful error handling with user-friendly messages

Affected Actions

All the following actions now properly check authentication:

  • ✅ Star/Unstar topic
  • ✅ Thanks author
  • ✅ Ignore topic
  • ✅ Report topic
  • ✅ Reply to topic

Test Plan

  • Launch app without logging in
  • Navigate to any topic detail page
  • Click on menu (ellipsis button) in top-right
  • Try clicking "Ignore" - should show login prompt instead of crashing
  • Try clicking "Report" - should show login prompt instead of crashing
  • Try other actions - all should prompt for login appropriately

Fixes #4

🤖 Generated with Claude Code

Added login checks for all user actions in FeedDetail:
- Star/Unstar topic
- Thanks author
- Ignore topic
- Report topic
- Reply to topic

These actions now:
1. Check if user is logged in before executing
2. Show login prompt if not authenticated
3. Properly handle nil values with guard statements
4. Show error messages if required data is missing

This fixes the crash reported in issue #4 when non-logged-in users
click Ignore or Report buttons.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Copilot Copilot AI review requested due to automatic review settings September 24, 2025 14:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a critical crash issue when non-authenticated users attempt to perform actions (Ignore/Report/Star/Thanks/Reply) in the FeedDetail view. The fix adds proper login status validation and replaces unsafe force unwrapping with safe guard statements to prevent nil pointer crashes.

  • Added authentication checks using AccountState.hasSignIn() before executing user actions
  • Replaced force unwrapping operators (!) with safe guard statements and proper error handling
  • Shows appropriate login prompts with contextual messages when unauthenticated users attempt actions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +64 to +65
Toast.show("请先登录")
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能收藏主题"))
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The login prompt logic is duplicated across all actions. Consider extracting this into a shared helper method to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

Toast.show(hadStared ? "取消收藏" : "收藏中")
let once = state?.model.once
guard let once = state?.model.once else {
Toast.show("操作失败,请刷新页面")
Copy link
Preview

Copilot AI Sep 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message '操作失败,请刷新页面' is duplicated multiple times. Consider defining this as a constant to ensure consistency and easier maintenance.

Copilot uses AI. Check for mistakes.

Copy link

Code Coverage Report ❌

Current coverage: 0%

@graycreate graycreate merged commit 0f7661b into main Sep 24, 2025
6 checks passed
@graycreate graycreate deleted the bugfix/splash-screen-crash-fix branch September 24, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Splash Screen
1 participant