-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSync.swift
More file actions
152 lines (122 loc) · 4.6 KB
/
Sync.swift
File metadata and controls
152 lines (122 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import Foundation
public struct MatrixSyncRequest: MatrixRequest {
public func components(for homeserver: MatrixHomeserver, with parameters: URLParameters) throws -> URLComponents {
var components = homeserver.url
components.path = "/_matrix/client/r0/sync"
var queryItems = [URLQueryItem]()
if let filter = parameters.filter {
queryItems.append(URLQueryItem(name: "filter", value: filter))
}
if let since = parameters.since {
queryItems.append(URLQueryItem(name: "since", value: since))
}
// TODO: fullState
// TODO: presence
if let timeout = parameters.timeout {
queryItems.append(URLQueryItem(name: "timeout", value: String(timeout)))
}
components.queryItems = queryItems
return components
}
public typealias Response = MatrixSyncResponse
public typealias URLParameters = Parameters
public static var httpMethod: HttpMethod = .GET
public static var requiresAuth = true
public struct Parameters {
public let filter: String?
public let since: String?
public let fullState: Bool?
public let presence: Presence?
public let timeout: Int?
public enum Presence: String {
case online
case offline
case unavailable
}
public init(filter: String? = nil,
since: String? = nil,
fullState: Bool? = nil,
presence: MatrixSyncRequest.Parameters.Presence? = nil,
timeout: Int? = nil) {
self.filter = filter
self.since = since
self.fullState = fullState
self.presence = presence
self.timeout = timeout
}
}
}
public struct MatrixSyncResponse: MatrixResponse {
public let nextBatch: String
public let rooms: Rooms?
// public let presence: Presence
// public let account_data: AccountData
// public let to_device: ToDevice
// public let device_lists: DeviceLists
// public let device_one_time_keys_count: OneTimeKeysCount
enum CodingKeys: String, CodingKey {
case nextBatch = "next_batch"
case rooms
}
public struct Rooms: Codable {
public let joined: [String: JoinedRoom]?
// public let invite: [String: InvitedRoom]?
public let left: [String: LeftRoom]?
enum CodingKeys: String, CodingKey {
case joined = "join"
case left = "leave"
}
}
public struct JoinedRoom: Codable {
public let summary: RoomSummary?
public let state: State?
public let timeline: Timeline?
// public let ephemeral: Ephemeral?
// public let account_data: AccountData?
public let unreadNotifications: UnreadNotificationCounts?
enum CodingKeys: String, CodingKey {
case summary
case state
case timeline
case unreadNotifications = "unread_notifications"
}
public struct RoomSummary: Codable {
public let heroes: [String]?
public let joinedMemberCount: Int?
public let invitedMemberCount: Int?
enum CodingKeys: String, CodingKey {
case heroes = "m.heroes"
case joinedMemberCount = "m.joined_member_count"
case invitedMemberCount = "m.invited_member_count"
}
}
public struct State: Codable {
@MatrixCodableEvents
public var events: [MatrixEvent]?
}
public struct Timeline: Codable {
@MatrixCodableEvents
public var events: [MatrixEvent]?
public let isLimited: Bool?
public let previousBatch: String?
enum CodingKeys: String, CodingKey {
case events
case isLimited = "limited"
case previousBatch = "prev_batch"
}
}
public struct UnreadNotificationCounts: Codable {
public let highlightCount: Int?
public let notificationCount: Int?
enum CodingKeys: String, CodingKey {
case highlightCount = "highlight_count"
case notificationCount = "notification_count"
}
}
}
public struct LeftRoom: Codable {
// public let state: State
// public let timeline: Timeline
// public let account_data: AccountData
}
}