Fix boost/favourite/bookmark actions for boosted statuses

This commit is contained in:
Marcin Czachurski 2023-09-30 13:52:46 +02:00
parent 89702c6e42
commit f8241c1488
7 changed files with 47 additions and 17 deletions

View File

@ -9,6 +9,7 @@ import PixelfedKit
public class StatusModel: ObservableObject {
public let id: EntityId
public let rebloggedStatusId: EntityId?
public let content: Html
public let uri: String?
@ -41,11 +42,12 @@ public class StatusModel: ObservableObject {
@Published public var mediaAttachments: [AttachmentModel]
public init(status: Status) {
self.id = status.id
self.rebloggedStatusId = status.reblog?.id
// If status has been rebloged we are saving orginal status here.
let orginalStatus = status.reblog ?? status
self.id = status.id
self.content = orginalStatus.content
self.uri = orginalStatus.uri
self.url = orginalStatus.url
@ -86,6 +88,13 @@ public class StatusModel: ObservableObject {
}
}
public extension StatusModel {
/// Function returns status Id for real status (status with images), even for reboosted statuses.
func getOrginalStatusId() -> EntityId {
return self.rebloggedStatusId ?? self.id
}
}
public extension StatusModel {
func getImageWidth() -> Int32? {
let highestImage = self.mediaAttachments.getHighestImage()

View File

@ -14,6 +14,7 @@ extension StatusData {
self.id = status.id
self.rebloggedStatusId = reblog.id
self.rebloggedAccountAvatar = status.account.avatar
self.rebloggedAccountDisplayName = status.account.displayName
self.rebloggedAccountId = status.account.id
@ -79,3 +80,9 @@ extension StatusData {
}
}
}
public extension StatusData {
func getOrginalStatusId() -> String {
return self.rebloggedStatusId ?? self.id
}
}

View File

@ -11,11 +11,25 @@ import ServicesKit
public extension View {
func imageContextMenu(statusModel: StatusModel, attachmentModel: AttachmentModel, uiImage: UIImage?) -> some View {
modifier(ImageContextMenu(id: statusModel.id, url: statusModel.url, altText: attachmentModel.description, uiImage: uiImage))
modifier(
ImageContextMenu(
id: statusModel.getOrginalStatusId(),
url: statusModel.url,
altText: attachmentModel.description,
uiImage: uiImage
)
)
}
func imageContextMenu(statusData: StatusData, attachmentData: AttachmentData, uiImage: UIImage?) -> some View {
modifier(ImageContextMenu(id: statusData.id, url: statusData.url, altText: attachmentData.text, uiImage: uiImage))
modifier(
ImageContextMenu(
id: statusData.getOrginalStatusId(),
url: statusData.url,
altText: attachmentData.text,
uiImage: uiImage
)
)
}
}

View File

@ -162,7 +162,7 @@ struct StatusView: View {
}
.padding(8)
CommentsSectionView(statusId: statusViewModel.id)
CommentsSectionView(statusId: statusViewModel.getOrginalStatusId())
}
}
.coordinateSpace(name: "scroll")

View File

@ -84,11 +84,11 @@ struct InteractionRow: View {
Spacer()
Menu {
NavigationLink(value: RouteurDestinations.accounts(listType: .reblogged(entityId: statusModel.id))) {
NavigationLink(value: RouteurDestinations.accounts(listType: .reblogged(entityId: statusModel.getOrginalStatusId()))) {
Label("status.title.reboostedBy", image: "custom.rocket")
}
NavigationLink(value: RouteurDestinations.accounts(listType: .favourited(entityId: statusModel.id))) {
NavigationLink(value: RouteurDestinations.accounts(listType: .favourited(entityId: statusModel.getOrginalStatusId()))) {
Label("status.title.favouritedBy", systemImage: "star")
}
@ -116,7 +116,7 @@ struct InteractionRow: View {
Divider()
Button {
self.routerPath.presentedSheet = .report(objectType: .post, objectId: self.statusModel.id)
self.routerPath.presentedSheet = .report(objectType: .post, objectId: self.statusModel.getOrginalStatusId())
} label: {
Label(NSLocalizedString("status.title.report", comment: "Report"), systemImage: "exclamationmark.triangle")
}
@ -144,8 +144,8 @@ struct InteractionRow: View {
private func reboost() async {
do {
let status = self.reblogged
? try await self.client.statuses?.unboost(statusId: self.statusModel.id)
: try await self.client.statuses?.boost(statusId: self.statusModel.id)
? try await self.client.statuses?.unboost(statusId: self.statusModel.getOrginalStatusId())
: try await self.client.statuses?.boost(statusId: self.statusModel.getOrginalStatusId())
if let status {
self.reblogsCount = status.reblogsCount == self.reblogsCount
@ -166,8 +166,8 @@ struct InteractionRow: View {
private func favourite() async {
do {
let status = self.favourited
? try await self.client.statuses?.unfavourite(statusId: self.statusModel.id)
: try await self.client.statuses?.favourite(statusId: self.statusModel.id)
? try await self.client.statuses?.unfavourite(statusId: self.statusModel.getOrginalStatusId())
: try await self.client.statuses?.favourite(statusId: self.statusModel.getOrginalStatusId())
if let status {
self.favouritesCount = status.favouritesCount == self.favouritesCount
@ -188,8 +188,8 @@ struct InteractionRow: View {
private func bookmark() async {
do {
_ = self.bookmarked
? try await self.client.statuses?.unbookmark(statusId: self.statusModel.id)
: try await self.client.statuses?.bookmark(statusId: self.statusModel.id)
? try await self.client.statuses?.unbookmark(statusId: self.statusModel.getOrginalStatusId())
: try await self.client.statuses?.bookmark(statusId: self.statusModel.getOrginalStatusId())
self.bookmarked.toggle()
ToastrService.shared.showSuccess(self.bookmarked

View File

@ -708,7 +708,7 @@ public struct BaseComposeView: View {
}
private func createStatus() -> Pixelfed.Statuses.Components {
return Pixelfed.Statuses.Components(inReplyToId: self.statusViewModel?.id,
return Pixelfed.Statuses.Components(inReplyToId: self.statusViewModel?.getOrginalStatusId(),
text: self.textModel.text.string,
spoilerText: self.isSensitive ? self.spoilerText : String.empty(),
mediaIds: self.photosAttachment.getUploadedPhotoIds(),

View File

@ -39,7 +39,7 @@ public struct ImageAvatar: View {
}
.font(.footnote)
.foregroundColor(.white.opacity(0.8))
.background(.black.opacity(0.4))
.background(.black.opacity(0.6))
.clipShape(Capsule())
.padding(.leading, 8)
.padding(.top, 8)
@ -58,7 +58,7 @@ public struct ImageAvatar: View {
}
.font(.footnote)
.foregroundColor(.white.opacity(0.8))
.background(.black.opacity(0.4))
.background(.black.opacity(0.6))
.clipShape(Capsule())
.padding(.leading, 8)
.padding(.top, 8)