feat(ratings): Wallapop-style ratings in chat and offer detail
- SocialSession grows a ratings transport (fifth interface on the one shared channel). - PeerRatingCubit: count, locale-aware average, and circleCount — how many ratings come from your own circle (reuses the ego-centric trust rule), the signal that makes strangers' review-stuffing irrelevant. - Chat: slim rating strip under the trust banner; you can rate only someone you've talked with (soft anchor until the signed bilateral exchange form lands). Sheet with 5 stars + optional comment, pre-filled for editing, with a take-back action. - Offer detail: author's stars under their name, with 'N from people you know' when your circle rated them; nothing shown when unrated. - i18n ratings.* (en/es/pt/ast); tests for cubit and sheet.
This commit is contained in:
parent
acdacf1821
commit
1926e3bd98
18 changed files with 873 additions and 12 deletions
|
|
@ -15,8 +15,10 @@ import '../services/social_connection.dart';
|
|||
import '../services/social_service.dart';
|
||||
import '../services/unread_service.dart';
|
||||
import '../state/messages_cubit.dart';
|
||||
import '../state/peer_rating_cubit.dart';
|
||||
import '../state/trust_cubit.dart';
|
||||
import 'peer_avatar.dart';
|
||||
import 'rating_sheet.dart';
|
||||
import 'theme.dart';
|
||||
|
||||
/// A 1:1 encrypted chat with one peer (redesign screen 10). Private and
|
||||
|
|
@ -52,6 +54,7 @@ class ChatScreen extends StatefulWidget {
|
|||
class _ChatScreenState extends State<ChatScreen> {
|
||||
MessagesCubit? _messages;
|
||||
TrustCubit? _trust;
|
||||
PeerRatingCubit? _rating;
|
||||
bool _loading = true;
|
||||
String? _peerName;
|
||||
String? _peerG1;
|
||||
|
|
@ -94,9 +97,17 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||
selfPubkey: self,
|
||||
);
|
||||
unawaited(trust.load());
|
||||
final rating = PeerRatingCubit(
|
||||
session?.ratings,
|
||||
peerPubkey: widget.peerPubkey,
|
||||
selfPubkey: self,
|
||||
trust: session?.trust,
|
||||
);
|
||||
unawaited(rating.load());
|
||||
setState(() {
|
||||
_messages = messages;
|
||||
_trust = trust;
|
||||
_rating = rating;
|
||||
_peerName = cachedName;
|
||||
_loading = false;
|
||||
});
|
||||
|
|
@ -166,6 +177,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||
unawaited(_unread?.markRead(widget.peerPubkey));
|
||||
_messages?.close();
|
||||
_trust?.close();
|
||||
_rating?.close();
|
||||
// The session belongs to the shared connection — don't close it here.
|
||||
_input.dispose();
|
||||
super.dispose();
|
||||
|
|
@ -175,6 +187,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||
Widget build(BuildContext context) {
|
||||
final messages = _messages;
|
||||
final trust = _trust;
|
||||
final rating = _rating;
|
||||
final t = context.t;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
|
|
@ -189,12 +202,13 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||
),
|
||||
],
|
||||
),
|
||||
body: _loading || messages == null || trust == null
|
||||
body: _loading || messages == null || trust == null || rating == null
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider.value(value: messages),
|
||||
BlocProvider.value(value: trust),
|
||||
BlocProvider.value(value: rating),
|
||||
],
|
||||
child: _ChatBody(
|
||||
controller: _input,
|
||||
|
|
@ -244,6 +258,7 @@ class _ChatBody extends StatelessWidget {
|
|||
child: Column(
|
||||
children: [
|
||||
const _TrustBanner(),
|
||||
const _RatingStrip(),
|
||||
Expanded(child: ChatMessageList(peerName: peerName)),
|
||||
_Composer(controller: controller, onSend: onSend),
|
||||
],
|
||||
|
|
@ -353,6 +368,56 @@ class _TrustBanner extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
/// A slim reputation strip under the trust banner: everyone's stars for this
|
||||
/// peer (highlighting how many come from people you know) and, once you've
|
||||
/// actually talked with them, a button to leave or edit your own rating.
|
||||
class _RatingStrip extends StatelessWidget {
|
||||
const _RatingStrip();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final t = context.t;
|
||||
return BlocBuilder<PeerRatingCubit, PeerRatingState>(
|
||||
builder: (context, state) {
|
||||
final cubit = context.read<PeerRatingCubit>();
|
||||
if (!cubit.isOnline || state.loading) return const SizedBox.shrink();
|
||||
// Soft anchor: you can only rate someone you've talked with.
|
||||
final canRate = context.select<MessagesCubit, bool>(
|
||||
(m) => m.state.messages.isNotEmpty,
|
||||
);
|
||||
if (!state.hasRatings && !canRate) return const SizedBox.shrink();
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
color: seedPrimaryContainer.withValues(alpha: 0.3),
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 8, 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: state.hasRatings
|
||||
? RatingStars(
|
||||
average: state.average,
|
||||
count: state.count,
|
||||
circleCount: state.circleCount,
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
if (canRate)
|
||||
TextButton(
|
||||
key: const Key('chat.rate'),
|
||||
onPressed: state.busy
|
||||
? null
|
||||
: () => showRatingSheet(context, cubit),
|
||||
child:
|
||||
Text(state.iRated ? t.ratings.edit : t.ratings.rate),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A centered pill introducing a new day ("Today", "Yesterday", or a
|
||||
/// locale-formatted date). Localized via [chatDayLabel].
|
||||
class _DaySeparator extends StatelessWidget {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue