diff --git a/DontBe-iOS/DontBe-iOS.xcodeproj/project.pbxproj b/DontBe-iOS/DontBe-iOS.xcodeproj/project.pbxproj index e060ebf5..8444a351 100644 --- a/DontBe-iOS/DontBe-iOS.xcodeproj/project.pbxproj +++ b/DontBe-iOS/DontBe-iOS.xcodeproj/project.pbxproj @@ -144,6 +144,7 @@ 3C70BE332B53EF92001AA5A6 /* MyPageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C70BE322B53EF92001AA5A6 /* MyPageViewModel.swift */; }; 3C7741522B5311750069E694 /* MyPageAccountInfoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C7741512B5311750069E694 /* MyPageAccountInfoTableViewCell.swift */; }; 3C7741542B531AC80069E694 /* AccountInfoDummy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C7741532B531AC80069E694 /* AccountInfoDummy.swift */; }; + 3C8CA0962C15744800D6D5C9 /* ReportRequestDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C8CA0952C15744800D6D5C9 /* ReportRequestDTO.swift */; }; 3CA32F532B81E200003DF637 /* MyPageAccountInfoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CA32F522B81E200003DF637 /* MyPageAccountInfoViewModel.swift */; }; 3CB634CA2B59080E00DB9DA5 /* DontBeTransparencyGrayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CB634C92B59080E00DB9DA5 /* DontBeTransparencyGrayView.swift */; }; 3CBCA3CA2B57212400D348D3 /* MyPageMemberCommentResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CBCA3C92B57212400D348D3 /* MyPageMemberCommentResponseDTO.swift */; }; @@ -307,6 +308,7 @@ 3C70BE322B53EF92001AA5A6 /* MyPageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageViewModel.swift; sourceTree = ""; }; 3C7741512B5311750069E694 /* MyPageAccountInfoTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageAccountInfoTableViewCell.swift; sourceTree = ""; }; 3C7741532B531AC80069E694 /* AccountInfoDummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountInfoDummy.swift; sourceTree = ""; }; + 3C8CA0952C15744800D6D5C9 /* ReportRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportRequestDTO.swift; sourceTree = ""; }; 3CA32F522B81E200003DF637 /* MyPageAccountInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageAccountInfoViewModel.swift; sourceTree = ""; }; 3CB634C92B59080E00DB9DA5 /* DontBeTransparencyGrayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DontBeTransparencyGrayView.swift; sourceTree = ""; }; 3CBCA3C92B57212400D348D3 /* MyPageMemberCommentResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageMemberCommentResponseDTO.swift; sourceTree = ""; }; @@ -844,6 +846,7 @@ 2A28453C2B531DAD0023F9B5 /* SocialLogin */, 3C70BE2A2B53EB81001AA5A6 /* MyPage */, 3CF465182B58393800997FCA /* Transparency */, + 3C8CA0932C15741A00D6D5C9 /* Report */, 3C61930E2B3A787000220CEB /* Foundation */, ); path = Network; @@ -1042,6 +1045,22 @@ path = Cells; sourceTree = ""; }; + 3C8CA0932C15741A00D6D5C9 /* Report */ = { + isa = PBXGroup; + children = ( + 3C8CA0942C15742B00D6D5C9 /* RequestDTO */, + ); + path = Report; + sourceTree = ""; + }; + 3C8CA0942C15742B00D6D5C9 /* RequestDTO */ = { + isa = PBXGroup; + children = ( + 3C8CA0952C15744800D6D5C9 /* ReportRequestDTO.swift */, + ); + path = RequestDTO; + sourceTree = ""; + }; 3CBF991F2B549B470015FE4B /* Write */ = { isa = PBXGroup; children = ( @@ -1323,6 +1342,7 @@ 3C61930A2B3A781300220CEB /* ImageLiterals.swift in Sources */, 2A8D70C52B4D8079009F4C6C /* UIViewController+.swift in Sources */, 2A6D54C12B479B4300F9891E /* adjusted+.swift in Sources */, + 3C8CA0962C15744800D6D5C9 /* ReportRequestDTO.swift in Sources */, 2A8D70D12B4DD356009F4C6C /* JoinAgreementViewController.swift in Sources */, 2A0A730C2B541A43004478C1 /* NetworkServiceType.swift in Sources */, 3C2F54522B51224500E7BF01 /* MyPageAccountInfoViewController.swift in Sources */, diff --git a/DontBe-iOS/DontBe-iOS/Global/Literals/StringLiterals.swift b/DontBe-iOS/DontBe-iOS/Global/Literals/StringLiterals.swift index 426cb28f..fbf56d8a 100644 --- a/DontBe-iOS/DontBe-iOS/Global/Literals/StringLiterals.swift +++ b/DontBe-iOS/DontBe-iOS/Global/Literals/StringLiterals.swift @@ -87,6 +87,7 @@ enum StringLiterals { static let commentTransparency = "님, 작성하신 답글로 인해 점점 투명해지고 있어요." static let emptyTitle = "아직 받은 알림이 없어요." static let emptyDescription = "새로운 소식이 도착하면 알려드릴게요." + static let popularWriter = "님이 작성하신 글이 인기글로 선정되었어요. 🥳🥳" } enum MyPage { diff --git a/DontBe-iOS/DontBe-iOS/Network/Report/RequestDTO/ReportRequestDTO.swift b/DontBe-iOS/DontBe-iOS/Network/Report/RequestDTO/ReportRequestDTO.swift new file mode 100644 index 00000000..15e5941d --- /dev/null +++ b/DontBe-iOS/DontBe-iOS/Network/Report/RequestDTO/ReportRequestDTO.swift @@ -0,0 +1,15 @@ +// +// ReportRequestDTO.swift +// DontBe-iOS +// +// Created by 변상우 on 6/9/24. +// + +import Foundation + +// MARK: - ReportRequestDTO + +struct ReportRequestDTO: Encodable { + let reportTargetNickname: String + let relateText: String +} diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewControllers/HomeViewController.swift b/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewControllers/HomeViewController.swift index ad60aa1e..12754ab8 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewControllers/HomeViewController.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewControllers/HomeViewController.swift @@ -24,9 +24,12 @@ final class HomeViewController: UIViewController { var alarmTriggerdId: Int = 0 var ghostReason: String = "" var hasAppearedBefore = false + var reportTargetNickname: String = "" + var relateText: String = "" var transparentReasonView = DontBePopupReasonView() var deletePostPopupVC = DeletePopupViewController(viewModel: DeletePostViewModel(networkProvider: NetworkService())) + var reportPopupView = DontBePopupView(popupTitle: "신고하시겠어요?", popupContent: "해당 유저 혹은 게시글을 신고하시려면\n신고하기 버튼을 눌러주세요.", leftButtonTitle: "취소", rightButtonTitle: "신고하기") let refreshControl = UIRefreshControl() @@ -169,9 +172,16 @@ extension HomeViewController { } @objc - func warnUser() { + func reportButtonTapped() { popWarnUserBottomsheetView() - showWarnUserSafariView() + + if let window = UIApplication.shared.keyWindowInConnectedScenes { + window.addSubviews(self.reportPopupView) + + self.reportPopupView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + } } func popWarnUserBottomsheetView() { @@ -187,11 +197,6 @@ extension HomeViewController { } } - func showWarnUserSafariView() { - let safariView: SFSafariViewController = SFSafariViewController(url: self.warnUserURL! as URL) - self.present(safariView, animated: true, completion: nil) - } - @objc private func popViewController() { self.navigationController?.popViewController(animated: true) @@ -201,6 +206,7 @@ extension HomeViewController { homeCollectionView.dataSource = self homeCollectionView.delegate = self transparentReasonView.delegate = self + reportPopupView.delegate = self } private func setNotification() { @@ -534,7 +540,9 @@ extension HomeViewController: UICollectionViewDataSource, UICollectionViewDelega cell.KebabButtonAction = { self.warnUserBottomsheetView.showSettings() - self.warnUserBottomsheetView.warnButton.addTarget(self, action: #selector(self.warnUser), for: .touchUpInside) + self.reportTargetNickname = cell.nicknameLabel.text ?? "" + self.relateText = cell.contentTextLabel.text ?? "" + self.warnUserBottomsheetView.warnButton.addTarget(self, action: #selector(self.reportButtonTapped), for: .touchUpInside) } } @@ -728,3 +736,26 @@ extension HomeViewController: DontBePopupReasonDelegate { } } } + +extension HomeViewController: DontBePopupDelegate { + func cancleButtonTapped() { + reportPopupView.removeFromSuperview() + } + + func confirmButtonTapped() { + reportPopupView.removeFromSuperview() + + Task { + do { + if let accessToken = KeychainWrapper.loadToken(forKey: "accessToken") { + let result = try await self.homeViewModel.postReportButtonAPI( + reportTargetNickname: self.reportTargetNickname, + relateText: self.relateText + ) + } + } catch { + print(error) + } + } + } +} diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewModel/HomeViewModel.swift b/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewModel/HomeViewModel.swift index 12483e9d..3afacef0 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewModel/HomeViewModel.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Home/ViewModel/HomeViewModel.swift @@ -258,6 +258,26 @@ extension HomeViewModel { } } + func postReportButtonAPI(reportTargetNickname: String, relateText: String) async throws -> BaseResponse? { + do { + guard let accessToken = KeychainWrapper.loadToken(forKey: "accessToken") else { return nil } + let data: BaseResponse? = try await + self.networkProvider.donNetwork( + type: .post, + baseURL: Config.baseURL + "/report/slack", + accessToken: accessToken, + body: ReportRequestDTO( + reportTargetNickname: reportTargetNickname, + relateText: relateText + ), + pathVariables: ["":""] + ) + return data + } catch { + return nil + } + } + func patchUserInfoDataAPI(isPushAlarmAllowed: Bool) { guard let url = URL(string: Config.baseURL + "/user-profile2") else { return } guard let accessToken = KeychainWrapper.loadToken(forKey: "accessToken") else { return } @@ -312,5 +332,4 @@ extension HomeViewModel { task.resume() } - } diff --git a/DontBe-iOS/DontBe-iOS/Presentation/MyPage/ViewControllers/MyPageViewController.swift b/DontBe-iOS/DontBe-iOS/Presentation/MyPage/ViewControllers/MyPageViewController.swift index b605429a..503b7819 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/MyPage/ViewControllers/MyPageViewController.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/MyPage/ViewControllers/MyPageViewController.swift @@ -37,6 +37,8 @@ final class MyPageViewController: UIViewController { var targetMemberId: Int = 0 var alarmTriggerdId: Int = 0 var ghostReason: String = "" + var reportTargetNickname: String = "" + var relateText: String = "마이페이지 유저 신고" var commentDatas: [MyPageMemberCommentResponseDTO] = [] var contentDatas: [MyPageMemberContentResponseDTO] = [] @@ -209,6 +211,7 @@ extension MyPageViewController { rootView.pageViewController.delegate = self rootView.pageViewController.dataSource = self transparentReasonView.delegate = self + rootView.reportPopupView.delegate = self } private func setNotification() { @@ -596,10 +599,15 @@ extension MyPageViewController { @objc private func warnButtonTapped() { rootView.warnBottomsheet.handleDismiss() - let warnView: SFSafariViewController - if let warnURL = self.warnUserURL { - warnView = SFSafariViewController(url: warnURL) - self.present(warnView, animated: true, completion: nil) + + self.reportTargetNickname = self.rootView.myPageProfileView.userNickname.text ?? "" + + if let window = UIApplication.shared.keyWindowInConnectedScenes { + window.addSubviews(rootView.reportPopupView) + + self.rootView.reportPopupView.snp.makeConstraints { + $0.edges.equalToSuperview() + } } } @@ -769,31 +777,52 @@ extension MyPageViewController: UICollectionViewDelegate { extension MyPageViewController: DontBePopupDelegate { func cancleButtonTapped() { - self.logoutPopupView?.removeFromSuperview() + if logoutPopupView != nil { + self.logoutPopupView?.removeFromSuperview() + } else { + rootView.reportPopupView.removeFromSuperview() + } } func confirmButtonTapped() { - self.logoutPopupView?.removeFromSuperview() - self.rootView.myPageBottomsheet.handleDismiss() - - if let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate { - DispatchQueue.main.async { - let rootViewController = LoginViewController(viewModel: LoginViewModel(networkProvider: NetworkService())) - sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: rootViewController) + if logoutPopupView != nil { + self.logoutPopupView?.removeFromSuperview() + self.rootView.myPageBottomsheet.handleDismiss() + + if let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate { + DispatchQueue.main.async { + let rootViewController = LoginViewController(viewModel: LoginViewModel(networkProvider: NetworkService())) + sceneDelegate.window?.rootViewController = UINavigationController(rootViewController: rootViewController) + } + } + + saveUserData(UserInfo(isSocialLogined: false, + isFirstUser: false, + isJoinedApp: true, + isOnboardingFinished: true, + userNickname: loadUserData()?.userNickname ?? "", + memberId: loadUserData()?.memberId ?? 0, + userProfileImage: loadUserData()?.userProfileImage ?? StringLiterals.Network.baseImageURL, + fcmToken: loadUserData()?.fcmToken ?? "", + isPushAlarmAllowed: loadUserData()?.isPushAlarmAllowed ?? false)) + + OnboardingViewController.pushCount = 0 + } else { + rootView.reportPopupView.removeFromSuperview() + + Task { + do { + if let accessToken = KeychainWrapper.loadToken(forKey: "accessToken") { + let result = try await self.homeViewModel.postReportButtonAPI( + reportTargetNickname: self.reportTargetNickname, + relateText: self.relateText + ) + } + } catch { + print(error) + } } } - - saveUserData(UserInfo(isSocialLogined: false, - isFirstUser: false, - isJoinedApp: true, - isOnboardingFinished: true, - userNickname: loadUserData()?.userNickname ?? "", - memberId: loadUserData()?.memberId ?? 0, - userProfileImage: loadUserData()?.userProfileImage ?? StringLiterals.Network.baseImageURL, - fcmToken: loadUserData()?.fcmToken ?? "", - isPushAlarmAllowed: loadUserData()?.isPushAlarmAllowed ?? false)) - - OnboardingViewController.pushCount = 0 } } diff --git a/DontBe-iOS/DontBe-iOS/Presentation/MyPage/Views/MyPageView.swift b/DontBe-iOS/DontBe-iOS/Presentation/MyPage/Views/MyPageView.swift index e1efdfd5..dee6e00f 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/MyPage/Views/MyPageView.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/MyPage/Views/MyPageView.swift @@ -82,6 +82,7 @@ final class MyPageView: UIView { var deleteBottomsheet = DontBeBottomSheetView(singleButtonImage: ImageLiterals.Posting.btnDelete) var warnBottomsheet = DontBeBottomSheetView(singleButtonImage: ImageLiterals.Posting.btnWarn) + var reportPopupView = DontBePopupView(popupTitle: "신고하시겠어요?", popupContent: "해당 유저 혹은 게시글을 신고하시려면\n신고하기 버튼을 눌러주세요.", leftButtonTitle: "취소", rightButtonTitle: "신고하기") // MARK: - Life Cycles diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Notification/Cells/NotificationTableViewCell.swift b/DontBe-iOS/DontBe-iOS/Presentation/Notification/Cells/NotificationTableViewCell.swift index 1da26cf0..e077f204 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Notification/Cells/NotificationTableViewCell.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Notification/Cells/NotificationTableViewCell.swift @@ -25,7 +25,7 @@ final class NotificationTableViewCell: UITableViewCell, UITableViewCellRegistera return profileImage }() - let notificationLabel: UILabel = { + var notificationLabel: UILabel = { let notificationLabel = UILabel() notificationLabel.textColor = .donGray12 notificationLabel.font = .font(.body4) @@ -148,6 +148,16 @@ extension NotificationTableViewCell { text: notificationLabel.text, targetString: list.memberNickname, font: .font(.body3)) + case .popularWriter: + nicknameLabel.text = list.memberNickname + notificationLabel.text = list.memberNickname + " " + list.notificationType.description + notificationLabel.setTextWithLineHeightAndFont( + text: notificationLabel.text, + targetString: list.memberNickname, + font: .font(.body3)) + case .popularContent: + nicknameLabel.text = "어제 가장 인기있었던 글이에요.\n" + notificationLabel.text = "" } minutes.text = list.time.formattedTime() diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificaitonType.swift b/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificaitonType.swift index 3384426d..981412cd 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificaitonType.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificaitonType.swift @@ -17,6 +17,8 @@ enum NotificaitonType: String { case contentGhost = "contentGhost" case commentGhost = "commentGhost" case userBan = "userBan" + case popularWriter = "popularWriter" + case popularContent = "popularContent" var description: String { switch self { @@ -36,6 +38,10 @@ enum NotificaitonType: String { return StringLiterals.Notification.commentTransparency case .userBan: return StringLiterals.Notification.violation + case .popularWriter: + return StringLiterals.Notification.popularWriter + case .popularContent: + return StringLiterals.Notification.violation } } } diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificationList.swift b/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificationList.swift index 0d858409..3cf16160 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificationList.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Notification/Models/NotificationList.swift @@ -16,6 +16,7 @@ struct NotificationList { let time: String let notificationId: Int let triggerMemberId: Int + let notificationText: String } extension NotificationList { @@ -26,5 +27,6 @@ extension NotificationList { notificationType: .contentLiked, time: "", notificationId: 0, - triggerMemberId: 0) + triggerMemberId: 0, + notificationText: "") } diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewControllers/NotificationViewController.swift b/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewControllers/NotificationViewController.swift index 177b1e17..51fed70c 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewControllers/NotificationViewController.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewControllers/NotificationViewController.swift @@ -198,7 +198,16 @@ extension NotificationViewController: UITableViewDataSource { return cell } else { guard let cell = tableView.dequeueReusableCell(withIdentifier: NotificationTableViewCell.reuseIdentifier, for: indexPath) as? NotificationTableViewCell else { return UITableViewCell() } - cell.configureCell(list: viewModel.notificationLists[indexPath.row]) + if viewModel.notificationLists[indexPath.row].notificationType == .popularContent { + cell.nicknameLabel.text = "어제 가장 인기있었던 글이에요.\n" + cell.notificationLabel.text = "어제 가장 인기있었던 글이에요.\n" + viewModel.notificationLists[indexPath.row].notificationText + cell.notificationLabel.setTextWithLineHeightAndFont( + text: cell.notificationLabel.text, + targetString: "어제 가장 인기있었던 글이에요.", + font: .font(.body3)) + } else { + cell.configureCell(list: viewModel.notificationLists[indexPath.row]) + } cell.selectionStyle = .none let numsOflines = UILabel.lineNumber(label: cell.notificationLabel, labelWidth: 216.adjusted) numsOfLinesOfCellLabel = numsOflines diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewModels/NotificationViewModel.swift b/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewModels/NotificationViewModel.swift index 09a7a78e..38c456b3 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewModels/NotificationViewModel.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Notification/ViewModels/NotificationViewModel.swift @@ -49,8 +49,10 @@ final class NotificationViewModel: ViewModelType { triggerMemberProfileUrl: data.triggerMemberProfileUrl, notificationTriggerId: data.notificationTriggerId, notificationType: notificationType, - time: data.time, notificationId: data.notificationId, - triggerMemberId: data.triggerMemberId) + time: data.time, + notificationId: data.notificationId, + triggerMemberId: data.triggerMemberId, + notificationText: data.notificationText) } self.notificationList = myNotiList ?? [] notificationLists.append(contentsOf: notificationList) @@ -76,7 +78,8 @@ final class NotificationViewModel: ViewModelType { notificationType: notificationType, time: data.time, notificationId: data.notificationId, - triggerMemberId: data.triggerMemberId) + triggerMemberId: data.triggerMemberId, + notificationText: data.notificationText) } self.notificationList = myNotiList ?? [] _ = try await self.patchNotificationCheck() diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewControllers/PostDetailViewController.swift b/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewControllers/PostDetailViewController.swift index d8c9d7c9..7fdd1a3a 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewControllers/PostDetailViewController.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewControllers/PostDetailViewController.swift @@ -53,6 +53,8 @@ final class PostDetailViewController: UIViewController { var userNickName: String = "" var userProfileURL: String = StringLiterals.Network.baseImageURL var contentText: String = "" + var reportTargetNickname: String = "" + var relateText: String = "" // MARK: - UI Components @@ -70,6 +72,8 @@ final class PostDetailViewController: UIViewController { private var deleteToastView: DontBeDeletePopupView? private var photoDetailView: DontBePhotoDetailView? + var reportPopupView = DontBePopupView(popupTitle: "신고하시겠어요?", popupContent: "해당 유저 혹은 게시글을 신고하시려면\n신고하기 버튼을 눌러주세요.", leftButtonTitle: "취소", rightButtonTitle: "신고하기") + // MARK: - Life Cycles override func viewDidLoad() { @@ -175,6 +179,7 @@ extension PostDetailViewController { postReplyCollectionView.dataSource = self postReplyCollectionView.delegate = self transparentReasonView.delegate = self + reportPopupView.delegate = self } private func setAppearNotification() { @@ -352,7 +357,7 @@ extension PostDetailViewController { private func addWarnUserButtonAction() { self.warnBottomsheet.deleteButton.removeFromSuperview() - self.warnBottomsheet.warnButton.addTarget(self, action: #selector(warnUser), for: .touchUpInside) + self.warnBottomsheet.warnButton.addTarget(self, action: #selector(reportButtonTapped), for: .touchUpInside) } @objc @@ -368,10 +373,16 @@ extension PostDetailViewController { } @objc - private func warnUser() { + private func reportButtonTapped() { popWarnView() - let safariView: SFSafariViewController = SFSafariViewController(url: self.warnUserURL! as URL) - self.present(safariView, animated: true, completion: nil) + + if let window = UIApplication.shared.keyWindowInConnectedScenes { + window.addSubviews(self.reportPopupView) + + self.reportPopupView.snp.makeConstraints { + $0.edges.equalToSuperview() + } + } } @objc @@ -793,7 +804,9 @@ extension PostDetailViewController: UICollectionViewDataSource, UICollectionView cell.KebabButtonAction = { self.warnBottomsheet.showSettings() - self.warnBottomsheet.warnButton.addTarget(self, action: #selector(self.warnUser), for: .touchUpInside) + self.reportTargetNickname = cell.nicknameLabel.text ?? "" + self.relateText = cell.contentTextLabel.text ?? "" + self.warnBottomsheet.warnButton.addTarget(self, action: #selector(self.reportButtonTapped), for: .touchUpInside) self.commentId = self.viewModel.postReplyDatas[indexPath.row].commentId } } @@ -1049,3 +1062,26 @@ extension PostDetailViewController: DontBePopupReasonDelegate { } } } + +extension PostDetailViewController: DontBePopupDelegate { + func cancleButtonTapped() { + reportPopupView.removeFromSuperview() + } + + func confirmButtonTapped() { + reportPopupView.removeFromSuperview() + + Task { + do { + if let accessToken = KeychainWrapper.loadToken(forKey: "accessToken") { + let result = try await self.viewModel.postReportButtonAPI( + reportTargetNickname: self.reportTargetNickname, + relateText: self.relateText + ) + } + } catch { + print(error) + } + } + } +} diff --git a/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewModel/PostDetailViewModel.swift b/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewModel/PostDetailViewModel.swift index 02d6367d..586952b5 100644 --- a/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewModel/PostDetailViewModel.swift +++ b/DontBe-iOS/DontBe-iOS/Presentation/Post/ViewModel/PostDetailViewModel.swift @@ -336,4 +336,24 @@ extension PostDetailViewModel { return nil } } + + func postReportButtonAPI(reportTargetNickname: String, relateText: String) async throws -> BaseResponse? { + do { + guard let accessToken = KeychainWrapper.loadToken(forKey: "accessToken") else { return nil } + let data: BaseResponse? = try await + self.networkProvider.donNetwork( + type: .post, + baseURL: Config.baseURL + "/report/slack", + accessToken: accessToken, + body: ReportRequestDTO( + reportTargetNickname: reportTargetNickname, + relateText: relateText + ), + pathVariables: ["":""] + ) + return data + } catch { + return nil + } + } }