Skip to content

Commit 8f0e444

Browse files
authored
Remove an invalid assertion (#24544)
* Remove an invalid assertion `siteID` (WP.com site id) is nil for self-hosted sites. * Make `SuggestionsListViewModel` support all sites
1 parent 938e983 commit 8f0e444

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

WordPress/Classes/ViewRelated/Comments/Controllers/Create/CommentCreateViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ final class CommentCreateViewModel {
4040
/// Create a reply to the given comment.
4141
init(replyingTo comment: Comment, save: @escaping (String) async throws -> Void) {
4242
let siteID = comment.associatedSiteID ?? 0
43-
wpAssert(siteID != 0, "missing required parameter siteID")
4443

4544
self.siteID = siteID
4645
self.replyToComment = comment
4746
self._save = save
4847

49-
self.suggestionsViewModel = SuggestionsListViewModel.make(siteID: siteID)
48+
self.suggestionsViewModel = comment.blog.flatMap { SuggestionsListViewModel.make(blog: $0) }
5049
self.suggestionsViewModel?.enableProminentSuggestions(
5150
postAuthorID: comment.post?.authorID,
5251
commentAuthorID: comment.commentID as NSNumber

WordPress/Classes/ViewRelated/Suggestions/SuggestionsListViewModel.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,17 @@ import CoreData
6969
service: SuggestionService = SuggestionService.shared,
7070
context: NSManagedObjectContext = ContextManager.shared.mainContext
7171
) -> SuggestionsListViewModel? {
72-
guard let blog = Blog.lookup(withID: siteID, in: context),
73-
service.shouldShowSuggestions(for: blog) else {
72+
guard siteID.intValue != 0, let blog = Blog.lookup(withID: siteID, in: context) else {
73+
return nil
74+
}
75+
return make(blog: blog, service: service)
76+
}
77+
78+
static func make(
79+
blog: Blog,
80+
service: SuggestionService = SuggestionService.shared
81+
) -> SuggestionsListViewModel? {
82+
guard service.shouldShowSuggestions(for: blog) else {
7483
return nil
7584
}
7685
return SuggestionsListViewModel(blog: blog)

0 commit comments

Comments
 (0)