Files
GroundedHelper/frontend/lib/Grounded/about/external/data/Group.dart
alvocool 4b71257429 Add groups with shared goals, objectives and chat; drop the water tracker
Groups let people keep each other honest: create one or join with a
six-letter invite code. Each group has shared goals split into measurable
objectives (km, sessions, words) that every member logs toward, a
leaderboard of kept rate and streak with nudges, and a group chat where
check-ins and nudges appear as cards beside the talk. The open chat polls
for new messages.

Reached from a new Groups tab (Training moves into the day rail), a Home
"Your groups" rail that opens the chat, and a Group tile in the add sheet.
Mock mode seeds two groups, a joinable one and members who reply.

The water tracker is removed; it did not fit the app. Bottom sheets are
now square app-wide via the theme.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KhQh614DMeYoQEH9SoMRUw
2026-11-03 11:46:41 +03:00

95 lines
2.4 KiB
Dart

import '../../../utils/ObjectConvertors.dart';
import 'GroupGoal.dart';
import 'GroupMember.dart';
/// People keeping each other honest: members, the goals they share, and the
/// chat they talk in.
class Group {
String id;
String name;
String description;
String colourHex;
/// Six characters a friend types to join.
String inviteCode;
List<GroupMember> members;
List<GroupGoal> goals;
/// Messages the signed-in user has not seen yet.
int unread;
String lastMessage;
String lastAuthor;
DateTime? lastMessageAt;
Group({
this.id = "",
this.name = "",
this.description = "",
this.colourHex = "",
this.inviteCode = "",
List<GroupMember>? members,
List<GroupGoal>? goals,
this.unread = 0,
this.lastMessage = "",
this.lastAuthor = "",
this.lastMessageAt,
}) : members = members ?? <GroupMember>[],
goals = goals ?? <GroupGoal>[];
/// Average progress across the shared goals.
double get progress {
if (goals.isEmpty) {
return 0;
}
double total = 0;
for (GroupGoal goal in goals) {
total = total + goal.progress;
}
return total / goals.length;
}
bool get iOwn => members.any((member) => member.me && member.owner);
factory Group.fromJson(Map<String, dynamic> json) {
return Group(
id: json['id'] ?? "",
name: json['name'] ?? "",
description: json['description'] ?? "",
colourHex: json['colourHex'] ?? "",
inviteCode: json['inviteCode'] ?? "",
members: getGroupMemberList(json['members']),
goals: getGroupGoalList(json['goals']),
unread: json['unread'] ?? 0,
lastMessage: json['lastMessage'] ?? "",
lastAuthor: json['lastAuthor'] ?? "",
lastMessageAt: json['lastMessageAt'] == null
? null
: DateTime.tryParse(json['lastMessageAt']),
);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['id'] = id;
data['name'] = name;
data['description'] = description;
data['colourHex'] = colourHex;
data['inviteCode'] = inviteCode;
data['members'] = members.map((item) => item.toJson()).toList();
data['goals'] = goals.map((item) => item.toJson()).toList();
data['unread'] = unread;
data['lastMessage'] = lastMessage;
data['lastAuthor'] = lastAuthor;
data['lastMessageAt'] = lastMessageAt?.toIso8601String();
return data;
}
}