Skip to content

Commit fd273ca

Browse files
committed
MatrixStoreRoomState
1 parent cfd386c commit fd273ca

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

Sources/MatrixClient/API/Events/Room/RoomStateEvent.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,27 @@ import AnyCodable
99
import Foundation
1010

1111
public struct MatrixStateEvent: MatrixEvent {
12+
public init(
13+
eventID: String? = nil,
14+
stateKey: String = "",
15+
sender: MatrixFullUserIdentifier? = nil,
16+
date: Date? = nil,
17+
unsigned: AnyCodable? = nil,
18+
content: MatrixStateEventType
19+
) {
20+
self.stateKey = stateKey
21+
self.eventID = eventID
22+
self.sender = sender
23+
self.date = date
24+
self.unsigned = unsigned
25+
self.content = content
26+
}
27+
1228
public static let type: String = ""
1329

1430
/// The content of the event.
1531
@MatrixCodableStateEventType
16-
var content: MatrixStateEventType
32+
public var content: MatrixStateEventType
1733

1834
public var stateKey: String = ""
1935

Sources/MatrixClient/API/Events/RoomEvent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public struct MatrixCodableEvents<Value: Collection>: Codable where Value.Elemen
149149
let wrappers = try container.decode([EventWrapper<Value.Element>].self)
150150
wrappedValue = wrappers.compactMap(\.wrappedEvent) as? Value
151151
} catch {
152-
if #available(iOS 14.0, *) {
152+
if #available(iOS 14.0, macOS 11.0, *) {
153153
MatrixClient.logger.warning("Failed to parse sync: \(error.localizedDescription)")
154154
} else {}
155155
}

Sources/MatrixClient/API/Events/State/StateEvent+Codable.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public extension CodingUserInfoKey {
2323
}
2424

2525
@propertyWrapper
26-
public struct MatrixCodableStateEventType {
26+
public struct MatrixCodableStateEventType: Encodable {
2727
public var wrappedValue: MatrixStateEventType
2828

2929
public init(wrappedValue: MatrixStateEventType) {
@@ -62,8 +62,4 @@ public struct MatrixCodableStateEventType {
6262
}
6363
}
6464
}
65-
66-
struct Container<T: MatrixStateEventType>: Codable {
67-
var content: T
68-
}
6965
}

Sources/MatrixClient/API/Events/State/StateEvent.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ public struct MatrixRoomCanonicalAliasEvent: MatrixStateEventType {
3131

3232
/// This is the first event in a room and cannot be changed. It acts as the root of all other events.
3333
public struct MatrixRoomCreateEvent: MatrixStateEventType {
34+
public init(
35+
creator: MatrixFullUserIdentifier,
36+
federate: Bool? = nil,
37+
predecessor: MatrixRoomCreateEvent.PreviousRoom? = nil,
38+
roomVersion: String? = nil,
39+
roomType: String? = nil
40+
) {
41+
self.creator = creator
42+
self.federate = federate
43+
self.predecessor = predecessor
44+
self.roomVersion = roomVersion
45+
self.roomType = roomType
46+
}
47+
3448
public static let type = "m.room.create"
3549

3650
/// The ``MatrixFullUserIdentifier`` of the room creator.
@@ -54,7 +68,7 @@ public struct MatrixRoomCreateEvent: MatrixStateEventType {
5468
/// Unspecified room types are possible using Namespaced Identifiers.
5569
public var roomType: String?
5670

57-
public struct PreviousRoom: Codable {
71+
public struct PreviousRoom: Codable, Equatable, Hashable {
5872
/// The event ID of the last known event in the old room.
5973
public var eventID: String
6074

Sources/MatrixCore/MatrixStoreRoomState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ public protocol MatrixStoreRoomState {
1212
var eventId: String { get }
1313
var roomId: String { get }
1414
var stateKey: String { get }
15-
var contentType: String { get }
15+
var sender: MatrixFullUserIdentifier? { get }
1616
var content: MatrixStateEventType { get }
1717
}

0 commit comments

Comments
 (0)