Use each room message's author when bulk-bookmarking
This commit is contained in:
1 parent
d11865b175
commit
a8b57d54e9
2 files changed
+77
-11
No files matched your search
@@ -837,12 +837,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
if (isRoom) {
|
||||
// Room-server messages carry the original author's 4-byte prefix
|
||||
// separately from message.text; use it only for resolving the name.
|
||||
roomAuthor = _resolveContactFrom4Bytes(
|
||||
connector,
|
||||
message.fourByteRoomContactKey.isEmpty
|
||||
? Uint8List.fromList([0, 0, 0, 0])
|
||||
: message.fourByteRoomContactKey,
|
||||
);
|
||||
roomAuthor = _roomAuthorOf(connector, message);
|
||||
fourByteHex = message.fourByteRoomContactKey
|
||||
.map((b) => b.toRadixString(16).padLeft(2, '0'))
|
||||
.join()
|
||||
@@ -886,8 +881,9 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
? AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary
|
||||
.withValues(alpha: 0.18),
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary.withValues(alpha: 0.18),
|
||||
borderRadius: BorderRadius.circular(MeshRadii.md),
|
||||
),
|
||||
child: bubble,
|
||||
@@ -1117,6 +1113,15 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
return connector.contacts[_resolveContactIndex];
|
||||
}
|
||||
|
||||
/// The known author of a room-server post, or null when unknown.
|
||||
Contact? _roomAuthorOf(MeshCoreConnector connector, Message message) =>
|
||||
_resolveContactFrom4Bytes(
|
||||
connector,
|
||||
message.fourByteRoomContactKey.isEmpty
|
||||
? Uint8List.fromList([0, 0, 0, 0])
|
||||
: message.fourByteRoomContactKey,
|
||||
);
|
||||
|
||||
Contact? _resolveContactFrom4Bytes(
|
||||
MeshCoreConnector connector,
|
||||
Uint8List key4Bytes,
|
||||
@@ -1715,6 +1720,7 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
void _bulkBookmark(List<Message> messages) {
|
||||
final connector = context.read<MeshCoreConnector>();
|
||||
final contact = _resolveContact(connector);
|
||||
final isRoom = contact.type == advTypeRoom;
|
||||
final me = connector.selfName ?? context.l10n.chat_me;
|
||||
setState(_selectedIds.clear);
|
||||
for (final m in messages) {
|
||||
@@ -1724,7 +1730,10 @@ class _ChatScreenState extends State<ChatScreen> with WidgetsBindingObserver {
|
||||
message: m,
|
||||
contactKey: widget.contact.publicKeyHex,
|
||||
contactName: widget.contact.name,
|
||||
senderName: m.isOutgoing ? me : contact.name,
|
||||
senderName: m.isOutgoing
|
||||
? me
|
||||
: (isRoom ? _roomAuthorOf(connector, m) : null)?.name ??
|
||||
contact.name,
|
||||
),
|
||||
isBookmarked: true,
|
||||
),
|
||||
|
||||
@@ -69,13 +69,38 @@ void main() {
|
||||
for (final room in [false, true]) {
|
||||
final p = room ? 'room' : 'dm';
|
||||
_view(tester, const Size(400, 800));
|
||||
await _pumpChat(tester, room: room);
|
||||
final (connector, chat) = await _pumpChat(tester, room: room);
|
||||
// Room posts name their author by key prefix; the bookmark must carry
|
||||
// that author's name, not the room server's.
|
||||
final authors = connector.contacts
|
||||
.where((c) => c.type == advTypeChat)
|
||||
.take(2)
|
||||
.toList();
|
||||
final posts = ['by author one', 'by author two'];
|
||||
if (room) {
|
||||
expect(authors, hasLength(2));
|
||||
for (var i = 0; i < 2; i++) {
|
||||
connector.handleFrameForTest(
|
||||
_roomPost(chat, authors[i], posts[i], _stamp++),
|
||||
);
|
||||
}
|
||||
await _settle(tester);
|
||||
}
|
||||
await _enterChatSelection(tester, '$p 8');
|
||||
await tester.tap(
|
||||
find.textContaining('$p 9', findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
if (room) {
|
||||
for (final post in posts) {
|
||||
await tester.tap(
|
||||
find.textContaining(post, findRichText: true),
|
||||
warnIfMissed: false,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
}
|
||||
}
|
||||
await tester.tap(find.byTooltip('Bookmark'));
|
||||
await _settle(tester);
|
||||
// Bookmarks are stored per radio in the preferences; the writes
|
||||
@@ -85,7 +110,11 @@ void main() {
|
||||
for (final key in prefs.getKeys())
|
||||
if (key.startsWith('message_bookmarks_')) prefs.getString(key) ?? '',
|
||||
].join();
|
||||
for (var i = 0; i < 200 && !stored().contains('$p 9'); i++) {
|
||||
for (
|
||||
var i = 0;
|
||||
i < 200 && !stored().contains(room ? posts[1] : '$p 9');
|
||||
i++
|
||||
) {
|
||||
await tester.runAsync(
|
||||
() => Future<void>.delayed(const Duration(milliseconds: 50)),
|
||||
);
|
||||
@@ -95,6 +124,16 @@ void main() {
|
||||
expect(saved, contains('"text":"$p 8"'));
|
||||
expect(saved, contains('"text":"$p 9"'));
|
||||
expect(saved, isNot(contains('"text":"$p 7"')));
|
||||
if (room) {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
final entry = RegExp(
|
||||
'\\{[^{}]*"text":"${posts[i]}"[^{}]*\\}',
|
||||
).firstMatch(saved)?.group(0);
|
||||
expect(entry, isNotNull, reason: 'missing ${posts[i]}');
|
||||
expect(entry, contains('"senderName":"${authors[i].name}"'));
|
||||
expect(entry, isNot(contains('"senderName":"${chat.name}"')));
|
||||
}
|
||||
}
|
||||
expect(find.textContaining('selected'), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
}
|
||||
@@ -360,6 +399,24 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
/// A room-server post: a signed contact message whose 4-byte "signature" is
|
||||
/// the author's public key prefix.
|
||||
Uint8List _roomPost(Contact room, Contact author, String text, int stamp) {
|
||||
final writer = BufferWriter();
|
||||
writer.writeByte(respCodeContactMsgRecvV3);
|
||||
writer.writeByte(24);
|
||||
writer.writeByte(0);
|
||||
writer.writeByte(0);
|
||||
writer.writeBytes(Uint8List.fromList(room.publicKey.sublist(0, 6)));
|
||||
writer.writeByte(0xFF);
|
||||
writer.writeByte(txtTypeSigned);
|
||||
writer.writeUInt32LE(stamp);
|
||||
writer.writeBytes(Uint8List.fromList(author.publicKey.sublist(0, 4)));
|
||||
writer.writeString(text);
|
||||
writer.writeByte(0);
|
||||
return writer.toBytes();
|
||||
}
|
||||
|
||||
String? clipboard;
|
||||
|
||||
void _view(WidgetTester tester, Size size) {
|
||||
|
||||
Reference in new issue
Block a user