diff --git a/lib/view/pages/talk/chatDetails/chatInfo.dart b/lib/view/pages/talk/chatDetails/chatInfo.dart index 7b0d542..1b5dea7 100644 --- a/lib/view/pages/talk/chatDetails/chatInfo.dart +++ b/lib/view/pages/talk/chatDetails/chatInfo.dart @@ -47,7 +47,7 @@ class _ChatInfoState extends State { const SizedBox(height: 30), GestureDetector( child: UserAvatar( - username: widget.room.name, + id: isGroup ? widget.room.token : widget.room.name, isGroup: isGroup, size: 80, ), diff --git a/lib/view/pages/talk/chatDetails/participants/participantsListView.dart b/lib/view/pages/talk/chatDetails/participants/participantsListView.dart index 82e5b06..c05a096 100644 --- a/lib/view/pages/talk/chatDetails/participants/participantsListView.dart +++ b/lib/view/pages/talk/chatDetails/participants/participantsListView.dart @@ -21,7 +21,7 @@ class _ParticipantsListViewState extends State { body: ListView( children: widget.participantsResponse.data.map((participant) { return ListTile( - leading: UserAvatar(username: participant.actorId), + leading: UserAvatar(id: participant.actorId), title: Text(participant.displayName), subtitle: participant.statusMessage != null ? Text(participant.statusMessage!) : null, ); diff --git a/lib/view/pages/talk/components/chatTile.dart b/lib/view/pages/talk/components/chatTile.dart index cdbbe8a..5dac10b 100644 --- a/lib/view/pages/talk/components/chatTile.dart +++ b/lib/view/pages/talk/components/chatTile.dart @@ -31,6 +31,7 @@ class ChatTile extends StatefulWidget { class _ChatTileState extends State { late String username; + late UserAvatar circleAvatar; @override void initState() { @@ -38,6 +39,9 @@ class _ChatTileState extends State { SharedPreferences.getInstance().then((value) => { username = value.getString("username")! }); + + bool isGroup = widget.data.type != GetRoomResponseObjectConversationType.oneToOne; + circleAvatar = UserAvatar(id: isGroup ? widget.data.token : widget.data.name, isGroup: isGroup); } void setCurrentAsRead() { @@ -50,10 +54,9 @@ class _ChatTileState extends State { ).run().then((value) => widget.query(renew: true)); } + @override Widget build(BuildContext context) { - bool isGroup = widget.data.type != GetRoomResponseObjectConversationType.oneToOne; - UserAvatar circleAvatar = UserAvatar(username: widget.data.name, isGroup: isGroup); return Consumer(builder: (context, chatData, child) { return ListTile( diff --git a/lib/view/pages/talk/messageReactions.dart b/lib/view/pages/talk/messageReactions.dart index 633ec88..96e3a07 100644 --- a/lib/view/pages/talk/messageReactions.dart +++ b/lib/view/pages/talk/messageReactions.dart @@ -55,7 +55,7 @@ class _MessageReactionsState extends State { children: entry.value.map((e) { bool isSelf = AccountData().getUsername() == e.actorId; return ListTile( - leading: UserAvatar(username: e.actorId, isGroup: false), + leading: UserAvatar(id: e.actorId, isGroup: false), title: Text(e.actorDisplayName), subtitle: isSelf ? const Text("Du") diff --git a/lib/widget/userAvatar.dart b/lib/widget/userAvatar.dart index e564733..7a77bd8 100644 --- a/lib/widget/userAvatar.dart +++ b/lib/widget/userAvatar.dart @@ -1,23 +1,45 @@ +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; +import '../model/accountData.dart'; import '../model/endpointData.dart'; class UserAvatar extends StatelessWidget { - final String username; + final String id; final bool isGroup; final int size; - const UserAvatar({required this.username, this.isGroup = false, this.size = 20, super.key}); + const UserAvatar({required this.id, this.isGroup = false, this.size = 20, super.key}); @override Widget build(BuildContext context) { - return CircleAvatar( - foregroundImage: !isGroup ? Image.network("https://${EndpointData().nextcloud().full()}/avatar/$username/$size").image : null, - backgroundColor: Theme.of(context).primaryColor, - foregroundColor: Colors.white, - onForegroundImageError: !isGroup ? (o, t) {} : null, - radius: size.toDouble(), - child: isGroup ? Icon(Icons.group, size: size.toDouble()) : Icon(Icons.person, size: size.toDouble()), - ); - + if(isGroup) { + return CircleAvatar( + foregroundImage: Image( + image: CachedNetworkImageProvider( + "https://${AccountData().buildHttpAuthString()}@${EndpointData().nextcloud().full()}/ocs/v2.php/apps/spreed/api/v1/room/$id/avatar", + errorListener: (p0) {} + ) + ).image, + backgroundColor: Theme.of(context).primaryColor, + foregroundColor: Colors.white, + onForegroundImageError: (o, t) {}, + radius: size.toDouble(), + child: Icon(Icons.group, size: size.toDouble()), + ); + } else { + return CircleAvatar( + foregroundImage: Image( + image: CachedNetworkImageProvider( + "https://${EndpointData().nextcloud().full()}/avatar/$id/$size", + errorListener: (p0) {} + ), + ).image, + backgroundColor: Theme.of(context).primaryColor, + foregroundColor: Colors.white, + onForegroundImageError: (o, t) {}, + radius: size.toDouble(), + child: Icon(Icons.person, size: size.toDouble()), + ); + } } }