diff --git a/Pachyderm/Model/Mention.swift b/Pachyderm/Model/Mention.swift index 2e60f4c6..b8898d61 100644 --- a/Pachyderm/Model/Mention.swift +++ b/Pachyderm/Model/Mention.swift @@ -12,6 +12,7 @@ public class Mention: Codable { public let url: URL public let username: String public let acct: String + /// The instance-local ID of the user being mentioned. public let id: String private enum CodingKeys: String, CodingKey { diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index 2e932d35..d7e180bc 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -156,7 +156,6 @@ extension MenuPreviewProvider { } let bookmarked = status.bookmarked ?? false - let muted = status.muted var actionsSection = [ 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 { @@ -186,18 +176,35 @@ extension MenuPreviewProvider { }), at: 0) } - if mastodonController.account != nil && mastodonController.account.id == status.account.id { - 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 - guard let self = self else { return } - let request = (pinned ? Status.unpin : Status.pin)(status.id) - self.mastodonController?.run(request, completion: { [weak self] (response) in + 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 } - if case let .success(status, _) = response { - self.mastodonController?.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false) + 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 + 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 } + let request = (pinned ? Status.unpin : Status.pin)(status.id) + self.mastodonController?.run(request, completion: { [weak self] (response) in + guard let self = self else { return } + if case let .success(status, _) = response { + self.mastodonController?.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false) + } + }) + })) + } } if status.poll != nil {