Skip to content

Commit ca2c7b2

Browse files
committed
add DeviceID to AccountInfo
1 parent bc0a2e3 commit ca2c7b2

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

Sources/MatrixSQLiteStore/AccountInfo.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,32 @@ public struct MatrixSQLAccountInfo: MatrixStoreAccountInfo {
1616
displayName: String? = nil,
1717
mxID: MatrixFullUserIdentifier,
1818
homeServer: MatrixHomeserver,
19-
accessToken: String? = nil
19+
accessToken: String? = nil,
20+
deviceID: String
2021
) {
2122
self.name = name
2223
self.displayName = displayName
2324
self.mxID = mxID
2425
self.homeServer = homeServer
2526
self.accessToken = accessToken
27+
self.deviceID = deviceID
28+
}
29+
30+
public init?(_ homeserver: MatrixHomeserver, login: MatrixLogin) {
31+
guard let mxID = login.userId,
32+
let accessToken = login.accessToken,
33+
let deviceID = login.deviceId
34+
else {
35+
return nil
36+
}
37+
self.init(
38+
name: mxID.localpart,
39+
displayName: nil,
40+
mxID: mxID,
41+
homeServer: homeserver,
42+
accessToken: accessToken,
43+
deviceID: deviceID
44+
)
2645
}
2746

2847
public typealias AccountIdentifier = MatrixFullUserIdentifier
@@ -36,6 +55,8 @@ public struct MatrixSQLAccountInfo: MatrixStoreAccountInfo {
3655
public var homeServer: MatrixHomeserver
3756

3857
public var accessToken: String?
58+
59+
public var deviceID: String
3960
}
4061

4162
extension MatrixSQLAccountInfo: Codable, FetchableRecord, PersistableRecord {
@@ -46,5 +67,6 @@ extension MatrixSQLAccountInfo: Codable, FetchableRecord, PersistableRecord {
4667
case displayName
4768
case mxID = "id"
4869
case homeServer = "homeserver"
70+
case deviceID = "device_id"
4971
}
5072
}

Sources/MatrixSQLiteStore/MatrixSQLiteStore.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public struct MatrixSQLiteStore {
4141
t.column("name", .text).notNull()
4242
t.column("displayName", .text)
4343
t.column("homeserver", .text).notNull()
44+
t.column("device_id", .text).notNull()
4445
}
4546
}
4647

0 commit comments

Comments
 (0)