diff --git a/utils/eventHandler.go b/utils/eventHandler.go index d01ec87..940e452 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -224,7 +224,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { cpicPath = RandomGroupImage(conversationInfo.Handle) defaultPath = RandomGroupImage(conversationInfo.Handle) } else { - cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath) + cpicPath = eh.GetProfileImage(profile, conversationInfo, settings.DownloadPath) defaultPath = RandomProfileImage(conversationInfo.Handle) } @@ -333,15 +333,17 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string { return string(json) } -func GetProfileImage(profile peer.CwtchPeer, conversationInfo *model.Conversation, basepath string) string { - fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) - if err == nil { - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) - // check if the file exists...if it does then set the path... - if _, err := os.Stat(fp); err == nil { - image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) - return image +func (eh *EventHandler) GetProfileImage(profile peer.CwtchPeer, conversationInfo *model.Conversation, basepath string) string { + if eh.app.IsFeatureEnabled(constants.ImagePreviewsExperiment) { + fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey))) + if err == nil { + if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { + fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true) + // check if the file exists...if it does then set the path... + if _, err := os.Stat(fp); err == nil { + image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) + return image + } } } } @@ -370,7 +372,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { if ci != nil && err == nil { ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, eh.app.ReadSettings().DownloadPath) + ev.Event.Data[constants2.Picture] = eh.GetProfileImage(profile, ci, eh.app.ReadSettings().DownloadPath) } else { // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... log.Errorf("todo wait for contact to be added before processing this event...") @@ -399,7 +401,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] } } - ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, eh.app.ReadSettings().DownloadPath) + ev.Event.Data[constants2.Picture] = eh.GetProfileImage(profile, ci, eh.app.ReadSettings().DownloadPath) } conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])