125 lines
4.2 KiB
Swift
125 lines
4.2 KiB
Swift
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(communityPostDetail comment: CreatorChannelCommunityCommentResponse, creatorId: Int) {
|
|
let currentUserId = UserDefaults.int(forKey: .userId)
|
|
self.init(
|
|
id: comment.commentId,
|
|
source: .community,
|
|
writerId: comment.writerId,
|
|
nickname: comment.writerNickname,
|
|
profileImageUrl: comment.writerProfileImageUrl,
|
|
content: comment.content,
|
|
relativeTimeText: DateParser.relativeTimeText(fromUTC: comment.createdAtUtc, fallback: comment.createdAtUtc),
|
|
isSecret: comment.isSecret,
|
|
isMine: comment.writerId == currentUserId,
|
|
isCreatorReply: comment.writerId == creatorId
|
|
)
|
|
}
|
|
|
|
init(communityPostDetailReply reply: CreatorChannelCommunityReplyResponse, creatorId: Int) {
|
|
let currentUserId = UserDefaults.int(forKey: .userId)
|
|
self.init(
|
|
id: reply.commentId,
|
|
source: .community,
|
|
writerId: reply.writerId,
|
|
nickname: reply.writerNickname,
|
|
profileImageUrl: reply.writerProfileImageUrl,
|
|
content: reply.content,
|
|
relativeTimeText: reply.relativeTimeText(),
|
|
isSecret: false,
|
|
isMine: reply.writerId == currentUserId,
|
|
isCreatorReply: reply.writerId == creatorId
|
|
)
|
|
}
|
|
|
|
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
|
|
)
|
|
}
|
|
}
|