2021-08-16 22:04:05 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-06-10 21:21:40 +00:00
|
|
|
import 'package:cwtch/controllers/open_link_modal.dart';
|
2022-01-18 21:26:52 +00:00
|
|
|
import 'package:cwtch/models/contact.dart';
|
2021-07-06 19:46:39 +00:00
|
|
|
import 'package:cwtch/models/message.dart';
|
2023-09-25 19:05:28 +00:00
|
|
|
import 'package:cwtch/models/redaction.dart';
|
2023-05-18 18:15:13 +00:00
|
|
|
import 'package:cwtch/themes/opaque.dart';
|
2022-01-18 21:17:27 +00:00
|
|
|
import 'package:cwtch/third_party/linkify/flutter_linkify.dart';
|
2022-01-18 21:26:52 +00:00
|
|
|
import 'package:cwtch/models/profile.dart';
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'package:cwtch/widgets/malformedbubble.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
import '../settings.dart';
|
2023-05-18 18:15:13 +00:00
|
|
|
import 'messageBubbleWidgetHelpers.dart';
|
2021-06-24 23:10:45 +00:00
|
|
|
import 'messagebubbledecorations.dart';
|
|
|
|
|
|
|
|
class MessageBubble extends StatefulWidget {
|
2021-07-06 19:46:39 +00:00
|
|
|
final String content;
|
|
|
|
|
|
|
|
MessageBubble(this.content);
|
|
|
|
|
2021-06-24 23:10:45 +00:00
|
|
|
@override
|
|
|
|
MessageBubbleState createState() => MessageBubbleState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class MessageBubbleState extends State<MessageBubble> {
|
|
|
|
FocusNode _focus = FocusNode();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-07-06 19:46:39 +00:00
|
|
|
var fromMe = Provider.of<MessageMetadata>(context).senderHandle == Provider.of<ProfileInfoState>(context).onion;
|
2021-06-24 23:10:45 +00:00
|
|
|
var borderRadiousEh = 15.0;
|
2021-11-06 05:38:45 +00:00
|
|
|
var showClickableLinks = Provider.of<Settings>(context).isExperimentEnabled(ClickableLinksExperiment);
|
2022-04-06 21:35:10 +00:00
|
|
|
var formatMessages = Provider.of<Settings>(context).isExperimentEnabled(FormattingExperiment);
|
2021-07-06 19:46:39 +00:00
|
|
|
DateTime messageDate = Provider.of<MessageMetadata>(context).timestamp;
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
// If the sender is not us, then we want to give them a nickname...
|
|
|
|
var senderDisplayStr = "";
|
2021-07-06 19:46:39 +00:00
|
|
|
if (!fromMe) {
|
2021-11-18 23:44:54 +00:00
|
|
|
ContactInfoState? contact = Provider.of<ProfileInfoState>(context).contactList.findContact(Provider.of<MessageMetadata>(context).senderHandle);
|
2021-06-24 23:10:45 +00:00
|
|
|
if (contact != null) {
|
2023-09-25 19:05:28 +00:00
|
|
|
senderDisplayStr = redactedNick(context, contact.onion, contact.nickname);
|
2021-06-24 23:10:45 +00:00
|
|
|
} else {
|
2021-07-06 19:46:39 +00:00
|
|
|
senderDisplayStr = Provider.of<MessageMetadata>(context).senderHandle;
|
2021-06-24 23:10:45 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-18 18:15:13 +00:00
|
|
|
var wdgSender = compileSenderWidget(context, fromMe, senderDisplayStr);
|
|
|
|
var wdgMessage = compileMessageContentWidget(context, fromMe, widget.content, _focus, formatMessages, showClickableLinks);
|
2022-03-01 06:35:09 +00:00
|
|
|
var wdgDecorations = MessageBubbleDecoration(ackd: Provider.of<MessageMetadata>(context).ackd, errored: Provider.of<MessageMetadata>(context).error, fromMe: fromMe, messageDate: messageDate);
|
2021-07-06 19:46:39 +00:00
|
|
|
var error = Provider.of<MessageMetadata>(context).error;
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
return LayoutBuilder(builder: (context, constraints) {
|
|
|
|
//print(constraints.toString()+", "+constraints.maxWidth.toString());
|
|
|
|
return RepaintBoundary(
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
2021-12-15 22:29:27 +00:00
|
|
|
color: error ? malformedColor : (fromMe ? Provider.of<Settings>(context).theme.messageFromMeBackgroundColor : Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor),
|
2021-06-24 23:10:45 +00:00
|
|
|
border: Border.all(
|
|
|
|
color: error
|
|
|
|
? malformedColor
|
2021-12-10 04:22:55 +00:00
|
|
|
: (fromMe ? Provider.of<Settings>(context).theme.messageFromMeBackgroundColor : Provider.of<Settings>(context).theme.messageFromOtherBackgroundColor),
|
2021-06-24 23:10:45 +00:00
|
|
|
width: 1),
|
|
|
|
borderRadius: BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(borderRadiousEh),
|
|
|
|
topRight: Radius.circular(borderRadiousEh),
|
|
|
|
bottomLeft: fromMe ? Radius.circular(borderRadiousEh) : Radius.zero,
|
|
|
|
bottomRight: fromMe ? Radius.zero : Radius.circular(borderRadiousEh),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.all(9.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: fromMe ? MainAxisAlignment.end : MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: fromMe ? [wdgMessage, wdgDecorations] : [wdgSender, wdgMessage, wdgDecorations])))));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|