Skip to content

Commit

Permalink
TW-893: Remove pill on mentionned users
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian KOUNE committed Nov 7, 2023
1 parent 8245805 commit fd9a0c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 45 deletions.
5 changes: 4 additions & 1 deletion lib/pages/chat/events/html_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,14 @@ class HtmlMessage extends StatelessWidget {
if (chatController == null) {
return null;
}
return Pill(
return TaggedUser(
identifier: identifier,
chatController: chatController!,
url: url,
onTap: onTap,
textStyle: defaultTextStyle?.copyWith(
color: themeData.colorScheme.primary,
),
);
},
);
Expand Down
57 changes: 13 additions & 44 deletions lib/widgets/pill.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import 'package:fluffychat/pages/chat/chat.dart';
import 'package:fluffychat/presentation/extensions/send_file_extension.dart';
import 'package:fluffychat/utils/string_extension.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_matrix_html/text_parser.dart';
import 'package:matrix/matrix.dart';

class Pill extends StatelessWidget {
class TaggedUser extends StatelessWidget {
final String identifier;
final String url;
final OnPillTap? onTap;
final TextStyle? textStyle;
final ChatController chatController;

const Pill({
const TaggedUser({
Key? key,
required this.identifier,
required this.chatController,
required this.url,
this.textStyle,
this.onTap,
}) : super(key: key);

Expand All @@ -27,48 +26,18 @@ class Pill extends StatelessWidget {
Widget build(BuildContext context) {
final user = chatController.room?.getUser(identifier);
final displayName = user?.displayName ?? identifier;
final avatarUrl =
user?.avatarUrl?.getDownloadLink(Matrix.of(context).client);
final avatarSize = DefaultTextStyle.of(context).style.fontSize ?? 14.0;
final padding = avatarSize / 20;
return InkWell(
child: Container(
padding: EdgeInsets.only(
top: padding,
bottom: padding,
left: avatarUrl != null ? padding * 3 : avatarSize / 2,
right: avatarSize / 2,
),
decoration: BoxDecoration(
color: Colors.grey[800],
borderRadius: BorderRadius.all(Radius.circular(avatarSize + padding)),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
if (avatarUrl?.toString().isNotEmpty == true)
CircleAvatar(
radius: avatarSize / 2,
backgroundImage:
CachedNetworkImageProvider(avatarUrl!.toString()),
),
Flexible(
child: Text(
displayName.shortenDisplayName(
maxCharacters: maxCharactersDisplayNameForPill,
),
style: const TextStyle(color: Colors.white),
maxLines: 1,
overflow: TextOverflow.clip,
),
),
],
),
),
return GestureDetector(
onTap: () {
onTap?.call(url);
},
child: Text(
displayName.shortenDisplayName(
maxCharacters: maxCharactersDisplayNameForPill,
),
style: textStyle,
maxLines: 1,
overflow: TextOverflow.clip,
),
);
}
}

0 comments on commit fd9a0c4

Please sign in to comment.