fix(content): 성인 콘텐츠 설정 동기화와 국가별 인증 분기를 적용한다
This commit is contained in:
@@ -74,6 +74,7 @@ class AppState: ObservableObject {
|
||||
|
||||
@Published var isShowErrorPopup = false
|
||||
@Published var errorMessage = ""
|
||||
@Published private var pendingContentSettingsGuideMessage: String? = nil
|
||||
@Published var liveDetailSheet: LiveDetailSheetState? = nil
|
||||
|
||||
private func syncStepWithNavigationPath() {
|
||||
@@ -180,6 +181,16 @@ class AppState: ObservableObject {
|
||||
pendingCommunityCommentCreatorId = 0
|
||||
pendingCommunityCommentPostId = 0
|
||||
}
|
||||
|
||||
func setPendingContentSettingsGuideMessage(_ message: String) {
|
||||
pendingContentSettingsGuideMessage = message
|
||||
}
|
||||
|
||||
func consumePendingContentSettingsGuideMessage() -> String? {
|
||||
let message = pendingContentSettingsGuideMessage
|
||||
pendingContentSettingsGuideMessage = nil
|
||||
return message
|
||||
}
|
||||
|
||||
// 언어 적용 직후 앱을 소프트 재시작(스플래시 -> 메인)하여 전역 UI를 새로고침
|
||||
func softRestart() {
|
||||
|
||||
@@ -75,6 +75,9 @@ final class AppViewModel: ObservableObject {
|
||||
UserDefaults.set(data.isAuth, forKey: .auth)
|
||||
UserDefaults.set(data.role.rawValue, forKey: .role)
|
||||
UserDefaults.set(data.auditionNotice ?? false, forKey: .isAuditionNotification)
|
||||
UserDefaults.set(data.countryCode, forKey: .countryCode)
|
||||
UserDefaults.set(data.isAdultContentVisible, forKey: .isAdultContentVisible)
|
||||
UserDefaults.set(data.contentType, forKey: .contentPreference)
|
||||
if data.followingChannelLiveNotice == nil && data.followingChannelUploadContentNotice == nil && data.messageNotice == nil {
|
||||
AppState.shared.isShowNotificationSettingsDialog = true
|
||||
}
|
||||
|
||||
@@ -41,7 +41,14 @@ struct ChatTabView: View {
|
||||
AppState.shared.setAppStep(step: .login)
|
||||
return
|
||||
}
|
||||
if auth == false {
|
||||
|
||||
let normalizedCountryCode = UserDefaults
|
||||
.string(forKey: .countryCode)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
let isKoreanCountry = normalizedCountryCode.isEmpty || normalizedCountryCode == "KR"
|
||||
|
||||
if isKoreanCountry && auth == false {
|
||||
pendingAction = {
|
||||
AppState.shared
|
||||
.setAppStep(step: .characterDetail(characterId: characterId))
|
||||
@@ -49,8 +56,20 @@ struct ChatTabView: View {
|
||||
isShowAuthConfirmView = true
|
||||
return
|
||||
}
|
||||
|
||||
if !UserDefaults.isAdultContentVisible() {
|
||||
pendingAction = nil
|
||||
moveToContentSettingsWithGuideToast()
|
||||
return
|
||||
}
|
||||
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: characterId))
|
||||
}
|
||||
|
||||
private func moveToContentSettingsWithGuideToast() {
|
||||
AppState.shared.setPendingContentSettingsGuideMessage(I18n.Settings.adultContentEnableGuide)
|
||||
AppState.shared.setAppStep(step: .contentViewSettings)
|
||||
}
|
||||
|
||||
private func handleCharacterSelection() {
|
||||
let trimmed = token.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
|
||||
@@ -25,6 +25,7 @@ enum UserDefaultsKey: String, CaseIterable {
|
||||
case notShowingEventPopupId
|
||||
case isAdultContentVisible
|
||||
case contentPreference
|
||||
case countryCode
|
||||
case isAuditionNotification
|
||||
case searchChannel
|
||||
case marketingPid
|
||||
@@ -73,7 +74,7 @@ extension UserDefaults {
|
||||
|
||||
static func isAdultContentVisible() -> Bool {
|
||||
let key = UserDefaultsKey.isAdultContentVisible.rawValue
|
||||
return UserDefaults.standard.object(forKey: key) != nil ? bool(forKey: .isAdultContentVisible) : true
|
||||
return UserDefaults.standard.object(forKey: key) != nil ? bool(forKey: .isAdultContentVisible) : false
|
||||
}
|
||||
|
||||
static func reset() {
|
||||
|
||||
@@ -44,7 +44,14 @@ struct HomeTabView: View {
|
||||
AppState.shared.setAppStep(step: .login)
|
||||
return
|
||||
}
|
||||
if auth == false {
|
||||
|
||||
let normalizedCountryCode = UserDefaults
|
||||
.string(forKey: .countryCode)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
let isKoreanCountry = normalizedCountryCode.isEmpty || normalizedCountryCode == "KR"
|
||||
|
||||
if isKoreanCountry && auth == false {
|
||||
pendingAction = {
|
||||
AppState.shared
|
||||
.setAppStep(step: .characterDetail(characterId: characterId))
|
||||
@@ -52,6 +59,15 @@ struct HomeTabView: View {
|
||||
isShowAuthConfirmView = true
|
||||
return
|
||||
}
|
||||
|
||||
if !UserDefaults.isAdultContentVisible() {
|
||||
pendingAction = nil
|
||||
AppState.shared.errorMessage = I18n.Settings.adultContentEnableGuide
|
||||
AppState.shared.isShowErrorPopup = true
|
||||
AppState.shared.setAppStep(step: .contentViewSettings)
|
||||
return
|
||||
}
|
||||
|
||||
AppState.shared.setAppStep(step: .characterDetail(characterId: characterId))
|
||||
}
|
||||
|
||||
|
||||
@@ -408,6 +408,30 @@ enum I18n {
|
||||
// 알림 다이얼로그 타이틀
|
||||
static var alertTitle: String { pick(ko: "알림", en: "Notice", ja: "お知らせ") }
|
||||
|
||||
static var adultContentAgeCheckTitle: String {
|
||||
pick(
|
||||
ko: "당신은 18세 이상입니까?",
|
||||
en: "Are you over 18 years old?",
|
||||
ja: "あなたは18歳以上ですか?"
|
||||
)
|
||||
}
|
||||
|
||||
static var adultContentAgeCheckDesc: String {
|
||||
pick(
|
||||
ko: "해당 콘텐츠는 18세 이상만 이용이 가능합니다!",
|
||||
en: "This content is available only to users aged 18 and over!",
|
||||
ja: "このコンテンツは18歳以上のみ利用可能です!"
|
||||
)
|
||||
}
|
||||
|
||||
static var adultContentEnableGuide: String {
|
||||
pick(
|
||||
ko: "민감한 콘텐츠를 보려면 콘텐츠 보기 설정에서 민감한 콘텐츠 보기를 켜주세요.",
|
||||
en: "To view sensitive content, turn on Sensitive Content in Content View Settings.",
|
||||
ja: "センシティブなコンテンツを表示するには、コンテンツ表示設定でセンシティブなコンテンツ表示をオンにしてください。"
|
||||
)
|
||||
}
|
||||
|
||||
// 로그아웃 확인 질문
|
||||
static var logoutQuestion: String {
|
||||
pick(
|
||||
|
||||
@@ -169,11 +169,29 @@ struct LiveNowAllView: View {
|
||||
AppState.shared.setAppStep(step: .login)
|
||||
return
|
||||
}
|
||||
if isAdult && auth == false {
|
||||
pendingAction = { openLiveDetail(roomId: roomId) }
|
||||
isShowAuthConfirmView = true
|
||||
return
|
||||
|
||||
if isAdult {
|
||||
let normalizedCountryCode = UserDefaults
|
||||
.string(forKey: .countryCode)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
let isKoreanCountry = normalizedCountryCode.isEmpty || normalizedCountryCode == "KR"
|
||||
|
||||
if isKoreanCountry && auth == false {
|
||||
pendingAction = { openLiveDetail(roomId: roomId) }
|
||||
isShowAuthConfirmView = true
|
||||
return
|
||||
}
|
||||
|
||||
if !UserDefaults.isAdultContentVisible() {
|
||||
pendingAction = nil
|
||||
AppState.shared.errorMessage = I18n.Settings.adultContentEnableGuide
|
||||
AppState.shared.isShowErrorPopup = true
|
||||
AppState.shared.setAppStep(step: .contentViewSettings)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
openLiveDetail(roomId: roomId)
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
@Published var isShowUserProfilePopup = false
|
||||
@Published var changeIsAdult = false {
|
||||
didSet {
|
||||
if changeIsAdult && !UserDefaults.bool(forKey: .auth) {
|
||||
if changeIsAdult && requiresAdultAuthenticationByCountry() {
|
||||
agora.speakerMute(true)
|
||||
}
|
||||
}
|
||||
@@ -653,7 +653,7 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
getTotalDonationCan()
|
||||
getTotalHeartCount()
|
||||
|
||||
if data.isAdult && !UserDefaults.bool(forKey: .auth) {
|
||||
if data.isAdult && requiresAdultAuthenticationByCountry() {
|
||||
changeIsAdult = true
|
||||
}
|
||||
|
||||
@@ -697,6 +697,16 @@ final class LiveRoomViewModel: NSObject, ObservableObject {
|
||||
}
|
||||
}
|
||||
|
||||
private func requiresAdultAuthenticationByCountry() -> Bool {
|
||||
let normalizedCountryCode = UserDefaults
|
||||
.string(forKey: .countryCode)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
let isKoreanCountry = normalizedCountryCode.isEmpty || normalizedCountryCode == "KR"
|
||||
|
||||
return isKoreanCountry && !UserDefaults.bool(forKey: .auth)
|
||||
}
|
||||
|
||||
func toggleMute() {
|
||||
setMute(!isMute)
|
||||
}
|
||||
|
||||
@@ -472,11 +472,29 @@ struct HomeView: View {
|
||||
AppState.shared.setAppStep(step: .login)
|
||||
return
|
||||
}
|
||||
if isAdult && auth == false {
|
||||
pendingAction = { openLiveDetail(roomId: roomId) }
|
||||
isShowAuthConfirmView = true
|
||||
return
|
||||
|
||||
if isAdult {
|
||||
let normalizedCountryCode = UserDefaults
|
||||
.string(forKey: .countryCode)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
let isKoreanCountry = normalizedCountryCode.isEmpty || normalizedCountryCode == "KR"
|
||||
|
||||
if isKoreanCountry && auth == false {
|
||||
pendingAction = { openLiveDetail(roomId: roomId) }
|
||||
isShowAuthConfirmView = true
|
||||
return
|
||||
}
|
||||
|
||||
if !UserDefaults.isAdultContentVisible() {
|
||||
pendingAction = nil
|
||||
AppState.shared.errorMessage = I18n.Settings.adultContentEnableGuide
|
||||
AppState.shared.isShowErrorPopup = true
|
||||
AppState.shared.setAppStep(step: .contentViewSettings)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
openLiveDetail(roomId: roomId)
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,9 @@ final class HomeViewModel: ObservableObject {
|
||||
UserDefaults.set(data.isAuth, forKey: .auth)
|
||||
UserDefaults.set(data.role.rawValue, forKey: .role)
|
||||
UserDefaults.set(data.auditionNotice ?? false, forKey: .isAuditionNotification)
|
||||
UserDefaults.set(data.countryCode, forKey: .countryCode)
|
||||
UserDefaults.set(data.isAdultContentVisible, forKey: .isAdultContentVisible)
|
||||
UserDefaults.set(data.contentType, forKey: .contentPreference)
|
||||
if data.followingChannelLiveNotice == nil && data.followingChannelUploadContentNotice == nil && data.messageNotice == nil {
|
||||
AppState.shared.isShowNotificationSettingsDialog = true
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ struct MyPageView: View {
|
||||
@AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
|
||||
|
||||
var body: some View {
|
||||
let normalizedCountryCode = UserDefaults
|
||||
.string(forKey: .countryCode)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
let isKoreanCountry = normalizedCountryCode.isEmpty || normalizedCountryCode == "KR"
|
||||
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty &&
|
||||
viewModel.isShowAuthView {
|
||||
@@ -114,6 +120,7 @@ struct MyPageView: View {
|
||||
CategoryButtonsView(
|
||||
isShowAuthView: $viewModel.isShowAuthView,
|
||||
isAuthenticated: viewModel.isAuth,
|
||||
isKoreanCountry: isKoreanCountry,
|
||||
showMessage: {
|
||||
viewModel.errorMessage = $0
|
||||
viewModel.isShowPopup = true
|
||||
@@ -381,6 +388,7 @@ struct CategoryButtonsView: View {
|
||||
@Binding var isShowAuthView: Bool
|
||||
|
||||
let isAuthenticated: Bool
|
||||
let isKoreanCountry: Bool
|
||||
let showMessage: (String) -> Void
|
||||
let refresh: () -> Void
|
||||
|
||||
@@ -420,12 +428,14 @@ struct CategoryButtonsView: View {
|
||||
AppState.shared.setAppStep(step: .serviceCenter)
|
||||
}
|
||||
|
||||
CategoryButtonItem(
|
||||
icon: "ic_my_auth",
|
||||
title: isAuthenticated ? "인증완료" : "본인인증"
|
||||
) {
|
||||
if !isAuthenticated {
|
||||
isShowAuthView = true
|
||||
if isKoreanCountry {
|
||||
CategoryButtonItem(
|
||||
icon: "ic_my_auth",
|
||||
title: isAuthenticated ? "인증완료" : "본인인증"
|
||||
) {
|
||||
if !isAuthenticated {
|
||||
isShowAuthView = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,113 +10,138 @@ import SwiftUI
|
||||
struct ContentSettingsView: View {
|
||||
|
||||
@StateObject var viewModel = ContentSettingsViewModel()
|
||||
@ObservedObject private var appState = AppState.shared
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color.black.ignoresSafeArea()
|
||||
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: "콘텐츠 보기 설정") {
|
||||
if AppState.shared.isRestartApp {
|
||||
AppState.shared.setAppStep(step: .splash)
|
||||
} else {
|
||||
AppState.shared.back()
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView(.vertical) {
|
||||
VStack(spacing: 0) {
|
||||
HStack(spacing: 0) {
|
||||
Text("민감한 콘텐츠 보기")
|
||||
.appFont(size: 15, weight: .bold)
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(viewModel.isAdultContentVisible ? "btn_toggle_on_big" : "btn_toggle_off_big")
|
||||
.resizable()
|
||||
.frame(width: 44, height: 27)
|
||||
.onTapGesture {
|
||||
viewModel.isAdultContentVisible.toggle()
|
||||
}
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
ZStack {
|
||||
Color.black.ignoresSafeArea()
|
||||
|
||||
VStack(spacing: 0) {
|
||||
DetailNavigationBar(title: "콘텐츠 보기 설정") {
|
||||
if AppState.shared.isRestartApp {
|
||||
AppState.shared.setAppStep(step: .splash)
|
||||
} else {
|
||||
AppState.shared.back()
|
||||
}
|
||||
.frame(height: 50)
|
||||
|
||||
if viewModel.isAdultContentVisible {
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(Color.gray90.opacity(0.3))
|
||||
|
||||
}
|
||||
|
||||
ScrollView(.vertical) {
|
||||
VStack(spacing: 0) {
|
||||
HStack(spacing: 0) {
|
||||
HStack(spacing: 13.3) {
|
||||
Image(
|
||||
viewModel.adultContentPreference == .ALL ?
|
||||
"btn_radio_select_selected" :
|
||||
"btn_radio_select_normal"
|
||||
)
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text("전체")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.adultContentPreference = .ALL
|
||||
}
|
||||
|
||||
Text("민감한 콘텐츠 보기")
|
||||
.appFont(size: 15, weight: .bold)
|
||||
.foregroundColor(Color(hex: "eeeeee"))
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 13.3) {
|
||||
Image(
|
||||
viewModel.adultContentPreference == .MALE ?
|
||||
"btn_radio_select_selected" :
|
||||
"btn_radio_select_normal"
|
||||
)
|
||||
|
||||
Image(viewModel.isAdultContentVisible ? "btn_toggle_on_big" : "btn_toggle_off_big")
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text("남성향")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.adultContentPreference = .MALE
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 13.3) {
|
||||
Image(
|
||||
viewModel.adultContentPreference == .FEMALE ?
|
||||
"btn_radio_select_selected" :
|
||||
"btn_radio_select_normal"
|
||||
)
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text("여성향")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.adultContentPreference = .FEMALE
|
||||
}
|
||||
Spacer()
|
||||
.frame(width: 44, height: 27)
|
||||
.onTapGesture {
|
||||
viewModel.handleAdultContentToggleTap()
|
||||
}
|
||||
}
|
||||
.frame(height: 50)
|
||||
|
||||
if viewModel.isAdultContentVisible {
|
||||
Rectangle()
|
||||
.frame(height: 1)
|
||||
.foregroundColor(Color.gray90.opacity(0.3))
|
||||
|
||||
HStack(spacing: 0) {
|
||||
HStack(spacing: 13.3) {
|
||||
Image(
|
||||
viewModel.adultContentPreference == .ALL ?
|
||||
"btn_radio_select_selected" :
|
||||
"btn_radio_select_normal"
|
||||
)
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text("전체")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.adultContentPreference = .ALL
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 13.3) {
|
||||
Image(
|
||||
viewModel.adultContentPreference == .MALE ?
|
||||
"btn_radio_select_selected" :
|
||||
"btn_radio_select_normal"
|
||||
)
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text("남성향")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.adultContentPreference = .MALE
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
HStack(spacing: 13.3) {
|
||||
Image(
|
||||
viewModel.adultContentPreference == .FEMALE ?
|
||||
"btn_radio_select_selected" :
|
||||
"btn_radio_select_normal"
|
||||
)
|
||||
.resizable()
|
||||
.frame(width: 20, height: 20)
|
||||
|
||||
Text("여성향")
|
||||
.appFont(size: 13.3, weight: .medium)
|
||||
.foregroundColor(Color.grayee)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
viewModel.adultContentPreference = .FEMALE
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.frame(height: 50)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 6.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
.background(Color.gray22)
|
||||
.cornerRadius(10)
|
||||
.padding(.top, 13.3)
|
||||
.padding(.horizontal, 13.3)
|
||||
}
|
||||
.padding(.vertical, 6.7)
|
||||
.padding(.horizontal, 13.3)
|
||||
.background(Color.gray22)
|
||||
.cornerRadius(10)
|
||||
.padding(.top, 13.3)
|
||||
.padding(.horizontal, 13.3)
|
||||
}
|
||||
|
||||
if viewModel.isShowAdultContentAgeCheckDialog {
|
||||
SodaDialog(
|
||||
title: I18n.Settings.adultContentAgeCheckTitle,
|
||||
desc: I18n.Settings.adultContentAgeCheckDesc,
|
||||
confirmButtonTitle: I18n.Common.yes,
|
||||
confirmButtonAction: {
|
||||
viewModel.confirmAdultContentAgeCheck()
|
||||
},
|
||||
cancelButtonTitle: I18n.Common.no,
|
||||
cancelButtonAction: {
|
||||
viewModel.cancelAdultContentAgeCheck()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2)
|
||||
.onAppear {
|
||||
if let pendingGuideMessage = appState.consumePendingContentSettingsGuideMessage() {
|
||||
viewModel.errorMessage = pendingGuideMessage
|
||||
viewModel.isShowPopup = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,28 +6,183 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class ContentSettingsViewModel: ObservableObject {
|
||||
@Published var isAdultContentVisible = UserDefaults.isAdultContentVisible() {
|
||||
didSet {
|
||||
if oldValue != isAdultContentVisible {
|
||||
UserDefaults.set(isAdultContentVisible, forKey: .isAdultContentVisible)
|
||||
AppState.shared.isRestartApp = true
|
||||
|
||||
if !isAdultContentVisible {
|
||||
adultContentPreference = .ALL
|
||||
UserDefaults.set(ContentType.ALL.rawValue, forKey: .contentPreference)
|
||||
private let userRepository = UserRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
private let contentPreferenceSubject = PassthroughSubject<ContentPreferenceState, Never>()
|
||||
private var latestRequestToken = UUID()
|
||||
private var isApplyingServerState = false
|
||||
private var lastSyncedState: ContentPreferenceState
|
||||
|
||||
@Published var isLoading = false
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isShowAdultContentAgeCheckDialog = false
|
||||
|
||||
@Published var isAdultContentVisible: Bool
|
||||
@Published var adultContentPreference: ContentType
|
||||
|
||||
init() {
|
||||
let isAdultContentVisible = UserDefaults.isAdultContentVisible()
|
||||
let contentPreference = ContentType(rawValue: UserDefaults.string(forKey: .contentPreference)) ?? .ALL
|
||||
let initialState = ContentPreferenceState(
|
||||
isAdultContentVisible: isAdultContentVisible,
|
||||
contentType: isAdultContentVisible ? contentPreference : .ALL
|
||||
)
|
||||
|
||||
_isAdultContentVisible = Published(initialValue: isAdultContentVisible)
|
||||
_adultContentPreference = Published(initialValue: isAdultContentVisible ? contentPreference : .ALL)
|
||||
lastSyncedState = initialState
|
||||
|
||||
bindContentPreference()
|
||||
}
|
||||
|
||||
private func bindContentPreference() {
|
||||
$isAdultContentVisible
|
||||
.dropFirst()
|
||||
.removeDuplicates()
|
||||
.sink { [weak self] isAdultContentVisible in
|
||||
guard let self = self else { return }
|
||||
if self.isApplyingServerState { return }
|
||||
|
||||
if !isAdultContentVisible && self.adultContentPreference != .ALL {
|
||||
self.adultContentPreference = .ALL
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
|
||||
Publishers.CombineLatest($isAdultContentVisible, $adultContentPreference)
|
||||
.map { isAdultContentVisible, adultContentPreference in
|
||||
ContentPreferenceState(
|
||||
isAdultContentVisible: isAdultContentVisible,
|
||||
contentType: isAdultContentVisible ? adultContentPreference : .ALL
|
||||
)
|
||||
}
|
||||
.removeDuplicates()
|
||||
.dropFirst()
|
||||
.sink { [weak self] state in
|
||||
guard let self = self else { return }
|
||||
if self.isApplyingServerState { return }
|
||||
|
||||
self.applyLocalState(state)
|
||||
self.contentPreferenceSubject.send(state)
|
||||
}
|
||||
.store(in: &subscription)
|
||||
|
||||
contentPreferenceSubject
|
||||
.removeDuplicates()
|
||||
.debounce(for: .seconds(0.3), scheduler: RunLoop.main)
|
||||
.sink { [weak self] state in
|
||||
self?.updateContentPreference(state: state)
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func updateContentPreference(state: ContentPreferenceState) {
|
||||
let request = makeUpdateContentPreferenceRequest(from: lastSyncedState, to: state)
|
||||
if request.isEmpty {
|
||||
return
|
||||
}
|
||||
|
||||
let requestToken = UUID()
|
||||
latestRequestToken = requestToken
|
||||
isLoading = true
|
||||
|
||||
userRepository
|
||||
.updateContentPreference(
|
||||
request: request
|
||||
)
|
||||
.sink { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
guard self.latestRequestToken == requestToken else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
self.isLoading = false
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
guard self.latestRequestToken == requestToken else { return }
|
||||
|
||||
do {
|
||||
let decoded = try JSONDecoder().decode(ApiResponse<UpdateContentPreferenceResponse>.self, from: response.data)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
let serverState = ContentPreferenceState(
|
||||
isAdultContentVisible: data.isAdultContentVisible,
|
||||
contentType: data.isAdultContentVisible ? data.contentType : .ALL
|
||||
)
|
||||
self.applyServerState(serverState)
|
||||
} else {
|
||||
self.errorMessage = decoded.message ?? I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = I18n.Common.commonError
|
||||
self.isShowPopup = true
|
||||
}
|
||||
|
||||
self.isLoading = false
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func applyLocalState(_ state: ContentPreferenceState) {
|
||||
UserDefaults.set(state.isAdultContentVisible, forKey: .isAdultContentVisible)
|
||||
UserDefaults.set(state.contentType.rawValue, forKey: .contentPreference)
|
||||
AppState.shared.isRestartApp = true
|
||||
}
|
||||
|
||||
private func applyServerState(_ state: ContentPreferenceState) {
|
||||
isApplyingServerState = true
|
||||
isAdultContentVisible = state.isAdultContentVisible
|
||||
adultContentPreference = state.contentType
|
||||
applyLocalState(state)
|
||||
lastSyncedState = state
|
||||
isApplyingServerState = false
|
||||
}
|
||||
|
||||
private func makeUpdateContentPreferenceRequest(from previousState: ContentPreferenceState, to currentState: ContentPreferenceState) -> UpdateContentPreferenceRequest {
|
||||
let isAdultContentVisible = previousState.isAdultContentVisible != currentState.isAdultContentVisible
|
||||
? currentState.isAdultContentVisible
|
||||
: nil
|
||||
let contentType = previousState.contentType != currentState.contentType
|
||||
? currentState.contentType
|
||||
: nil
|
||||
|
||||
return UpdateContentPreferenceRequest(
|
||||
isAdultContentVisible: isAdultContentVisible,
|
||||
contentType: contentType
|
||||
)
|
||||
}
|
||||
|
||||
func handleAdultContentToggleTap() {
|
||||
if isAdultContentVisible {
|
||||
isAdultContentVisible = false
|
||||
} else {
|
||||
isShowAdultContentAgeCheckDialog = true
|
||||
}
|
||||
}
|
||||
|
||||
@Published var adultContentPreference = ContentType(rawValue: UserDefaults.string(forKey: .contentPreference)) ?? ContentType.ALL {
|
||||
didSet {
|
||||
if oldValue != adultContentPreference {
|
||||
UserDefaults.set(adultContentPreference.rawValue, forKey: .contentPreference)
|
||||
AppState.shared.isRestartApp = true
|
||||
}
|
||||
}
|
||||
|
||||
func confirmAdultContentAgeCheck() {
|
||||
isShowAdultContentAgeCheckDialog = false
|
||||
isAdultContentVisible = true
|
||||
}
|
||||
|
||||
func cancelAdultContentAgeCheck() {
|
||||
isShowAdultContentAgeCheckDialog = false
|
||||
}
|
||||
}
|
||||
|
||||
private struct ContentPreferenceState: Equatable {
|
||||
let isAdultContentVisible: Bool
|
||||
let contentType: ContentType
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import Foundation
|
||||
|
||||
struct UpdateContentPreferenceRequest: Encodable {
|
||||
let isAdultContentVisible: Bool?
|
||||
let contentType: ContentType?
|
||||
|
||||
var isEmpty: Bool {
|
||||
return isAdultContentVisible == nil && contentType == nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import Foundation
|
||||
|
||||
struct UpdateContentPreferenceResponse: Decodable {
|
||||
let isAdultContentVisible: Bool
|
||||
let contentType: ContentType
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case isAdultContentVisible
|
||||
case contentType
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
isAdultContentVisible = try container.decodeIfPresent(Bool.self, forKey: .isAdultContentVisible) ?? true
|
||||
|
||||
let rawContentType =
|
||||
try container
|
||||
.decodeIfPresent(String.self, forKey: .contentType)?
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
contentType = ContentType(rawValue: rawContentType ?? "") ?? .ALL
|
||||
}
|
||||
}
|
||||
@@ -23,4 +23,55 @@ struct GetMemberInfoResponse: Decodable {
|
||||
let followingChannelLiveNotice: Bool?
|
||||
let followingChannelUploadContentNotice: Bool?
|
||||
let auditionNotice: Bool?
|
||||
let countryCode: String
|
||||
let isAdultContentVisible: Bool
|
||||
let contentType: String
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case can
|
||||
case point
|
||||
case isAuth
|
||||
case gender
|
||||
case signupDate
|
||||
case chargeCount
|
||||
case role
|
||||
case messageNotice
|
||||
case followingChannelLiveNotice
|
||||
case followingChannelUploadContentNotice
|
||||
case auditionNotice
|
||||
case countryCode
|
||||
case isAdultContentVisible
|
||||
case contentType
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
can = try container.decode(Int.self, forKey: .can)
|
||||
point = try container.decode(Int.self, forKey: .point)
|
||||
isAuth = try container.decode(Bool.self, forKey: .isAuth)
|
||||
gender = try container.decodeIfPresent(String.self, forKey: .gender)
|
||||
signupDate = try container.decode(String.self, forKey: .signupDate)
|
||||
chargeCount = try container.decode(Int.self, forKey: .chargeCount)
|
||||
role = try container.decode(MemberRole.self, forKey: .role)
|
||||
messageNotice = try container.decodeIfPresent(Bool.self, forKey: .messageNotice)
|
||||
followingChannelLiveNotice = try container.decodeIfPresent(Bool.self, forKey: .followingChannelLiveNotice)
|
||||
followingChannelUploadContentNotice = try container.decodeIfPresent(Bool.self, forKey: .followingChannelUploadContentNotice)
|
||||
auditionNotice = try container.decodeIfPresent(Bool.self, forKey: .auditionNotice)
|
||||
|
||||
countryCode =
|
||||
try container
|
||||
.decodeIfPresent(String.self, forKey: .countryCode)?
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased() ?? ""
|
||||
|
||||
isAdultContentVisible = try container.decodeIfPresent(Bool.self, forKey: .isAdultContentVisible) ?? true
|
||||
|
||||
let rawContentType =
|
||||
try container
|
||||
.decodeIfPresent(String.self, forKey: .contentType)?
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
contentType = ["ALL", "MALE", "FEMALE"].contains(rawContentType ?? "") ? (rawContentType ?? "ALL") : "ALL"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ struct SettingsView: View {
|
||||
|
||||
var body: some View {
|
||||
let cardWidth = screenSize().width - 26.7
|
||||
let isAuth = UserDefaults.bool(forKey: .auth)
|
||||
let normalizedCountryCode = UserDefaults
|
||||
.string(forKey: .countryCode)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.uppercased()
|
||||
let isNonKoreanCountry = !normalizedCountryCode.isEmpty && normalizedCountryCode != "KR"
|
||||
|
||||
BaseView(isLoading: $viewModel.isLoading) {
|
||||
GeometryReader { geo in
|
||||
@@ -65,7 +71,7 @@ struct SettingsView: View {
|
||||
AppState.shared.setAppStep(step: .languageSettings)
|
||||
}
|
||||
|
||||
if UserDefaults.bool(forKey: .auth) {
|
||||
if isAuth || isNonKoreanCountry {
|
||||
Rectangle()
|
||||
.frame(width: cardWidth - 26.7, height: 0.3)
|
||||
.foregroundColor(Color.gray90)
|
||||
|
||||
@@ -19,6 +19,7 @@ enum UserApi {
|
||||
case searchUser(nickname: String)
|
||||
case getMypage
|
||||
case getMemberInfo
|
||||
case updateContentPreference(request: UpdateContentPreferenceRequest)
|
||||
case notification(request: UpdateNotificationSettingRequest)
|
||||
case logout
|
||||
case logoutAllDevice
|
||||
@@ -77,6 +78,9 @@ extension UserApi: TargetType {
|
||||
|
||||
case .getMemberInfo:
|
||||
return "/member/info"
|
||||
|
||||
case .updateContentPreference:
|
||||
return "/member/content-preference"
|
||||
|
||||
case .notification:
|
||||
return "/member/notification"
|
||||
@@ -142,6 +146,9 @@ extension UserApi: TargetType {
|
||||
|
||||
case .searchUser, .getMypage, .getMemberInfo, .getMyProfile, .getChangeNicknamePrice, .checkNickname, .getBlockedMemberList, .getBlockedMemberIdList, .getMemberProfile:
|
||||
return .get
|
||||
|
||||
case .updateContentPreference:
|
||||
return .patch
|
||||
|
||||
case .updatePushToken, .profileUpdate, .changeNickname, .updateIdfa, .updateMarketingInfo:
|
||||
return .put
|
||||
@@ -182,6 +189,9 @@ extension UserApi: TargetType {
|
||||
|
||||
case .notification(let request):
|
||||
return .requestJSONEncodable(request)
|
||||
|
||||
case .updateContentPreference(let request):
|
||||
return .requestJSONEncodable(request)
|
||||
|
||||
case .signOut(let request):
|
||||
return .requestJSONEncodable(request)
|
||||
|
||||
@@ -52,6 +52,10 @@ final class UserRepository {
|
||||
func getMemberInfo() -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.getMemberInfo)
|
||||
}
|
||||
|
||||
func updateContentPreference(request: UpdateContentPreferenceRequest) -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.updateContentPreference(request: request))
|
||||
}
|
||||
|
||||
func getMemberCan() -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.getMemberInfo)
|
||||
|
||||
Reference in New Issue
Block a user