Migrate Invites to use Message Draft
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
This commit is contained in:
parent
1b4d79e5be
commit
294279f34e
|
@ -6,7 +6,7 @@ import 'package:flutter/foundation.dart';
|
||||||
/// Only one draft is stored per conversation.
|
/// Only one draft is stored per conversation.
|
||||||
class MessageDraft extends ChangeNotifier {
|
class MessageDraft extends ChangeNotifier {
|
||||||
QuotedReference? _quotedReference;
|
QuotedReference? _quotedReference;
|
||||||
|
int? _inviteHandle;
|
||||||
TextEditingController ctrlCompose = TextEditingController();
|
TextEditingController ctrlCompose = TextEditingController();
|
||||||
|
|
||||||
static MessageDraft empty() {
|
static MessageDraft empty() {
|
||||||
|
@ -29,6 +29,15 @@ class MessageDraft extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void attachInvite(int handle) {
|
||||||
|
this._inviteHandle = handle;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
int? getInviteHandle() {
|
||||||
|
return this._inviteHandle;
|
||||||
|
}
|
||||||
|
|
||||||
QuotedReference? getQuotedMessage() {
|
QuotedReference? getQuotedMessage() {
|
||||||
return this._quotedReference;
|
return this._quotedReference;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +50,7 @@ class MessageDraft extends ChangeNotifier {
|
||||||
void clearDraft() {
|
void clearDraft() {
|
||||||
this._quotedReference = null;
|
this._quotedReference = null;
|
||||||
this.ctrlCompose.clear();
|
this.ctrlCompose.clear();
|
||||||
|
this._inviteHandle = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +59,10 @@ class MessageDraft extends ChangeNotifier {
|
||||||
ctrlCompose.dispose();
|
ctrlCompose.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clearInvite() {
|
||||||
|
this._inviteHandle = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A QuotedReference encapsulates the state of replied-to message.
|
/// A QuotedReference encapsulates the state of replied-to message.
|
||||||
|
|
|
@ -12,10 +12,12 @@ import 'package:cwtch/models/contact.dart';
|
||||||
import 'package:cwtch/models/message.dart';
|
import 'package:cwtch/models/message.dart';
|
||||||
import 'package:cwtch/models/message_draft.dart';
|
import 'package:cwtch/models/message_draft.dart';
|
||||||
import 'package:cwtch/models/messagecache.dart';
|
import 'package:cwtch/models/messagecache.dart';
|
||||||
|
import 'package:cwtch/models/messages/invitemessage.dart';
|
||||||
import 'package:cwtch/models/messages/quotedmessage.dart';
|
import 'package:cwtch/models/messages/quotedmessage.dart';
|
||||||
import 'package:cwtch/models/profile.dart';
|
import 'package:cwtch/models/profile.dart';
|
||||||
import 'package:cwtch/themes/opaque.dart';
|
import 'package:cwtch/themes/opaque.dart';
|
||||||
import 'package:cwtch/third_party/linkify/flutter_linkify.dart';
|
import 'package:cwtch/third_party/linkify/flutter_linkify.dart';
|
||||||
|
import 'package:cwtch/widgets/invitationbubble.dart';
|
||||||
import 'package:cwtch/widgets/malformedbubble.dart';
|
import 'package:cwtch/widgets/malformedbubble.dart';
|
||||||
import 'package:cwtch/widgets/messageloadingbubble.dart';
|
import 'package:cwtch/widgets/messageloadingbubble.dart';
|
||||||
import 'package:cwtch/widgets/profileimage.dart';
|
import 'package:cwtch/widgets/profileimage.dart';
|
||||||
|
@ -345,6 +347,11 @@ class _MessageViewState extends State<MessageView> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var attachedInvite = Provider.of<ContactInfoState>(context, listen: false).messageDraft.getInviteHandle();
|
||||||
|
if (attachedInvite != null) {
|
||||||
|
this._sendInvitation(attachedInvite);
|
||||||
|
}
|
||||||
|
|
||||||
// Trim message
|
// Trim message
|
||||||
var messageText = Provider.of<ContactInfoState>(context, listen: false).messageDraft.messageText ?? "";
|
var messageText = Provider.of<ContactInfoState>(context, listen: false).messageDraft.messageText ?? "";
|
||||||
final messageWithoutNewLine = messageText.trimRight();
|
final messageWithoutNewLine = messageText.trimRight();
|
||||||
|
@ -385,10 +392,10 @@ class _MessageViewState extends State<MessageView> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _sendInvitation([String? ignoredParam]) {
|
void _sendInvitation(int contact) {
|
||||||
Provider.of<FlwtchState>(context, listen: false)
|
Provider.of<FlwtchState>(context, listen: false)
|
||||||
.cwtch
|
.cwtch
|
||||||
.SendInvitation(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier, this.selectedContact)
|
.SendInvitation(Provider.of<ContactInfoState>(context, listen: false).profileOnion, Provider.of<ContactInfoState>(context, listen: false).identifier, contact)
|
||||||
.then(_sendMessageHandler);
|
.then(_sendMessageHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,6 +441,27 @@ class _MessageViewState extends State<MessageView> {
|
||||||
focusNode.requestFocus();
|
focusNode.requestFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget senderInviteChrome(String chrome, String targetName) {
|
||||||
|
var settings = Provider.of<Settings>(context);
|
||||||
|
|
||||||
|
return Wrap(children: [
|
||||||
|
SelectableText(
|
||||||
|
chrome + '\u202F',
|
||||||
|
style: settings.scaleFonts(defaultMessageTextStyle.copyWith(color: Provider.of<Settings>(context).theme.messageFromMeTextColor)),
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
maxLines: 2,
|
||||||
|
textWidthBasis: TextWidthBasis.longestLine,
|
||||||
|
),
|
||||||
|
SelectableText(
|
||||||
|
targetName + '\u202F',
|
||||||
|
style: settings.scaleFonts(defaultMessageTextStyle.copyWith(color: Provider.of<Settings>(context).theme.messageFromMeTextColor)),
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
maxLines: 2,
|
||||||
|
textWidthBasis: TextWidthBasis.longestLine,
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildPreviewBox() {
|
Widget _buildPreviewBox() {
|
||||||
var showClickableLinks = Provider.of<Settings>(context).isExperimentEnabled(ClickableLinksExperiment);
|
var showClickableLinks = Provider.of<Settings>(context).isExperimentEnabled(ClickableLinksExperiment);
|
||||||
|
|
||||||
|
@ -686,6 +714,54 @@ class _MessageViewState extends State<MessageView> {
|
||||||
Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, padding: EdgeInsets.all(2), margin: EdgeInsets.all(2), height: 164, child: Column(children: textEditChildren));
|
Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, padding: EdgeInsets.all(2), margin: EdgeInsets.all(2), height: 164, child: Column(children: textEditChildren));
|
||||||
|
|
||||||
var children;
|
var children;
|
||||||
|
Widget invite = Container();
|
||||||
|
if (Provider.of<ContactInfoState>(context).messageDraft.getInviteHandle() != null) {
|
||||||
|
invite = FutureBuilder(
|
||||||
|
future: Future.value(Provider.of<ContactInfoState>(context).messageDraft.getInviteHandle()),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
var contactInvite = snapshot.data! as int;
|
||||||
|
var contact = Provider.of<ProfileInfoState>(context, listen: false).contactList.getContact(contactInvite);
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.all(5),
|
||||||
|
padding: EdgeInsets.all(5),
|
||||||
|
color: Provider.of<Settings>(context).theme.messageFromMeBackgroundColor,
|
||||||
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
|
Stack(children: [
|
||||||
|
Container(
|
||||||
|
margin: EdgeInsets.all(5),
|
||||||
|
padding: EdgeInsets.all(5),
|
||||||
|
clipBehavior: Clip.antiAlias,
|
||||||
|
decoration: BoxDecoration(color: Provider.of<Settings>(context).theme.messageFromMeBackgroundColor),
|
||||||
|
height: 75,
|
||||||
|
child: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||||
|
Padding(padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 10.0), child: Icon(CwtchIcons.send_invite, size: 32)),
|
||||||
|
Flexible(
|
||||||
|
child: DefaultTextStyle(
|
||||||
|
textWidthBasis: TextWidthBasis.parent,
|
||||||
|
child: senderInviteChrome("", contact!.nickname),
|
||||||
|
style: Provider.of<Settings>(context).scaleFonts(defaultTextStyle),
|
||||||
|
overflow: TextOverflow.fade,
|
||||||
|
))
|
||||||
|
])),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.topRight,
|
||||||
|
child: IconButton(
|
||||||
|
icon: Icon(Icons.highlight_remove),
|
||||||
|
splashRadius: Material.defaultSplashRadius / 2,
|
||||||
|
tooltip: AppLocalizations.of(context)!.tooltipRemoveThisQuotedMessage,
|
||||||
|
onPressed: () {
|
||||||
|
Provider.of<ContactInfoState>(context, listen: false).messageDraft.clearInvite();
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
]),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
return Container();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (Provider.of<AppState>(context).selectedConversation != null && Provider.of<ContactInfoState>(context).messageDraft.getQuotedMessage() != null) {
|
if (Provider.of<AppState>(context).selectedConversation != null && Provider.of<ContactInfoState>(context).messageDraft.getQuotedMessage() != null) {
|
||||||
var quoted = FutureBuilder(
|
var quoted = FutureBuilder(
|
||||||
future: messageHandler(context, Provider.of<AppState>(context).selectedProfile!, Provider.of<AppState>(context).selectedConversation!,
|
future: messageHandler(context, Provider.of<AppState>(context).selectedProfile!, Provider.of<AppState>(context).selectedConversation!,
|
||||||
|
@ -743,9 +819,9 @@ class _MessageViewState extends State<MessageView> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
children = [quoted, composeBox];
|
children = [invite, quoted, composeBox];
|
||||||
} else {
|
} else {
|
||||||
children = [composeBox];
|
children = [invite, composeBox];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: children));
|
return Container(color: Provider.of<Settings>(context).theme.backgroundMainColor, child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: children));
|
||||||
|
@ -803,9 +879,10 @@ class _MessageViewState extends State<MessageView> {
|
||||||
child: Text(AppLocalizations.of(bcontext)!.inviteBtn, semanticsLabel: AppLocalizations.of(bcontext)!.inviteBtn),
|
child: Text(AppLocalizations.of(bcontext)!.inviteBtn, semanticsLabel: AppLocalizations.of(bcontext)!.inviteBtn),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (this.selectedContact != -1) {
|
if (this.selectedContact != -1) {
|
||||||
this._sendInvitation();
|
Provider.of<ContactInfoState>(context, listen: false).messageDraft.attachInvite(this.selectedContact);
|
||||||
}
|
}
|
||||||
Navigator.pop(bcontext);
|
Navigator.pop(bcontext);
|
||||||
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue