diff --git a/SodaLive/Sources/V2/CreatorChannel/ReplyDetail/Models/CreatorChannelReplyDetailContext.swift b/SodaLive/Sources/V2/CreatorChannel/ReplyDetail/Models/CreatorChannelReplyDetailContext.swift new file mode 100644 index 00000000..a5f6899d --- /dev/null +++ b/SodaLive/Sources/V2/CreatorChannel/ReplyDetail/Models/CreatorChannelReplyDetailContext.swift @@ -0,0 +1,13 @@ +import Foundation + +enum CreatorChannelReplyDetailContext { + case community( + creatorId: Int, + postId: Int, + parentComment: GetCommunityPostCommentListItem + ) + case fanTalk( + creatorId: Int, + parentFanTalk: CreatorChannelFanTalkItemResponse + ) +} diff --git a/SodaLive/Sources/V2/CreatorChannel/ReplyDetail/Models/CreatorChannelReplyDetailDisplayItem.swift b/SodaLive/Sources/V2/CreatorChannel/ReplyDetail/Models/CreatorChannelReplyDetailDisplayItem.swift new file mode 100644 index 00000000..6db52bc5 --- /dev/null +++ b/SodaLive/Sources/V2/CreatorChannel/ReplyDetail/Models/CreatorChannelReplyDetailDisplayItem.swift @@ -0,0 +1,92 @@ +import Foundation + +struct CreatorChannelReplyDetailDisplayItem: Identifiable, Equatable { + enum Source: Equatable { + case community + case fanTalk + } + + let id: Int + let source: Source + let writerId: Int + let nickname: String + let profileImageUrl: String + let content: String + let relativeTimeText: String + let isSecret: Bool + let isMine: Bool + let isCreatorReply: Bool + + var canEdit: Bool { + isMine || isCreatorReply + } + + var canDelete: Bool { + isMine || isCreatorReply + } + + func updatingContent(_ content: String) -> CreatorChannelReplyDetailDisplayItem { + CreatorChannelReplyDetailDisplayItem( + id: id, + source: source, + writerId: writerId, + nickname: nickname, + profileImageUrl: profileImageUrl, + content: content, + relativeTimeText: relativeTimeText, + isSecret: isSecret, + isMine: isMine, + isCreatorReply: isCreatorReply + ) + } +} + +extension CreatorChannelReplyDetailDisplayItem { + init(communityComment: GetCommunityPostCommentListItem) { + let currentUserId = UserDefaults.int(forKey: .userId) + self.init( + id: communityComment.id, + source: .community, + writerId: communityComment.writerId, + nickname: communityComment.nickname, + profileImageUrl: communityComment.profileUrl, + content: communityComment.comment, + relativeTimeText: communityComment.date, + isSecret: communityComment.isSecret, + isMine: communityComment.writerId == currentUserId, + isCreatorReply: false + ) + } + + init(fanTalk: CreatorChannelFanTalkItemResponse) { + let currentUserId = UserDefaults.int(forKey: .userId) + self.init( + id: fanTalk.fanTalkId, + source: .fanTalk, + writerId: fanTalk.writerId, + nickname: fanTalk.writerNickname, + profileImageUrl: fanTalk.writerProfileImageUrl, + content: fanTalk.content, + relativeTimeText: fanTalk.relativeTimeText(), + isSecret: false, + isMine: fanTalk.writerId == currentUserId, + isCreatorReply: false + ) + } + + init(fanTalkReply: CreatorChannelFanTalkReplyResponse, creatorId: Int) { + let currentUserId = UserDefaults.int(forKey: .userId) + self.init( + id: fanTalkReply.fanTalkId, + source: .fanTalk, + writerId: fanTalkReply.writerId, + nickname: fanTalkReply.writerNickname, + profileImageUrl: fanTalkReply.writerProfileImageUrl, + content: fanTalkReply.content, + relativeTimeText: fanTalkReply.relativeTimeText(), + isSecret: false, + isMine: fanTalkReply.writerId == currentUserId, + isCreatorReply: fanTalkReply.writerId == creatorId + ) + } +}