diff --git a/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailView.swift b/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailView.swift index 1b39d8e8..d0e22b20 100644 --- a/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailView.swift +++ b/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailView.swift @@ -22,7 +22,7 @@ struct CreatorChannelCommunityPostDetailView: View { onTapPurchase: viewModel.presentPurchaseDialog ) - if detail.isCommentAvailable { + if viewModel.isCommentInteractionAvailable { Rectangle() .fill(Color.gray800) .frame(height: 1) @@ -83,7 +83,7 @@ struct CreatorChannelCommunityPostDetailView: View { viewModel.configure(postId: postId, onCommunityRefresh: onCommunityRefresh) } .safeAreaInset(edge: .bottom) { - if viewModel.detail?.isCommentAvailable == true { + if viewModel.isCommentInteractionAvailable { CreatorChannelCommunityPostDetailInputBar( text: $viewModel.commentText, isSecret: $viewModel.isSecret, diff --git a/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailViewModel.swift b/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailViewModel.swift index 118d6523..88bf2cb8 100644 --- a/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailViewModel.swift +++ b/SodaLive/Sources/V2/CreatorChannel/Community/Detail/CreatorChannelCommunityPostDetailViewModel.swift @@ -33,13 +33,18 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject { detail?.creatorId == UserDefaults.int(forKey: .userId) } + var isCommentInteractionAvailable: Bool { + guard let detail, detail.isCommentAvailable else { return false } + return detail.price <= 0 || detail.existOrdered || isOwnPost + } + var isShowSecret: Bool { guard let detail else { return false } return detail.price > 0 && detail.existOrdered && detail.creatorId != UserDefaults.int(forKey: .userId) } var isCommentSendEnabled: Bool { - guard detail?.isCommentAvailable == true else { return false } + guard isCommentInteractionAvailable else { return false } return commentText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false && isLoading == false } @@ -102,7 +107,7 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject { func fetchNextCommentsIfNeeded(currentComment: CreatorChannelCommunityCommentResponse) { guard comments.last?.commentId == currentComment.commentId else { return } - guard detail?.isCommentAvailable == true else { return } + guard isCommentInteractionAvailable else { return } guard hasNext, isLoadingNextPage == false, isLoading == false else { return } guard postId > 0 else { return } @@ -227,7 +232,7 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject { } func sendComment() { - guard isCommentSendEnabled else { return } + guard isCommentInteractionAvailable, isCommentSendEnabled else { return } if let editingComment { modify(comment: editingComment) @@ -253,7 +258,7 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject { } func beginEditing(_ comment: CreatorChannelCommunityCommentResponse) { - guard canEdit(comment) else { return } + guard isCommentInteractionAvailable, canEdit(comment) else { return } selectedComment = nil editingComment = comment commentText = comment.content @@ -265,14 +270,14 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject { } func presentDeleteDialog(_ comment: CreatorChannelCommunityCommentResponse) { - guard canDelete(comment) else { return } + guard isCommentInteractionAvailable, canDelete(comment) else { return } selectedComment = nil deletingComment = comment isShowDeleteDialog = true } func confirmDelete() { - guard let deletingComment, isLoading == false else { return } + guard isCommentInteractionAvailable, let deletingComment, isLoading == false else { return } isShowDeleteDialog = false delete(comment: deletingComment) } @@ -284,7 +289,7 @@ final class CreatorChannelCommunityPostDetailViewModel: ObservableObject { hasNext = data.comments.hasNext hasLoaded = true - if data.isCommentAvailable { + if isCommentInteractionAvailable { comments = data.comments.comments } else { comments = []