Files
buzz/mobile/lib/features/activity/feed_item.dart
Tom Brow 8222e99915 fix(mobile): keep thread references consistent across push and Inbox (#8332)
Follow-up to [#8294](https://github.com/block/buzz/pull/8294). Malformed
trailing thread tags could make a notification open the right thread
while Flutter indexed its reply elsewhere; uppercase references could
similarly miss lowercase event IDs.

Share one validated thread-reference parser between the mobile timeline,
Inbox, and feed helper. It ignores malformed markers, keeps the last
valid root/reply, and normalizes lookup IDs to lowercase. Native push
parsing now uses the same casing. Existing thread fixtures use valid
event IDs so they continue exercising real thread relationships.

Add RunnerTests coverage for the production native-to-Flutter argument
conversion, including buffered cold-start navigation and omitted
optional thread IDs, and run it in the native CI lane.

### Validation

- New parser and Inbox regressions cover malformed markers and uppercase
references. Widget regressions open and highlight the exact reply for
valid, uppercase, and trailing-malformed tags.
- After integrating [#8106](https://github.com/block/buzz/pull/8106),
Flutter analysis and the complete mobile suite pass: 3,337 tests, four
existing skips. Integration preserves per-event read predicates and
migrates incoming thread fixtures to valid IDs. An unchanged
keyboard-history test also failed with main's original parser; recording
reads before the scroll transition fixes its timing assumption while
retaining visibility assertions.
- Native package tests passed (127 tests), and both Runner bridge tests
passed on an iOS simulator with Xcode 26.5. Removing the production
`threadRootId` assignment made the bridge regression fail; restoring it
passed. Native code is unchanged by the main integration.
- [Current-head CI
passed](https://github.com/block/buzz/actions/runs/38659307247),
including Mobile and Mobile Swift. [Codex
review](https://github.com/block/buzz/pull/8332#issuecomment-6181458528)
and [security
review](https://github.com/block/buzz/pull/8332#issuecomment-6181449235)
found no issues on the integrated commit. [Owner
approval](https://github.com/block/buzz/pull/8332#pullrequestreview-5526812957)
covers the exact integrated commit.
- Standards and spec reviews found no blockers, including the merge
resolutions and test adjustments. Validation is scoped to mobile/native
per VISION_MOBILE; unrelated repository-wide checks were stopped, not
counted as passing.

The bridge test covers serialization and buffering, not end-to-end APNs
delivery or app launch. No new physical-device acceptance is claimed;
routine post-merge dogfood remains human-owned.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
2026-10-14 18:42:39 -07:00

133 lines
3.8 KiB
Dart

import 'package:flutter/foundation.dart';
import '../../shared/relay/thread_reference.dart';
@immutable
class FeedItem {
final String id;
final int kind;
final String pubkey;
final String content;
final int createdAt;
final String? channelId;
final String channelName;
final List<List<String>> tags;
final String
category; // "mention", "needs_action", "activity", "agent_activity"
const FeedItem({
required this.id,
required this.kind,
required this.pubkey,
required this.content,
required this.createdAt,
required this.channelId,
required this.channelName,
required this.tags,
required this.category,
});
factory FeedItem.fromJson(Map<String, dynamic> json) => FeedItem(
id: json['id'] as String,
kind: json['kind'] as int,
pubkey: json['pubkey'] as String,
content: json['content'] as String,
createdAt: json['created_at'] as int,
channelId: json['channel_id'] as String?,
channelName: (json['channel_name'] as String?) ?? '',
tags:
(json['tags'] as List<dynamic>?)
?.map((t) => (t as List<dynamic>).map((e) => e as String).toList())
.toList() ??
const [],
category: json['category'] as String,
);
/// The message whose thread directly contains this item, when this event is
/// a reply. For nested replies this is the direct parent, not the outer root.
String? get threadHeadId => parseThreadReference(tags).parentId;
/// Human-readable headline based on event kind and category.
String get headline {
switch (kind) {
case 45001:
return 'Forum post';
case 45003:
return 'Forum reply';
case 46010:
return 'Approval requested';
case 43001:
return 'Job requested';
case 43002:
return 'Job accepted';
case 43003:
return 'Progress update';
case 43004:
return 'Job result';
case 43005:
return 'Job cancelled';
case 43006:
return 'Job failed';
default:
if (category == 'mention') return 'Mention';
if (category == 'agent_activity') return 'Agent update';
return 'Channel update';
}
}
/// Trimmed content, with a fallback for empty events.
String get displayContent {
final trimmed = content.trim();
if (trimmed.isNotEmpty) return trimmed;
if (kind == 46010) return 'A workflow is waiting for approval.';
return 'No additional details.';
}
}
/// Parsed response from GET /api/feed.
@immutable
class HomeFeedResponse {
final List<FeedItem> mentions;
final List<FeedItem> needsAction;
final List<FeedItem> activity;
final List<FeedItem> agentActivity;
HomeFeedResponse({
required this.mentions,
required this.needsAction,
required this.activity,
required this.agentActivity,
});
factory HomeFeedResponse.fromJson(Map<String, dynamic> json) {
final feed = json['feed'] as Map<String, dynamic>;
return HomeFeedResponse(
mentions: _parseItems(feed['mentions']),
needsAction: _parseItems(feed['needs_action']),
activity: _parseItems(feed['activity']),
agentActivity: _parseItems(feed['agent_activity']),
);
}
/// All items merged into a single list, sorted newest-first.
late final List<FeedItem> all = () {
final items = [...mentions, ...needsAction, ...activity, ...agentActivity];
items.sort((a, b) => b.createdAt.compareTo(a.createdAt));
return List<FeedItem>.unmodifiable(items);
}();
bool get isEmpty =>
mentions.isEmpty &&
needsAction.isEmpty &&
activity.isEmpty &&
agentActivity.isEmpty;
}
List<FeedItem> _parseItems(dynamic json) {
if (json == null) return const [];
return (json as List<dynamic>)
.cast<Map<String, dynamic>>()
.map(FeedItem.fromJson)
.toList();
}