-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
322 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:rtchat/components/chat_history/decorated_event.dart'; | ||
import 'package:rtchat/models/channels.dart'; | ||
import 'package:rtchat/models/messages/twitch/raiding_event.dart'; | ||
import 'package:rtchat/models/user.dart'; | ||
|
||
class TwitchRaidingEventWidget extends StatelessWidget { | ||
final TwitchRaidingEventModel model; | ||
|
||
const TwitchRaidingEventWidget(this.model, {Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (!model.isComplete) { | ||
return StreamBuilder<int>( | ||
stream: Stream.periodic(const Duration(milliseconds: 500), (x) => x), | ||
builder: (context, snapshot) { | ||
final flash = snapshot.data == null || snapshot.data! % 2 == 0; | ||
final expiration = model.timestamp.add(model.duration); | ||
final remaining = expiration.difference(DateTime.now()); | ||
return Stack(children: [ | ||
Positioned.fill( | ||
child: AnimatedContainer( | ||
duration: const Duration(milliseconds: 500), | ||
color: flash | ||
? Theme.of(context).highlightColor | ||
: Theme.of(context).colorScheme.secondary)), | ||
DecoratedEventWidget.avatar( | ||
decoration: const BoxDecoration(color: Colors.transparent), | ||
avatar: NetworkImage(model.targetUser.profilePictureUrl), | ||
child: Row(children: [ | ||
Text.rich(TextSpan( | ||
children: [ | ||
const TextSpan(text: "Raiding "), | ||
TextSpan( | ||
text: model.targetUser.displayName, | ||
style: Theme.of(context).textTheme.subtitle2), | ||
const TextSpan(text: "."), | ||
], | ||
)), | ||
const Spacer(), | ||
Text.rich(TextSpan( | ||
text: remaining.isNegative | ||
? "0s" | ||
: "${remaining.inSeconds}s", | ||
style: Theme.of(context).textTheme.subtitle2)) | ||
])), | ||
]); | ||
}); | ||
} else if (model.isSuccessful) { | ||
return GestureDetector( | ||
child: DecoratedEventWidget.avatar( | ||
avatar: NetworkImage(model.targetUser.profilePictureUrl), | ||
child: Row(children: [ | ||
Text.rich(TextSpan( | ||
children: [ | ||
const TextSpan(text: "Raided "), | ||
TextSpan( | ||
text: model.targetUser.displayName, | ||
style: Theme.of(context).textTheme.subtitle2), | ||
const TextSpan(text: "."), | ||
], | ||
)), | ||
const Spacer(), | ||
Text.rich(TextSpan( | ||
text: "Join", | ||
style: Theme.of(context).textTheme.subtitle2?.copyWith( | ||
color: Theme.of(context) | ||
.buttonTheme | ||
.colorScheme | ||
?.primary))), | ||
])), | ||
onTap: () { | ||
final userModel = Provider.of<UserModel>(context, listen: false); | ||
userModel.activeChannel = model.targetUser.asChannel; | ||
}); | ||
} else { | ||
return DecoratedEventWidget.avatar( | ||
avatar: NetworkImage(model.targetUser.profilePictureUrl), | ||
child: Text.rich(TextSpan( | ||
children: [ | ||
const TextSpan(text: "Raid to "), | ||
TextSpan( | ||
text: model.targetUser.displayName, | ||
style: Theme.of(context).textTheme.subtitle2), | ||
const TextSpan(text: " canceled."), | ||
], | ||
))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:rtchat/models/messages/message.dart'; | ||
import 'package:rtchat/models/messages/twitch/user.dart'; | ||
|
||
class RaidingEventConfig { | ||
bool showEvent; | ||
Duration eventDuration; | ||
|
||
RaidingEventConfig(this.showEvent, this.eventDuration); | ||
|
||
RaidingEventConfig.fromJson(Map<String, dynamic> json) | ||
: showEvent = json['showEvent'], | ||
eventDuration = Duration(seconds: json['eventDuration'].toInt()); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"showEvent": showEvent, | ||
"eventDuration": eventDuration.inSeconds.toInt(), | ||
}; | ||
} | ||
|
||
class TwitchRaidingEventModel extends MessageModel { | ||
// we don't populate viewer count because it's not accurate anyways. | ||
final Duration duration; | ||
final TwitchUserModel targetUser; | ||
final bool isComplete; | ||
final bool isSuccessful; | ||
|
||
const TwitchRaidingEventModel( | ||
{required DateTime timestamp, | ||
required String messageId, | ||
required this.duration, | ||
required this.targetUser, | ||
this.isComplete = false, | ||
this.isSuccessful = false}) | ||
: super(messageId: messageId, timestamp: timestamp); | ||
|
||
static TwitchRaidingEventModel fromDocumentData(Map<String, dynamic> data) { | ||
return TwitchRaidingEventModel( | ||
timestamp: data['timestamp'].toDate(), | ||
messageId: "raiding.${data['raid']['id']}", | ||
duration: Duration(seconds: data['raid']['force_raid_now_seconds']), | ||
targetUser: TwitchUserModel( | ||
userId: data['raid']['target_id'], | ||
displayName: data['raid']['target_display_name'], | ||
login: data['raid']['target_login'], | ||
), | ||
); | ||
} | ||
|
||
TwitchRaidingEventModel withSuccessful() { | ||
return TwitchRaidingEventModel( | ||
timestamp: timestamp, | ||
messageId: messageId, | ||
duration: duration, | ||
targetUser: targetUser, | ||
isComplete: true, | ||
isSuccessful: true, | ||
); | ||
} | ||
|
||
TwitchRaidingEventModel withCancel() { | ||
return TwitchRaidingEventModel( | ||
timestamp: timestamp, | ||
messageId: messageId, | ||
duration: duration, | ||
targetUser: targetUser, | ||
isComplete: true, | ||
isSuccessful: false, | ||
); | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
other is TwitchRaidingEventModel && | ||
other.duration == duration && | ||
other.targetUser == targetUser && | ||
other.isComplete == isComplete && | ||
other.isSuccessful == isSuccessful; | ||
|
||
@override | ||
int get hashCode => | ||
hashValues(duration, targetUser, isComplete, isSuccessful); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.