Fallback to Default Profile Images when Image Previews are Disabled
This commit is contained in:
parent
2a2d808b60
commit
b280765631
|
@ -55,7 +55,7 @@ class CwtchNotifier {
|
|||
}
|
||||
EnvironmentConfig.debugLog("NewPeer $data");
|
||||
// if tag != v1-defaultPassword then it is either encrypted OR it is an unencrypted account created during pre-beta...
|
||||
profileCN.add(data["Identity"], data["name"], data["picture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["tag"] != "v1-defaultPassword");
|
||||
profileCN.add(data["Identity"], data["name"], data["picture"], data["defaultPicture"], data["ContactsJson"], data["ServerList"], data["Online"] == "true", data["tag"] != "v1-defaultPassword");
|
||||
break;
|
||||
case "ContactCreated":
|
||||
EnvironmentConfig.debugLog("ContactCreated $data");
|
||||
|
@ -67,6 +67,7 @@ class CwtchNotifier {
|
|||
nickname: data["nick"],
|
||||
status: data["status"],
|
||||
imagePath: data["picture"],
|
||||
defaultImagePath: data["defaultPicture"],
|
||||
blocked: data["blocked"] == "true",
|
||||
accepted: data["accepted"] == "true",
|
||||
savePeerHistory: data["saveConversationHistory"] == null ? "DeleteHistoryConfirmed" : data["saveConversationHistory"],
|
||||
|
@ -107,6 +108,7 @@ class CwtchNotifier {
|
|||
blocked: false, // we created
|
||||
accepted: true, // we created
|
||||
imagePath: data["picture"],
|
||||
defaultImagePath: data["picture"],
|
||||
nickname: data["GroupName"],
|
||||
status: status,
|
||||
server: data["GroupServer"],
|
||||
|
|
|
@ -14,6 +14,7 @@ class ContactInfoState extends ChangeNotifier {
|
|||
late bool _blocked;
|
||||
late String _status;
|
||||
late String _imagePath;
|
||||
late String _defaultImagePath;
|
||||
late String _savePeerHistory;
|
||||
late int _unreadMessages = 0;
|
||||
late int _totalMessages = 0;
|
||||
|
@ -37,6 +38,7 @@ class ContactInfoState extends ChangeNotifier {
|
|||
blocked = false,
|
||||
status = "",
|
||||
imagePath = "",
|
||||
defaultImagePath = "",
|
||||
savePeerHistory = "DeleteHistoryConfirmed",
|
||||
numMessages = 0,
|
||||
numUnread = 0,
|
||||
|
@ -49,6 +51,7 @@ class ContactInfoState extends ChangeNotifier {
|
|||
this._blocked = blocked;
|
||||
this._status = status;
|
||||
this._imagePath = imagePath;
|
||||
this._defaultImagePath = defaultImagePath;
|
||||
this._totalMessages = numMessages;
|
||||
this._unreadMessages = numUnread;
|
||||
this._savePeerHistory = savePeerHistory;
|
||||
|
@ -166,6 +169,13 @@ class ContactInfoState extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
String get defaultImagePath => this._defaultImagePath;
|
||||
|
||||
set defaultImagePath(String newVal) {
|
||||
this._defaultImagePath = newVal;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
DateTime get lastMessageTime => this._lastMessageTime;
|
||||
|
||||
set lastMessageTime(DateTime newVal) {
|
||||
|
|
|
@ -14,6 +14,7 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
final String onion;
|
||||
String _nickname = "";
|
||||
String _imagePath = "";
|
||||
String _defaultImagePath = "";
|
||||
int _unreadMessages = 0;
|
||||
bool _online = false;
|
||||
Map<String, FileDownloadProgress> _downloads = Map<String, FileDownloadProgress>();
|
||||
|
@ -27,14 +28,17 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
required this.onion,
|
||||
nickname = "",
|
||||
imagePath = "",
|
||||
defaultImagePath = "",
|
||||
unreadMessages = 0,
|
||||
contactsJson = "",
|
||||
serversJson = "",
|
||||
online = false,
|
||||
encrypted = true,
|
||||
String,
|
||||
}) {
|
||||
this._nickname = nickname;
|
||||
this._imagePath = imagePath;
|
||||
this._defaultImagePath = defaultImagePath;
|
||||
this._unreadMessages = unreadMessages;
|
||||
this._online = online;
|
||||
this._encrypted = encrypted;
|
||||
|
@ -50,6 +54,7 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
nickname: contact["name"],
|
||||
status: contact["status"],
|
||||
imagePath: contact["picture"],
|
||||
defaultImagePath: contact["isGroup"] ? contact["picture"] : contact["defaultPicture"],
|
||||
accepted: contact["accepted"],
|
||||
blocked: contact["blocked"],
|
||||
savePeerHistory: contact["saveConversationHistory"],
|
||||
|
@ -115,6 +120,12 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
String get defaultImagePath => this._defaultImagePath;
|
||||
set defaultImagePath(String newVal) {
|
||||
this._defaultImagePath = newVal;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int get unreadMessages => this._unreadMessages;
|
||||
set unreadMessages(int newVal) {
|
||||
this._unreadMessages = newVal;
|
||||
|
@ -161,6 +172,7 @@ class ProfileInfoState extends ChangeNotifier {
|
|||
contact["identifier"],
|
||||
contact["onion"],
|
||||
nickname: contact["name"],
|
||||
defaultImagePath: contact["defaultPicture"],
|
||||
status: contact["status"],
|
||||
imagePath: contact["picture"],
|
||||
accepted: contact["accepted"],
|
||||
|
|
|
@ -6,10 +6,11 @@ class ProfileListState extends ChangeNotifier {
|
|||
List<ProfileInfoState> _profiles = [];
|
||||
int get num => _profiles.length;
|
||||
|
||||
void add(String onion, String name, String picture, String contactsJson, String serverJson, bool online, bool encrypted) {
|
||||
void add(String onion, String name, String picture, String defaultPicture, String contactsJson, String serverJson, bool online, bool encrypted) {
|
||||
var idx = _profiles.indexWhere((element) => element.onion == onion);
|
||||
if (idx == -1) {
|
||||
_profiles.add(ProfileInfoState(onion: onion, nickname: name, imagePath: picture, contactsJson: contactsJson, serversJson: serverJson, online: online, encrypted: encrypted));
|
||||
_profiles.add(ProfileInfoState(
|
||||
onion: onion, nickname: name, imagePath: picture, defaultImagePath: defaultPicture, contactsJson: contactsJson, serversJson: serverJson, online: online, encrypted: encrypted));
|
||||
} else {
|
||||
_profiles[idx].updateFrom(onion, name, picture, contactsJson, serverJson, online);
|
||||
}
|
||||
|
|
|
@ -112,9 +112,12 @@ class _AddEditProfileViewState extends State<AddEditProfileView> {
|
|||
}, () {});
|
||||
},
|
||||
child: ProfileImage(
|
||||
imagePath: Provider.of<ProfileInfoState>(context).imagePath,
|
||||
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
|
||||
? Provider.of<ProfileInfoState>(context).imagePath
|
||||
: Provider.of<ProfileInfoState>(context).defaultImagePath,
|
||||
diameter: 120,
|
||||
tooltip: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment) ? AppLocalizations.of(context)!.tooltipSelectACustomProfileImage : "",
|
||||
tooltip:
|
||||
Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment) ? AppLocalizations.of(context)!.tooltipSelectACustomProfileImage : "",
|
||||
maskOut: false,
|
||||
border: theme.theme.portraitOnlineBorderColor,
|
||||
badgeTextColor: Colors.red,
|
||||
|
|
|
@ -103,7 +103,9 @@ class _ContactsViewState extends State<ContactsView> {
|
|||
title: RepaintBoundary(
|
||||
child: Row(children: [
|
||||
ProfileImage(
|
||||
imagePath: Provider.of<ProfileInfoState>(context).imagePath,
|
||||
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
|
||||
? Provider.of<ProfileInfoState>(context).imagePath
|
||||
: Provider.of<ProfileInfoState>(context).defaultImagePath,
|
||||
diameter: 42,
|
||||
border: Provider.of<Settings>(context).current().portraitOnlineBorderColor,
|
||||
badgeTextColor: Colors.red,
|
||||
|
|
|
@ -139,7 +139,9 @@ class _MessageViewState extends State<MessageView> {
|
|||
leading: Provider.of<Settings>(context).uiColumns(appState.isLandscape(context)).length > 1 ? Container() : null,
|
||||
title: Row(children: [
|
||||
ProfileImage(
|
||||
imagePath: Provider.of<ContactInfoState>(context).imagePath,
|
||||
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment)
|
||||
? Provider.of<ContactInfoState>(context).imagePath
|
||||
: Provider.of<ContactInfoState>(context).defaultImagePath,
|
||||
diameter: 42,
|
||||
border: Provider.of<Settings>(context).current().portraitOnlineBorderColor,
|
||||
badgeTextColor: Colors.red,
|
||||
|
|
|
@ -50,7 +50,7 @@ class _ContactRowState extends State<ContactRow> {
|
|||
badgeColor: Provider.of<Settings>(context).theme.portraitContactBadgeColor,
|
||||
badgeTextColor: Provider.of<Settings>(context).theme.portraitContactBadgeTextColor,
|
||||
diameter: 64.0,
|
||||
imagePath: contact.imagePath,
|
||||
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment) ? contact.imagePath : contact.defaultImagePath,
|
||||
maskOut: !contact.isOnline(),
|
||||
border: contact.isOnline()
|
||||
? Provider.of<Settings>(context).theme.portraitOnlineBorderColor
|
||||
|
|
|
@ -153,6 +153,12 @@ class MessageRowState extends State<MessageRow> with SingleTickerProviderStateMi
|
|||
} else {
|
||||
var contact = Provider.of<ContactInfoState>(context);
|
||||
ContactInfoState? sender = Provider.of<ProfileInfoState>(context).contactList.findContact(Provider.of<MessageMetadata>(context).senderHandle);
|
||||
|
||||
String imagePath = Provider.of<MessageMetadata>(context).senderImage!;
|
||||
if (sender != null) {
|
||||
imagePath =
|
||||
Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment) ? sender.imagePath : sender.defaultImagePath;
|
||||
}
|
||||
Widget wdgPortrait = GestureDetector(
|
||||
onTap: !isGroup
|
||||
? null
|
||||
|
@ -164,7 +170,7 @@ class MessageRowState extends State<MessageRow> with SingleTickerProviderStateMi
|
|||
child: ProfileImage(
|
||||
diameter: 48.0,
|
||||
// default to the contact image...otherwise use a derived sender image...
|
||||
imagePath: sender?.imagePath ?? Provider.of<MessageMetadata>(context).senderImage!,
|
||||
imagePath: imagePath,
|
||||
border: contact.status == "Authenticated" ? Provider.of<Settings>(context).theme.portraitOnlineBorderColor : Provider.of<Settings>(context).theme.portraitOfflineBorderColor,
|
||||
badgeTextColor: Colors.red,
|
||||
badgeColor: Colors.red,
|
||||
|
|
|
@ -38,7 +38,7 @@ class _ProfileRowState extends State<ProfileRow> {
|
|||
badgeColor: Provider.of<Settings>(context).theme.portraitProfileBadgeColor,
|
||||
badgeTextColor: Provider.of<Settings>(context).theme.portraitProfileBadgeTextColor,
|
||||
diameter: 64.0,
|
||||
imagePath: profile.imagePath,
|
||||
imagePath: Provider.of<Settings>(context).isExperimentEnabled(ImagePreviewsExperiment) ? profile.imagePath : profile.defaultImagePath,
|
||||
border: profile.isOnline ? Provider.of<Settings>(context).theme.portraitOnlineBorderColor : Provider.of<Settings>(context).theme.portraitOfflineBorderColor)),
|
||||
Expanded(
|
||||
child: Column(
|
||||
|
|
Loading…
Reference in New Issue