Skip to content

Commit

Permalink
chore: clean up subscription events
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 committed May 12, 2024
1 parent fb73599 commit 5bb09db
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 54 deletions.
104 changes: 50 additions & 54 deletions lib/components/chat_history/twitch/subscription_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ import 'package:rtchat/models/messages/twitch/subscription_message_event.dart';
import 'package:rtchat/models/style.dart';
import 'package:rtchat/models/user.dart';

Color tierColor(BuildContext context, String tier) {
if (tier == '2000') {
return const Color(0xFF9A93A9);
} else if (tier == '3000') {
return const Color(0xFFC09C39);
} else {
return Theme.of(context).colorScheme.primary;
}
}

class TwitchSubscriptionEventWidget extends StatelessWidget {
final TwitchSubscriptionEventModel model;

const TwitchSubscriptionEventWidget(this.model, {super.key});

@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme.titleSmall;
return DecoratedEventWidget.icon(
icon: Icons.star,
child: Text.rich(
Expand All @@ -24,9 +35,11 @@ class TwitchSubscriptionEventWidget extends StatelessWidget {
TextSpan(
text: model.subscriberUserName,
style: Theme.of(context).textTheme.titleSmall),
const TextSpan(text: " subscribed "),
TextSpan(
text:
" subscribed at Tier ${model.tier.replaceAll("000", "")}."),
text: "Tier ${model.tier.replaceAll("000", "")}",
style: textTheme?.copyWith(color: tierColor(context, model.tier)),
),
],
),
),
Expand All @@ -41,22 +54,23 @@ class TwitchSubscriptionGiftEventWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme.titleSmall;
return DecoratedEventWidget.icon(
icon: Icons.star,
icon: Icons.redeem,
child: Text.rich(
TextSpan(
children: [
TextSpan(text: model.gifterUserName, style: textTheme),
TextSpan(text: " gifted ${model.total} "),
TextSpan(
text: model.gifterUserName,
style: Theme.of(context).textTheme.titleSmall),
text: "Tier ${model.tier.replaceAll("000", "")}",
style:
textTheme?.copyWith(color: tierColor(context, model.tier))),
TextSpan(
text:
" gifted ${model.total} Tier ${model.tier.replaceAll("000", "")} "),
TextSpan(
text: model.total > 1 ? "subscriptions. " : "subscription. "),
text: model.total > 1 ? " subscriptions" : " subscription"),
TextSpan(
text: model.cumulativeTotal > 0
? "They've gifted ${model.cumulativeTotal} subs in the channel"
? " (${model.cumulativeTotal} total)"
: ""),
],
),
Expand All @@ -70,16 +84,6 @@ class TwitchSubscriptionMessageEventWidget extends StatelessWidget {

const TwitchSubscriptionMessageEventWidget(this.model, {super.key});

Color chipBackgroundColor(BuildContext context, String tier) {
if (tier == '2000') {
return const Color(0xFF9A93A9);
} else if (tier == '3000') {
return const Color(0xFFC09C39);
} else {
return Theme.of(context).colorScheme.secondary;
}
}

Iterable<InlineSpan> _render(
BuildContext context, StyleModel styleModel, MessageToken token) sync* {
final tagStyleStreamer = TextStyle(
Expand Down Expand Up @@ -128,53 +132,45 @@ class TwitchSubscriptionMessageEventWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
return DecoratedEventWidget(
padding: const EdgeInsets.symmetric(horizontal: 12),
final textTheme = Theme.of(context).textTheme.titleSmall;
return DecoratedEventWidget.icon(
icon: Icons.star,
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text.rich(
TextSpan(
children: [
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Padding(
padding: const EdgeInsets.only(right: 8),
child: Chip(
label: Text("Tier ${model.tier.replaceAll("000", "")}"),
backgroundColor: chipBackgroundColor(context, model.tier),
),
),
),
TextSpan(
text: model.subscriberUserName,
style: Theme.of(context).textTheme.titleSmall),
const TextSpan(text: " subscribed for "),
const TextSpan(text: " subscribed "),
TextSpan(
text: "Tier ${model.tier.replaceAll("000", "")}",
style:
textTheme?.copyWith(color: tierColor(context, model.tier)),
),
const TextSpan(text: " for "),
TextSpan(
text: model.cumulativeMonths == 1
? "1 month!"
: "${model.cumulativeMonths} months!",
style: Theme.of(context).textTheme.titleSmall),
? "1 month"
: "${model.cumulativeMonths} months",
style: textTheme),
],
),
),
if (model.text.isNotEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child:
Consumer<StyleModel>(builder: (context, styleModel, child) {
return Text.rich(
TextSpan(
children: [
TextSpan(
text: model.subscriberUserName,
style: Theme.of(context).textTheme.titleSmall),
const TextSpan(text: ": "),
...model.tokenize().expand((token) {
return _render(context, styleModel, token);
}),
],
),
);
})),
Consumer<StyleModel>(builder: (context, styleModel, child) {
return Text.rich(
TextSpan(
children: [
TextSpan(text: model.subscriberUserName, style: textTheme),
const TextSpan(text: ": "),
...model.tokenize().expand((token) {
return _render(context, styleModel, token);
}),
],
),
);
}),
]),
);
}
Expand Down
29 changes: 29 additions & 0 deletions lib/screens/settings/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import 'package:rtchat/models/messages/twitch/hype_train_event.dart';
import 'package:rtchat/models/messages/twitch/prediction_event.dart';
import 'package:rtchat/models/messages/twitch/raiding_event.dart';
import 'package:rtchat/models/messages/twitch/subscription_event.dart';
import 'package:rtchat/models/messages/twitch/subscription_gift_event.dart';
import 'package:rtchat/models/messages/twitch/subscription_message_event.dart';
import 'package:rtchat/models/messages/twitch/user.dart';

class EventsScreen extends StatelessWidget {
Expand Down Expand Up @@ -70,6 +72,33 @@ class EventsScreen extends StatelessWidget {
subscriberUserName: 'muxfd',
tier: '1000',
)))),
Padding(
padding: const EdgeInsets.fromLTRB(16, 20, 16, 0),
child: StyleModelTheme(
child: TwitchSubscriptionGiftEventWidget(
TwitchSubscriptionGiftEventModel(
messageId: '',
timestamp: DateTime.now(),
tier: '2000',
gifterUserName: 'muxfd',
total: 10,
cumulativeTotal: 20,
)))),
Padding(
padding: const EdgeInsets.fromLTRB(16, 20, 16, 0),
child: StyleModelTheme(
child: TwitchSubscriptionMessageEventWidget(
TwitchSubscriptionMessageEventModel(
messageId: '',
timestamp: DateTime.now(),
subscriberUserName: 'muxfd',
tier: '3000',
cumulativeMonths: 10,
durationMonths: 10,
streakMonths: 10,
emotes: [],
text: 'Thanks for the stream!',
)))),
EventConfigListTile(
title: const Text('Subscribe event config'),
subtitle: const Text('Customize your subscription event'),
Expand Down

0 comments on commit 5bb09db

Please sign in to comment.