126 lines
4.1 KiB
Dart
126 lines
4.1 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import '../services/spam_protection_service.dart';
|
||
|
|
||
|
class UserActivityStatus extends StatelessWidget {
|
||
|
final SpamProtectionService spamService;
|
||
|
|
||
|
const UserActivityStatus({
|
||
|
super.key,
|
||
|
required this.spamService,
|
||
|
});
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final userId = spamService.getCurrentUserId();
|
||
|
final stats = spamService.getUserStats(userId);
|
||
|
final blockMessage = spamService.getBlockMessage(userId);
|
||
|
|
||
|
if (blockMessage != null) {
|
||
|
return Container(
|
||
|
margin: const EdgeInsets.all(16),
|
||
|
padding: const EdgeInsets.all(16),
|
||
|
decoration: BoxDecoration(
|
||
|
color: Colors.red.withOpacity(0.1),
|
||
|
borderRadius: BorderRadius.circular(12),
|
||
|
border: Border.all(color: Colors.red.withOpacity(0.3)),
|
||
|
),
|
||
|
child: Row(
|
||
|
children: [
|
||
|
const Icon(Icons.block, color: Colors.red),
|
||
|
const SizedBox(width: 12),
|
||
|
Expanded(
|
||
|
child: Text(
|
||
|
blockMessage,
|
||
|
style: const TextStyle(color: Colors.red, fontSize: 14),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
// Show activity limits if user is getting close
|
||
|
final votesUsed = stats['votesThisHour']!;
|
||
|
final suggestionsUsed = stats['suggestionsThisHour']!;
|
||
|
final maxVotes = stats['maxVotesPerHour']!;
|
||
|
final maxSuggestions = stats['maxSuggestionsPerHour']!;
|
||
|
|
||
|
final showWarning = votesUsed > maxVotes * 0.8 || suggestionsUsed > maxSuggestions * 0.8;
|
||
|
|
||
|
if (!showWarning) {
|
||
|
return const SizedBox.shrink();
|
||
|
}
|
||
|
|
||
|
return Container(
|
||
|
margin: const EdgeInsets.all(16),
|
||
|
padding: const EdgeInsets.all(12),
|
||
|
decoration: BoxDecoration(
|
||
|
color: Colors.orange.withOpacity(0.1),
|
||
|
borderRadius: BorderRadius.circular(12),
|
||
|
border: Border.all(color: Colors.orange.withOpacity(0.3)),
|
||
|
),
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
const Row(
|
||
|
children: [
|
||
|
Icon(Icons.warning, color: Colors.orange, size: 16),
|
||
|
SizedBox(width: 8),
|
||
|
Text(
|
||
|
'Activity Limits',
|
||
|
style: TextStyle(
|
||
|
color: Colors.orange,
|
||
|
fontWeight: FontWeight.bold,
|
||
|
fontSize: 12,
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
const SizedBox(height: 8),
|
||
|
Row(
|
||
|
children: [
|
||
|
Expanded(
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
'Votes: $votesUsed/$maxVotes',
|
||
|
style: const TextStyle(color: Colors.white, fontSize: 11),
|
||
|
),
|
||
|
LinearProgressIndicator(
|
||
|
value: votesUsed / maxVotes,
|
||
|
backgroundColor: Colors.grey.withOpacity(0.3),
|
||
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||
|
votesUsed > maxVotes * 0.9 ? Colors.red : Colors.orange,
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
const SizedBox(width: 16),
|
||
|
Expanded(
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
'Suggestions: $suggestionsUsed/$maxSuggestions',
|
||
|
style: const TextStyle(color: Colors.white, fontSize: 11),
|
||
|
),
|
||
|
LinearProgressIndicator(
|
||
|
value: suggestionsUsed / maxSuggestions,
|
||
|
backgroundColor: Colors.grey.withOpacity(0.3),
|
||
|
valueColor: AlwaysStoppedAnimation<Color>(
|
||
|
suggestionsUsed > maxSuggestions * 0.9 ? Colors.red : Colors.orange,
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|