Skip to content

Commit 78b2d80

Browse files
NMC 2023 - Localisation changes
1 parent cd6e136 commit 78b2d80

20 files changed

Lines changed: 1604 additions & 133 deletions

File Provider Extension/FileProviderData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FileProviderData: NSObject {
3232
case workingSet
3333
}
3434

35-
// MARK: -
35+
// MARK: -
3636

3737
@discardableResult
3838
func setupAccount(domain: NSFileProviderDomain? = nil,
@@ -173,7 +173,7 @@ class FileProviderData: NSObject {
173173

174174
if error == .success {
175175
if let metadata = await NCManageDatabase.shared.getMetadataFromOcIdAsync(ocId) {
176-
await NCManageDatabase.shared.addLocalFilesAsync(metadatas: [metadata])
176+
await NCManageDatabase.shared.addLocalFileAsync(metadata: metadata)
177177
}
178178
}
179179

iOSClient/Data/NCManageDatabase+LocalFile.swift

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,35 @@ extension NCManageDatabase {
2929

3030
// MARK: - Realm Write
3131

32-
/// Adds or updates multiple local file entries corresponding to the given metadata array.
33-
/// Uses async Realm read + single write transaction. Assumes `tableLocalFile` has a primary key.
3432
/// - Parameters:
35-
/// - metadatas: Array of `tableMetadata` to map into `tableLocalFile`.
36-
/// - offline: Optional override for the `offline` flag applied to all items.
37-
func addLocalFilesAsync(metadatas: [tableMetadata], offline: Bool? = nil) async {
38-
guard !metadatas.isEmpty else {
39-
return
40-
}
41-
42-
// Extract ocIds for efficient lookup
43-
let ocIds = metadatas.compactMap { $0.ocId }
44-
guard !ocIds.isEmpty else {
45-
return
33+
/// - metadata: The `tableMetadata` containing file details.
34+
/// - offline: Optional flag to mark the file as available offline.
35+
/// - Returns: Nothing. Realm write is performed asynchronously.
36+
func addLocalFileAsync(metadata: tableMetadata, offline: Bool? = nil) async {
37+
// Read (non-blocking): safely detach from Realm thread
38+
let existing: tableLocalFile? = performRealmRead { realm in
39+
realm.objects(tableLocalFile.self)
40+
.filter(NSPredicate(format: "ocId == %@", metadata.ocId))
41+
.first
42+
.map { tableLocalFile(value: $0) }
4643
}
4744

48-
// Preload existing entries to avoid creating duplicates
49-
let existingMap: [String: tableLocalFile] = await core.performRealmReadAsync { realm in
50-
let existing = realm.objects(tableLocalFile.self)
51-
.filter(NSPredicate(format: "ocId IN %@", ocIds))
52-
return Dictionary(uniqueKeysWithValues:
53-
existing.map { ($0.ocId, tableLocalFile(value: $0)) } // detached copy via value init
54-
)
55-
} ?? [:]
45+
await performRealmWriteAsync { realm in
46+
let addObject = existing ?? tableLocalFile()
5647

57-
await core.performRealmWriteAsync { realm in
58-
for metadata in metadatas {
59-
// Reuse existing object or create a new one
60-
let local = existingMap[metadata.ocId] ?? tableLocalFile()
61-
62-
local.account = metadata.account
63-
local.etag = metadata.etag
64-
local.exifDate = NSDate()
65-
local.exifLatitude = "-1"
66-
local.exifLongitude = "-1"
67-
local.ocId = metadata.ocId
68-
local.fileName = metadata.fileName
69-
70-
if let offline {
71-
local.offline = offline
72-
}
48+
addObject.account = metadata.account
49+
addObject.etag = metadata.etag
50+
addObject.exifDate = NSDate()
51+
addObject.exifLatitude = "-1"
52+
addObject.exifLongitude = "-1"
53+
addObject.ocId = metadata.ocId
54+
addObject.fileName = metadata.fileName
7355

74-
realm.add(local, update: .all)
56+
if let offline {
57+
addObject.offline = offline
7558
}
59+
60+
realm.add(addObject, update: .all)
7661
}
7762
}
7863

iOSClient/Data/NCManageDatabase+Metadata.swift

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,37 @@ extension tableMetadata {
151151
(fileNameView as NSString).deletingPathExtension
152152
}
153153

154+
var isRenameable: Bool {
155+
if !NCMetadataPermissions.canRename(self) {
156+
return false
157+
}
158+
if lock {
159+
return false
160+
}
161+
if !isDirectoryE2EE && e2eEncrypted {
162+
return false
163+
}
164+
return true
165+
}
166+
167+
var isPrintable: Bool {
168+
if isDocumentViewableOnly {
169+
return false
170+
}
171+
if ["application/pdf", "com.adobe.pdf"].contains(contentType) || contentType.hasPrefix("text/") || classFile == NKTypeClassFile.image.rawValue {
172+
return true
173+
}
174+
return false
175+
}
176+
154177
var isSavebleInCameraRoll: Bool {
155178
return (classFile == NKTypeClassFile.image.rawValue && contentType != "image/svg+xml") || classFile == NKTypeClassFile.video.rawValue
156179
}
157180

181+
var isDocumentViewableOnly: Bool {
182+
sharePermissionsCollaborationServices == NCPermissions().permissionReadShare && classFile == NKTypeClassFile.document.rawValue
183+
}
184+
158185
var isAudioOrVideo: Bool {
159186
return classFile == NKTypeClassFile.audio.rawValue || classFile == NKTypeClassFile.video.rawValue
160187
}
@@ -343,6 +370,17 @@ extension tableMetadata {
343370
return !lock || (lockOwner == user && lockOwnerType == 0)
344371
}
345372

373+
// Return if is sharable
374+
func isSharable() -> Bool {
375+
guard let capabilities = NCNetworking.shared.capabilities[account] else {
376+
return false
377+
}
378+
if !capabilities.fileSharingApiEnabled || (capabilities.e2EEEnabled && isDirectoryE2EE), !e2eEncrypted {
379+
return false
380+
}
381+
return !e2eEncrypted
382+
}
383+
346384
/// Returns a detached (unmanaged) deep copy of the current `tableMetadata` object.
347385
///
348386
/// - Note: Primitive properties and lists of primitive values (for example `shareType`)
@@ -917,6 +955,34 @@ extension NCManageDatabase {
917955
.map { $0.detachedCopy() }
918956
} ?? []
919957
}
958+
959+
func getMediaMetadatas(predicate: NSPredicate, sorted: String? = nil, ascending: Bool = false) -> ThreadSafeArray<tableMetadata>? {
960+
961+
do {
962+
let realm = try Realm()
963+
if let sorted {
964+
var results: [tableMetadata] = []
965+
switch sorted {//NCPreferences().mediaSortDate {
966+
case "date":
967+
results = realm.objects(tableMetadata.self).filter(predicate).sorted { ($0.date as Date) > ($1.date as Date) }
968+
case "creationDate":
969+
results = realm.objects(tableMetadata.self).filter(predicate).sorted { ($0.creationDate as Date) > ($1.creationDate as Date) }
970+
case "uploadDate":
971+
results = realm.objects(tableMetadata.self).filter(predicate).sorted { ($0.uploadDate as Date) > ($1.uploadDate as Date) }
972+
default:
973+
let results = realm.objects(tableMetadata.self).filter(predicate)
974+
return ThreadSafeArray(results.map { tableMetadata.init(value: $0) })
975+
}
976+
return ThreadSafeArray(results.map { tableMetadata.init(value: $0) })
977+
} else {
978+
let results = realm.objects(tableMetadata.self).filter(predicate)
979+
return ThreadSafeArray(results.map { tableMetadata.init(value: $0) })
980+
}
981+
} catch let error as NSError {
982+
// NextcloudKit.shared.nkCommonInstance.writeLog("Could not access database: \(error)")
983+
}
984+
return nil
985+
}
920986

921987
func getMetadatas(predicate: NSPredicate,
922988
sortedByKeyPath: String,

iOSClient/NCBackgroundLocationUploadManager.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,19 @@ class NCBackgroundLocationUploadManager: NSObject, CLLocationManagerDelegate {
102102
}
103103

104104
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
105-
// Must work only in background
106105
guard isAppInBackground else {
107106
return
108107
}
109108

110109
// Open Realm
111-
guard NCManageDatabase.shared.openRealmBackground() else {
112-
nkLog(tag: self.global.logTagLocation, emoji: .error, message: "Failed to open Realm in Location Manager")
113-
return
114-
}
115-
116-
let location = locations.last
117-
nkLog(tag: self.global.logTagLocation, emoji: .start, message: "Triggered by location change: \(location?.coordinate.latitude ?? 0), \(location?.coordinate.longitude ?? 0)")
118-
119-
Task.detached {
120-
await NCAutoUpload.shared.autoUploadBackgroundSync()
110+
if database.openRealmBackground() {
111+
let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
112+
let location = locations.last
113+
nkLog(tag: self.global.logTagLocation, emoji: .start, message: "Triggered by location change: \(location?.coordinate.latitude ?? 0), \(location?.coordinate.longitude ?? 0)")
114+
115+
Task.detached {
116+
await NCAutoUpload.shared.autoUploadBackgroundSync()
117+
}
121118
}
122119
}
123120

iOSClient/NCGlobal.swift

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ final class NCGlobal: Sendable {
4343
// Intro selector
4444
//
4545
let introLogin: Int = 0
46+
let introSignup: Int = 1
4647
let introSignUpWithProvider: Int = 1
4748

4849
// Avatar
4950
//
5051
let avatarSize: Int = 128 * Int(UIScreen.main.scale)
5152
let avatarSizeRounded: Int = 128
52-
53+
5354
// Preview size
5455
//
5556
let size1024: CGSize = CGSize(width: 1024, height: 1024)
@@ -113,7 +114,35 @@ final class NCGlobal: Sendable {
113114
//
114115
let buttonMoreMore = "more"
115116
let buttonMoreLock = "moreLock"
116-
117+
let buttonMoreStop = "stop"
118+
119+
// Standard height sections header/footer
120+
//
121+
let heightButtonsView: CGFloat = 50
122+
let heightHeaderTransfer: CGFloat = 50
123+
let heightSection: CGFloat = 30
124+
let heightFooter: CGFloat = 1
125+
let heightFooterButton: CGFloat = 30
126+
let endHeightFooter: CGFloat = 85
127+
128+
129+
// Text - OnlyOffice - Collabora - QuickLook
130+
//
131+
let editorText = "text"
132+
let editorOnlyoffice = "onlyoffice"
133+
let editorCollabora = "collabora"
134+
let editorQuickLook = "quicklook"
135+
136+
let onlyofficeDocx = "onlyoffice_docx"
137+
let onlyofficeXlsx = "onlyoffice_xlsx"
138+
let onlyofficePptx = "onlyoffice_pptx"
139+
140+
// Template
141+
//
142+
let templateDocument = "document"
143+
let templateSpreadsheet = "spreadsheet"
144+
let templatePresentation = "presentation"
145+
117146
// Rich Workspace
118147
//
119148
let fileNameRichWorkspace = "Readme.md"
@@ -198,6 +227,8 @@ final class NCGlobal: Sendable {
198227
let selectorSaveAsScan = "saveAsScan"
199228
let selectorOpenDetail = "openDetail"
200229
let selectorSynchronizationOffline = "synchronizationOffline"
230+
let selectorPrint = "print"
231+
let selectorDeleteFile = "deleteFile"
201232

202233
// Metadata : Status
203234
//
@@ -228,7 +259,6 @@ final class NCGlobal: Sendable {
228259
let metadataStatusForScreenAwake = [-1, -2, 1, 2]
229260
let metadataStatusHideInView = [1, 2, 3, 11]
230261
let metadataStatusWaitWebDav = [10, 11, 12, 13, 14, 15]
231-
let metadataStatusTransfers = [-2, -3, 2, 3, 10, 11, 12, 13, 14, 15]
232262

233263
let metadatasStatusInWaiting = [-1, 1, 10, 11, 12, 13, 14, 15]
234264
let metadatasStatusInWaitingDownloadUpload = [-1, 1]
@@ -246,13 +276,17 @@ final class NCGlobal: Sendable {
246276
let notificationCenterChangeTheming = "changeTheming" // userInfo: account
247277
let notificationCenterRichdocumentGrabFocus = "richdocumentGrabFocus"
248278
let notificationCenterReloadDataNCShare = "reloadDataNCShare"
279+
let notificationCenterDidCreateShareLink = "didCreateShareLink"
280+
249281
let notificationCenterCloseRichWorkspaceWebView = "closeRichWorkspaceWebView"
250282
let notificationCenterReloadAvatar = "reloadAvatar"
251283
let notificationCenterClearCache = "clearCache"
252284
let notificationCenterCheckUserDelaultErrorDone = "checkUserDelaultErrorDone" // userInfo: account, controller
253285
let notificationCenterServerDidUpdate = "serverDidUpdate" // userInfo: account
254286
let notificationCenterNetworkReachability = "networkReachability"
255287

288+
let notificationCenterRenameFile = "renameFile" // userInfo: serverUrl, account, error
289+
256290
let notificationCenterMenuSearchTextPDF = "menuSearchTextPDF"
257291
let notificationCenterMenuGotToPageInPDF = "menuGotToPageInPDF"
258292

@@ -270,6 +304,7 @@ final class NCGlobal: Sendable {
270304

271305
let notificationCenterNetworkingProcess = "networkingProcess"
272306
let notificationCenterTransferCountChanged = "transferCountChanged"
307+
let notificationCenterFavoriteStatusChanged = "favoriteStatusChanged"
273308

274309
// Networking Status
275310
let networkingStatusCreateFolder = "statusCreateFolder"
@@ -286,6 +321,7 @@ final class NCGlobal: Sendable {
286321
let networkingStatusUploaded = "statusUploaded"
287322

288323
let networkingStatusReloadAvatar = "statusReloadAvatar"
324+
let notificationCenterUpdateIcons = "updateIcons"
289325

290326
// TIP
291327
//
@@ -368,6 +404,20 @@ final class NCGlobal: Sendable {
368404
//
369405
let taskDescriptionRetrievesProperties = "retrievesProperties"
370406
let taskDescriptionSynchronization = "synchronization"
407+
let taskDescriptionDeleteFileOrFolder = "deleteFileOrFolder"
408+
409+
// MoEngage App Version
410+
//
411+
let moEngageAppVersion = 854
412+
413+
// Filename Mask and Type
414+
//
415+
let keyFileNameMask = "fileNameMask"
416+
let keyFileNameType = "fileNameType"
417+
let keyFileNameAutoUploadMask = "fileNameAutoUploadMask"
418+
let keyFileNameAutoUploadType = "fileNameAutoUploadType"
419+
let keyFileNameOriginal = "fileNameOriginal"
420+
let keyFileNameOriginalAutoUpload = "fileNameOriginalAutoUpload"
371421

372422
// LOG TAG
373423
//

iOSClient/Networking/E2EE/NCNetworkingE2EEUpload.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class NCNetworkingE2EEUpload: NSObject {
218218

219219
await self.database.addMetadataAsync(metadata)
220220
await self.database.addLocalFilesAsync(metadatas: [metadata])
221+
// await self.database.addLocalFileAsync(metadata: metadata)
221222

222223
utility.createImageFileFrom(metadata: metadata)
223224

iOSClient/Networking/NCConfigServer.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
// SPDX-FileCopyrightText: Nextcloud GmbH
2-
// SPDX-FileCopyrightText: 2022 Marino Faggiana
3-
// SPDX-License-Identifier: GPL-3.0-or-later
1+
//
2+
// NCConfigServer.swift
3+
// Nextcloud
4+
//
5+
// Created by Marino Faggiana on 05/12/22.
6+
// Copyright © 2022 Marino Faggiana. All rights reserved.
7+
//
8+
// Author Marino Faggiana <marino.faggiana@nextcloud.com>
9+
//
10+
// This program is free software: you can redistribute it and/or modify
11+
// it under the terms of the GNU General Public License as published by
12+
// the Free Software Foundation, either version 3 of the License, or
13+
// (at your option) any later version.
14+
//
15+
// This program is distributed in the hope that it will be useful,
16+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
// GNU General Public License for more details.
19+
//
20+
// You should have received a copy of the GNU General Public License
21+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
//
423

524
import Foundation
625
import UIKit

0 commit comments

Comments
 (0)