Skip to content

Commit adbe551

Browse files
committed
Merge branch 'main' of https://github.com/nextcloud/NextcloudKit into declarative-ui
2 parents 2284de8 + 6e63c6a commit adbe551

23 files changed

+893
-519
lines changed

.github/workflows/xcode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
- name: Setup Xcode
6565
uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
6666
with:
67-
xcode-version: latest-stable
67+
xcode-version: '26.0.1'
6868

6969
- name: Build & Test NextcloudKit
7070
run: |

Sources/NextcloudKit/Models/NKDataFileXML.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,27 @@ public class NKDataFileXML: NSObject {
429429
file.richWorkspace = richWorkspace
430430
}
431431

432-
if let lock = NKLock(xml: propstat["d:prop"]) {
433-
file.lock = lock
432+
if let lock = propstat["d:prop", "nc:lock"].int {
433+
file.lock = lock > 0
434+
}
435+
436+
if let lockOwner = propstat["d:prop", "nc:lock-owner"].text {
437+
file.lockOwner = lockOwner
438+
}
439+
if let lockOwnerEditor = propstat["d:prop", "nc:lock-owner-editor"].text {
440+
file.lockOwnerEditor = lockOwnerEditor
441+
}
442+
if let lockOwnerType = propstat["d:prop", "nc:lock-owner-type"].int {
443+
file.lockOwnerType = lockOwnerType
444+
}
445+
if let lockOwnerDisplayName = propstat["d:prop", "nc:lock-owner-displayname"].text {
446+
file.lockOwnerDisplayName = lockOwnerDisplayName
447+
}
448+
if let lockTime = propstat["d:prop", "nc:lock-time"].int {
449+
file.lockTime = Date(timeIntervalSince1970: TimeInterval(lockTime))
450+
}
451+
if let lockTimeOut = propstat["d:prop", "nc:lock-timeout"].int {
452+
file.lockTimeOut = file.lockTime?.addingTimeInterval(TimeInterval(lockTimeOut))
434453
}
435454

436455
let tagsElements = propstat["d:prop", "nc:system-tags"]

Sources/NextcloudKit/Models/NKFile.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ public struct NKFile: Sendable {
3838
public var ocId: String
3939
public var ownerId: String
4040
public var ownerDisplayName: String
41-
42-
///
43-
/// An optional lock on this file. `nil` equals the file not being locked.
44-
///
45-
public var lock: NKLock?
46-
41+
public var lock: Bool
42+
public var lockOwner: String
43+
public var lockOwnerEditor: String
44+
public var lockOwnerType: Int
45+
public var lockOwnerDisplayName: String
46+
public var lockTime: Date?
47+
public var lockTimeOut: Date?
4748
public var path: String
4849
public var permissions: String
4950
public var quotaUsedBytes: Int64
@@ -109,7 +110,13 @@ public struct NKFile: Sendable {
109110
ocId: String = "",
110111
ownerId: String = "",
111112
ownerDisplayName: String = "",
112-
lock: NKLock? = nil,
113+
lock: Bool = false,
114+
lockOwner: String = "",
115+
lockOwnerEditor: String = "",
116+
lockOwnerType: Int = 0,
117+
lockOwnerDisplayName: String = "",
118+
lockTime: Date? = nil,
119+
lockTimeOut: Date? = nil,
113120
path: String = "",
114121
permissions: String = "",
115122
quotaUsedBytes: Int64 = 0,
@@ -167,6 +174,12 @@ public struct NKFile: Sendable {
167174
self.ownerId = ownerId
168175
self.ownerDisplayName = ownerDisplayName
169176
self.lock = lock
177+
self.lockOwner = lockOwner
178+
self.lockOwnerEditor = lockOwnerEditor
179+
self.lockOwnerType = lockOwnerType
180+
self.lockOwnerDisplayName = lockOwnerDisplayName
181+
self.lockTime = lockTime
182+
self.lockTimeOut = lockTimeOut
170183
self.path = path
171184
self.permissions = permissions
172185
self.quotaUsedBytes = quotaUsedBytes

Sources/NextcloudKit/Models/NKLock.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public struct NKLock: Equatable, Sendable {
1818
///
1919
/// App id of an app owned lock to allow clients to suggest joining the collaborative editing session through the web or direct editing.
2020
///
21-
public let ownerEditor: String
21+
public let ownerEditor: String?
2222

2323
///
2424
/// What kind of lock this is.
@@ -53,19 +53,19 @@ public struct NKLock: Equatable, Sendable {
5353
/// This is intended for creating an instance based on a superset of required properties returned by a `PROPFIND` request to the server about an item.
5454
///
5555
public init?(xml properties: XML.Accessor) {
56-
guard let isLocked = properties["nc:lock"].bool else {
56+
guard let rawIsLocked = properties["nc:lock"].int else {
5757
return nil
5858
}
5959

60-
guard let owner = properties["nc:lock-owner"].text else {
60+
guard rawIsLocked > 0 else {
6161
return nil
6262
}
6363

64-
guard let ownerDisplayName = properties["nc:lock-owner-displayname"].text else {
64+
guard let owner = properties["nc:lock-owner"].text else {
6565
return nil
6666
}
6767

68-
guard let ownerEditor = properties["nc:lock-owner-editor"].text else {
68+
guard let ownerDisplayName = properties["nc:lock-owner-displayname"].text else {
6969
return nil
7070
}
7171

@@ -84,7 +84,7 @@ public struct NKLock: Equatable, Sendable {
8484
let lockToken = properties["nc:lock-token"].text
8585

8686
self.owner = owner
87-
self.ownerEditor = ownerEditor
87+
self.ownerEditor = properties["nc:lock-owner-editor"].text
8888
self.ownerType = lockOwnerType
8989
self.ownerDisplayName = ownerDisplayName
9090
self.time = Date(timeIntervalSince1970: rawTime)
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
import Foundation
5+
6+
///
7+
/// Represents a Nextcloud share with its associated properties and permissions.
8+
///
9+
public final class NKShare: NSObject {
10+
///
11+
/// Bitmask values defining share permissions as used in `permissions`.
12+
///
13+
/// As defined in the [OCS Share API documentation](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html).
14+
///
15+
public struct Permission: OptionSet {
16+
public let rawValue: Int
17+
18+
public init(rawValue: Int) {
19+
self.rawValue = rawValue
20+
}
21+
22+
/// Access the shared item.
23+
/// Default value for public shares.
24+
public static let read = Permission(rawValue: 1)
25+
26+
/// Edit the shared item.
27+
public static let update = Permission(rawValue: 2)
28+
29+
/// Create the shared item.
30+
public static let create = Permission(rawValue: 4)
31+
32+
/// Delete the shared item.
33+
public static let delete = Permission(rawValue: 8)
34+
35+
/// Reshare the shared item.
36+
public static let share = Permission(rawValue: 16)
37+
38+
/// Default value except for public shares.
39+
public static let all: Permission = [.read, .update, .create, .delete, .share]
40+
41+
///
42+
/// Determine the default permission value based on the given type value.
43+
///
44+
/// - Parameters:
45+
/// - type: The share type enum value.
46+
///
47+
public static func defaultPermission(for type: NKShare.ShareType) -> Permission {
48+
if type == .publicLink {
49+
return .read
50+
} else {
51+
return .all
52+
}
53+
}
54+
}
55+
56+
///
57+
/// The kind of the share.
58+
///
59+
public enum ShareType: Int {
60+
///
61+
/// A link which works internally only.
62+
///
63+
case internalLink = -1
64+
65+
///
66+
/// A share which is directly tied to a Nextcloud user.
67+
///
68+
case user = 0
69+
70+
///
71+
/// A share which is directly tied to a Nextcloud group.
72+
///
73+
case group = 1
74+
75+
///
76+
/// A publicly accessible link.
77+
///
78+
case publicLink = 3
79+
80+
///
81+
/// Shared by mail.
82+
///
83+
case email = 4
84+
85+
///
86+
/// A federated share.
87+
///
88+
case federatedCloud = 6
89+
90+
///
91+
/// Shared with a Nextcloud team.
92+
///
93+
case team = 7
94+
95+
///
96+
/// Shared by a guest.
97+
///
98+
case guest = 8
99+
100+
///
101+
/// A federated group share.
102+
///
103+
case federatedGroup = 9
104+
105+
///
106+
/// Shared within a Nextcloud Talk conversation.
107+
///
108+
case talkConversation = 10
109+
}
110+
111+
public var account = ""
112+
public var canEdit: Bool = false
113+
public var canDelete: Bool = false
114+
public var date: Date?
115+
public var displaynameFileOwner = ""
116+
public var displaynameOwner = ""
117+
public var expirationDate: NSDate?
118+
public var fileParent: Int = 0
119+
public var fileSource: Int = 0
120+
public var fileTarget = ""
121+
public var hideDownload: Bool = false
122+
public var idShare: Int = 0
123+
public var itemSource: Int = 0
124+
public var itemType = ""
125+
public var label = ""
126+
public var mailSend: Bool = false
127+
public var mimeType = ""
128+
public var note = ""
129+
public var parent = ""
130+
public var password = ""
131+
public var path = ""
132+
133+
///
134+
/// See ``Permission`` for possible bitmask values.
135+
///
136+
public var permissions: Int = 0
137+
138+
public var sendPasswordByTalk: Bool = false
139+
public var shareType: Int = 0
140+
public var shareWith = ""
141+
public var shareWithDisplayname = ""
142+
public var storage: Int = 0
143+
public var storageId = ""
144+
public var token = ""
145+
public var uidFileOwner = ""
146+
public var uidOwner = ""
147+
public var url = ""
148+
public var userClearAt: Date?
149+
public var userIcon = ""
150+
public var userMessage = ""
151+
public var userStatus = ""
152+
public var attributes: String?
153+
}

Sources/NextcloudKit/Models/NKUserStatus.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import Foundation
77

8-
public class NKUserStatus: NSObject {
8+
public class NKUserStatus: NSObject, Identifiable {
99
public var clearAt: Date?
1010
public var clearAtTime: String?
1111
public var clearAtType: String?

0 commit comments

Comments
 (0)