Merge branch 'trunk' into notificationPolicy

This commit is contained in:
Dan Ballard 2022-02-08 17:13:34 -05:00
commit 419c39cc68
3 changed files with 31 additions and 17 deletions

2
lib.go
View File

@ -775,7 +775,7 @@ func c_CheckDownloadStatus(profilePtr *C.char, profileLen C.int, fileKeyPtr *C.c
func CheckDownloadStatus(profileOnion, fileKey string) { func CheckDownloadStatus(profileOnion, fileKey string) {
profile := application.GetPeer(profileOnion) profile := application.GetPeer(profileOnion)
path, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) path, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey))
if _, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists { if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True {
eventHandler.Push(event.NewEvent(event.FileDownloaded, map[event.Field]string{ eventHandler.Push(event.NewEvent(event.FileDownloaded, map[event.Field]string{
ProfileOnion: profileOnion, ProfileOnion: profileOnion,
event.FileKey: fileKey, event.FileKey: fileKey,

View File

@ -16,5 +16,5 @@ type Contact struct {
GroupServer string `json:"groupServer"` GroupServer string `json:"groupServer"`
IsArchived bool `json:"isArchived"` IsArchived bool `json:"isArchived"`
Identifier int `json:"identifier"` Identifier int `json:"identifier"`
NotificationPolicy string `json:"notificationPolicy""` NotificationPolicy string `json:"notificationPolicy"`
} }

View File

@ -3,6 +3,7 @@ package utils
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"strconv" "strconv"
"cwtch.im/cwtch/app" "cwtch.im/cwtch/app"
@ -113,7 +114,8 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
// If the user has chosen to block unknown profiles // If the user has chosen to block unknown profiles
// then explicitly configure the protocol engine to do so.. // then explicitly configure the protocol engine to do so..
if ReadGlobalSettings().BlockUnknownConnections { settings := ReadGlobalSettings()
if settings.BlockUnknownConnections {
profile.BlockUnknownConnections() profile.BlockUnknownConnections()
} else { } else {
// For completeness // For completeness
@ -181,7 +183,7 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
if conversationInfo.IsGroup() { if conversationInfo.IsGroup() {
cpicPath = RandomGroupImage(conversationInfo.Handle) cpicPath = RandomGroupImage(conversationInfo.Handle)
} else { } else {
cpicPath = GetProfileImage(profile, conversationInfo) cpicPath = GetProfileImage(profile, conversationInfo, settings.DownloadPath)
} }
// Resolve Save History Setting // Resolve Save History Setting
@ -261,12 +263,16 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
return string(json) return string(json)
} }
func GetProfileImage(profile peer.CwtchPeer, conversationInfo *model.Conversation) string { 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))) fileKey, err := profile.GetConversationAttribute(conversationInfo.ID, attr.PublicScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants.CustomProfileImageKey)))
if err == nil { if err == nil {
if _, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists { if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True {
image, _ := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.path", fileKey)) fp, _ := filesharing.GenerateDownloadPath(basepath, fileKey, true)
return image // 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
}
} }
} }
return RandomProfileImage(conversationInfo.Handle) return RandomProfileImage(conversationInfo.Handle)
@ -290,7 +296,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
if ci != nil && err == nil { if ci != nil && err == nil {
ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID) ev.Event.Data[event.ConversationID] = strconv.Itoa(ci.ID)
profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) profile.SetConversationAttribute(ci.ID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False)
ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci) ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath)
} else { } else {
// TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... // 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...") log.Errorf("todo wait for contact to be added before processing this event...")
@ -326,7 +332,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"] ev.Event.Data["Nick"] = ev.Event.Data["RemotePeer"]
} }
} }
ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci) ev.Event.Data[constants2.Picture] = GetProfileImage(profile, ci, ReadGlobalSettings().DownloadPath)
} }
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
@ -458,18 +464,26 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
fileKey := val fileKey := val
fsf, err := filesharing.FunctionalityGate(settings.Experiments) fsf, err := filesharing.FunctionalityGate(settings.Experiments)
imagePreviewsEnabled := settings.Experiments["filesharing-images"] imagePreviewsEnabled := settings.Experiments["filesharing-images"]
if err == nil && imagePreviewsEnabled { if err == nil && imagePreviewsEnabled && conversation.Accepted {
basepath := settings.DownloadPath basepath := settings.DownloadPath
fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true)
if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True {
if _, err := os.Stat(fp); err == nil {
// file is marked as completed downloaded and exists...
return ""
} else {
// the user probably deleted the file, mark completed as false...
profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False)
}
}
log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey)
ev.Event.Data[event.FilePath] = fp ev.Event.Data[event.FilePath] = fp
if _, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists { fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes)
ev.Event.Data[event.FileDownloadFinished] = constants.True
} else {
ev.Event.Data[event.FileDownloadFinished] = constants.False
fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes)
}
} else { } else {
// if image previews are disabled then ignore this event...
return "" return ""
} }
} }