mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-04-27 02:14:45 +00:00
Follow requests improvements (#679)
* fix: when accepting/rejecting followers, only disable the current request button * fix: fetch followers request when updating notifications
This commit is contained in:
parent
d930871b04
commit
2f5e170983
4 changed files with 18 additions and 6 deletions
|
@ -35,7 +35,7 @@ public struct FollowRequestButtons: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.buttonStyle(.bordered)
|
.buttonStyle(.bordered)
|
||||||
.disabled(currentAccount.isUpdating)
|
.disabled(currentAccount.updatingFollowRequestAccountIds.contains(account.id))
|
||||||
.padding(.top, 4)
|
.padding(.top, 4)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ public class CurrentAccount: ObservableObject {
|
||||||
@Published public private(set) var tags: [Tag] = []
|
@Published public private(set) var tags: [Tag] = []
|
||||||
@Published public private(set) var followRequests: [Account] = []
|
@Published public private(set) var followRequests: [Account] = []
|
||||||
@Published public private(set) var isUpdating: Bool = false
|
@Published public private(set) var isUpdating: Bool = false
|
||||||
|
@Published public private(set) var updatingFollowRequestAccountIds = Set<String>()
|
||||||
@Published public private(set) var isLoadingAccount: Bool = false
|
@Published public private(set) var isLoadingAccount: Bool = false
|
||||||
|
|
||||||
private var client: Client?
|
private var client: Client?
|
||||||
|
@ -122,9 +123,9 @@ public class CurrentAccount: ObservableObject {
|
||||||
public func acceptFollowerRequest(id: String) async {
|
public func acceptFollowerRequest(id: String) async {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
isUpdating = true
|
updatingFollowRequestAccountIds.insert(id)
|
||||||
defer {
|
defer {
|
||||||
isUpdating = false
|
updatingFollowRequestAccountIds.remove(id)
|
||||||
}
|
}
|
||||||
_ = try await client.post(endpoint: FollowRequests.accept(id: id))
|
_ = try await client.post(endpoint: FollowRequests.accept(id: id))
|
||||||
await fetchFollowerRequests()
|
await fetchFollowerRequests()
|
||||||
|
@ -134,9 +135,9 @@ public class CurrentAccount: ObservableObject {
|
||||||
public func rejectFollowerRequest(id: String) async {
|
public func rejectFollowerRequest(id: String) async {
|
||||||
guard let client else { return }
|
guard let client else { return }
|
||||||
do {
|
do {
|
||||||
isUpdating = true
|
updatingFollowRequestAccountIds.insert(id)
|
||||||
defer {
|
defer {
|
||||||
isUpdating = false
|
updatingFollowRequestAccountIds.remove(id)
|
||||||
}
|
}
|
||||||
_ = try await client.post(endpoint: FollowRequests.reject(id: id))
|
_ = try await client.post(endpoint: FollowRequests.reject(id: id))
|
||||||
await fetchFollowerRequests()
|
await fetchFollowerRequests()
|
||||||
|
|
|
@ -52,6 +52,7 @@ public struct NotificationsListView: View {
|
||||||
.background(theme.primaryBackgroundColor)
|
.background(theme.primaryBackgroundColor)
|
||||||
.task {
|
.task {
|
||||||
viewModel.client = client
|
viewModel.client = client
|
||||||
|
viewModel.currentAccount = account
|
||||||
if let lockedType {
|
if let lockedType {
|
||||||
viewModel.selectedType = lockedType
|
viewModel.selectedType = lockedType
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import Env
|
||||||
import Foundation
|
import Foundation
|
||||||
import Models
|
import Models
|
||||||
import Network
|
import Network
|
||||||
|
@ -27,6 +28,7 @@ class NotificationsViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var currentAccount: CurrentAccount?
|
||||||
|
|
||||||
@Published var state: State = .loading
|
@Published var state: State = .loading
|
||||||
@Published var selectedType: Models.Notification.NotificationType? {
|
@Published var selectedType: Models.Notification.NotificationType? {
|
||||||
|
@ -52,7 +54,7 @@ class NotificationsViewModel: ObservableObject {
|
||||||
private var consolidatedNotifications: [ConsolidatedNotification] = []
|
private var consolidatedNotifications: [ConsolidatedNotification] = []
|
||||||
|
|
||||||
func fetchNotifications() async {
|
func fetchNotifications() async {
|
||||||
guard let client else { return }
|
guard let client, let currentAccount else { return }
|
||||||
do {
|
do {
|
||||||
var nextPageState: State.PagingState = .hasNextPage
|
var nextPageState: State.PagingState = .hasNextPage
|
||||||
if consolidatedNotifications.isEmpty {
|
if consolidatedNotifications.isEmpty {
|
||||||
|
@ -77,6 +79,9 @@ class NotificationsViewModel: ObservableObject {
|
||||||
at: 0
|
at: 0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await currentAccount.fetchFollowerRequests()
|
||||||
|
|
||||||
withAnimation {
|
withAnimation {
|
||||||
state = .display(notifications: consolidatedNotifications,
|
state = .display(notifications: consolidatedNotifications,
|
||||||
nextPageState: consolidatedNotifications.isEmpty ? .none : nextPageState)
|
nextPageState: consolidatedNotifications.isEmpty ? .none : nextPageState)
|
||||||
|
@ -96,6 +101,7 @@ class NotificationsViewModel: ObservableObject {
|
||||||
maxId: lastId,
|
maxId: lastId,
|
||||||
types: queryTypes))
|
types: queryTypes))
|
||||||
consolidatedNotifications.append(contentsOf: newNotifications.consolidated(selectedType: selectedType))
|
consolidatedNotifications.append(contentsOf: newNotifications.consolidated(selectedType: selectedType))
|
||||||
|
await currentAccount?.fetchFollowerRequests()
|
||||||
state = .display(notifications: consolidatedNotifications, nextPageState: newNotifications.count < 15 ? .none : .hasNextPage)
|
state = .display(notifications: consolidatedNotifications, nextPageState: newNotifications.count < 15 ? .none : .hasNextPage)
|
||||||
} catch {
|
} catch {
|
||||||
state = .error(error: error)
|
state = .error(error: error)
|
||||||
|
@ -136,6 +142,10 @@ class NotificationsViewModel: ObservableObject {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if event.notification.supportedType == .follow_request, let currentAccount {
|
||||||
|
await currentAccount.fetchFollowerRequests()
|
||||||
|
}
|
||||||
|
|
||||||
withAnimation {
|
withAnimation {
|
||||||
state = .display(notifications: consolidatedNotifications, nextPageState: .hasNextPage)
|
state = .display(notifications: consolidatedNotifications, nextPageState: .hasNextPage)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue