mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-19 08:03:50 +02:00
Stop requesting URL previews if the feature has been disabled on the homeserver.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import AFNetworking
|
||||
|
||||
enum URLPreviewServiceError: Error {
|
||||
case missingResponse
|
||||
@@ -74,7 +75,10 @@ class URLPreviewService: NSObject {
|
||||
success(previewData)
|
||||
}
|
||||
|
||||
}, failure: failure)
|
||||
}, failure: { error in
|
||||
self.checkForDisabledAPI(in: error)
|
||||
failure(error)
|
||||
})
|
||||
}
|
||||
|
||||
/// Removes any cached preview data that has expired.
|
||||
@@ -156,4 +160,21 @@ class URLPreviewService: NSObject {
|
||||
|
||||
return components?.url ?? url
|
||||
}
|
||||
|
||||
/// Checks an error returned from `MXRestClient` to see whether the previews API
|
||||
/// has been disabled on the homeserver. If this is true, link detection will be disabled
|
||||
/// to prevent further requests being made and stop any previews loaders being presented.
|
||||
private func checkForDisabledAPI(in error: Error?) {
|
||||
// The error will contain a 404 and no matrix error code.
|
||||
guard
|
||||
let error = error as NSError?,
|
||||
error.userInfo[kMXErrorCodeKey] == nil,
|
||||
let response = error.userInfo[AFNetworkingOperationFailingURLResponseErrorKey] as? HTTPURLResponse
|
||||
else { return }
|
||||
|
||||
if response.statusCode == 404 {
|
||||
MXLog.debug("[URLPreviewService] Disabling link detection as homeserver does not support URL previews.")
|
||||
MXKAppSettings.standard().enableBubbleComponentLinkDetection = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user