[Room] Add getter and setter for states
This commit is contained in:
parent
a408764c86
commit
930bc26be6
|
@ -76,6 +76,18 @@ class Room {
|
||||||
/// Key-Value store for private account data only visible for this user.
|
/// Key-Value store for private account data only visible for this user.
|
||||||
Map<String, RoomAccountData> roomAccountData = {};
|
Map<String, RoomAccountData> 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.
|
/// ID of the fully read marker event.
|
||||||
String get fullyRead => roomAccountData["m.fully_read"] != null
|
String get fullyRead => roomAccountData["m.fully_read"] != null
|
||||||
? roomAccountData["m.fully_read"].content["event_id"]
|
? roomAccountData["m.fully_read"].content["event_id"]
|
||||||
|
|
|
@ -8,6 +8,7 @@ class StatesMap {
|
||||||
/// Returns either the [RoomState] or a map of state_keys to [RoomState] objects.
|
/// 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.
|
/// If you just enter a MatrixID, it will try to return the corresponding m.room.member event.
|
||||||
dynamic operator [](String key) {
|
dynamic operator [](String key) {
|
||||||
|
//print("[Warning] This method will be depracated in the future!");
|
||||||
if (key.startsWith("@") && key.contains(":")) {
|
if (key.startsWith("@") && key.contains(":")) {
|
||||||
if (!states.containsKey("m.room.member")) states["m.room.member"] = {};
|
if (!states.containsKey("m.room.member")) states["m.room.member"] = {};
|
||||||
return states["m.room.member"][key];
|
return states["m.room.member"][key];
|
||||||
|
@ -22,6 +23,7 @@ class StatesMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator []=(String key, RoomState val) {
|
void operator []=(String key, RoomState val) {
|
||||||
|
//print("[Warning] This method will be depracated in the future!");
|
||||||
if (key.startsWith("@") && key.contains(":")) {
|
if (key.startsWith("@") && key.contains(":")) {
|
||||||
if (!states.containsKey("m.room.member")) states["m.room.member"] = {};
|
if (!states.containsKey("m.room.member")) states["m.room.member"] = {};
|
||||||
states["m.room.member"][key] = val;
|
states["m.room.member"][key] = val;
|
||||||
|
|
Loading…
Reference in a new issue