Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rajveermalviya committed Nov 6, 2024
1 parent 8bbca00 commit 56ab27a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/model/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:html/dom.dart' as dom;
import 'package:html/parser.dart';
import 'package:intl/intl.dart';

import '../api/model/model.dart';
import '../api/model/submessage.dart';
Expand Down Expand Up @@ -96,9 +97,10 @@ class PollContent implements ZulipMessageContent {
/// [Stream.renderedDescription], or other text from a Zulip server that comes
/// in the same Zulip HTML format.
class ZulipContent extends ContentNode implements ZulipMessageContent {
const ZulipContent({super.debugHtmlNode, required this.nodes});
const ZulipContent({super.debugHtmlNode, required this.nodes, required this.isRTL});

final List<BlockContentNode> nodes;
final bool isRTL;

@override
List<DiagnosticsNode> debugDescribeChildren() {
Expand Down Expand Up @@ -1594,8 +1596,9 @@ class _ZulipContentParser {

ZulipContent parse(String html) {
final fragment = HtmlParser(html, parseMeta: false).parseFragment();
final isRTL = Bidi.detectRtlDirectionality(html, isHtml: true);
final nodes = parseBlockContentList(fragment.nodes);
return ZulipContent(nodes: nodes, debugHtmlNode: kDebugMode ? fragment : null);
return ZulipContent(nodes: nodes, debugHtmlNode: kDebugMode ? fragment : null, isRTL: isRTL);
}
}

Expand Down
9 changes: 7 additions & 2 deletions lib/widgets/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:html/dom.dart' as dom;
import 'package:intl/intl.dart';
import 'package:intl/intl.dart' hide TextDirection;
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';

import '../api/core.dart';
Expand Down Expand Up @@ -279,7 +279,12 @@ class MessageContent extends StatelessWidget {
child: DefaultTextStyle(
style: ContentTheme.of(context).textStylePlainParagraph,
child: switch (content) {
ZulipContent() => BlockContentList(nodes: content.nodes),
ZulipContent() =>
content.isRTL
? Directionality(
textDirection: TextDirection.rtl,
child: BlockContentList(nodes: content.nodes))
: BlockContentList(nodes: content.nodes),
PollContent() => PollWidget(messageId: message.id, poll: content.poll),
}));
}
Expand Down

0 comments on commit 56ab27a

Please sign in to comment.