Save Peer History Settings #23

Merged
erinn merged 1 commits from peersettings into trunk 2021-03-17 22:49:33 +00:00
2 changed files with 60 additions and 11 deletions

View File

@ -139,7 +139,13 @@ class ProfileInfoState extends ChangeNotifier {
List<dynamic> contacts = jsonDecode(contactsJson);
this._contacts.addAll(contacts.map((contact) {
return ContactInfoState(
profileOnion: this.onion, onion: contact["onion"], nickname: contact["name"], status: contact["status"], imagePath: contact["picture"], isBlocked: contact["authorization"] == "blocked");
profileOnion: this.onion,
onion: contact["onion"],
nickname: contact["name"],
status: contact["status"],
imagePath: contact["picture"],
isBlocked: contact["authorization"] == "blocked",
savePeerHistory: contact["saveConversationHistory"]);
}));
}
}
@ -180,27 +186,27 @@ class ContactInfoState extends ChangeNotifier {
bool _isBlocked;
String _status;
String _imagePath;
String _savePeerHistory;
int _unreadMessages = 0;
ContactInfoState({
this.profileOnion,
this.onion,
nickname = "",
isGroup = false,
isInvitation = false,
isBlocked = false,
status = "",
imagePath = "",
}) {
ContactInfoState({this.profileOnion, this.onion, nickname = "", isGroup = false, isInvitation = false, isBlocked = false, status = "", imagePath = "", savePeerHistory = "DeleteHistoryConfirmed"}) {
this._nickname = nickname;
this._isGroup = isGroup;
this._isInvitation = isInvitation;
this._isBlocked = isBlocked;
this._status = status;
this._imagePath = imagePath;
this._savePeerHistory = savePeerHistory;
}
get nickname => this._nickname;
get savePeerHistory => this._savePeerHistory;
set savePeerHistory(String newVal) {
this._savePeerHistory = newVal;
notifyListeners();
}
set nickname(String newVal) {
this._nickname = newVal;
notifyListeners();

View File

@ -143,6 +143,49 @@ class _PeerSettingsViewState extends State<PeerSettingsView> {
},
secondary: Icon(Icons.block, color: settings.current().mainTextColor()),
),
ListTile(
title: Text(AppLocalizations.of(context).savePeerHistory, style: TextStyle(color: settings.current().mainTextColor())),
subtitle: Text(AppLocalizations.of(context).savePeerHistoryDescription),
leading: Icon(Icons.history_sharp, color: settings.current().mainTextColor()),
trailing: DropdownButton(
value: Provider.of<ContactInfoState>(context).savePeerHistory == "DefaultDeleteHistory"
? AppLocalizations.of(context).dontSavePeerHistory
: (Provider.of<ContactInfoState>(context).savePeerHistory == "SaveHistory"
? AppLocalizations.of(context).savePeerHistory
: AppLocalizations.of(context).dontSavePeerHistory),
onChanged: (newValue) {
setState(() {
// Set whether or not to dave the Contact History...
var profileOnion = Provider.of<ContactInfoState>(context, listen: false).profileOnion;
var onion = Provider.of<ContactInfoState>(context, listen: false).onion;
const SaveHistoryKey = "SavePeerHistory";
if (newValue == AppLocalizations.of(context).savePeerHistory) {
Provider.of<ContactInfoState>(context, listen: false).savePeerHistory = "SaveHistory";
final setPeerAttribute = {
"EventType": "SetPeerAttribute",
"Data": {"RemotePeer": onion, "Key": SaveHistoryKey, "Data": "SaveHistory"},
};
final setPeerAttributeJson = jsonEncode(setPeerAttribute);
Provider.of<FlwtchState>(context, listen: false).cwtch.SendProfileEvent(profileOnion, setPeerAttributeJson);
} else {
Provider.of<ContactInfoState>(context, listen: false).savePeerHistory = "DeleteHistoryConfirmed";
final setPeerAttribute = {
"EventType": "SetPeerAttribute",
"Data": {"RemotePeer": onion, "Key": SaveHistoryKey, "Data": "DeleteHistoryConfirmed"},
};
final setPeerAttributeJson = jsonEncode(setPeerAttribute);
Provider.of<FlwtchState>(context, listen: false).cwtch.SendProfileEvent(profileOnion, setPeerAttributeJson);
}
});
},
items: [AppLocalizations.of(context).savePeerHistory, AppLocalizations.of(context).dontSavePeerHistory].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList())),
]),
])))));
});