Skip to content

Commit

Permalink
perf: Read number of pending invitations from header
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Müller <[email protected]>
  • Loading branch information
SystemKeeper committed Jan 21, 2025
1 parent fc0001c commit d8c0d71
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
10 changes: 10 additions & 0 deletions NextcloudTalk/FederationInvitationTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//

extension Notification.Name {
static let FederationInvitationDidAcceptNotification = Notification.Name(rawValue: "FederationInvitationDidAccept")
}

@objc extension NSNotification {
public static let FederationInvitationDidAcceptNotification = Notification.Name.FederationInvitationDidAcceptNotification
}

class FederationInvitationTableViewController: UITableViewController, FederationInvitationCellDelegate {

private let federationInvitationCellIdentifier = "FederationInvitationCell"
Expand Down Expand Up @@ -120,6 +128,8 @@ class FederationInvitationTableViewController: UITableViewController, Federation
NCAPIController.sharedInstance().acceptFederationInvitation(for: invitation.accountId, with: invitation.invitationId) { [weak self] success in
if !success {
NotificationPresenter.shared().present(text: NSLocalizedString("Failed to accept invitation", comment: ""), dismissAfterDelay: 5.0, includedStyle: .error)
} else {
NotificationCenter.default.post(name: .FederationInvitationDidAcceptNotification, object: self, userInfo: nil)
}

self?.getData()
Expand Down
2 changes: 1 addition & 1 deletion NextcloudTalk/NCAPIControllerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ import Foundation

let urlString = "\(account.server)/ocs/v2.php/apps/notifications/api/v3/test/self"

apiSessionManager.postOcs(urlString, account: account) { ocsResponse, ocsError in
apiSessionManager.postOcs(urlString, account: account) { ocsResponse, _ in
let message = ocsResponse?.dataDict?["message"] as? String
completionBlock(message)
}
Expand Down
8 changes: 8 additions & 0 deletions NextcloudTalk/NCAPISessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import Foundation
NCDatabaseManager.sharedInstance().updateLastModifiedSince(forAccountId: account.accountId, with: modifiedSince)
}

if let federationInvitesString = response.allHeaderFields["x-nextcloud-talk-federation-invites"] as? String,
let federatedInvites = Int(federationInvitesString) {

if account.pendingFederationInvitations != federatedInvites {
NCDatabaseManager.sharedInstance().setPendingFederationInvitationForAccountId(account.accountId, with: federatedInvites)
}
}

if let configurationHash = response.allHeaderFields["x-nextcloud-talk-hash"] as? String, configurationHash != account.lastReceivedConfigurationHash {
if account.lastReceivedConfigurationHash != nil {
// We previously stored a configuration hash which now changed -> Update settings and capabilities
Expand Down
4 changes: 2 additions & 2 deletions NextcloudTalk/NCRoomsManagerExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ import Foundation
guard NCDatabaseManager.sharedInstance().serverHasTalkCapability(kCapabilityFederationV1) else { return }

let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
let tenMinutesAgo = Int(Date().timeIntervalSince1970 - (10 * 60))
let twoHoursAgo = Int(Date().timeIntervalSince1970 - (2 * 60 * 60))

if activeAccount.lastPendingFederationInvitationFetch == 0 || activeAccount.lastPendingFederationInvitationFetch < tenMinutesAgo {
if activeAccount.lastPendingFederationInvitationFetch == 0 || activeAccount.lastPendingFederationInvitationFetch < twoHoursAgo {
self.updatePendingFederationInvitations()
}
}
Expand Down
8 changes: 7 additions & 1 deletion NextcloudTalk/RoomsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ - (void)viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(roomCreated:) name:NCRoomCreatedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activeAccountDidChange:) name:NCSettingsControllerDidChangeActiveAccountNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pendingInvitationsDidUpdate:) name:NCDatabaseManagerPendingFederationInvitationsDidChange object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(inviationDidAccept:) name:NSNotification.FederationInvitationDidAcceptNotification object:nil];
}

- (void)setupNavigationBar
Expand Down Expand Up @@ -329,7 +330,12 @@ - (void)roomsDidUpdate:(NSNotification *)notification

- (void)pendingInvitationsDidUpdate:(NSNotification *)notification
{
// Update the rooms: In case we accepted an invitation, we want to show the new room directly
[self refreshRoomList];
}

- (void)inviationDidAccept:(NSNotification *)notification
{
// We accepted an invitation, so we refresh the rooms from the API to show it directly
[self refreshRooms];
}

Expand Down

0 comments on commit d8c0d71

Please sign in to comment.