Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat [#189] 신고하기 기능, 노티 인기글 카테고리 추가 #191

Merged
merged 8 commits into from
Jun 16, 2024
20 changes: 20 additions & 0 deletions DontBe-iOS/DontBe-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -307,6 +308,7 @@
3C70BE322B53EF92001AA5A6 /* MyPageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageViewModel.swift; sourceTree = "<group>"; };
3C7741512B5311750069E694 /* MyPageAccountInfoTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageAccountInfoTableViewCell.swift; sourceTree = "<group>"; };
3C7741532B531AC80069E694 /* AccountInfoDummy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountInfoDummy.swift; sourceTree = "<group>"; };
3C8CA0952C15744800D6D5C9 /* ReportRequestDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportRequestDTO.swift; sourceTree = "<group>"; };
3CA32F522B81E200003DF637 /* MyPageAccountInfoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageAccountInfoViewModel.swift; sourceTree = "<group>"; };
3CB634C92B59080E00DB9DA5 /* DontBeTransparencyGrayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DontBeTransparencyGrayView.swift; sourceTree = "<group>"; };
3CBCA3C92B57212400D348D3 /* MyPageMemberCommentResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageMemberCommentResponseDTO.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -844,6 +846,7 @@
2A28453C2B531DAD0023F9B5 /* SocialLogin */,
3C70BE2A2B53EB81001AA5A6 /* MyPage */,
3CF465182B58393800997FCA /* Transparency */,
3C8CA0932C15741A00D6D5C9 /* Report */,
3C61930E2B3A787000220CEB /* Foundation */,
);
path = Network;
Expand Down Expand Up @@ -1042,6 +1045,22 @@
path = Cells;
sourceTree = "<group>";
};
3C8CA0932C15741A00D6D5C9 /* Report */ = {
isa = PBXGroup;
children = (
3C8CA0942C15742B00D6D5C9 /* RequestDTO */,
);
path = Report;
sourceTree = "<group>";
};
3C8CA0942C15742B00D6D5C9 /* RequestDTO */ = {
isa = PBXGroup;
children = (
3C8CA0952C15744800D6D5C9 /* ReportRequestDTO.swift */,
);
path = RequestDTO;
sourceTree = "<group>";
};
3CBF991F2B549B470015FE4B /* Write */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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 */,
Expand Down
1 change: 1 addition & 0 deletions DontBe-iOS/DontBe-iOS/Global/Literals/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ enum StringLiterals {
static let commentTransparency = "님, 작성하신 답글로 인해 점점 투명해지고 있어요."
static let emptyTitle = "아직 받은 알림이 없어요."
static let emptyDescription = "새로운 소식이 도착하면 알려드릴게요."
static let popularWriter = "님이 작성하신 글이 인기글로 선정되었어요. 🥳🥳"
}

enum MyPage {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -201,6 +206,7 @@ extension HomeViewController {
homeCollectionView.dataSource = self
homeCollectionView.delegate = self
transparentReasonView.delegate = self
reportPopupView.delegate = self
}

private func setNotification() {
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,26 @@ extension HomeViewModel {
}
}

func postReportButtonAPI(reportTargetNickname: String, relateText: String) async throws -> BaseResponse<EmptyResponse>? {
do {
guard let accessToken = KeychainWrapper.loadToken(forKey: "accessToken") else { return nil }
let data: BaseResponse<EmptyResponse>? = 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 }
Expand Down Expand Up @@ -312,5 +332,4 @@ extension HomeViewModel {

task.resume()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []
Expand Down Expand Up @@ -209,6 +211,7 @@ extension MyPageViewController {
rootView.pageViewController.delegate = self
rootView.pageViewController.dataSource = self
transparentReasonView.delegate = self
rootView.reportPopupView.delegate = self
}

private func setNotification() {
Expand Down Expand Up @@ -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()
}
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct NotificationList {
let time: String
let notificationId: Int
let triggerMemberId: Int
let notificationText: String
}

extension NotificationList {
Expand All @@ -26,5 +27,6 @@ extension NotificationList {
notificationType: .contentLiked,
time: "",
notificationId: 0,
triggerMemberId: 0)
triggerMemberId: 0,
notificationText: "")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading