image previews
This commit is contained in:
parent
cac25c0d67
commit
d59d54ab6a
|
@ -3,7 +3,6 @@ package utils
|
|||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"cwtch.im/cwtch/app"
|
||||
"cwtch.im/cwtch/app/plugins"
|
||||
|
@ -15,14 +14,11 @@ import (
|
|||
"git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups"
|
||||
"git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
<<<<<<< HEAD
|
||||
|
||||
"time"
|
||||
|
||||
"cwtch.im/cwtch/event"
|
||||
"cwtch.im/cwtch/functionality/filesharing"
|
||||
=======
|
||||
"strconv"
|
||||
"time"
|
||||
>>>>>>> aa102bd169a9f4d71b18d9c16c590f61ba827ab3
|
||||
)
|
||||
|
||||
type EventProfileEnvelope struct {
|
||||
|
@ -280,31 +276,21 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
err := json.Unmarshal([]byte(ev.Event.Data[event.Data]), &cm)
|
||||
if err == nil && cm.Overlay == model.OverlayFileSharing {
|
||||
var fm filesharing.OverlayMessage
|
||||
log.Debugf("parsing: %v", cm.Data)
|
||||
err = json.Unmarshal([]byte(cm.Data), &fm)
|
||||
if err == nil {
|
||||
lname := strings.ToLower(fm.Name)
|
||||
if strings.HasSuffix(lname, "jpg") || strings.HasSuffix(lname, "jpeg") || strings.HasSuffix(lname, "png") || strings.HasSuffix(lname, "gif") || strings.HasSuffix(lname, "webp") || strings.HasSuffix(lname, "bmp") {
|
||||
if fm.ShouldAutoDL() {
|
||||
settings := ReadGlobalSettings()
|
||||
basepath := settings.DownloadPath
|
||||
//todo: security
|
||||
fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name)
|
||||
log.Debugf("NMFP: autodownloading file!!!")
|
||||
log.Debugf("%v | %v | %v | %v | %v | %v", basepath, fm.Name, fp, mp, fm.FileKey(), fm)
|
||||
fh.DownloadFile(peer, ev.Event.Data[event.RemotePeer], fp, mp, fm.FileKey())
|
||||
} else {
|
||||
log.Debugf("NMFP: suffix not jpg/jpeg/png")
|
||||
log.Debugf("autodownloading file!")
|
||||
ev.Event.Data["Auto"] = "true"
|
||||
mID, _ := strconv.Atoi(ev.Event.Data["Index"])
|
||||
profile.UpdateMessageAttribute(ci.ID, 0, mID, "file-downloaded", "true")
|
||||
fh.DownloadFile(profile, ci.ID, fp, mp, fm.FileKey())
|
||||
}
|
||||
} else {
|
||||
log.Debugf("NMFP: not a file overlay message")
|
||||
}
|
||||
} else {
|
||||
log.Debugf("NMFP: not a message wrapper")
|
||||
}
|
||||
} else {
|
||||
log.Debugf("NMFP: file experiment is off")
|
||||
}
|
||||
|
||||
case event.NewMessageFromGroup:
|
||||
// only needs contact nickname and picture, for displaying on popup notifications
|
||||
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
||||
|
@ -321,6 +307,29 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
|||
ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data[event.RemotePeer])
|
||||
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
|
||||
profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False)
|
||||
|
||||
// note careful use of ci.ID versus conversationID
|
||||
fh, err := filesharing.PreviewFunctionalityGate(ReadGlobalSettings().Experiments)
|
||||
if err == nil && ci != nil && ci.Accepted {
|
||||
var cm model.MessageWrapper
|
||||
err := json.Unmarshal([]byte(ev.Event.Data[event.Data]), &cm)
|
||||
if err == nil && cm.Overlay == model.OverlayFileSharing {
|
||||
var fm filesharing.OverlayMessage
|
||||
err = json.Unmarshal([]byte(cm.Data), &fm)
|
||||
if err == nil {
|
||||
if fm.ShouldAutoDL() {
|
||||
settings := ReadGlobalSettings()
|
||||
basepath := settings.DownloadPath
|
||||
fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name)
|
||||
log.Debugf("autodownloading file!")
|
||||
ev.Event.Data["Auto"] = "true"
|
||||
mID, _ := strconv.Atoi(ev.Event.Data["Index"])
|
||||
profile.UpdateMessageAttribute(conversationID, 0, mID, "file-downloaded", "true")
|
||||
fh.DownloadFile(profile, ci.ID, fp, mp, fm.FileKey())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case event.PeerAcknowledgement:
|
||||
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
||||
if ci != nil && err == nil {
|
||||
|
|
Reference in New Issue