Files
sepot/app/lib/models/conversation.dart
T
Julius Joska 5246a97db2 feat(app): redesigned interface, polls, drafts, forwarding and mentions
A new look across the app and a set of everyday messaging features.

Interface
- Home screen with Chats, Contacts and Settings tabs, a large title,
  search across chats and message text (diacritics-insensitive), filters
  and pinned chats.
- Conversation view with a translucent header and composer, grouped
  bubbles, author avatars and colours in groups, swipe to reply, an
  "N new messages" marker, a jump-to-latest button and in-chat search.
- Contact and group profiles: verification, shared photos, groups in
  common, disappearing messages, mute, block; members, admin badges,
  adding people, rename and leave for groups.
- Full-screen photo viewer that pages through the whole conversation.
- A stable avatar colour per person and a clearly visible read state.

Messaging
- Polls in chats and groups, single or multiple choice, with votes that
  can be changed or withdrawn; older clients see them as text.
- Drafts survive leaving a chat and show in the chat list.
- Forwarding of messages, photos, files and voice messages.
- Notes to self: a local-only, encrypted chat that never reaches the
  relay.
- @mentions in groups that notify even when the group is muted.
- Typing indicators sent as ephemeral messages, opt-in and mutual like
  read receipts.
- Delivery and read times per message and per group member.
- Profile photos, cropped, resized and stripped of metadata, delivered
  encrypted to contacts.
- Voice message playback at 1.5x and 2x.
- Call buttons in 1:1 chats and call log entries.

Fixes
- Muted groups no longer notify: muting was checked against the
  author's chat instead of the group.
- A blocked contact could unblock itself by changing its delivery
  address.
- Read receipts no longer regress to delivered when a late delivery
  receipt arrives.
- A message marked as failed corrects itself once it is delivered.
- Double ticks in groups now mean delivered to every member.
2026-10-03 22:44:53 +02:00

102 lines
3.5 KiB
Dart

import 'package:sepot/models/message.dart';
/// Konverzace s kontaktem
///
/// Odpovídá Rust: Conversation
class Conversation {
final String contactId;
final List<Message> messages;
DateTime lastActivity;
int? disappearAfterSeconds; // Globální nastavení mizících zpráv
/// Ztlumení, archivace a připnutí — čistě LOKÁLNÍ (neopouští zařízení).
bool muted;
DateTime? mutedUntil; // null + muted = navždy; jinak dočasně
bool archived;
bool pinned; // připnutý nahoře v seznamu chatů (lokální)
Conversation({
required this.contactId,
List<Message>? messages,
DateTime? lastActivity,
this.disappearAfterSeconds,
this.muted = false,
this.mutedUntil,
this.archived = false,
this.pinned = false,
}) : messages = messages ?? [],
lastActivity = lastActivity ?? DateTime.now();
/// Je konverzace teď ztlumená? (dočasné ztlumení sama vyprší)
bool get isMuted =>
muted && (mutedUntil == null || mutedUntil!.isAfter(DateTime.now()));
/// Poslední zpráva
Message? get lastMessage => messages.isEmpty ? null : messages.last;
/// Počet nepřečtených zpráv
int unreadCount(String myId) {
return messages
.where((m) => !m.isRead && m.senderId != myId)
.length;
}
/// Přidej zprávu. Vrací false, když už zpráva s tímhle id v konverzaci je.
///
/// Id zprávy nese odesílatel (pole `id` na drátě), takže opakované doručení
/// téhož obsahu — retry odesílatele po výpadku spojení nebo redelivery
/// z fronty relaye — nesmí založit druhou bublinu.
bool addMessage(Message message) {
if (messages.any((m) => m.id == message.id)) return false;
messages.add(message);
lastActivity = DateTime.now();
return true;
}
/// Nahraď zprávu se stejným id (změna stavu přílohy, doručenka…).
/// Neexistující id se tiše ignoruje (zpráva mohla být smazána).
void updateMessage(Message message) {
final index = messages.indexWhere((m) => m.id == message.id);
if (index >= 0) messages[index] = message;
}
/// Označ všechny zprávy jako přečtené
void markAllRead(String myId) {
for (var i = 0; i < messages.length; i++) {
if (!messages[i].isRead && messages[i].senderId != myId) {
messages[i] = messages[i].copyWith(isRead: true);
}
}
}
Map<String, dynamic> toJson() => {
'contactId': contactId,
'messages': messages.map((m) => m.toJson()).toList(),
'lastActivity': lastActivity.toIso8601String(),
'disappearAfterSeconds': disappearAfterSeconds,
'muted': muted,
'mutedUntil': mutedUntil?.toIso8601String(),
'archived': archived,
'pinned': pinned,
};
factory Conversation.fromJson(Map<String, dynamic> json) {
return Conversation(
contactId: json['contactId'] as String,
messages: (json['messages'] as List<dynamic>?)
?.map((m) => Message.fromJson(m as Map<String, dynamic>))
.toList() ??
[],
lastActivity: DateTime.parse(json['lastActivity'] as String),
disappearAfterSeconds: json['disappearAfterSeconds'] as int?,
// Defaulty — legacy JSON bez těchto klíčů musí projít
muted: json['muted'] as bool? ?? false,
mutedUntil: json['mutedUntil'] == null
? null
: DateTime.parse(json['mutedUntil'] as String),
archived: json['archived'] as bool? ?? false,
pinned: json['pinned'] as bool? ?? false,
);
}
}