[Event] load reply event when loading timeline
[Room] load creator user [Timeline] fix sendUser not being passed, fix stateKeyUser not being resolved Took 46 minutes
This commit is contained in:
parent
fab4604b08
commit
0823473bdf
|
@ -22,11 +22,13 @@
|
|||
*/
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:famedlysdk/src/Client.dart';
|
||||
import 'package:famedlysdk/src/sync/EventUpdate.dart';
|
||||
import 'package:famedlysdk/src/utils/ChatTime.dart';
|
||||
import 'package:famedlysdk/src/Client.dart';
|
||||
import './User.dart';
|
||||
|
||||
import './Room.dart';
|
||||
import './User.dart';
|
||||
|
||||
/// A single Matrix event, e.g. a message in a chat.
|
||||
class Event {
|
||||
|
@ -48,6 +50,8 @@ class Event {
|
|||
/// The type of this event. Mostly this is 'timeline'.
|
||||
final String environment;
|
||||
|
||||
Event replyEvent;
|
||||
|
||||
/// The status of this event.
|
||||
/// -1=ERROR
|
||||
/// 0=SENDING
|
||||
|
@ -67,6 +71,7 @@ class Event {
|
|||
this.status = 2,
|
||||
this.environment,
|
||||
this.content,
|
||||
this.replyEvent,
|
||||
});
|
||||
|
||||
/// Returns the body of this event if it has a body.
|
||||
|
|
|
@ -22,11 +22,12 @@
|
|||
*/
|
||||
|
||||
import 'package:famedlysdk/src/Client.dart';
|
||||
import 'package:famedlysdk/src/utils/ChatTime.dart';
|
||||
import 'package:famedlysdk/src/utils/MxContent.dart';
|
||||
import 'package:famedlysdk/src/Event.dart';
|
||||
import 'package:famedlysdk/src/responses/ErrorResponse.dart';
|
||||
import 'package:famedlysdk/src/sync/EventUpdate.dart';
|
||||
import 'package:famedlysdk/src/Event.dart';
|
||||
import 'package:famedlysdk/src/utils/ChatTime.dart';
|
||||
import 'package:famedlysdk/src/utils/MxContent.dart';
|
||||
|
||||
import './User.dart';
|
||||
import 'Timeline.dart';
|
||||
|
||||
|
@ -86,6 +87,9 @@ class Room {
|
|||
|
||||
Event lastEvent;
|
||||
|
||||
// The user who created the room based on m.create events
|
||||
User creator;
|
||||
|
||||
/// Your current client instance.
|
||||
final Client client;
|
||||
|
||||
|
@ -118,6 +122,7 @@ class Room {
|
|||
this.joinRules,
|
||||
this.powerLevels,
|
||||
this.lastEvent,
|
||||
this.creator,
|
||||
this.client,
|
||||
});
|
||||
|
||||
|
@ -365,6 +370,13 @@ class Room {
|
|||
return resp;
|
||||
}
|
||||
|
||||
/// Load the creator event of this room
|
||||
Future<Event> getCreatorEvent(Client matrix) async {
|
||||
List<Event> events = await this.loadEvents();
|
||||
return events.firstWhere((event) => event.type == EventTypes.RoomCreate,
|
||||
orElse: null);
|
||||
}
|
||||
|
||||
/// Returns a Room from a json String which comes normally from the store.
|
||||
static Future<Room> getRoomFromTableRow(
|
||||
Map<String, dynamic> row, Client matrix) async {
|
||||
|
@ -376,7 +388,7 @@ class Room {
|
|||
if (avatarUrl == "")
|
||||
avatarUrl = await matrix.store?.getAvatarFromSingleChat(row["id"]) ?? "";
|
||||
|
||||
return Room(
|
||||
Room room = Room(
|
||||
id: row["id"],
|
||||
name: name,
|
||||
membership: row["membership"],
|
||||
|
@ -411,6 +423,17 @@ class Room {
|
|||
lastEvent: Event.fromJson(row, null),
|
||||
client: matrix,
|
||||
);
|
||||
|
||||
// Lets get the creator too if not a test as tests cant use the stpre :(
|
||||
if (matrix.homeserver != "https://fakeServer.notExisting") {
|
||||
Event creatorEvent = await room.getCreatorEvent(matrix);
|
||||
if (creatorEvent != null) {
|
||||
room.creator = await matrix.store
|
||||
?.getUser(matrixID: creatorEvent.id, room: row["id"]);
|
||||
}
|
||||
}
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
@Deprecated("Use client.store.getRoomById(String id) instead!")
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'Event.dart';
|
||||
import 'Room.dart';
|
||||
import 'User.dart';
|
||||
|
@ -79,14 +80,41 @@ class Timeline {
|
|||
events[i] = Event.fromJson(eventUpdate.content, room);
|
||||
}
|
||||
} else {
|
||||
User user = await room.client.store
|
||||
Event newEvent;
|
||||
User senderUser = await room.client.store
|
||||
?.getUser(matrixID: eventUpdate.content["sender"], room: room);
|
||||
if (user != null) {
|
||||
eventUpdate.content["displayname"] = user.displayName;
|
||||
eventUpdate.content["avatar_url"] = user.avatarUrl.mxc;
|
||||
if (senderUser != null) {
|
||||
eventUpdate.content["displayname"] = senderUser.displayName;
|
||||
eventUpdate.content["avatar_url"] = senderUser.avatarUrl.mxc;
|
||||
}
|
||||
|
||||
Event newEvent = Event.fromJson(eventUpdate.content, room);
|
||||
User stateKeyUser;
|
||||
if (eventUpdate.content.containsKey("state_key")) {
|
||||
stateKeyUser = await room.client.store?.getUser(
|
||||
matrixID: eventUpdate.content["state_key"], room: room);
|
||||
}
|
||||
|
||||
if (senderUser != null && stateKeyUser != null) {
|
||||
newEvent = Event.fromJson(eventUpdate.content, room,
|
||||
senderUser: senderUser, stateKeyUser: stateKeyUser);
|
||||
} else if (senderUser != null) {
|
||||
newEvent = Event.fromJson(eventUpdate.content, room,
|
||||
senderUser: senderUser);
|
||||
} else if (stateKeyUser != null) {
|
||||
newEvent = Event.fromJson(eventUpdate.content, room,
|
||||
stateKeyUser: stateKeyUser);
|
||||
} else {
|
||||
newEvent = Event.fromJson(eventUpdate.content, room);
|
||||
}
|
||||
|
||||
// TODO update to type check when https://gitlab.com/famedly/famedlysdk/merge_requests/28/ is merged
|
||||
if (newEvent.content.containsKey("m.relates_to")) {
|
||||
Map<String, dynamic> relates_to = newEvent.content["m.relates_to"];
|
||||
if (relates_to.containsKey("m.in_reply_to")) {
|
||||
newEvent.replyEvent = await room.getEventById(newEvent
|
||||
.content["m.relates_to"]["m.in_reply_to"]["event_id"]);
|
||||
}
|
||||
}
|
||||
|
||||
events.insert(0, newEvent);
|
||||
if (onInsert != null) onInsert(0);
|
||||
|
|
10
pubspec.lock
10
pubspec.lock
|
@ -1,5 +1,5 @@
|
|||
# Generated by pub
|
||||
# See https://www.dartlang.org/tools/pub/glossary#lockfile
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
|
@ -21,7 +21,7 @@ packages:
|
|||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
version: "2.2.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -297,7 +297,7 @@ packages:
|
|||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.0"
|
||||
version: "1.7.0"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -325,7 +325,7 @@ packages:
|
|||
name: quiver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
version: "2.0.3"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -414,7 +414,7 @@ packages:
|
|||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.4"
|
||||
version: "0.2.5"
|
||||
timing:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
Loading…
Reference in a new issue