Commit cad238c6 authored by Wilko Manger's avatar Wilko Manger

Remove avatar url and display name extensions

parent d7725e2c
......@@ -24,12 +24,12 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:meta/meta.dart';
import 'package:bloc/bloc.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/section/main/chats/models/chat.dart';
import 'package:pattle/src/section/main/models/chat_member.dart';
import '../auth/bloc.dart';
import '../matrix.dart';
import '../util/room.dart';
import '../util/url.dart';
import 'event.dart';
......@@ -174,9 +174,11 @@ class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
return;
}
final chat = Chat(room: room);
await plugin.show(
event.id.hashCode,
room.getDisplayName(),
chat.name,
message.text,
NotificationDetails(
AndroidNotificationDetails(
......@@ -190,8 +192,7 @@ class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
style: AndroidNotificationStyle.Messaging,
styleInformation: MessagingStyleInformation(
senderPerson,
conversationTitle:
!room.isDirect ? await room.getDisplayName() : null,
conversationTitle: !room.isDirect ? await chat.name : null,
groupConversation: room.isDirect,
messages: [message],
),
......
......@@ -33,7 +33,6 @@ import 'package:pattle/src/section/main/widgets/title_with_sub.dart';
import '../../../matrix.dart';
import '../../../util/color.dart';
import '../../../util/room.dart';
import '../../../util/url.dart';
import 'bloc.dart';
......@@ -88,7 +87,7 @@ class _ChatPageState extends State<ChatPage> {
@override
Widget build(BuildContext context) {
Widget avatar = Container();
final avatarUrl = widget.chat.room.displayAvatarUrl;
final avatarUrl = widget.chat.avatarUrl;
if (avatarUrl != null) {
avatar = Hero(
tag: _room.id,
......
......@@ -31,7 +31,6 @@ import 'package:pattle/src/section/main/widgets/chat_member_tile.dart';
import '../../../../matrix.dart';
import '../../../../util/url.dart';
import '../../../../util/color.dart';
import '../../../../util/room.dart';
import 'bloc.dart';
class ChatSettingsPage extends StatefulWidget {
......@@ -69,8 +68,7 @@ class _ChatSettingsPageState extends State<ChatSettingsPage> {
),
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
final url =
widget.chat.room.displayAvatarUrl?.toDownloadString(context);
final url = widget.chat.avatarUrl?.toDownloadString(context);
return <Widget>[
SliverAppBar(
expandedHeight: 128.0,
......
......@@ -77,7 +77,6 @@ class ChatsBloc extends Bloc<ChatsEvent, ChatsState> {
final chat = Chat(
room: room,
name: await room.getDisplayName(),
isJustYou: room.members.count == 1,
latestMessage: latestEvent != null
? await ChatMessage.create(
......
......@@ -24,8 +24,12 @@ import 'package:pattle/src/section/main/models/chat_message.dart';
class Chat {
final Room room;
// TODO: When members are able to being accessed syncly, use member names
// for groups
final String name;
final Uri avatarUrl;
final ChatMessage latestMessage;
final ChatMessage latestMessageForSorting;
......@@ -35,10 +39,12 @@ class Chat {
Chat({
@required this.room,
@required this.name,
@required this.latestMessage,
@required this.latestMessageForSorting,
this.latestMessage,
this.latestMessageForSorting,
this.isJustYou = false,
this.directMember,
});
}) : name = room.name ??
(room.isDirect ? directMember.name : room.id.toString()),
avatarUrl = room.avatarUrl ??
(room.isDirect ? directMember.user.avatarUrl : room.avatarUrl);
}
......@@ -22,7 +22,6 @@ 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';
......@@ -33,7 +32,7 @@ class ChatAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final avatarUrl = chat.room.displayAvatarUrl;
final avatarUrl = chat.avatarUrl;
if (avatarUrl != null) {
return Container(
width: 48,
......
......@@ -15,71 +15,9 @@
// You should have received a copy of the GNU Affero General Public License
// along with Pattle. If not, see <https://www.gnu.org/licenses/>.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:matrix_sdk/matrix_sdk.dart';
import 'package:pattle/src/resources/localizations.dart';
import '../matrix.dart';
// TODO: Incorporate into Chat
extension RoomExtension on Room {
Uri get displayAvatarUrl =>
avatarUrl ?? (isDirect ? directUser.avatarUrl : avatarUrl);
FutureOr<String> getDisplayName([BuildContext context]) {
if (name != null) {
return name;
}
if (isDirect) {
return directUser.name;
}
String calculateName(Iterable<User> members) {
var name = '';
if (members != null) {
if (members.length == 1 && context != null) {
return l(context).you;
// TODO: Check for aliases (public chats)
} else {
final nonMeMembers = members
.where(
(user) => context != null && user != Matrix.of(context).user)
.toList(growable: false);
var i = 0;
for (User member in nonMeMembers) {
if (i > 4) {
name += ' ${l(context).andOthers}';
break;
}
name += member.name;
if (i != nonMeMembers.length - 1) {
name += ', ';
}
i++;
}
}
} else {
return id.toString();
}
return name.isNotEmpty ? name : id.toString();
}
final futureOrMembers = members.get(upTo: 6);
if (futureOrMembers is Future<Iterable<User>>) {
return futureOrMembers.then(calculateName);
} else {
return calculateName(futureOrMembers);
}
}
List<Type> get ignoredEvents => [
RedactionEvent,
AvatarChangeEvent,
......
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