Don't show Mute action when not applicable to status

This commit is contained in:
Shadowfacts 2021-11-22 21:50:02 -05:00
parent ca5ac8b826
commit 5a914ea5a3
2 changed files with 28 additions and 20 deletions

View File

@ -12,6 +12,7 @@ public class Mention: Codable {
public let url: URL public let url: URL
public let username: String public let username: String
public let acct: String public let acct: String
/// The instance-local ID of the user being mentioned.
public let id: String public let id: String
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {

View File

@ -156,7 +156,6 @@ extension MenuPreviewProvider {
} }
let bookmarked = status.bookmarked ?? false let bookmarked = status.bookmarked ?? false
let muted = status.muted
var actionsSection = [ var actionsSection = [
createAction(identifier: "bookmark", title: bookmarked ? "Unbookmark" : "Bookmark", systemImageName: bookmarked ? "bookmark.fill" : "bookmark", handler: { [weak self] (_) in createAction(identifier: "bookmark", title: bookmarked ? "Unbookmark" : "Bookmark", systemImageName: bookmarked ? "bookmark.fill" : "bookmark", handler: { [weak self] (_) in
@ -168,15 +167,6 @@ extension MenuPreviewProvider {
} }
} }
}), }),
createAction(identifier: "mute", title: muted ? "Unmute" : "Mute", systemImageName: muted ? "speaker" : "speaker.slash", handler: { [weak self] (_) in
guard let self = self else { return }
let request = (muted ? Status.unmuteConversation : Status.muteConversation)(status.id)
self.mastodonController?.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController?.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
}
}
})
] ]
if includeReply { if includeReply {
@ -186,7 +176,23 @@ extension MenuPreviewProvider {
}), at: 0) }), at: 0)
} }
if mastodonController.account != nil && mastodonController.account.id == status.account.id { if let account = mastodonController.account {
// only allow muting conversations that either current user posted or is participating in (technically, is mentioned, since that's the best we can do)
if status.account.id == account.id || status.mentions.contains(where: { $0.id == account.id }) {
let muted = status.muted
actionsSection.append(createAction(identifier: "mute", title: muted ? "Unmute Conversation" : "Mute Conversation", systemImageName: muted ? "speaker" : "speaker.slash", handler: { [weak self] (_) in
guard let self = self else { return }
let request = (muted ? Status.unmuteConversation : Status.muteConversation)(status.id)
self.mastodonController?.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController?.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
}
}
}))
}
// only allowing pinning user's own statuses
if account.id == status.account.id {
let pinned = status.pinned ?? false let pinned = status.pinned ?? false
actionsSection.append(createAction(identifier: "pin", title: pinned ? "Unpin from Profile" : "Pin to Profile", systemImageName: pinned ? "pin.slash" : "pin", handler: { [weak self] (_) in actionsSection.append(createAction(identifier: "pin", title: pinned ? "Unpin from Profile" : "Pin to Profile", systemImageName: pinned ? "pin.slash" : "pin", handler: { [weak self] (_) in
guard let self = self else { return } guard let self = self else { return }
@ -199,6 +205,7 @@ extension MenuPreviewProvider {
}) })
})) }))
} }
}
if status.poll != nil { if status.poll != nil {
actionsSection.insert(createAction(identifier: "refresh", title: "Refresh Poll", systemImageName: "arrow.clockwise", handler: { [weak self] (_) in actionsSection.insert(createAction(identifier: "refresh", title: "Refresh Poll", systemImageName: "arrow.clockwise", handler: { [weak self] (_) in