Fix Self-Invitations
This commit is contained in:
parent
b0f4a085b8
commit
a4c7fe6ebf
|
@ -177,7 +177,9 @@ class _MessageViewState extends State<MessageView> {
|
||||||
),
|
),
|
||||||
ChangeNotifierProvider.value(
|
ChangeNotifierProvider.value(
|
||||||
value: Provider.of<ProfileInfoState>(ctx, listen: false),
|
value: Provider.of<ProfileInfoState>(ctx, listen: false),
|
||||||
child: DropdownContacts(onChanged: (newVal) {
|
child: DropdownContacts(filter: (contact) {
|
||||||
|
return contact.onion != Provider.of<ContactInfoState>(context).onion;
|
||||||
|
}, onChanged: (newVal) {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.selectedContact = newVal;
|
this.selectedContact = newVal;
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,6 +3,10 @@ import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import '../model.dart';
|
import '../model.dart';
|
||||||
|
|
||||||
|
bool noFilter(ContactInfoState peer) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Dropdown menu populated from Provider.of<ProfileInfoState>'s contact list
|
// Dropdown menu populated from Provider.of<ProfileInfoState>'s contact list
|
||||||
// Includes both peers and groups; begins empty/nothing selected
|
// Includes both peers and groups; begins empty/nothing selected
|
||||||
// Displays nicknames to UI but uses handles as values
|
// Displays nicknames to UI but uses handles as values
|
||||||
|
@ -10,8 +14,10 @@ import '../model.dart';
|
||||||
class DropdownContacts extends StatefulWidget {
|
class DropdownContacts extends StatefulWidget {
|
||||||
DropdownContacts({
|
DropdownContacts({
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
|
this.filter = noFilter,
|
||||||
});
|
});
|
||||||
final Function(dynamic) onChanged;
|
final Function(dynamic) onChanged;
|
||||||
|
final bool Function(ContactInfoState) filter;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_DropdownContactsState createState() => _DropdownContactsState();
|
_DropdownContactsState createState() => _DropdownContactsState();
|
||||||
|
@ -24,7 +30,7 @@ class _DropdownContactsState extends State<DropdownContacts> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DropdownButton(
|
return DropdownButton(
|
||||||
value: this.selected,
|
value: this.selected,
|
||||||
items: Provider.of<ProfileInfoState>(context, listen: false).contactList.contacts.map<DropdownMenuItem<String>>((ContactInfoState contact) {
|
items: Provider.of<ProfileInfoState>(context, listen: false).contactList.contacts.where(widget.filter).map<DropdownMenuItem<String>>((ContactInfoState contact) {
|
||||||
return DropdownMenuItem<String>(value: contact.onion, child: Text(contact.nickname));
|
return DropdownMenuItem<String>(value: contact.onion, child: Text(contact.nickname));
|
||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged: (String? newVal) {
|
onChanged: (String? newVal) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:cwtch/cwtch_icons_icons.dart';
|
import 'package:cwtch/cwtch_icons_icons.dart';
|
||||||
|
import 'package:cwtch/widgets/malformedbubble.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import '../main.dart';
|
import '../main.dart';
|
||||||
|
@ -54,10 +55,18 @@ class InvitationBubbleState extends State<InvitationBubble> {
|
||||||
style: TextStyle(fontSize: 9.0, color: fromMe ? Provider.of<Settings>(context).theme.messageFromMeTextColor() : Provider.of<Settings>(context).theme.messageFromOtherTextColor())));
|
style: TextStyle(fontSize: 9.0, color: fromMe ? Provider.of<Settings>(context).theme.messageFromMeTextColor() : Provider.of<Settings>(context).theme.messageFromOtherTextColor())));
|
||||||
|
|
||||||
// todo: translations
|
// todo: translations
|
||||||
|
|
||||||
|
// If we receive an invite for ourselves, treat it as a bug. The UI no longer allows this so it could have only come from
|
||||||
|
// some kind of malfeasance.
|
||||||
|
var selfInvite = Provider.of<MessageState>(context).inviteNick == Provider.of<ProfileInfoState>(context).onion;
|
||||||
|
if (selfInvite) {
|
||||||
|
return MalformedBubble();
|
||||||
|
}
|
||||||
|
|
||||||
var wdgMessage = fromMe
|
var wdgMessage = fromMe
|
||||||
? senderInviteChrome("You sent an invitation for", isGroup ? "a group" : Provider.of<MessageState>(context).message, myKey)
|
? senderInviteChrome("You sent an invitation for", isGroup ? "a group" : Provider.of<MessageState>(context).message, myKey)
|
||||||
: inviteChrome(isGroup ? AppLocalizations.of(context)!.inviteToGroup : "This is a contact suggestion for:", Provider.of<MessageState>(context).inviteNick,
|
: (inviteChrome(isGroup ? AppLocalizations.of(context)!.inviteToGroup : "This is a contact suggestion for:", Provider.of<MessageState>(context).inviteNick,
|
||||||
Provider.of<MessageState>(context).inviteTarget, myKey);
|
Provider.of<MessageState>(context).inviteTarget, myKey));
|
||||||
|
|
||||||
Widget wdgDecorations;
|
Widget wdgDecorations;
|
||||||
if (fromMe) {
|
if (fromMe) {
|
||||||
|
@ -98,12 +107,13 @@ class InvitationBubbleState extends State<InvitationBubble> {
|
||||||
child: Wrap(runAlignment: WrapAlignment.spaceEvenly, alignment: WrapAlignment.spaceEvenly, runSpacing: 1.0, crossAxisAlignment: WrapCrossAlignment.center, children: [
|
child: Wrap(runAlignment: WrapAlignment.spaceEvenly, alignment: WrapAlignment.spaceEvenly, runSpacing: 1.0, crossAxisAlignment: WrapCrossAlignment.center, children: [
|
||||||
Center(widthFactor: 1, child: Padding(padding: EdgeInsets.all(10.0), child: Icon(CwtchIcons.send_invite, size: 32))),
|
Center(widthFactor: 1, child: Padding(padding: EdgeInsets.all(10.0), child: Icon(CwtchIcons.send_invite, size: 32))),
|
||||||
Center(
|
Center(
|
||||||
widthFactor: 1.0,
|
widthFactor: 1.0,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
|
crossAxisAlignment: fromMe ? CrossAxisAlignment.end : CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: fromMe ? MainAxisAlignment.end : MainAxisAlignment.start,
|
mainAxisAlignment: fromMe ? MainAxisAlignment.end : MainAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: fromMe ? [wdgMessage, wdgDecorations] : [wdgSender, wdgMessage, wdgDecorations])),
|
children: fromMe ? [wdgMessage, wdgDecorations] : [wdgSender, wdgMessage, wdgDecorations]),
|
||||||
|
)
|
||||||
])))));
|
])))));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue