feat(explorer): 채널 후원 목록/등록 기능을 추가한다
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// GetChannelDonationListResponse.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 2/25/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct GetChannelDonationListResponse: Decodable {
|
||||
let totalCount: Int
|
||||
let items: [GetChannelDonationListItem]
|
||||
}
|
||||
|
||||
struct GetChannelDonationListItem: Decodable {
|
||||
let id: Int
|
||||
let memberId: Int
|
||||
let nickname: String
|
||||
let profileUrl: String
|
||||
let can: Int
|
||||
let isSecret: Bool
|
||||
let message: String
|
||||
let createdAt: String
|
||||
}
|
||||
|
||||
extension GetChannelDonationListItem {
|
||||
func relativeTimeText(now: Date = Date()) -> String {
|
||||
guard let createdDate = DateParser.parse(createdAt) else {
|
||||
return createdAt
|
||||
}
|
||||
|
||||
let interval = max(0, now.timeIntervalSince(createdDate))
|
||||
|
||||
let calendar = Calendar.current
|
||||
let ym = calendar.dateComponents([.year, .month],
|
||||
from: createdDate,
|
||||
to: now)
|
||||
|
||||
if let years = ym.year, years >= 1 {
|
||||
return I18n.Time.yearsAgo(years)
|
||||
}
|
||||
|
||||
if let months = ym.month, months >= 1 {
|
||||
return I18n.Time.monthsAgo(months)
|
||||
}
|
||||
|
||||
if interval < 60 {
|
||||
return I18n.Time.justNow
|
||||
}
|
||||
|
||||
if interval < 3600 {
|
||||
let minutes = max(1, Int(interval / 60))
|
||||
return I18n.Time.minutesAgo(minutes)
|
||||
}
|
||||
|
||||
if interval < 86_400 {
|
||||
let hours = max(1, Int(interval / 3600))
|
||||
return I18n.Time.hoursAgo(hours)
|
||||
}
|
||||
|
||||
let days = max(1, Int(interval / 86_400))
|
||||
return I18n.Time.daysAgo(days)
|
||||
}
|
||||
|
||||
var messageBodyText: String {
|
||||
let trimmed = message.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
if trimmed.isEmpty {
|
||||
return I18n.MemberChannel.channelDonationDefaultMessage
|
||||
}
|
||||
|
||||
return " \(trimmed)"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user