Skip to content

Commit

Permalink
ui/timeline: 포스트 삭제 시 Azurea처럼 취소선 표시 함
Browse files Browse the repository at this point in the history
  • Loading branch information
unstabler committed Nov 30, 2024
1 parent c6def39 commit 4bb689c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion reazure/fediverse/mastodon/MastodonAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class MastodonClient {

func deleteStatus(statusId: String) async throws {
_ = try await request(to: MastodonEndpoint.status(of: statusId),
expects: String.self, // <- FIXME: ???
expects: String.self, // <- FIXME: 이거 때문에 요청은 성공해도 call이 실패함
method: .delete)
}

Expand Down
2 changes: 2 additions & 0 deletions reazure/fediverse/mastodon/objdef/Status.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class MastodonStatusAdaptor: StatusAdaptor {
var favourited: Bool { _status.favourited }
var reblogged: Bool { _status.reblogged }

var deleted: Bool { false }

var reblog: (any StatusAdaptor)?

var emojis: [EmojiAdaptor]
Expand Down
7 changes: 4 additions & 3 deletions reazure/fediverse/models/StatusAdaptor+mask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@


extension StatusAdaptor {
func mask(favourited: Bool? = nil, reblogged: Bool? = nil) -> MaskedStatusAdaptor {
func mask(favourited: Bool? = nil, reblogged: Bool? = nil, deleted: Bool? = nil) -> MaskedStatusAdaptor {
// check instance of MaskedStatusAdaptor
if let masked = self as? MaskedStatusAdaptor {
let favourited = favourited ?? masked.favourited
let reblogged = reblogged ?? masked.reblogged
let deleted = deleted ?? masked.deleted

return MaskedStatusAdaptor(status: masked.status, favourited: favourited, reblogged: reblogged)
return MaskedStatusAdaptor(status: masked.status, favourited: favourited, reblogged: reblogged, deleted: deleted)
}

return MaskedStatusAdaptor(status: self, favourited: favourited, reblogged: reblogged)
return MaskedStatusAdaptor(status: self, favourited: favourited, reblogged: reblogged, deleted: deleted)
}
}

7 changes: 3 additions & 4 deletions reazure/fediverse/models/StatusModelBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,10 @@ extension StatusModelBase {

func delete(depth: Int) async throws {
// TODO: 모델 자체가 지워져야 하는 오퍼레이션이기 때문에 설계에 대해 더 생각해봐야 함
guard let status = resolve(depth: depth) else {
return
try await withReplacingOperation(at: depth) { status in
try? await performer?.statusModel(wantsDelete: status, model: self)
return status.mask(deleted: true)
}

try await performer?.statusModel(wantsDelete: status, model: self)
}

func composeReply(to depth: Int) async throws {
Expand Down
12 changes: 11 additions & 1 deletion reazure/fediverse/models/adaptors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ protocol StatusAdaptor: AnyObject {
var favourited: Bool { get }
var reblogged: Bool { get }

// extension
var deleted: Bool { get }

var reblog: (any StatusAdaptor)? { get }

var emojis: [EmojiAdaptor] { get }
Expand Down Expand Up @@ -120,6 +123,10 @@ class MaskedStatusAdaptor: StatusAdaptor {
var reblogged: Bool {
_parent.reblogged
}

var deleted: Bool {
_parent.deleted
}

var id: String { status.id }
var createdAt: String { status.createdAt }
Expand Down Expand Up @@ -155,6 +162,8 @@ class MaskedStatusAdaptor: StatusAdaptor {
var favourited: Bool
var reblogged: Bool

var deleted: Bool

var id: String { status.id }
var createdAt: String { status.createdAt }

Expand All @@ -176,11 +185,12 @@ class MaskedStatusAdaptor: StatusAdaptor {
var attachments: [AttachmentAdaptor] { status.attachments }
var application: ApplicationAdaptor? { status.application }

init(status: StatusAdaptor, favourited: Bool? = nil, reblogged: Bool? = nil) {
init(status: StatusAdaptor, favourited: Bool? = nil, reblogged: Bool? = nil, deleted: Bool? = nil) {
self.status = status

self.favourited = favourited ?? status.favourited
self.reblogged = reblogged ?? status.reblogged
self.deleted = deleted ?? false

if let reblog = status.reblog {
self.reblog = ReblogMaskedStatusAdaptor(self)
Expand Down
25 changes: 25 additions & 0 deletions reazure/modifiers/View+if.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// View+if.swift
// reazure
//
// Created by Gyuhwan Park on 11/30/24.
//

import SwiftUI


extension View {
/// Applies the given transform if the given condition evaluates to `true`.
/// - Parameters:
/// - condition: The condition to evaluate.
/// - transform: The transform to apply to the source `View`.
/// - Returns: Either the original `View` or the modified `View` if the condition is `true`.
@ViewBuilder
func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View {
if condition() {
transform(self)
} else {
self
}
}
}
4 changes: 4 additions & 0 deletions reazure/views/timeline/CompactPostItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ struct CompactPostItem: View, Equatable {
.foregroundColor(textColor)
.lineLimit(1)
}
.if(status.deleted) {
$0.strikethrough()
}
// .containerRelativeFrame([.horizontal], alignment: .topLeading)
.frame(maxWidth: .infinity, alignment: .topLeading)
.contentShape(Rectangle())
Expand All @@ -75,6 +78,7 @@ struct CompactPostItem: View, Equatable {
lhs.status.id == rhs.status.id &&
lhs.status.favourited == rhs.status.favourited &&
lhs.status.reblogged == rhs.status.reblogged &&
lhs.status.deleted == rhs.status.deleted &&
lhs.flags == rhs.flags
)
}
Expand Down
4 changes: 4 additions & 0 deletions reazure/views/timeline/PostItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ struct PostItem: View, Equatable {
}
}
}
.if(status.deleted) {
$0.strikethrough()
}
.padding(.horizontal, 12)
.padding(.vertical, 8)
// .containerRelativeFrame([.horizontal], alignment: .topLeading)
Expand All @@ -211,6 +214,7 @@ struct PostItem: View, Equatable {
lhs.status.id == rhs.status.id &&
lhs.status.favourited == rhs.status.favourited &&
lhs.status.reblogged == rhs.status.reblogged &&
lhs.status.deleted == rhs.status.deleted &&
lhs.flags == rhs.flags
)
}
Expand Down

0 comments on commit 4bb689c

Please sign in to comment.