[SDK] Bugfixing
This commit is contained in:
parent
7401a0dc20
commit
a5fc893a48
|
@ -42,7 +42,7 @@ class Event extends RawEvent {
|
|||
String typeKey,
|
||||
String eventId,
|
||||
String roomId,
|
||||
String sender,
|
||||
String senderId,
|
||||
ChatTime time,
|
||||
dynamic unsigned,
|
||||
Room room})
|
||||
|
@ -51,25 +51,24 @@ class Event extends RawEvent {
|
|||
typeKey: typeKey,
|
||||
eventId: eventId,
|
||||
roomId: roomId,
|
||||
sender: sender,
|
||||
senderId: senderId,
|
||||
time: time,
|
||||
unsigned: unsigned,
|
||||
room: room);
|
||||
|
||||
/// Get a State event from a table row or from the event stream.
|
||||
factory Event.fromJson(
|
||||
Map<String, dynamic> jsonPayload, int status, Room room) {
|
||||
factory Event.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']);
|
||||
return Event(
|
||||
status: status,
|
||||
status: jsonPayload['status'] ?? 1,
|
||||
content: content,
|
||||
typeKey: jsonPayload['type'],
|
||||
eventId: jsonPayload['event_id'],
|
||||
roomId: jsonPayload['room_id'],
|
||||
sender: jsonPayload['sender'],
|
||||
senderId: jsonPayload['sender'],
|
||||
time: ChatTime(jsonPayload['origin_server_ts']),
|
||||
unsigned: unsigned,
|
||||
room: room);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:famedlysdk/src/utils/ChatTime.dart';
|
||||
import './Room.dart';
|
||||
|
@ -41,7 +42,9 @@ class RawEvent {
|
|||
final String roomId;
|
||||
|
||||
/// The user who has sent this event if it is not a global account data event.
|
||||
final String sender;
|
||||
final String senderId;
|
||||
|
||||
User get sender => room.states[senderId] ?? User(senderId);
|
||||
|
||||
/// The time this event has received at the server. May be null for events like
|
||||
/// account data.
|
||||
|
@ -58,7 +61,7 @@ class RawEvent {
|
|||
@required this.typeKey,
|
||||
this.eventId,
|
||||
this.roomId,
|
||||
this.sender,
|
||||
this.senderId,
|
||||
this.time,
|
||||
this.unsigned,
|
||||
this.room});
|
||||
|
@ -79,7 +82,7 @@ class RawEvent {
|
|||
typeKey: jsonPayload['type'],
|
||||
eventId: jsonPayload['event_id'],
|
||||
roomId: jsonPayload['room_id'],
|
||||
sender: jsonPayload['sender'],
|
||||
senderId: jsonPayload['sender'],
|
||||
time: ChatTime(jsonPayload['origin_server_ts']),
|
||||
unsigned: unsigned,
|
||||
room: room);
|
||||
|
|
|
@ -122,6 +122,7 @@ class Room {
|
|||
this.mInvitedMemberCount,
|
||||
this.mJoinedMemberCount,
|
||||
this.states,
|
||||
this.roomAccountData,
|
||||
});
|
||||
|
||||
/// Calculates the displayname. First checks if there is a name, then checks for a canonical alias and
|
||||
|
@ -393,7 +394,8 @@ class Room {
|
|||
/// state are also given, the method will await them.
|
||||
static Future<Room> getRoomFromTableRow(
|
||||
Map<String, dynamic> row, Client matrix,
|
||||
{Future<List<Map<String, dynamic>>> states}) async {
|
||||
{Future<List<Map<String, dynamic>>> states,
|
||||
Future<List<Map<String, dynamic>>> roomAccountData}) async {
|
||||
Room newRoom = Room(
|
||||
id: row["id"],
|
||||
notificationCount: row["notification_count"],
|
||||
|
@ -416,22 +418,20 @@ class Room {
|
|||
newRoom.states = newStates;
|
||||
}
|
||||
|
||||
Map<String, RoomAccountData> newRoomAccountData = {};
|
||||
if (roomAccountData != null) {
|
||||
List<Map<String, dynamic>> rawRoomAccountData = await roomAccountData;
|
||||
for (int i = 0; i < rawRoomAccountData.length; i++) {
|
||||
RoomAccountData newData =
|
||||
RoomAccountData.fromJson(rawRoomAccountData[i], newRoom);
|
||||
newRoomAccountData[newData.typeKey] = newData;
|
||||
}
|
||||
newRoom.roomAccountData = newRoomAccountData;
|
||||
}
|
||||
|
||||
return newRoom;
|
||||
}
|
||||
|
||||
@Deprecated("Use client.store.getRoomById(String id) instead!")
|
||||
static Future<Room> getRoomById(String id, Client matrix) async {
|
||||
Room room = await matrix.store.getRoomById(id);
|
||||
return room;
|
||||
}
|
||||
|
||||
/// Load a room from the store including all room events.
|
||||
static Future<Room> loadRoomEvents(String id, Client matrix) async {
|
||||
Room room = await matrix.store.getRoomById(id);
|
||||
await room.loadEvents();
|
||||
return room;
|
||||
}
|
||||
|
||||
/// Creates a timeline from the store. Returns a [Timeline] object.
|
||||
Future<Timeline> getTimeline(
|
||||
{onTimelineUpdateCallback onUpdate,
|
||||
|
@ -467,14 +467,7 @@ class Room {
|
|||
return participants;
|
||||
|
||||
for (num i = 0; i < res["chunk"].length; i++) {
|
||||
User newUser = User(res["chunk"][i]["state_key"],
|
||||
displayName: res["chunk"][i]["content"]["displayname"] ?? "",
|
||||
membership: Membership.values.firstWhere((e) =>
|
||||
e.toString() ==
|
||||
'Membership.' + res["chunk"][i]["content"]["membership"] ??
|
||||
""),
|
||||
avatarUrl: MxContent(res["chunk"][i]["content"]["avatar_url"] ?? ""),
|
||||
room: this);
|
||||
User newUser = State.fromJson(res["chunk"][i], this) as User;
|
||||
if (newUser.membership != Membership.leave) participants.add(newUser);
|
||||
}
|
||||
|
||||
|
@ -489,7 +482,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 User.fromJson(resp, this);
|
||||
return State.fromJson(resp, this) as User;
|
||||
}
|
||||
|
||||
/// Searches for the event in the store. If it isn't found, try to request it
|
||||
|
|
|
@ -21,12 +21,29 @@
|
|||
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:famedlysdk/src/AccountData.dart';
|
||||
import 'package:famedlysdk/src/RawEvent.dart';
|
||||
|
||||
class RoomAccountData extends AccountData {
|
||||
/// The user who has sent this event if it is not a global account data event.
|
||||
final String room_id;
|
||||
final String roomId;
|
||||
|
||||
RoomAccountData({this.room_id, Map<String, dynamic> content, String typeKey})
|
||||
final Room room;
|
||||
|
||||
RoomAccountData(
|
||||
{this.roomId, this.room, Map<String, dynamic> content, String typeKey})
|
||||
: super(content: content, typeKey: typeKey);
|
||||
|
||||
/// Get a State event from a table row or from the event stream.
|
||||
factory RoomAccountData.fromJson(
|
||||
Map<String, dynamic> jsonPayload, Room room) {
|
||||
final Map<String, dynamic> content =
|
||||
RawEvent.getMapFromPayload(jsonPayload['content']);
|
||||
return RoomAccountData(
|
||||
content: content,
|
||||
typeKey: jsonPayload['type'],
|
||||
roomId: jsonPayload['room_id'],
|
||||
room: room);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with famedlysdk. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:famedlysdk/src/utils/ChatTime.dart';
|
||||
|
||||
import './Room.dart';
|
||||
|
@ -35,6 +36,8 @@ class State extends RawEvent {
|
|||
/// the overwriting semantics for this piece of room state.
|
||||
final String stateKey;
|
||||
|
||||
User get stateKeyUser => room.states[stateKey] ?? User(stateKey);
|
||||
|
||||
State(
|
||||
{this.prevContent,
|
||||
this.stateKey,
|
||||
|
@ -42,7 +45,7 @@ class State extends RawEvent {
|
|||
String typeKey,
|
||||
String eventId,
|
||||
String roomId,
|
||||
String sender,
|
||||
String senderId,
|
||||
ChatTime time,
|
||||
dynamic unsigned,
|
||||
Room room})
|
||||
|
@ -51,7 +54,7 @@ class State extends RawEvent {
|
|||
typeKey: typeKey,
|
||||
eventId: eventId,
|
||||
roomId: roomId,
|
||||
sender: sender,
|
||||
senderId: senderId,
|
||||
time: time,
|
||||
unsigned: unsigned,
|
||||
room: room);
|
||||
|
@ -71,7 +74,7 @@ class State extends RawEvent {
|
|||
typeKey: jsonPayload['type'],
|
||||
eventId: jsonPayload['event_id'],
|
||||
roomId: jsonPayload['room_id'],
|
||||
sender: jsonPayload['sender'],
|
||||
senderId: jsonPayload['sender'],
|
||||
time: ChatTime(jsonPayload['origin_server_ts']),
|
||||
unsigned: unsigned,
|
||||
room: room);
|
||||
|
|
|
@ -25,6 +25,7 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
import 'dart:core';
|
||||
|
||||
import 'package:famedlysdk/src/State.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
|
||||
|
@ -297,7 +298,7 @@ class Store {
|
|||
"SELECT * FROM States WHERE state_key=? AND room_id=?",
|
||||
[matrixID, room.id]);
|
||||
if (res.length != 1) return null;
|
||||
return User.fromJson(res[0], room);
|
||||
return State.fromJson(res[0], room) as User;
|
||||
}
|
||||
|
||||
/// Loads all Users in the database to provide a contact list
|
||||
|
@ -308,7 +309,8 @@ class Store {
|
|||
[client.userID, exceptRoomID]);
|
||||
List<User> userList = [];
|
||||
for (int i = 0; i < res.length; i++)
|
||||
userList.add(User.fromJson(res[i], Room(id: "", client: client)));
|
||||
userList
|
||||
.add(State.fromJson(res[i], Room(id: "", client: client)) as User);
|
||||
return userList;
|
||||
}
|
||||
|
||||
|
@ -324,7 +326,7 @@ class Store {
|
|||
List<User> participants = [];
|
||||
|
||||
for (num i = 0; i < res.length; i++) {
|
||||
participants.add(User.fromJson(res[i], room));
|
||||
participants.add(State.fromJson(res[i], room) as User);
|
||||
}
|
||||
|
||||
return participants;
|
||||
|
|
|
@ -32,7 +32,7 @@ enum Membership { join, invite, leave, ban }
|
|||
|
||||
/// Represents a Matrix User which may be a participant in a Matrix Room.
|
||||
class User extends State {
|
||||
User(String sender) : super(sender: sender);
|
||||
User(String userId) : super(senderId: userId);
|
||||
|
||||
/// The full qualified Matrix ID in the format @username:server.abc.
|
||||
String get id => stateKey;
|
||||
|
|
Loading…
Reference in a new issue