Commit d7725e2c authored by Wilko Manger's avatar Wilko Manger

Use Chat in ChatAvatar

parent 307c9387
......@@ -97,6 +97,13 @@ class ChatsBloc extends Bloc<ChatsEvent, ChatsState> {
),
)
: null,
directMember: room.isDirect
? await ChatMember.fromUser(
room,
room.directUser,
isYou: room.directUser == _matrix.user,
)
: null,
);
chats.add(chat);
......
......@@ -17,6 +17,7 @@
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:meta/meta.dart';
import 'package:pattle/src/section/main/models/chat_member.dart';
import 'package:pattle/src/section/main/models/chat_message.dart';
/// Chat overview used in the 'chats' page.
......@@ -30,11 +31,14 @@ class Chat {
final bool isJustYou;
final ChatMember directMember;
Chat({
@required this.room,
@required this.name,
@required this.latestMessage,
@required this.latestMessageForSorting,
this.isJustYou = false,
this.directMember,
});
}
......@@ -17,21 +17,23 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:mdi/mdi.dart';
import 'package:pattle/src/resources/theme.dart';
import 'package:pattle/src/section/main/chats/models/chat.dart';
import 'package:transparent_image/transparent_image.dart';
import '../../../../util/room.dart';
import '../../../../util/chat_member.dart';
import '../../../../util/url.dart';
class ChatAvatar extends StatelessWidget {
final Room room;
final Chat chat;
const ChatAvatar({Key key, this.room}) : super(key: key);
const ChatAvatar({Key key, this.chat}) : super(key: key);
@override
Widget build(BuildContext context) {
final avatarUrl = room.displayAvatarUrl;
final avatarUrl = chat.room.displayAvatarUrl;
if (avatarUrl != null) {
return Container(
width: 48,
......@@ -49,10 +51,9 @@ class ChatAvatar extends StatelessWidget {
} else {
return CircleAvatar(
foregroundColor: Colors.white,
// TODO: Use Chat
/*backgroundColor: room.isDirect
? room.directUser.color(context)
: LightColors.red[500],*/
backgroundColor: chat.room.isDirect
? chat.directMember.color(context)
: LightColors.red[500],
radius: 24,
child: _icon(),
);
......@@ -60,9 +61,9 @@ class ChatAvatar extends StatelessWidget {
}
Icon _icon() {
if (room.isDirect) {
if (chat.room.isDirect) {
return Icon(Icons.person);
} else if (room.aliases != null && room.aliases.isNotEmpty) {
} else if (chat.room.aliases != null && chat.room.aliases.isNotEmpty) {
return Icon(Mdi.bullhorn);
} else {
return Icon(Icons.group);
......
......@@ -77,7 +77,7 @@ class ChatListState extends State<ChatList> {
onTap: () {
Navigator.pushNamed(context, Routes.chats, arguments: chat);
},
leading: ChatAvatar(room: chat.room),
leading: ChatAvatar(chat: chat),
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),
subtitle: Subtitle.withContent(chat),
);
......
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