Merge pull request 'image previews' (#51) from ipreview into trunk
continuous-integration/drone/push Build is passing Details

Reviewed-on: #51
Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
Sarah Jamie Lewis 2021-12-19 01:21:40 +00:00
commit e4244aeb31
5 changed files with 54 additions and 10 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/libcwtch-go
go 1.15 go 1.15
require ( 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/cwtch.im/server v1.4.1
git.openprivacy.ca/openprivacy/connectivity v1.5.0 git.openprivacy.ca/openprivacy/connectivity v1.5.0
git.openprivacy.ca/openprivacy/log v1.0.3 git.openprivacy.ca/openprivacy/log v1.0.3

1
go.sum
View File

@ -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.4/go.mod h1:/fLuoYLY/7JHw6RojFojpd245CiOcU24QpWqzh9FRDI=
cwtch.im/cwtch v0.14.5 h1:GY86C8UgqmuGh7ATR4C14hndc+c7PwPI8WH3l2iwnaQ= 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.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= 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 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=

8
lib.go
View File

@ -8,17 +8,20 @@ import "C"
import ( import (
"crypto/rand" "crypto/rand"
constants2 "cwtch.im/cwtch/model/constants"
"encoding/json" "encoding/json"
"fmt" "fmt"
constants2 "cwtch.im/cwtch/model/constants"
// Import SQL Cipher // Import SQL Cipher
_ "github.com/mutecomm/go-sqlcipher/v4"
"os/user" "os/user"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"unsafe" "unsafe"
_ "github.com/mutecomm/go-sqlcipher/v4"
"cwtch.im/cwtch/app" "cwtch.im/cwtch/app"
"cwtch.im/cwtch/event" "cwtch.im/cwtch/event"
"cwtch.im/cwtch/functionality/filesharing" "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" { if logLevel := os.Getenv("LOG_LEVEL"); strings.ToLower(logLevel) == "debug" {
log.SetLevel(log.LevelDebug) log.SetLevel(log.LevelDebug)
} }
log.Infof("StartCwtch(...)") log.Infof("StartCwtch(...)")
// Quick hack check that we're being called with the correct params // 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 // 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

View File

@ -1,21 +1,26 @@
package utils package utils
import ( import (
"encoding/json"
"strconv"
"cwtch.im/cwtch/app" "cwtch.im/cwtch/app"
"cwtch.im/cwtch/app/plugins" "cwtch.im/cwtch/app/plugins"
"cwtch.im/cwtch/model" "cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/model/constants" "cwtch.im/cwtch/model/constants"
"cwtch.im/cwtch/peer"
"cwtch.im/cwtch/protocol/connections" "cwtch.im/cwtch/protocol/connections"
"encoding/json"
constants2 "git.openprivacy.ca/cwtch.im/libcwtch-go/constants" 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/groups"
"git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers" "git.openprivacy.ca/cwtch.im/libcwtch-go/features/servers"
"git.openprivacy.ca/openprivacy/log" "git.openprivacy.ca/openprivacy/log"
"strconv"
"time" "time"
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/functionality/filesharing"
) )
import "cwtch.im/cwtch/event"
type EventProfileEnvelope struct { type EventProfileEnvelope struct {
Event event.Event Event event.Event
@ -264,6 +269,9 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
} }
ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data["RemotePeer"]) ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data["RemotePeer"])
if ci.Accepted {
handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID)
}
case event.NewMessageFromGroup: case event.NewMessageFromGroup:
// only needs contact nickname and picture, for displaying on popup notifications // only needs contact nickname and picture, for displaying on popup notifications
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) 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]) ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data[event.RemotePeer])
conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID])
profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) 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: case event.PeerAcknowledgement:
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"]) ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
if ci != nil && err == nil { if ci != nil && err == nil {
@ -453,3 +465,28 @@ func getLastMessageTime(conversationMessages []model.ConversationMessage) int {
} }
return int(time.Unix()) 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())
}
}
}
}
}

View File

@ -1,15 +1,17 @@
package utils package utils
import ( import (
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/storage/v1"
"sync" "sync"
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/storage/v1"
"encoding/json" "encoding/json"
"git.openprivacy.ca/openprivacy/log"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"git.openprivacy.ca/openprivacy/log"
) )
const ( const (
@ -37,6 +39,7 @@ type GlobalSettings struct {
FirstTime bool FirstTime bool
UIColumnModePortrait string UIColumnModePortrait string
UIColumnModeLandscape string UIColumnModeLandscape string
DownloadPath string
} }
var DefaultGlobalSettings = GlobalSettings{ var DefaultGlobalSettings = GlobalSettings{
@ -51,6 +54,7 @@ var DefaultGlobalSettings = GlobalSettings{
StreamerMode: false, StreamerMode: false,
UIColumnModePortrait: "DualpaneMode.Single", UIColumnModePortrait: "DualpaneMode.Single",
UIColumnModeLandscape: "DualpaneMode.CopyPortrait", UIColumnModeLandscape: "DualpaneMode.CopyPortrait",
DownloadPath: "",
} }
func InitGlobalSettingsFile(directory string, password string) error { func InitGlobalSettingsFile(directory string, password string) error {