Skip to content

Commit d201ef3

Browse files
sm-sayedichrisbobbe
andcommitted
content: Add UserStatusEmoji widget
Co-authored-by: Chris Bobbe <[email protected]>
1 parent 2f9faa7 commit d201ef3

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

lib/widgets/content.dart

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import '../generated/l10n/zulip_localizations.dart';
1414
import '../model/avatar_url.dart';
1515
import '../model/binding.dart';
1616
import '../model/content.dart';
17+
import '../model/emoji.dart';
1718
import '../model/internal_link.dart';
1819
import '../model/katex.dart';
1920
import '../model/presence.dart';
2021
import 'actions.dart';
2122
import 'code_block.dart';
2223
import 'dialog.dart';
24+
import 'emoji.dart';
2325
import 'icons.dart';
2426
import 'inset_shadow.dart';
2527
import 'lightbox.dart';
@@ -1933,6 +1935,75 @@ class _PresenceCircleState extends State<PresenceCircle> with PerAccountStoreAwa
19331935
}
19341936
}
19351937

1938+
/// A user status emoji to be displayed in different parts of the app.
1939+
///
1940+
/// Use [neverAnimate] to forcefully disable the animation for animated emojis.
1941+
class UserStatusEmoji extends StatelessWidget {
1942+
const UserStatusEmoji({
1943+
super.key,
1944+
required this.userId,
1945+
required this.size,
1946+
required this.notoColorEmojiTextSize,
1947+
this.neverAnimate = true,
1948+
});
1949+
1950+
final int userId;
1951+
final double size;
1952+
final double notoColorEmojiTextSize;
1953+
final bool neverAnimate;
1954+
1955+
/// Creates a [WidgetSpan] with a [UserStatusEmoji], for use in rich text
1956+
/// after a user's name.
1957+
static InlineSpan asWidgetSpan({
1958+
required int userId,
1959+
required double size,
1960+
required double notoColorEmojiTextSize,
1961+
bool noAnimation = true,
1962+
}) {
1963+
return WidgetSpan(
1964+
alignment: PlaceholderAlignment.middle,
1965+
child: Padding(
1966+
padding: const EdgeInsetsDirectional.only(start: 4.0),
1967+
child: UserStatusEmoji(userId: userId, size: size,
1968+
notoColorEmojiTextSize: notoColorEmojiTextSize, neverAnimate: noAnimation)));
1969+
}
1970+
1971+
@override
1972+
Widget build(BuildContext context) {
1973+
final store = PerAccountStoreWidget.of(context);
1974+
final emoji = store.getUserStatus(userId).emoji;
1975+
1976+
final placeholder = SizedBox.shrink();
1977+
if (emoji == null) return placeholder;
1978+
1979+
final emojiDisplay = store.emojiDisplayFor(
1980+
emojiType: emoji.reactionType,
1981+
emojiCode: emoji.emojiCode,
1982+
emojiName: emoji.emojiName)
1983+
// Web doesn't seem to respect the emojiset user settings for user status.
1984+
// .resolve(store.userSettings)
1985+
;
1986+
return switch (emojiDisplay) {
1987+
UnicodeEmojiDisplay() => UnicodeEmojiWidget(
1988+
size: size,
1989+
emojiDisplay: emojiDisplay,
1990+
notoColorEmojiTextSize: notoColorEmojiTextSize,
1991+
),
1992+
ImageEmojiDisplay() => ImageEmojiWidget(
1993+
size: size,
1994+
emojiDisplay: emojiDisplay,
1995+
neverAnimate: neverAnimate,
1996+
// If image emoji fails to load, show nothing.
1997+
errorBuilder: (_, _, _) => placeholder,
1998+
),
1999+
// The user-status feature doesn't support a :text_emoji:-style display.
2000+
// Also, if an image emoji's URL string doesn't parse, it'll fall back to
2001+
// a :text_emoji:-style display. We show nothing for this case.
2002+
TextEmojiDisplay() => placeholder,
2003+
};
2004+
}
2005+
}
2006+
19362007
//
19372008
// Small helpers.
19382009
//

0 commit comments

Comments
 (0)