wip image previews
This commit is contained in:
parent
7f5d466d49
commit
1b0333d468
|
@ -1,20 +1,24 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"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/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"
|
|
||||||
|
"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
|
||||||
|
@ -262,6 +266,37 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
ev.Event.Data["Nick"] = ph.GetNick(ev.Event.Data["RemotePeer"])
|
ev.Event.Data["Nick"] = ph.GetNick(ev.Event.Data["RemotePeer"])
|
||||||
ev.Event.Data["Picture"] = ph.GetProfilePic(ev.Event.Data["RemotePeer"])
|
ev.Event.Data["Picture"] = ph.GetProfilePic(ev.Event.Data["RemotePeer"])
|
||||||
peer.SetContactAttribute(ev.Event.Data["RemotePeer"], attr.GetLocalScope(constants2.Archived), event.False)
|
peer.SetContactAttribute(ev.Event.Data["RemotePeer"], attr.GetLocalScope(constants2.Archived), event.False)
|
||||||
|
|
||||||
|
fh, err := filesharing.PreviewFunctionalityGate(ReadGlobalSettings().Experiments)
|
||||||
|
if err == nil {
|
||||||
|
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
|
||||||
|
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") {
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
} 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:
|
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
|
||||||
ev.Event.Data["Nick"] = ph.GetNick(ev.Event.Data[event.GroupID])
|
ev.Event.Data["Nick"] = ph.GetNick(ev.Event.Data[event.GroupID])
|
||||||
|
|
|
@ -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 (
|
||||||
|
@ -36,6 +38,7 @@ type GlobalSettings struct {
|
||||||
FirstTime bool
|
FirstTime bool
|
||||||
UIColumnModePortrait string
|
UIColumnModePortrait string
|
||||||
UIColumnModeLandscape string
|
UIColumnModeLandscape string
|
||||||
|
DownloadPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
var DefaultGlobalSettings = GlobalSettings{
|
var DefaultGlobalSettings = GlobalSettings{
|
||||||
|
@ -50,6 +53,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 {
|
||||||
|
@ -111,6 +115,7 @@ func WriteGlobalSettings(globalSettings GlobalSettings) {
|
||||||
lock.Lock()
|
lock.Lock()
|
||||||
defer lock.Unlock()
|
defer lock.Unlock()
|
||||||
bytes, _ := json.Marshal(globalSettings)
|
bytes, _ := json.Marshal(globalSettings)
|
||||||
|
log.Debugf("writing settings: %v", string(bytes))
|
||||||
// override first time setting
|
// override first time setting
|
||||||
globalSettings.FirstTime = true
|
globalSettings.FirstTime = true
|
||||||
err := GlobalSettingsFile.Write(bytes)
|
err := GlobalSettingsFile.Write(bytes)
|
||||||
|
|
Reference in New Issue