diff --git a/go.mod b/go.mod index b5e5651..8b7e273 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go go 1.15 require ( - cwtch.im/cwtch v0.14.5 + cwtch.im/cwtch v0.14.6 git.openprivacy.ca/cwtch.im/server v1.4.1 git.openprivacy.ca/openprivacy/connectivity v1.5.0 git.openprivacy.ca/openprivacy/log v1.0.3 diff --git a/go.sum b/go.sum index 02918ee..fa5ea4f 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,7 @@ cwtch.im/cwtch v0.14.4 h1:QbQVzrAqczAG5tGazQvRVfN7MyQPWVN5Fwv7MzCXZs4= cwtch.im/cwtch v0.14.4/go.mod h1:/fLuoYLY/7JHw6RojFojpd245CiOcU24QpWqzh9FRDI= cwtch.im/cwtch v0.14.5 h1:GY86C8UgqmuGh7ATR4C14hndc+c7PwPI8WH3l2iwnaQ= cwtch.im/cwtch v0.14.5/go.mod h1:/fLuoYLY/7JHw6RojFojpd245CiOcU24QpWqzh9FRDI= +cwtch.im/cwtch v0.14.6/go.mod h1:/fLuoYLY/7JHw6RojFojpd245CiOcU24QpWqzh9FRDI= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/lib.go b/lib.go index 3eb5a77..26d1a0e 100644 --- a/lib.go +++ b/lib.go @@ -8,17 +8,20 @@ import "C" import ( "crypto/rand" - constants2 "cwtch.im/cwtch/model/constants" "encoding/json" "fmt" + + constants2 "cwtch.im/cwtch/model/constants" + // Import SQL Cipher - _ "github.com/mutecomm/go-sqlcipher/v4" "os/user" "runtime" "strconv" "strings" "unsafe" + _ "github.com/mutecomm/go-sqlcipher/v4" + "cwtch.im/cwtch/app" "cwtch.im/cwtch/event" "cwtch.im/cwtch/functionality/filesharing" @@ -96,7 +99,6 @@ func StartCwtch(appDir string, torPath string) int { if logLevel := os.Getenv("LOG_LEVEL"); strings.ToLower(logLevel) == "debug" { log.SetLevel(log.LevelDebug) } - log.Infof("StartCwtch(...)") // Quick hack check that we're being called with the correct params // On android a stale worker could be calling us with "last apps" directory. Best to abort fast so the app can make a new worker diff --git a/utils/eventHandler.go b/utils/eventHandler.go index c4a6cc2..7316544 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -1,21 +1,26 @@ package utils import ( + "encoding/json" + "strconv" + "cwtch.im/cwtch/app" "cwtch.im/cwtch/app/plugins" "cwtch.im/cwtch/model" "cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/model/constants" + "cwtch.im/cwtch/peer" "cwtch.im/cwtch/protocol/connections" - "encoding/json" constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" "git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups" "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" "git.openprivacy.ca/openprivacy/log" - "strconv" + "time" + + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/functionality/filesharing" ) -import "cwtch.im/cwtch/event" type EventProfileEnvelope struct { Event event.Event @@ -264,6 +269,9 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { } ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data["RemotePeer"]) + if ci.Accepted { + handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID) + } case event.NewMessageFromGroup: // only needs contact nickname and picture, for displaying on popup notifications ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) @@ -280,6 +288,10 @@ 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) + + if ci != nil && ci.Accepted { + handleImagePreviews(profile, &ev.Event, conversationID, ci.ID) + } case event.PeerAcknowledgement: ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) if ci != nil && err == nil { @@ -453,3 +465,28 @@ func getLastMessageTime(conversationMessages []model.ConversationMessage) int { } return int(time.Unix()) } + +// handleImagePreviews checks settings and, if appropriate, auto-downloads any images +func handleImagePreviews(profile peer.CwtchPeer, ev *event.Event, conversationID, senderID int) { + settings := ReadGlobalSettings() + fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) + if err == nil { + var cm model.MessageWrapper + err := json.Unmarshal([]byte(ev.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() { + basepath := settings.DownloadPath + fp, mp := filesharing.GenerateDownloadPath(basepath, fm.Name) + log.Debugf("autodownloading file!") + ev.Data["Auto"] = constants.True + mID, _ := strconv.Atoi(ev.Data["Index"]) + profile.UpdateMessageAttribute(conversationID, 0, mID, constants.AttrDownloaded, constants.True) + fh.DownloadFile(profile, senderID, fp, mp, fm.FileKey()) + } + } + } + } +} diff --git a/utils/settings.go b/utils/settings.go index 1786729..cf4ee70 100644 --- a/utils/settings.go +++ b/utils/settings.go @@ -1,15 +1,17 @@ package utils import ( - "cwtch.im/cwtch/event" - "cwtch.im/cwtch/storage/v1" "sync" + "cwtch.im/cwtch/event" + "cwtch.im/cwtch/storage/v1" + "encoding/json" - "git.openprivacy.ca/openprivacy/log" "io/ioutil" "os" "path" + + "git.openprivacy.ca/openprivacy/log" ) const ( @@ -37,6 +39,7 @@ type GlobalSettings struct { FirstTime bool UIColumnModePortrait string UIColumnModeLandscape string + DownloadPath string } var DefaultGlobalSettings = GlobalSettings{ @@ -51,6 +54,7 @@ var DefaultGlobalSettings = GlobalSettings{ StreamerMode: false, UIColumnModePortrait: "DualpaneMode.Single", UIColumnModeLandscape: "DualpaneMode.CopyPortrait", + DownloadPath: "", } func InitGlobalSettingsFile(directory string, password string) error {