1+ import 'package:chatwoot/screens/conversations/controllers/chat.dart' ;
12import 'package:flutter_markdown/flutter_markdown.dart' ;
23import '/imports.dart' ;
34
45class Message extends StatelessWidget {
56 final auth = Get .find <AuthService >();
67 final realtime = Get .find <RealtimeService >();
78
9+ final ConversationChatController controller;
810 final MessageInfo info;
911 final BorderRadius borderRadius;
1012
1113 Message ({
1214 super .key,
15+ required this .controller,
1316 required this .info,
1417 required this .borderRadius,
1518 });
@@ -146,54 +149,58 @@ class Message extends StatelessWidget {
146149 }),
147150 ),
148151 Flexible (
149- child: Container (
152+ child: Ink (
150153 decoration: BoxDecoration (
151154 color: backgroundColor,
152155 border: Border .all (color: backgroundColor),
153156 borderRadius: borderRadius,
154157 ),
155- child: Column (
156- crossAxisAlignment: CrossAxisAlignment .start,
157- children: [
158- if (info.attachments.isNotEmpty) buildAttachments (context),
159- if (info.content != null && info.content! .isNotEmpty)
160- buildContent (context),
161- // TODO: align right
162- Padding (
163- padding: const EdgeInsets .all (8 ),
164- child: Row (
165- mainAxisSize: MainAxisSize .min,
166- spacing: 8 ,
167- children: [
168- if (info.private)
169- Text (
170- t.private,
171- style: TextStyle (
172- fontSize: Get .textTheme.labelSmall! .fontSize,
158+ child: InkWell (
159+ child: Column (
160+ crossAxisAlignment: CrossAxisAlignment .start,
161+ children: [
162+ if (info.attachments.isNotEmpty)
163+ buildAttachments (context),
164+ if (info.content != null && info.content! .isNotEmpty)
165+ buildContent (context),
166+ // TODO: align right
167+ Padding (
168+ padding: const EdgeInsets .all (8 ),
169+ child: Row (
170+ mainAxisSize: MainAxisSize .min,
171+ spacing: 8 ,
172+ children: [
173+ if (info.private)
174+ Text (
175+ t.private,
176+ style: TextStyle (
177+ fontSize: Get .textTheme.labelSmall! .fontSize,
178+ ),
179+ ),
180+ if (isOwner == false )
181+ Text (
182+ sender.display_name,
183+ style: TextStyle (
184+ fontSize: Get .textTheme.labelSmall! .fontSize,
185+ ),
173186 ),
174- ),
175- if (isOwner == false )
176187 Text (
177- sender.display_name ,
188+ created_at ,
178189 style: TextStyle (
179190 fontSize: Get .textTheme.labelSmall! .fontSize,
180191 ),
181192 ),
182- Text (
183- created_at,
184- style: TextStyle (
185- fontSize: Get .textTheme.labelSmall! .fontSize,
186- ),
187- ),
188- if (statusIcon != null )
189- Padding (
190- padding: EdgeInsets .only (right: 4 ),
191- child: statusIcon,
192- ),
193- ],
193+ if (statusIcon != null )
194+ Padding (
195+ padding: EdgeInsets .only (right: 4 ),
196+ child: statusIcon,
197+ ),
198+ ],
199+ ),
194200 ),
195- ),
196- ],
201+ ],
202+ ),
203+ onLongPress: () => controller.showMessageActions (info),
197204 ),
198205 ),
199206 ),
@@ -210,14 +217,21 @@ class Message extends StatelessWidget {
210217 right: 8 ,
211218 top: 8 ,
212219 ),
213- child: MarkdownBody (
214- data: info.content! .trim (),
215- selectable: true ,
216- onTapLink: (text, href, title) {
217- if (href == null || href.isEmpty) return ;
218- openInAppBrowser (href);
219- },
220- ),
220+ child: Obx (() {
221+ final translated = controller.translated.value;
222+ final content = translated.containsKey (info.id) &&
223+ isNotNullOrEmpty (translated[info.id])
224+ ? translated[info.id]!
225+ : info.content! .trim ();
226+
227+ return MarkdownBody (
228+ data: content,
229+ onTapLink: (text, href, title) {
230+ if (href == null || href.isEmpty) return ;
231+ openInAppBrowser (href);
232+ },
233+ );
234+ }),
221235 );
222236 }
223237
0 commit comments