Commit bececf5d authored by Wilko Manger's avatar Wilko Manger

Set _directUser based on InviteEvent too

parent 94280db9
Pipeline #440 passed with stages
in 55 seconds
- Set `_directUser` based on `InviteEvent` too
- Don't serialize `width` and `height` if `null`
- Add proper `toString` to `MatrixException`
......@@ -36,8 +36,12 @@ abstract class MemberChangeEvent extends StateEvent {
this.content, RoomEventArgs args)
: super(args, stateKey: content.subject.id.toString());
factory MemberChangeEvent.fromJson(RoomEventArgs args, String stateKey, Map<String, dynamic> json) {
final membershipType = json['content']['membership'];
factory MemberChangeEvent.fromJson(
RoomEventArgs args, String stateKey,
Map<String, dynamic> json) {
final content = json['content'];
final membershipType = content['membership'];
final subjectId = UserId(stateKey);
final prevContent = json.containsKey('unsigned')
......@@ -47,7 +51,7 @@ abstract class MemberChangeEvent extends StateEvent {
final prevDisplayName = prevContent != null
? prevContent['displayname'] : null;
final displayName = json['content']['displayname'] ?? prevDisplayName;
final displayName = content['displayname'] ?? prevDisplayName;
var prevAvatarUrl = prevContent != null
? prevContent['avatar_url'] : null;
......@@ -55,7 +59,7 @@ abstract class MemberChangeEvent extends StateEvent {
prevAvatarUrl = Uri.parse(prevAvatarUrl);
}
var avatarUrl = json['content']['avatar_url'] ?? prevAvatarUrl;
var avatarUrl = content['avatar_url'] ?? prevAvatarUrl;
if (avatarUrl != null && avatarUrl is String) {
avatarUrl = Uri.parse(avatarUrl);
......@@ -99,7 +103,11 @@ abstract class MemberChangeEvent extends StateEvent {
case BanEvent.type:
return BanEvent(subject, args);
case InviteEvent.type:
return InviteEvent(subject, args);
return InviteEvent(
subject,
args,
isDirect: content['is_direct'] ?? false
);
case KnockEvent.type:
default:
return KnockEvent(subject, args);
......@@ -117,15 +125,16 @@ class MemberChange extends StateEventContent {
/// The [User] of who has joined, left, was banned, etc.
final User subject;
final bool isDirect;
@protected
final String membershipType;
MemberChange(
{
@required this.subject,
@required this.membershipType,
})
: stateKey = subject.id.toString();
MemberChange({
@required this.subject,
@required this.membershipType,
this.isDirect = false,
}) : stateKey = subject.id.toString();
@override
Map<String, dynamic> toJson() => super.toJson()
......@@ -174,10 +183,11 @@ class BanEvent extends MemberChangeEvent {
class InviteEvent extends MemberChangeEvent {
static const String type = 'invite';
InviteEvent(User subject, RoomEventArgs args)
InviteEvent(User subject, RoomEventArgs args, {bool isDirect = false})
: super(MemberChange(
subject: subject,
membershipType: type
membershipType: type,
isDirect: isDirect
), args);
}
......
......@@ -21,6 +21,7 @@ import 'dart:convert';
import 'package:kiwi/kiwi.dart';
import 'package:matrix_sdk/src/api/client.dart';
import 'package:matrix_sdk/src/event/event.dart';
import 'package:matrix_sdk/src/event/room/state/member_change_event.dart';
import 'package:matrix_sdk/src/event/room/state/room_creation_event.dart';
import 'package:matrix_sdk/src/event/timeline.dart';
import 'package:matrix_sdk/src/event/room/redaction_event.dart';
......@@ -52,6 +53,8 @@ class Room extends Identifiable<RoomId> {
/// [UserId] of the user that created this room.
User get creator => _creator;
final LocalUser _me;
Room({
@required this.id,
@required String scope,
......@@ -65,6 +68,7 @@ class Room extends Identifiable<RoomId> {
_avatarUrl = avatarUrl,
_directUser = directUser,
_creator = creator,
_me = Container().resolve(scope),
members = Members(id, store: Container().resolve(scope)) {
_timeline = Timeline(this, store: Container().resolve(scope));
......@@ -162,6 +166,12 @@ class Room extends Identifiable<RoomId> {
_avatarUrl = event.content.url;
} else if (event is RoomCreationEvent) {
creationEvent = event;
} else if (event is InviteEvent && event.content.isDirect) {
if (!event.content.subject.isIdenticalTo(_me)) {
_directUser = event.content.subject;
} else if (!event.sender.isIdenticalTo(_me)) {
_directUser = event.sender;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment