simplify: dedupe boilerplate and remove dead code across all layers

This commit is contained in:
2026-07-13 22:22:39 +02:00
parent 15791423ea
commit 398b147c76
69 changed files with 345 additions and 651 deletions
+7 -11
View File
@@ -110,10 +110,7 @@ class _ChatViewState extends State<ChatView> with RouteAware {
if (state.currentToken != widget.room.token) return;
final response = state.chatResponse;
if (response == null) return;
var maxId = 0;
for (final m in response.data) {
if (m.id > maxId) maxId = m.id;
}
final maxId = response.data.map((m) => m.id).fold<int>(0, math.max);
if (maxId == 0) return;
_chatListBlocRef?.markRoomAsRead(widget.room.token, maxId);
unawaited(_chatBlocRef!.sendServerReadMarker(widget.room.token, maxId));
@@ -230,21 +227,20 @@ class _ChatViewState extends State<ChatView> with RouteAware {
? _searchQuery
: null;
final commonRead = int.parse(
response.headers?['x-chat-last-common-read'] ?? '0',
);
final messages = <Widget>[];
final chronologicalMatchIndex = <int, int>{};
var lastDate = DateTime.now();
for (final element in response.sortByTimestamp()) {
if (ChatSearchController.isHiddenSystemMessage(element)) continue;
final elementDate = DateTime.fromMillisecondsSinceEpoch(
element.timestamp * 1000,
);
if (element.systemMessage.contains('reaction')) continue;
if (element.systemMessage.contains('poll_voted')) continue;
if (element.systemMessage.contains('message_deleted')) continue;
final commonRead = int.parse(
response.headers?['x-chat-last-common-read'] ?? '0',
);
if (!elementDate.isSameDay(lastDate)) {
lastDate = elementDate;
messages.add(
@@ -4,18 +4,6 @@ import '../../../../theming/app_theme.dart';
import '../widgets/bubble.dart';
extension ColorExtensions on Color {
Color invert() {
final invertedR = 1.0 - r;
final invertedG = 1.0 - g;
final invertedB = 1.0 - b;
return Color.from(
alpha: a,
red: invertedR,
green: invertedG,
blue: invertedB,
);
}
Color withWhite(int whiteValue) {
final value = whiteValue / 255.0;
return Color.from(alpha: a, red: value, green: value, blue: value);
@@ -16,8 +16,6 @@ class ChatMessage {
RichObjectString? file;
String content = '';
bool get containsFile => file != null;
ChatMessage({required this.originalMessage, this.originalData}) {
if (originalData?.containsKey('file') ?? false) {
file = originalData?['file'];
@@ -10,6 +10,14 @@ class ChatSearchMatch {
}
class ChatSearchController {
/// System messages that are folded into other bubbles (reactions, poll
/// votes, deletions) and therefore never rendered nor searched as their own
/// entry.
static bool isHiddenSystemMessage(GetChatResponseObject element) =>
element.systemMessage.contains('reaction') ||
element.systemMessage.contains('poll_voted') ||
element.systemMessage.contains('message_deleted');
static List<ChatSearchMatch> findMatches(
GetChatResponse response,
String query,
@@ -19,9 +27,7 @@ class ChatSearchController {
final matches = <ChatSearchMatch>[];
for (final element in response.sortByTimestamp()) {
if (element.systemMessage.contains('reaction')) continue;
if (element.systemMessage.contains('poll_voted')) continue;
if (element.systemMessage.contains('message_deleted')) continue;
if (isHiddenSystemMessage(element)) continue;
final haystackText = RichObjectStringProcessor.parseToString(
element.message,
@@ -17,28 +17,17 @@ class AnswerReference extends StatelessWidget {
@override
Widget build(BuildContext context) {
var style = ChatBubbleStyles(context);
final style = ChatBubbleStyles(context);
final isSelf = referenceMessage.actorId == selfId;
final accent = isSelf
? style.getSelfStyle(false).color!.withGreen(200)
: style.getRemoteStyle(false).color!.withWhite(200);
return DecoratedBox(
decoration: BoxDecoration(
color: referenceMessage.actorId == selfId
? style
.getSelfStyle(false)
.color!
.withGreen(200)
.withValues(alpha: 0.2)
: style
.getRemoteStyle(false)
.color!
.withWhite(200)
.withValues(alpha: 0.2),
color: accent.withValues(alpha: 0.2),
borderRadius: const BorderRadius.all(Radius.circular(5)),
border: Border(
left: BorderSide(
color: referenceMessage.actorId == selfId
? style.getSelfStyle(false).color!.withGreen(200)
: style.getRemoteStyle(false).color!.withWhite(200),
width: 5,
),
left: BorderSide(color: accent, width: 5),
),
),
child: Padding(
@@ -51,9 +40,7 @@ class AnswerReference extends StatelessWidget {
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: referenceMessage.actorId == selfId
? style.getSelfStyle(false).color!.withGreen(200)
: style.getRemoteStyle(false).color!.withWhite(200),
color: accent,
fontSize: 12,
),
),