diff --git a/lib/src/Room.dart b/lib/src/Room.dart index bd27bf2..67178d7 100644 --- a/lib/src/Room.dart +++ b/lib/src/Room.dart @@ -76,6 +76,18 @@ class Room { /// Key-Value store for private account data only visible for this user. Map roomAccountData = {}; + /// Returns the [RoomState] for the given [typeKey] and optional [stateKey]. + /// If no [stateKey] is provided, it defaults to an empty string. + RoomState getState(String typeKey, [String stateKey = ""]) => + states.states[typeKey] != null ? states.states[typeKey][stateKey] : null; + + /// Sets the [RoomState] for the given [typeKey] and optional [stateKey]. + /// If no [stateKey] is provided, it defaults to an empty string. + void setState(RoomState state, String typeKey, [String stateKey = ""]) { + if (!states.states.containsKey(typeKey)) states.states[typeKey] = {}; + states.states[typeKey][stateKey] = state; + } + /// ID of the fully read marker event. String get fullyRead => roomAccountData["m.fully_read"] != null ? roomAccountData["m.fully_read"].content["event_id"] diff --git a/lib/src/utils/StatesMap.dart b/lib/src/utils/StatesMap.dart index cfc57c6..5a0bdf9 100644 --- a/lib/src/utils/StatesMap.dart +++ b/lib/src/utils/StatesMap.dart @@ -8,6 +8,7 @@ class StatesMap { /// Returns either the [RoomState] or a map of state_keys to [RoomState] objects. /// If you just enter a MatrixID, it will try to return the corresponding m.room.member event. dynamic operator [](String key) { + //print("[Warning] This method will be depracated in the future!"); if (key.startsWith("@") && key.contains(":")) { if (!states.containsKey("m.room.member")) states["m.room.member"] = {}; return states["m.room.member"][key]; @@ -22,6 +23,7 @@ class StatesMap { } void operator []=(String key, RoomState val) { + //print("[Warning] This method will be depracated in the future!"); if (key.startsWith("@") && key.contains(":")) { if (!states.containsKey("m.room.member")) states["m.room.member"] = {}; states["m.room.member"][key] = val;