Files
GroundedHelper/frontend/lib/Grounded/see/group/ViewGroupChat.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

54 lines
1.6 KiB
Dart

import '../../about/external/data/GroupMessage.dart';
import '../../about/external/initial/GroupMessageRequest.dart';
import '../../about/external/initial/IdRequest.dart';
import '../../utils/ObjectConvertors.dart';
import '../parent/ParentViewModel.dart';
import 'ConnectGroupChat.dart';
class ViewGroupChat extends ParentViewModel {
ConnectGroupChat connection;
ViewGroupChat(super.context, this.connection);
void loadMessages(String groupId) async {
if (!await hasNetwork(() => loadMessages(groupId))) return;
showLoading("Opening the chat");
try {
final response =
await getDataManager().getGroupMessages(IdRequest(id: groupId));
closeLoading();
connection.onMessagesLoaded(getGroupMessageList(response.data));
} catch (e) {
handleError(e, () => loadMessages(groupId), () => dismissError(), "Retry");
}
}
/// The background refresh while the chat is open. Silent either way — a
/// missed poll is picked up by the next one.
void refresh(String groupId) async {
try {
final response =
await getDataManager().getGroupMessages(IdRequest(id: groupId));
connection.onMessagesLoaded(getGroupMessageList(response.data));
} catch (e) {
// Next tick tries again.
}
}
void send(GroupMessageRequest request) async {
try {
final response = await getDataManager().sendGroupMessage(request);
connection.onMessageSent(GroupMessage.fromJson(response.data));
} catch (e) {
connection.onSendFailed(request.body);
handleError(e, () => send(request), () => dismissError(), "Retry");
}
}
}