image previews sarah comments
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
This commit is contained in:
parent
8b38a8b159
commit
f4ff802460
2
go.mod
2
go.mod
|
@ -10,3 +10,5 @@ require (
|
||||||
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
|
||||||
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
|
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
replace cwtch.im/cwtch => /home/erinn/Android/Goprojects/cwtch
|
||||||
|
|
17
lib.go
17
lib.go
|
@ -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"
|
||||||
|
@ -92,11 +95,11 @@ func StartCwtch(appDir string, torPath string) int {
|
||||||
if runtime.GOOS == "android" {
|
if runtime.GOOS == "android" {
|
||||||
log.SetUseColor(false)
|
log.SetUseColor(false)
|
||||||
}
|
}
|
||||||
log.SetLevel(log.LevelInfo)
|
// log.SetLevel(log.LevelInfo)
|
||||||
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.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
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"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"
|
||||||
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"
|
||||||
|
@ -268,26 +269,8 @@ 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"])
|
||||||
|
|
||||||
fh, err := filesharing.PreviewFunctionalityGate(ReadGlobalSettings().Experiments)
|
if ci.Accepted {
|
||||||
if err == nil && ci.Accepted {
|
handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID)
|
||||||
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(ci.ID, 0, mID, "file-downloaded", "true")
|
|
||||||
fh.DownloadFile(profile, ci.ID, fp, mp, fm.FileKey())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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
|
||||||
|
@ -306,27 +289,8 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
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)
|
||||||
|
|
||||||
// note careful use of ci.ID versus conversationID
|
if ci != nil && ci.Accepted {
|
||||||
fh, err := filesharing.PreviewFunctionalityGate(ReadGlobalSettings().Experiments)
|
handleImagePreviews(profile, &ev.Event, conversationID, ci.ID)
|
||||||
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:
|
case event.PeerAcknowledgement:
|
||||||
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
ci, err := profile.FetchConversationInfo(ev.Event.Data["RemotePeer"])
|
||||||
|
@ -501,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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue