[RoomState] Rename State to RoomState

This commit is contained in:
Christian Pauly 2019-08-08 12:51:07 +02:00
parent fbbb90aac6
commit 8d563c9757
10 changed files with 35 additions and 34 deletions

View File

@ -36,7 +36,7 @@ export 'package:famedlysdk/src/Event.dart';
export 'package:famedlysdk/src/RawEvent.dart';
export 'package:famedlysdk/src/Room.dart';
export 'package:famedlysdk/src/RoomList.dart';
export 'package:famedlysdk/src/State.dart';
export 'package:famedlysdk/src/RoomState.dart';
export 'package:famedlysdk/src/Store.dart';
export 'package:famedlysdk/src/Timeline.dart';
export 'package:famedlysdk/src/User.dart';

View File

@ -21,7 +21,7 @@
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'package:famedlysdk/src/sync/EventUpdate.dart';
import 'package:famedlysdk/src/utils/ChatTime.dart';
@ -29,7 +29,7 @@ import './Room.dart';
import './RawEvent.dart';
/// Defines a timeline event for a room.
class Event extends State {
class Event extends RoomState {
/// The status of this event.
/// -1=ERROR
/// 0=SENDING

View File

@ -24,7 +24,7 @@
import 'package:famedlysdk/src/Client.dart';
import 'package:famedlysdk/src/Event.dart';
import 'package:famedlysdk/src/RoomAccountData.dart';
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'package:famedlysdk/src/responses/ErrorResponse.dart';
import 'package:famedlysdk/src/sync/EventUpdate.dart';
import 'package:famedlysdk/src/utils/ChatTime.dart';
@ -54,7 +54,7 @@ class Room {
int mJoinedMemberCount;
int mInvitedMemberCount;
Map<String, State> states = {};
Map<String, RoomState> states = {};
Map<String, RoomAccountData> roomAccountData = {};
@ -431,11 +431,11 @@ class Room {
roomAccountData: {},
);
Map<String, State> newStates = {};
Map<String, RoomState> newStates = {};
if (states != null) {
List<Map<String, dynamic>> rawStates = await states;
for (int i = 0; i < rawStates.length; i++) {
State newState = State.fromJson(rawStates[i], newRoom);
RoomState newState = RoomState.fromJson(rawStates[i], newRoom);
newStates[newState.key] = newState;
}
newRoom.states = newStates;
@ -492,7 +492,7 @@ class Room {
return participants;
for (num i = 0; i < res["chunk"].length; i++) {
User newUser = State.fromJson(res["chunk"][i], this).asUser;
User newUser = RoomState.fromJson(res["chunk"][i], this).asUser;
if (newUser.membership != Membership.leave) participants.add(newUser);
}
@ -507,7 +507,7 @@ class Room {
if (resp is ErrorResponse) return null;
// Somehow we miss the mxid in the response and only get the content of the event.
resp["matrix_id"] = mxID;
return State.fromJson(resp, this).asUser;
return RoomState.fromJson(resp, this).asUser;
}
/// Searches for the event in the store. If it isn't found, try to request it
@ -526,7 +526,7 @@ class Room {
/// Returns the user's own power level.
int getPowerLevelByUserId(String userId) {
int powerLevel = 0;
State powerLevelState = states["m.room.power_levels"];
RoomState powerLevelState = states["m.room.power_levels"];
if (powerLevelState == null) return powerLevel;
if (powerLevelState.content["users_default"] is int)
powerLevel = powerLevelState.content["users_default"];
@ -541,7 +541,7 @@ class Room {
/// Returns the power levels from all users for this room or null if not given.
Map<String, int> get powerLevels {
State powerLevelState = states["m.room.power_levels"];
RoomState powerLevelState = states["m.room.power_levels"];
if (powerLevelState.content["users"] is Map<String, int>)
return powerLevelState.content["users"];
return null;

View File

@ -24,7 +24,7 @@
import 'dart:async';
import 'dart:core';
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'Client.dart';
import 'Room.dart';
@ -141,7 +141,7 @@ class RoomList {
final bool found = (j < rooms.length && rooms[j].id == eventUpdate.roomID);
if (!found) return;
State stateEvent = State.fromJson(eventUpdate.content, rooms[j]);
RoomState stateEvent = RoomState.fromJson(eventUpdate.content, rooms[j]);
if (rooms[j].states[stateEvent.key] != null &&
rooms[j].states[stateEvent.key].time > stateEvent.time) return;
rooms[j].states[stateEvent.key] = stateEvent;

View File

@ -26,7 +26,7 @@ import 'package:famedlysdk/src/utils/ChatTime.dart';
import './Room.dart';
import './RawEvent.dart';
class State extends RawEvent {
class RoomState extends RawEvent {
/// Optional. The previous content for this state.
/// This will be present only for state events appearing in the timeline.
/// If this is not a state event, or there is no previous content, this key will be null.
@ -38,7 +38,7 @@ class State extends RawEvent {
User get stateKeyUser => room.states[stateKey] ?? User(stateKey);
State(
RoomState(
{this.prevContent,
this.stateKey,
dynamic content,
@ -60,14 +60,14 @@ class State extends RawEvent {
room: room);
/// Get a State event from a table row or from the event stream.
factory State.fromJson(Map<String, dynamic> jsonPayload, Room room) {
factory RoomState.fromJson(Map<String, dynamic> jsonPayload, Room room) {
final Map<String, dynamic> content =
RawEvent.getMapFromPayload(jsonPayload['content']);
final Map<String, dynamic> unsigned =
RawEvent.getMapFromPayload(jsonPayload['unsigned']);
final Map<String, dynamic> prevContent =
RawEvent.getMapFromPayload(jsonPayload['prev_content']);
return State(
return RoomState(
stateKey: jsonPayload['state_key'],
prevContent: prevContent,
content: content,

View File

@ -27,7 +27,7 @@ import 'dart:core';
import 'package:famedlysdk/src/AccountData.dart';
import 'package:famedlysdk/src/Presence.dart';
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'package:path/path.dart' as p;
import 'package:sqflite/sqflite.dart';
@ -303,7 +303,7 @@ class Store {
"SELECT * FROM States WHERE state_key=? AND room_id=?",
[matrixID, room.id]);
if (res.length != 1) return null;
return State.fromJson(res[0], room).asUser;
return RoomState.fromJson(res[0], room).asUser;
}
/// Loads all Users in the database to provide a contact list
@ -314,7 +314,8 @@ class Store {
[client.userID, exceptRoomID]);
List<User> userList = [];
for (int i = 0; i < res.length; i++)
userList.add(State.fromJson(res[i], Room(id: "", client: client)).asUser);
userList
.add(RoomState.fromJson(res[i], Room(id: "", client: client)).asUser);
return userList;
}
@ -330,7 +331,7 @@ class Store {
List<User> participants = [];
for (num i = 0; i < res.length; i++) {
participants.add(State.fromJson(res[i], room).asUser);
participants.add(RoomState.fromJson(res[i], room).asUser);
}
return participants;

View File

@ -22,7 +22,7 @@
*/
import 'package:famedlysdk/src/Room.dart';
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'package:famedlysdk/src/responses/ErrorResponse.dart';
import 'package:famedlysdk/src/utils/ChatTime.dart';
import 'package:famedlysdk/src/utils/MxContent.dart';
@ -32,7 +32,7 @@ import 'Connection.dart';
enum Membership { join, invite, leave, ban }
/// Represents a Matrix User which may be a participant in a Matrix Room.
class User extends State {
class User extends RoomState {
factory User(
String id, {
String membership,

View File

@ -25,7 +25,7 @@ import 'dart:convert';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:famedlysdk/src/RawEvent.dart';
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'package:flutter_test/flutter_test.dart';
import 'FakeMatrixApi.dart';
@ -64,7 +64,7 @@ void main() {
expect(event.getBody(), body);
expect(event.type, EventTypes.Text);
jsonObj["state_key"] = "";
State state = State.fromJson(jsonObj, null);
RoomState state = RoomState.fromJson(jsonObj, null);
expect(state.eventId, id);
expect(state.stateKey, "");
expect(state.key, "m.room.message");

View File

@ -24,7 +24,7 @@
import 'package:famedlysdk/src/Client.dart';
import 'package:famedlysdk/src/Event.dart';
import 'package:famedlysdk/src/Room.dart';
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'package:famedlysdk/src/Timeline.dart';
import 'package:famedlysdk/src/User.dart';
import 'package:famedlysdk/src/utils/ChatTime.dart';
@ -85,7 +85,7 @@ void main() {
expect(room.mHeroes, heroes);
expect(room.displayname, "alice, bob, charley");
room.states["m.room.canonical_alias"] = State(
room.states["m.room.canonical_alias"] = RoomState(
senderId: "@test:example.com",
typeKey: "m.room.canonical_alias",
roomId: room.id,
@ -96,7 +96,7 @@ void main() {
expect(room.displayname, "testalias");
expect(room.canonicalAlias, "#testalias:example.com");
room.states["m.room.name"] = State(
room.states["m.room.name"] = RoomState(
senderId: "@test:example.com",
typeKey: "m.room.name",
roomId: room.id,
@ -107,7 +107,7 @@ void main() {
expect(room.displayname, "testname");
expect(room.topic, "");
room.states["m.room.topic"] = State(
room.states["m.room.topic"] = RoomState(
senderId: "@test:example.com",
typeKey: "m.room.topic",
roomId: room.id,
@ -118,7 +118,7 @@ void main() {
expect(room.topic, "testtopic");
expect(room.avatar.mxc, "");
room.states["m.room.avatar"] = State(
room.states["m.room.avatar"] = RoomState(
senderId: "@test:example.com",
typeKey: "m.room.avatar",
roomId: room.id,
@ -129,7 +129,7 @@ void main() {
expect(room.avatar.mxc, "mxc://testurl");
expect(room.lastEvent, null);
room.states["m.room.message"] = State(
room.states["m.room.message"] = RoomState(
senderId: "@test:example.com",
typeKey: "m.room.message",
roomId: room.id,
@ -191,7 +191,7 @@ void main() {
});
test("PowerLevels", () async {
room.states["m.room.power_levels"] = State(
room.states["m.room.power_levels"] = RoomState(
senderId: "@test:example.com",
typeKey: "m.room.power_levels",
roomId: room.id,

View File

@ -21,7 +21,7 @@
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:famedlysdk/src/State.dart';
import 'package:famedlysdk/src/RoomState.dart';
import 'package:famedlysdk/src/User.dart';
import 'package:flutter_test/flutter_test.dart';
@ -49,7 +49,7 @@ void main() {
"state_key": id
};
User user = State.fromJson(jsonObj, null).asUser;
User user = RoomState.fromJson(jsonObj, null).asUser;
expect(user.id, id);
expect(user.membership, membership);