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