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.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:sepot/core/crypto/attachment_cipher.dart';
|
||||
import 'package:sepot/core/storage/attachment_store.dart';
|
||||
|
||||
/// Odkaz na profilovou fotku: šifrovaný blob na relayi + klíč k němu.
|
||||
///
|
||||
/// Fotka sama nejde v každé zprávě — v profilu `p` cestuje jen tenhle
|
||||
/// odkaz (pár set bajtů). Příjemce blob stáhne jednou, ověří digest
|
||||
/// a drží si ho šifrovaný u sebe.
|
||||
class AvatarRef {
|
||||
const AvatarRef({
|
||||
required this.blobId,
|
||||
required this.key,
|
||||
required this.nonce,
|
||||
required this.digest,
|
||||
this.uploadedAt,
|
||||
});
|
||||
|
||||
/// Profilová fotka je malá (256 px JPEG) — cokoli většího je podvrh.
|
||||
static const maxBlobBytes = 256 * 1024;
|
||||
|
||||
final String blobId;
|
||||
final Uint8List key;
|
||||
final Uint8List nonce;
|
||||
final Uint8List digest;
|
||||
|
||||
/// Kdy jsem blob nahrál (jen u vlastní fotky — kvůli obnově před
|
||||
/// vypršením na relayi).
|
||||
final DateTime? uploadedAt;
|
||||
|
||||
Map<String, dynamic> toWire() => {
|
||||
'b': blobId,
|
||||
'k': base64Encode(key),
|
||||
'n': base64Encode(nonce),
|
||||
'd': base64Encode(digest),
|
||||
};
|
||||
|
||||
/// Odkaz od protistrany; cokoli podezřelého = null (fotka se neukáže).
|
||||
static AvatarRef? fromWire(Object? raw) {
|
||||
if (raw is! Map) return null;
|
||||
final b = raw['b'];
|
||||
if (b is! String || !AttachmentStore.isValidBlobId(b)) return null;
|
||||
try {
|
||||
final key = base64Decode(raw['k'] as String);
|
||||
final nonce = base64Decode(raw['n'] as String);
|
||||
final digest = base64Decode(raw['d'] as String);
|
||||
if (key.length != AttachmentCipher.keyLength ||
|
||||
nonce.length != AttachmentCipher.nonceLength ||
|
||||
digest.length != 32) {
|
||||
return null;
|
||||
}
|
||||
return AvatarRef(blobId: b, key: key, nonce: nonce, digest: digest);
|
||||
} on Object {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
...toWire(),
|
||||
if (uploadedAt != null) 'u': uploadedAt!.millisecondsSinceEpoch,
|
||||
};
|
||||
|
||||
static AvatarRef? fromJson(Object? raw) {
|
||||
final ref = fromWire(raw);
|
||||
if (ref == null || raw is! Map) return ref;
|
||||
final u = raw['u'];
|
||||
return u is int
|
||||
? AvatarRef(
|
||||
blobId: ref.blobId,
|
||||
key: ref.key,
|
||||
nonce: ref.nonce,
|
||||
digest: ref.digest,
|
||||
uploadedAt: DateTime.fromMillisecondsSinceEpoch(u),
|
||||
)
|
||||
: ref;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:sepot/models/avatar_ref.dart';
|
||||
import 'package:sepot/models/identity.dart';
|
||||
|
||||
/// Kontakt — osoba, se kterou můžeme chatovat
|
||||
@@ -14,6 +15,9 @@ class Contact {
|
||||
/// nezobrazí) a odesílání je v UI zablokované.
|
||||
bool blocked;
|
||||
|
||||
/// Profilová fotka, kterou kontakt sdílí (null = iniciály).
|
||||
AvatarRef? avatar;
|
||||
|
||||
Contact({
|
||||
required this.displayName,
|
||||
required this.publicIdentity,
|
||||
@@ -21,6 +25,7 @@ class Contact {
|
||||
this.verified = false,
|
||||
this.notes,
|
||||
this.blocked = false,
|
||||
this.avatar,
|
||||
});
|
||||
|
||||
/// ID kontaktu = fingerprint identity klíče (identita = klíč).
|
||||
@@ -58,6 +63,7 @@ class Contact {
|
||||
'verified': verified,
|
||||
'notes': notes,
|
||||
'blocked': blocked,
|
||||
'avatar': avatar?.toJson(),
|
||||
};
|
||||
|
||||
factory Contact.fromJson(Map<String, dynamic> json) {
|
||||
@@ -70,6 +76,7 @@ class Contact {
|
||||
verified: json['verified'] as bool? ?? false,
|
||||
notes: json['notes'] as String?,
|
||||
blocked: json['blocked'] as bool? ?? false,
|
||||
avatar: AvatarRef.fromJson(json['avatar']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,11 @@ class Conversation {
|
||||
DateTime lastActivity;
|
||||
int? disappearAfterSeconds; // Globální nastavení mizících zpráv
|
||||
|
||||
/// Ztlumení a archivace — čistě LOKÁLNÍ (neopouští zařízení).
|
||||
/// 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,
|
||||
@@ -22,6 +23,7 @@ class Conversation {
|
||||
this.muted = false,
|
||||
this.mutedUntil,
|
||||
this.archived = false,
|
||||
this.pinned = false,
|
||||
}) : messages = messages ?? [],
|
||||
lastActivity = lastActivity ?? DateTime.now();
|
||||
|
||||
@@ -75,6 +77,7 @@ class Conversation {
|
||||
'muted': muted,
|
||||
'mutedUntil': mutedUntil?.toIso8601String(),
|
||||
'archived': archived,
|
||||
'pinned': pinned,
|
||||
};
|
||||
|
||||
factory Conversation.fromJson(Map<String, dynamic> json) {
|
||||
@@ -92,6 +95,7 @@ class Conversation {
|
||||
? null
|
||||
: DateTime.parse(json['mutedUntil'] as String),
|
||||
archived: json['archived'] as bool? ?? false,
|
||||
pinned: json['pinned'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'package:sepot/models/attachment.dart';
|
||||
import 'package:sepot/models/call_log.dart';
|
||||
import 'package:sepot/models/group.dart';
|
||||
import 'package:sepot/models/poll.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
/// Typy zpráv — odpovídá Rust: MessageType
|
||||
@@ -11,8 +14,8 @@ enum MessageType {
|
||||
keyExchange,
|
||||
}
|
||||
|
||||
/// Stav odeslané (mojí) zprávy — poctivá hranice: read receipts zatím
|
||||
/// NEjsou (design: default OFF), takže „přečteno" se nezobrazuje.
|
||||
/// Stav odeslané (mojí) zprávy. Potvrzení přečtení je volitelné (default
|
||||
/// vypnuto) a reciproční — kdo ho nesdílí, „přečteno" neuvidí ani sám.
|
||||
/// sending — lokálně zařazeno, čeká na potvrzení relaye (⏱)
|
||||
/// sent — relay přijal, příjemce byl offline → v jeho frontě (✓)
|
||||
/// delivered — doručeno na zařízení příjemce (✓✓)
|
||||
@@ -43,6 +46,21 @@ class Message {
|
||||
final bool isDeleted; // smazáno pro všechny (tombstone)
|
||||
/// Reakce: fingerprint odesílatele reakce → emoji. Prázdné = žádné.
|
||||
final Map<String, String> reactions;
|
||||
/// Kdy mou zprávu dostal / přečetl který příjemce (fingerprint → čas).
|
||||
/// 1:1 má nejvýš jeden záznam, skupina jeden na člena — z toho se
|
||||
/// skládá „Info o zprávě". Čas je z hodin příjemce (pole `ts` doručenky).
|
||||
final Map<String, DateTime> deliveredTo;
|
||||
final Map<String, DateTime> readBy;
|
||||
|
||||
/// Anketa (textová zpráva, `content` nese záložní text pro starší appky).
|
||||
final Poll? poll;
|
||||
|
||||
/// Fingerprinty lidí zmíněných přes @ ve skupině — zmínka projde i přes
|
||||
/// ztlumení skupiny.
|
||||
final List<String> mentions;
|
||||
|
||||
/// Lokální záznam hovoru — taková zpráva nemá text ani přílohu.
|
||||
final CallLog? callLog;
|
||||
|
||||
const Message({
|
||||
required this.id,
|
||||
@@ -62,6 +80,11 @@ class Message {
|
||||
this.editedAt,
|
||||
this.isDeleted = false,
|
||||
this.reactions = const {},
|
||||
this.deliveredTo = const {},
|
||||
this.readBy = const {},
|
||||
this.poll,
|
||||
this.mentions = const [],
|
||||
this.callLog,
|
||||
});
|
||||
|
||||
/// Vytvoř textovou zprávu
|
||||
@@ -72,6 +95,8 @@ class Message {
|
||||
String? replyToId,
|
||||
int? disappearAfterSeconds,
|
||||
MessageStatus status = MessageStatus.sending,
|
||||
Poll? poll,
|
||||
List<String> mentions = const [],
|
||||
}) {
|
||||
return Message(
|
||||
id: const Uuid().v4(),
|
||||
@@ -83,6 +108,8 @@ class Message {
|
||||
timestamp: DateTime.now(),
|
||||
status: status,
|
||||
disappearAfterSeconds: disappearAfterSeconds,
|
||||
poll: poll,
|
||||
mentions: mentions,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -137,6 +164,9 @@ class Message {
|
||||
DateTime? editedAt,
|
||||
bool? isDeleted,
|
||||
Map<String, String>? reactions,
|
||||
Map<String, DateTime>? deliveredTo,
|
||||
Map<String, DateTime>? readBy,
|
||||
Poll? poll,
|
||||
}) {
|
||||
return Message(
|
||||
id: id,
|
||||
@@ -156,9 +186,22 @@ class Message {
|
||||
editedAt: editedAt ?? this.editedAt,
|
||||
isDeleted: isDeleted ?? this.isDeleted,
|
||||
reactions: reactions ?? this.reactions,
|
||||
deliveredTo: deliveredTo ?? this.deliveredTo,
|
||||
readBy: readBy ?? this.readBy,
|
||||
poll: poll ?? this.poll,
|
||||
mentions: mentions,
|
||||
callLog: callLog,
|
||||
);
|
||||
}
|
||||
|
||||
/// Nejdřívější doručení / přečtení napříč příjemci (null = zatím nic).
|
||||
DateTime? get firstDeliveredAt => _earliest(deliveredTo.values);
|
||||
DateTime? get firstReadAt => _earliest(readBy.values);
|
||||
|
||||
static DateTime? _earliest(Iterable<DateTime> times) => times.isEmpty
|
||||
? null
|
||||
: times.reduce((a, b) => a.isBefore(b) ? a : b);
|
||||
|
||||
/// Má zpráva mizet?
|
||||
bool get isDisappearing => disappearAfterSeconds != null;
|
||||
|
||||
@@ -183,8 +226,27 @@ class Message {
|
||||
'editedAt': editedAt?.toIso8601String(),
|
||||
'isDeleted': isDeleted,
|
||||
'reactions': reactions,
|
||||
'deliveredTo': _timesToJson(deliveredTo),
|
||||
'readBy': _timesToJson(readBy),
|
||||
'poll': poll?.toJson(),
|
||||
if (mentions.isNotEmpty) 'mentions': mentions,
|
||||
if (callLog != null) 'call': callLog!.toJson(),
|
||||
};
|
||||
|
||||
static Map<String, int> _timesToJson(Map<String, DateTime> times) =>
|
||||
times.map((k, v) => MapEntry(k, v.millisecondsSinceEpoch));
|
||||
|
||||
/// Tolerantní čtení: starší záznamy pole nemají, vadné položky se
|
||||
/// přeskočí — kvůli nim nesmí spadnout načtení celé konverzace.
|
||||
static Map<String, DateTime> _timesFromJson(Object? raw) {
|
||||
if (raw is! Map) return const {};
|
||||
return {
|
||||
for (final e in raw.entries)
|
||||
if (e.key is String && e.value is int)
|
||||
e.key as String: DateTime.fromMillisecondsSinceEpoch(e.value as int),
|
||||
};
|
||||
}
|
||||
|
||||
factory Message.fromJson(Map<String, dynamic> json) {
|
||||
return Message(
|
||||
id: json['id'] as String,
|
||||
@@ -215,6 +277,18 @@ class Message {
|
||||
reactions: (json['reactions'] as Map<String, dynamic>?)
|
||||
?.map((k, v) => MapEntry(k, v as String)) ??
|
||||
const {},
|
||||
deliveredTo: _timesFromJson(json['deliveredTo']),
|
||||
readBy: _timesFromJson(json['readBy']),
|
||||
poll: Poll.fromJson(json['poll']),
|
||||
mentions: mentionsFromWire(json['mentions']),
|
||||
callLog: CallLog.fromJson(json['call']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Zmínky z drátu i z úložiště: jen řetězce a rozumný počet — obálka od
|
||||
/// cizího klienta nesmí rozbít zprávu ani nafouknout úložiště.
|
||||
List<String> mentionsFromWire(Object? raw) {
|
||||
if (raw is! List) return const [];
|
||||
return raw.whereType<String>().take(Group.maxMembers).toList();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
/// Anketa uvnitř zprávy.
|
||||
///
|
||||
/// Na drátě jede jako běžná textová zpráva s polem `poll` — starší verze
|
||||
/// appky pole neznají a ukážou záložní text (otázku a možnosti), nové
|
||||
/// z něj vykreslí anketu. Hlasy jsou samostatné řídicí zprávy `vote`;
|
||||
/// klíč hlasu je otisk odesílatele ověřený sealed senderem, nikdy údaj
|
||||
/// z obsahu.
|
||||
class Poll {
|
||||
const Poll({
|
||||
required this.question,
|
||||
required this.options,
|
||||
this.multi = false,
|
||||
this.votes = const {},
|
||||
});
|
||||
|
||||
static const minOptions = 2;
|
||||
static const maxOptions = 12;
|
||||
static const maxQuestionLength = 200;
|
||||
static const maxOptionLength = 100;
|
||||
|
||||
final String question;
|
||||
final List<String> options;
|
||||
|
||||
/// Smí jeden člověk zvolit víc možností.
|
||||
final bool multi;
|
||||
|
||||
/// Otisk hlasujícího → zvolené indexy možností.
|
||||
final Map<String, List<int>> votes;
|
||||
|
||||
/// Kolik lidí zvolilo možnost [index].
|
||||
int countFor(int index) =>
|
||||
votes.values.where((choice) => choice.contains(index)).length;
|
||||
|
||||
/// Otisky lidí, kteří zvolili možnost [index].
|
||||
List<String> votersFor(int index) => [
|
||||
for (final e in votes.entries)
|
||||
if (e.value.contains(index)) e.key,
|
||||
];
|
||||
|
||||
int get voterCount => votes.length;
|
||||
|
||||
/// Nový hlas [voter]. Neplatné indexy se zahodí, duplicity sloučí;
|
||||
/// u ankety s jednou volbou platí jen první. Prázdná volba = hlas zrušen.
|
||||
Poll withVote(String voter, List<int> choice) {
|
||||
final clean = <int>[
|
||||
for (final i in choice.toSet())
|
||||
if (i >= 0 && i < options.length) i,
|
||||
]..sort();
|
||||
final picked = multi ? clean : clean.take(1).toList();
|
||||
final next = Map<String, List<int>>.from(votes);
|
||||
if (picked.isEmpty) {
|
||||
next.remove(voter);
|
||||
} else {
|
||||
next[voter] = picked;
|
||||
}
|
||||
return Poll(question: question, options: options, multi: multi, votes: next);
|
||||
}
|
||||
|
||||
/// Co jde na drát (bez hlasů — ty cestují zvlášť).
|
||||
Map<String, dynamic> toWire() => {
|
||||
'q': question,
|
||||
'o': options,
|
||||
if (multi) 'm': true,
|
||||
};
|
||||
|
||||
/// Anketa od protistrany. Cokoli mimo limity = null (zpráva se pak
|
||||
/// ukáže jako obyčejný text), aby cizí data nemohla rozbít vykreslení.
|
||||
static Poll? fromWire(Object? raw) {
|
||||
if (raw is! Map) return null;
|
||||
final q = raw['q'];
|
||||
final o = raw['o'];
|
||||
if (q is! String || o is! List) return null;
|
||||
final question = q.trim();
|
||||
if (question.isEmpty || question.length > maxQuestionLength) return null;
|
||||
final options = [
|
||||
for (final item in o)
|
||||
if (item is String) item.trim(),
|
||||
];
|
||||
if (options.length != o.length ||
|
||||
options.length < minOptions ||
|
||||
options.length > maxOptions ||
|
||||
options.any((x) => x.isEmpty || x.length > maxOptionLength)) {
|
||||
return null;
|
||||
}
|
||||
return Poll(question: question, options: options, multi: raw['m'] == true);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
...toWire(),
|
||||
'votes': votes,
|
||||
};
|
||||
|
||||
static Poll? fromJson(Object? raw) {
|
||||
final poll = fromWire(raw);
|
||||
if (poll == null || raw is! Map) return poll;
|
||||
final stored = raw['votes'];
|
||||
var result = poll;
|
||||
if (stored is Map) {
|
||||
for (final e in stored.entries) {
|
||||
final choice = e.value;
|
||||
if (e.key is String && choice is List) {
|
||||
result = result.withVote(
|
||||
e.key as String, choice.whereType<int>().toList());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user