Update Matrix SDK

parent 27fd29c7
......@@ -105,7 +105,7 @@ class ChatBloc {
chatItems.add(DateItem(previousEvent.time));
}
chatItems.add(ChatEvent(event));
chatItems.add(ChatEvent(room, event));
previousEvent = event;
}
......
......@@ -272,6 +272,7 @@ class ChatPageState extends State<ChatPage> {
children: List.generate(
20,
(i) => LoadingBubble(
room: room,
isMine: i % 2 == 0,
),
),
......
......@@ -18,6 +18,7 @@
import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/ui/main/chat/image/image_bloc.dart';
import 'package:pattle/src/ui/main/models/chat_item.dart';
import 'package:pattle/src/ui/util/date_format.dart';
import 'package:pattle/src/ui/util/user.dart';
import 'package:pattle/src/ui/util/matrix_image.dart';
......@@ -34,9 +35,10 @@ class ImagePageState extends State<ImagePage> {
var _messageSender;
var _date;
ImagePageState(this.message) {
ImagePageState(ChatEvent<ImageMessageEvent> chatEvent)
: message = chatEvent.event {
bloc = ImageBloc(message);
bloc.room = message.room;
bloc.room = chatEvent.room;
}
@override
......@@ -135,10 +137,10 @@ class ImagePageState extends State<ImagePage> {
}
class ImagePage extends StatefulWidget {
final ImageMessageEvent message;
final ChatEvent<ImageMessageEvent> chatEvent;
ImagePage(this.message);
ImagePage(this.chatEvent);
@override
State<StatefulWidget> createState() => ImagePageState(message);
State<StatefulWidget> createState() => ImagePageState(chatEvent);
}
......@@ -113,11 +113,12 @@ abstract class Bubble extends Item {
}
factory Bubble.asReply({
@required Room room,
@required RoomEvent reply,
@required RoomEvent replyTo,
@required bool isMine,
}) {
final item = ChatEvent(replyTo);
final item = ChatEvent(room, replyTo);
if (replyTo is TextMessageEvent) {
return TextBubble(
item: item,
......
......@@ -58,7 +58,11 @@ class ImageBubble extends MessageBubble {
class ImageBubbleState extends MessageBubbleState<ImageBubble> {
void _onTap(BuildContext context) {
Navigator.pushNamed(context, Routes.image, arguments: widget.event);
Navigator.pushNamed(
context,
Routes.image,
arguments: widget.item.as<ImageMessageEvent>(),
);
}
Widget buildContent(BuildContext context) =>
......
......@@ -42,9 +42,10 @@ class LoadingBubble extends MessageBubble {
final TextMessageEvent event = _mockEvent;
LoadingBubble({
@required Room room,
@required bool isMine,
}) : super(
item: ChatEvent(_mockEvent),
item: ChatEvent(room, _mockEvent),
isMine: isMine,
);
......
......@@ -120,7 +120,7 @@ abstract class MessageBubbleState<T extends MessageBubble>
@protected
Widget buildSender(BuildContext context, {Color color}) {
if ((isStartOfGroup || (widget.isRepliedTo && !widget.isMine)) &&
!widget.event.room.isDirect) {
!widget.item.room.isDirect) {
return Text(
displayNameOf(widget.event.sender, context),
style: senderTextStyle(context, color: color),
......
......@@ -50,7 +50,7 @@ class CreationBubbleState extends StateBubbleState<CreationBubble> {
@protected
Widget buildContent(BuildContext context) {
return FutureOrBuilder<User>(
futureOr: widget.event.room.creator,
futureOr: widget.item.room.creator,
builder: (BuildContext context, AsyncSnapshot<User> snapshot) {
return super.buildContent(context);
},
......@@ -62,7 +62,7 @@ class CreationBubbleState extends StateBubbleState<CreationBubble> {
List<TextSpan> buildContentSpans(BuildContext context) =>
l(context).createdThisGroup(
TextSpan(
text: displayNameOf(widget.event.room.creator),
text: displayNameOf(widget.item.room.creator),
style: defaultEmphasisTextStyle,
),
);
......
......@@ -46,7 +46,7 @@ class TopicBubble extends StateBubble {
get onTap => (context) {
return Navigator.of(context).pushNamed(
Routes.chatsSettings,
arguments: event.room,
arguments: item.room,
);
};
......
......@@ -77,7 +77,7 @@ class TextBubbleState extends MessageBubbleState<TextBubble> {
Widget _buildRepliedTo(BuildContext context) {
if (widget.event.content.inReplyToId != null) {
final repliedTo =
widget.event.room.timeline[widget.event.content.inReplyToId];
widget.item.room.timeline[widget.event.content.inReplyToId];
return FutureOrBuilder<RoomEvent>(
futureOr: repliedTo,
builder: (BuildContext context, AsyncSnapshot<RoomEvent> snapshot) {
......@@ -93,6 +93,7 @@ class TextBubbleState extends MessageBubbleState<TextBubble> {
// is not a replied-to message (to prevent very long
// reply chains)
child: Bubble.asReply(
room: widget.item.room,
reply: widget.event,
replyTo: repliedTo,
isMine: repliedTo.sender == widget.me,
......
......@@ -25,8 +25,18 @@ class DateItem implements ChatItem {
DateItem(this.date);
}
class ChatEvent implements ChatItem {
final RoomEvent event;
class ChatEvent<T extends RoomEvent> implements ChatItem {
final Room room;
final T event;
ChatEvent(this.event);
ChatEvent(this.room, this.event);
ChatEvent<E> as<E extends RoomEvent>() {
final e = event;
if (e is E) {
return ChatEvent<E>(room, e);
} else {
return null;
}
}
}
......@@ -25,7 +25,7 @@ class ImageSubtitle extends Subtitle {
@override
final ImageMessageEvent event;
ImageSubtitle(this.event) : super(event);
ImageSubtitle(Room room, this.event) : super(room, event);
@override
Widget build(BuildContext context) => Row(
......
......@@ -25,7 +25,7 @@ class MemberSubtitle extends Subtitle {
@override
final MemberChangeEvent event;
MemberSubtitle(this.event) : super(event);
MemberSubtitle(Room room, this.event) : super(room, event);
@override
Widget build(BuildContext context) {
......
......@@ -25,7 +25,7 @@ class RedactedSubtitle extends Subtitle {
@override
final RedactedEvent event;
RedactedSubtitle(this.event) : super(event);
RedactedSubtitle(Room room, this.event) : super(room, event);
@override
Widget build(BuildContext context) => Row(
......
......@@ -33,22 +33,20 @@ import 'unsupported_subtitle.dart';
abstract class Subtitle extends StatelessWidget {
static const iconSize = 20.0;
final Room room;
final RoomEvent event;
@protected
final String senderName;
final bool isMine;
final Room room;
Subtitle(this.event)
Subtitle(this.room, this.event)
: isMine = event?.sender == di.getLocalUser(),
room = event?.room,
senderName = event != null &&
event.sender != di.getLocalUser() &&
!event.room.isDirect
? '${displayNameOf(event.sender)}: '
: '';
senderName =
event != null && event.sender != di.getLocalUser() && !room.isDirect
? '${displayNameOf(event.sender)}: '
: '';
factory Subtitle.forChat(ChatOverview chat) {
// TODO: typingUsers should not contain nulls
......@@ -58,22 +56,22 @@ abstract class Subtitle extends StatelessWidget {
} else {
final event = chat.latestEvent;
if (event == null) {
return UnsupportedSubtitle(event);
return UnsupportedSubtitle(chat.room, event);
}
if (event is TextMessageEvent) {
return TextSubtitle(event);
return TextSubtitle(chat.room, event);
} else if (event is ImageMessageEvent) {
return ImageSubtitle(event);
return ImageSubtitle(chat.room, event);
} else if (event is MemberChangeEvent) {
return MemberSubtitle(event);
return MemberSubtitle(chat.room, event);
} else if (event is RedactedEvent) {
return RedactedSubtitle(event);
return RedactedSubtitle(chat.room, event);
} else if (event is TopicChangeEvent) {
return TopicSubtitle(event);
return TopicSubtitle(chat.room, event);
}
return UnsupportedSubtitle(event);
return UnsupportedSubtitle(chat.room, event);
}
}
......
......@@ -25,7 +25,7 @@ class TextSubtitle extends Subtitle {
@override
final TextMessageEvent event;
TextSubtitle(this.event) : super(event);
TextSubtitle(Room room, this.event) : super(room, event);
@override
Widget build(BuildContext context) {
......
......@@ -26,7 +26,7 @@ class TopicSubtitle extends Subtitle {
@override
final TopicChangeEvent event;
TopicSubtitle(this.event) : super(event);
TopicSubtitle(Room room, this.event) : super(room, event);
@override
Widget build(BuildContext context) {
......
......@@ -26,7 +26,7 @@ class TypingSubtitle extends Subtitle {
@override
final Room room;
TypingSubtitle(this.room) : super(null);
TypingSubtitle(this.room) : super(room, null);
@override
Widget build(BuildContext context) {
......
......@@ -21,7 +21,7 @@ import 'package:matrix_sdk/matrix_sdk.dart';
import 'subtitle.dart';
class UnsupportedSubtitle extends Subtitle {
UnsupportedSubtitle(RoomEvent event) : super(event);
UnsupportedSubtitle(Room room, RoomEvent event) : super(room, event);
@override
Widget build(BuildContext context) =>
......
......@@ -220,14 +220,14 @@ packages:
name: matrix_sdk
url: "https://pub.dartlang.org"
source: hosted
version: "0.24.3"
version: "0.25.0"
matrix_sdk_sqflite:
dependency: "direct main"
description:
name: matrix_sdk_sqflite
url: "https://pub.dartlang.org"
source: hosted
version: "0.18.0"
version: "0.19.0"
meta:
dependency: transitive
description:
......
......@@ -12,8 +12,8 @@ dependencies:
injector: ^1.0.8
matrix_sdk: ^0.24.3
matrix_sdk_sqflite: ^0.18.0
matrix_sdk: ^0.25.0
matrix_sdk_sqflite: ^0.19.0
sqflite: ^1.1.6
......
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