diff --git a/.drone.yml b/.drone.yml index 9cb4db2..36ad59f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,6 +17,8 @@ steps: - git fetch --tags - go mod download - echo `git describe --tags` > VERSION + - echo `git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M` > COMMIT_DATE + - export GOSUMDB="off" - name: build-linux image: golang:1.19.1 @@ -68,9 +70,9 @@ steps: - echo $BUILDFILES_KEY > ~/id_rsab64 - base64 -d ~/id_rsab64 > ~/id_rsa - chmod 400 ~/id_rsa - - export DIR=libCwtch-autobindings-`cat VERSION` + - export DIR=libCwtch-autobindings-`cat VERSION`-`cat COMMIT_DATE` - mkdir -p $DIR - - mv libCwtch.so libCwtch.dll cwtch.aar cwtch-sources.jar libCwtch.h $DIR/ + - mv windows android linux $DIR/ - cd $DIR - find . -type f -exec sha256sum {} \; > ./../sha256s.txt - mv ./../sha256s.txt . @@ -136,6 +138,7 @@ steps: - export PATH=$PATH:/usr/local/go/bin/ - git fetch --tags - echo `git describe --tags` > VERSION + - echo `git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M` > COMMIT_DATE - name: build-macos-x64 commands: - export PATH=$PATH:/usr/local/go/bin/ @@ -163,10 +166,9 @@ steps: - echo $BUILDFILES_KEY > ~/id_rsab64 - base64 -d ~/id_rsab64 > ~/id_rsa - chmod 400 ~/id_rsa - - export DIR=libCwtch-autobindings-`cat VERSION` + - export DIR=libCwtch-autobindings-`cat VERSION`-`cat COMMIT_DATE` - mkdir -p $DIR - - mv libCwtch.x64.dylib $DIR/ - - mv libCwtch.arm64.dylib $DIR/ + - mv macos $DIR/ - cd $DIR - find . -type f -exec shasum -a 512 {} \; > ./../sha512s.txt - mv ./../sha512s.txt . diff --git a/Makefile b/Makefile index 3f02a70..c490f14 100644 --- a/Makefile +++ b/Makefile @@ -17,18 +17,29 @@ windows: libCwtch.dll libCwtch.so: lib.go ./switch-ffi.sh go build -trimpath -ldflags "-buildid=autobindings-$(shell git describe --tags) -X main.buildVer=autobindings-$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.so + mkdir -p build/linux + mv libCwtch.so build/linux/ + mv libCwtch.h build/linux/ libCwtch.x64.dylib: lib.go ./switch-ffi.sh go build -trimpath -ldflags "-buildid=autobindings-$(shell git describe --tags) -X main.buildVer=autobindings-$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.x64.dylib + mkdir -p build/macos + mv libCwtch.x64.dylib build/macos/ libCwtch.arm64.dylib: lib.go ./switch-ffi.sh env GOARCH=arm64 GOOS=darwin CGO_ENABLED=1 go build -trimpath -ldflags "-buildid=$(shell git describe --tags) -X main.buildVer=$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" -buildmode c-shared -o libCwtch.arm64.dylib + mkdir -p build/macos + mv libCwtch.arm64.dylib build/macos/ + mv libCwtch.h build/macos/ cwtch.aar: lib.go ./switch-gomobile.sh gomobile bind -trimpath -target android/arm,android/arm64,android/amd64 -ldflags="-buildid=$(shell git describe --tags) -X cwtch.buildVer=$(shell git describe --tags) -X cwtch.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M)" + mkdir -p build/android + mv cwtch.aar build/android/ + mv cwtch-sources.jar build/android/ libCwtch.dll: lib.go ./switch-ffi.sh @@ -37,9 +48,12 @@ libCwtch.dll: lib.go # note: the above documentation also references an ability to set an optional timestamp - this behaviour seems to no longer be supported in more recent versions of mingw32-gcc (the help docs no longer reference that functionality) # these flags have to be passed through to the underlying gcc process using the -extldflags option in the underlying go linker, note that the whole flag is quoted...this is necessary. GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc-win32 go build -trimpath -ldflags "-buildid=$(shell git describe --tags) -X main.buildVer=$(shell git describe --tags) -X main.buildDate=$(shell git log -1 --format=%cd --date=format:%G-%m-%d-%H-%M) '-extldflags=-Xlinker --no-insert-timestamp'" -buildmode c-shared -o libCwtch.dll + mkdir -p build/windows + mv libCwtch.dll build/windows/ + mv libCwtch.h build/windows/ clean: - rm -f cwtch.aar cwtch_go.apk libCwtch.h libCwtch.so cwtch-sources.jar libCwtch.dll libCwtch.dylib + rm -f cwtch.aar cwtch_go.apk libCwtch.h libCwtch.so cwtch-sources.jar libCwtch.dll libCwtch.dylib build # iOS - for testing purposes only for now, not officially supported diff --git a/generate/generate_bindings.go b/generate/generate_bindings.go index 60f6198..ead8ac4 100644 --- a/generate/generate_bindings.go +++ b/generate/generate_bindings.go @@ -405,7 +405,7 @@ func c_{{FNAME}}({{C_ARGS}}) { func {{FNAME}}({{GO_ARGS_SPEC}}) { cwtchProfile := application.GetPeer(profile) if cwtchProfile != nil { - functionality, _ := {{EXPERIMENT}}.FunctionalityGate(application.ReadSettings().Experiments) + functionality := {{EXPERIMENT}}.FunctionalityGate() if functionality != nil { functionality.{{LIBNAME}}(cwtchProfile, {{GO_ARG}}) } @@ -439,7 +439,7 @@ func c_{{FNAME}}({{C_ARGS}}) *C.char { func {{FNAME}}({{GO_ARGS_SPEC}}) string { cwtchProfile := application.GetPeer(profile) if cwtchProfile != nil { - functionality, _ := {{EXPERIMENT}}.FunctionalityGate(application.ReadSettings().Experiments) + functionality := {{EXPERIMENT}}.FunctionalityGate() if functionality != nil { return functionality.{{LIBNAME}}(cwtchProfile, {{GO_ARG}}) } diff --git a/go.mod b/go.mod index 7284ee7..05dbcc4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/cwtch-autobindings go 1.19 require ( - cwtch.im/cwtch v0.19.1 + cwtch.im/cwtch v0.19.2 git.openprivacy.ca/cwtch.im/server v1.4.5 git.openprivacy.ca/openprivacy/connectivity v1.8.6 git.openprivacy.ca/openprivacy/log v1.0.3 diff --git a/go.sum b/go.sum index 3cce690..5d4543a 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,6 @@ cwtch.im/cwtch v0.18.0/go.mod h1:StheazFFY7PKqBbEyDVLhzWW6WOat41zV0ckC240c5Y= -cwtch.im/cwtch v0.19.0 h1:s5YkU3od1ZJB+8OXoJAy8vjgi6lkIVhbdkXIE8V+iZY= -cwtch.im/cwtch v0.19.0/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A= -cwtch.im/cwtch v0.19.1 h1:PRZtIZa1AIZ4jtIItUCN4ROcNLpPE4Ds8VksbbVa3ks= -cwtch.im/cwtch v0.19.1/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A= +cwtch.im/cwtch v0.19.2 h1:H7DrSKQ9J7aNkKQkdyGGWckEV+dPKbL5PMRq0GoAn6I= +cwtch.im/cwtch v0.19.2/go.mod h1:h8S7EgEM+8pE1k+XLB5jAFdIPlOzwoXEY0GH5mQye5A= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= diff --git a/templates/lib_template.go b/templates/lib_template.go index 7fe82dd..f5cbed1 100644 --- a/templates/lib_template.go +++ b/templates/lib_template.go @@ -10,6 +10,7 @@ import ( "cwtch.im/cwtch/event" "cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/model/constants" + "cwtch.im/cwtch/settings" "encoding/json" "fmt" "git.openprivacy.ca/cwtch.im/cwtch-autobindings/utils" @@ -149,7 +150,7 @@ func _startCwtch(appDir string, torPath string) { } log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath) - app.InitGlobalSettingsFile(appDir, app.DefactoPasswordForUnencryptedProfiles) + settings.InitGlobalSettingsFile(appDir, app.DefactoPasswordForUnencryptedProfiles) log.Infof("making directory %v", appDir) err = os.MkdirAll(path.Join(appDir, "tor"), 0700) @@ -164,17 +165,17 @@ func _startCwtch(appDir string, torPath string) { globalAppDir = appDir globalTorPath = torPath settingsFile := app.LoadAppSettings(appDir) - newACN, settings := buildACN(settingsFile.ReadGlobalSettings(), globalTorPath, globalAppDir) + newACN, globalSettings := buildACN(settingsFile.ReadGlobalSettings(), globalTorPath, globalAppDir) globalACN = connectivity.NewProxyACN(newACN) - settingsFile.WriteGlobalSettings(settings) + settingsFile.WriteGlobalSettings(globalSettings) application = app.NewApp(&globalACN, appDir, settingsFile) // Subscribe to all App Events... eventHandler.HandleApp(application) // Settings may have changed... - settings = settings - settingsJson, _ := json.Marshal(settings) + globalSettings = settingsFile.ReadGlobalSettings() + settingsJson, _ := json.Marshal(globalSettings) // FIXME: This code exists to allow the Splash Screen test in the new UI integration tests to pass // it doesn't actually fix the problem in theory, and we should get around to ensuring that application @@ -184,10 +185,10 @@ func _startCwtch(appDir string, torPath string) { return } // Send global settings to the UI... - application.UpdateSettings(application.ReadSettings()) - application.GetPrimaryBus().Publish(event.NewEvent(app.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) + application.UpdateSettings(globalSettings) + application.GetPrimaryBus().Publish(event.NewEvent(settings.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) log.Infof("libcwtch-go application launched") - application.GetPrimaryBus().Publish(event.NewEvent(app.CwtchStarted, map[event.Field]string{})) + application.GetPrimaryBus().Publish(event.NewEvent(settings.CwtchStarted, map[event.Field]string{})) application.QueryACNVersion() application.LoadProfiles(app.DefactoPasswordForUnencryptedProfiles) @@ -233,8 +234,8 @@ func ReconnectCwtchForeground() { // TODO: Need To Repopulate UI settingsJson, _ := json.Marshal(application.ReadSettings()) - application.GetPrimaryBus().Publish(event.NewEvent(app.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) - application.GetPrimaryBus().Publish(event.NewEvent(app.CwtchStarted, map[event.Field]string{})) + application.GetPrimaryBus().Publish(event.NewEvent(settings.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)})) + application.GetPrimaryBus().Publish(event.NewEvent(settings.CwtchStarted, map[event.Field]string{})) application.QueryACNStatus() application.QueryACNVersion() } @@ -397,7 +398,7 @@ const ( UpdateGlobalSettings = event.Type("UpdateGlobalSettings") ) -func buildACN(settings app.GlobalSettings, torPath string, appDir string) (connectivity.ACN, app.GlobalSettings) { +func buildACN(globalSettings settings.GlobalSettings, torPath string, appDir string) (connectivity.ACN, settings.GlobalSettings) { mrand.Seed(int64(time.Now().Nanosecond())) socksPort := mrand.Intn(1000) + 9600 @@ -416,24 +417,24 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne if err != nil { log.Errorf("error creating tor data directory: %v. Aborting app start up", err) eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err))) - return &connectivity.ErrorACN{}, settings + return &connectivity.ErrorACN{}, globalSettings } - if settings.AllowAdvancedTorConfig { - controlPort = settings.CustomControlPort - socksPort = settings.CustomSocksPort + if globalSettings.AllowAdvancedTorConfig { + controlPort = globalSettings.CustomControlPort + socksPort = globalSettings.CustomSocksPort } torrc := tor.NewTorrc().WithSocksPort(socksPort).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)) // torrc.WithLog(path.Join(appDir, "tor", "tor.log"), tor.TorLogLevelNotice) - if settings.UseCustomTorrc { - customTorrc := settings.CustomTorrc + if globalSettings.UseCustomTorrc { + customTorrc := globalSettings.CustomTorrc torrc.WithCustom(strings.Split(customTorrc, "\n")) } else { // Fallback to showing the freshly generated torrc for this session. - settings.CustomTorrc = torrc.Preview() - settings.CustomControlPort = controlPort - settings.CustomSocksPort = socksPort + globalSettings.CustomTorrc = torrc.Preview() + globalSettings.CustomControlPort = controlPort + globalSettings.CustomSocksPort = socksPort } err = torrc.Build(path.Join(appDir, "tor", "torrc")) @@ -441,11 +442,11 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne if err != nil { log.Errorf("error constructing torrc: %v", err) eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err))) - return &connectivity.ErrorACN{}, settings + return &connectivity.ErrorACN{}, globalSettings } - dataDir := settings.TorCacheDir - if !settings.UseTorCache { + dataDir := globalSettings.TorCacheDir + if !globalSettings.UseTorCache { // purge data dir directories if we are not using them for a cache torDir := path.Join(appDir, "tor") @@ -461,12 +462,12 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne if dataDir, err = os.MkdirTemp(torDir, "data-dir-"); err != nil { eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err))) - return &connectivity.ErrorACN{}, settings + return &connectivity.ErrorACN{}, globalSettings } } // Persist Current Data Dir as Tor Cache... - settings.TorCacheDir = dataDir + globalSettings.TorCacheDir = dataDir acn, err := tor.NewTorACNWithAuth(appDir, torPath, dataDir, controlPort, tor.HashedPasswordAuthenticator{Password: base64.StdEncoding.EncodeToString(key)}) if err != nil { @@ -474,7 +475,7 @@ func buildACN(settings app.GlobalSettings, torPath string, appDir string) (conne eventHandler.Push(event.NewEventList(CwtchStartError, event.Error, fmt.Sprintf("Error connecting to Tor: %v", err))) acn = &connectivity.ErrorACN{} } - return acn, settings + return acn, globalSettings } @@ -485,7 +486,7 @@ func c_UpdateSettings(json_ptr *C.char, json_len C.int) { } func UpdateSettings(settingsJson string) { - var newSettings app.GlobalSettings + var newSettings settings.GlobalSettings json.Unmarshal([]byte(settingsJson), &newSettings) application.UpdateSettings(newSettings) {{EXPERIMENT_UPDATESETTINGS}} diff --git a/utils/eventHandler.go b/utils/eventHandler.go index 72fc91c..ddab3db 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -1,6 +1,7 @@ package utils import ( + "cwtch.im/cwtch/settings" "encoding/json" "fmt" "git.openprivacy.ca/cwtch.im/cwtch-autobindings/experiments/servers" @@ -66,8 +67,8 @@ func (eh *EventHandler) HandleApp(application app.Application) { application.GetPrimaryBus().Subscribe(event.AppError, eh.appBusQueue) application.GetPrimaryBus().Subscribe(event.ACNStatus, eh.appBusQueue) application.GetPrimaryBus().Subscribe(event.ACNVersion, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(app.UpdateGlobalSettings, eh.appBusQueue) - application.GetPrimaryBus().Subscribe(app.CwtchStarted, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(settings.UpdateGlobalSettings, eh.appBusQueue) + application.GetPrimaryBus().Subscribe(settings.CwtchStarted, eh.appBusQueue) application.GetPrimaryBus().Subscribe(servers.NewServer, eh.appBusQueue) application.GetPrimaryBus().Subscribe(servers.ServerIntentUpdate, eh.appBusQueue) application.GetPrimaryBus().Subscribe(servers.ServerDeleted, eh.appBusQueue) @@ -393,10 +394,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { } } - if ci.Accepted { - handleImagePreviews(profile, &ev.Event, ci.ID, ci.ID, eh.app.ReadSettings()) - } - ev.Event.Data["notification"] = string(determineNotification(ci, eh.app.ReadSettings())) case event.NewMessageFromGroup: // only needs contact nickname and picture, for displaying on popup notifications @@ -417,10 +414,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { 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, eh.app.ReadSettings()) - } - gci, _ := profile.GetConversationInfo(conversationID) groupServer := gci.Attributes[attr.LocalScope.ConstructScopedZonedPath(attr.LegacyGroupZone.ConstructZonedPath(constants.GroupServer)).ToString()] state := profile.GetPeerState(groupServer) @@ -550,7 +543,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { onion := ev.Event.Data[event.RemotePeer] scope := ev.Event.Data[event.Scope] path := ev.Event.Data[event.Path] - val := ev.Event.Data[event.Data] exists, _ := strconv.ParseBool(ev.Event.Data[event.Exists]) conversation, err := profile.FetchConversationInfo(onion) @@ -558,36 +550,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { if exists && attr.IntoScope(scope) == attr.PublicScope { zone, path := attr.ParseZone(path) - - // auto download profile images from contacts... - settings := eh.app.ReadSettings() - if settings.ExperimentsEnabled && zone == attr.ProfileZone && path == constants.CustomProfileImageKey { - fileKey := val - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if err == nil && imagePreviewsEnabled && conversation.Accepted { - - basepath := settings.DownloadPath - fp, mp := filesharing.GenerateDownloadPath(basepath, fileKey, true) - - if value, exists := profile.GetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey)); exists && value == event.True { - if _, err := os.Stat(fp); err == nil { - // file is marked as completed downloaded and exists... - return "" - } else { - // the user probably deleted the file, mark completed as false... - profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.complete", fileKey), event.False) - } - } - - log.Debugf("Downloading Profile Image %v %v %v", fp, mp, fileKey) - ev.Event.Data[event.FilePath] = fp - fsf.DownloadFile(profile, conversation.ID, fp, mp, val, constants.ImagePreviewMaxSizeInBytes) - } else { - // if image previews are disabled then ignore this event... - return "" - } - } if val, err := profile.GetConversationAttribute(conversation.ID, attr.LocalScope.ConstructScopedZonedPath(zone.ConstructZonedPath(path))); err == nil || val != "" { // we have a locally set override, don't pass this remote set public scope update to UI return "" @@ -623,24 +585,6 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { } else { profile.AllowUnknownConnections() } - - // Now that the Peer Engine is Activated, Share Files - key, exists := profile.GetScopedZonedAttribute(attr.PublicScope, attr.ProfileZone, constants.CustomProfileImageKey) - if exists { - serializedManifest, _ := profile.GetScopedZonedAttribute(attr.ConversationScope, attr.FilesharingZone, fmt.Sprintf("%s.manifest", key)) - // reset the share timestamp, currently file shares are hardcoded to expire after 30 days... - // we reset the profile image here so that it is always available. - profile.SetScopedZonedAttribute(attr.LocalScope, attr.FilesharingZone, fmt.Sprintf("%s.ts", key), strconv.FormatInt(time.Now().Unix(), 10)) - log.Infof("Custom Profile Image: %v %s", key, serializedManifest) - - } - // If file sharing is enabled then reshare all active files... - fsf, err := filesharing.FunctionalityGate(settings.Experiments) - if err == nil { - fsf.ReShareFiles(profile) - info, _ := fsf.GetFileShareInfo(profile, key) - log.Infof("Custom Profile Image: %v %v", key, info) - } } } @@ -718,46 +662,3 @@ 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 app.GlobalSettings) { - fh, err := filesharing.PreviewFunctionalityGate(settings.Experiments) - - // Short-circuit if file sharing is disabled - if err != nil { - return - } - - // Short-circuit failures - // Don't autodownload images if the download path does not exist. - if settings.DownloadPath == "" { - return - } - - // Don't autodownload images if the download path does not exist. - if _, err := os.Stat(settings.DownloadPath); os.IsNotExist(err) { - return - } - - // Now look at the image preview experiment - imagePreviewsEnabled := settings.Experiments["filesharing-images"] - if imagePreviewsEnabled { - 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, false) - 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(), constants.ImagePreviewMaxSizeInBytes) - } - } - } - } -} diff --git a/utils/notifications.go b/utils/notifications.go index 614ccd2..901ffb7 100644 --- a/utils/notifications.go +++ b/utils/notifications.go @@ -1,17 +1,17 @@ package utils import ( - "cwtch.im/cwtch/app" "cwtch.im/cwtch/model" "cwtch.im/cwtch/model/attr" + "cwtch.im/cwtch/settings" "git.openprivacy.ca/cwtch.im/cwtch-autobindings/constants" ) -func determineNotification(ci *model.Conversation, settings app.GlobalSettings) constants.NotificationType { - switch settings.NotificationPolicy { - case app.NotificationPolicyMute: +func determineNotification(ci *model.Conversation, gsettings settings.GlobalSettings) constants.NotificationType { + switch gsettings.NotificationPolicy { + case settings.NotificationPolicyMute: return constants.NotificationNone - case app.NotificationPolicyOptIn: + case settings.NotificationPolicyOptIn: if ci != nil { if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists { switch policy { @@ -20,12 +20,12 @@ func determineNotification(ci *model.Conversation, settings app.GlobalSettings) case constants.ConversationNotificationPolicyNever: return constants.NotificationNone case constants.ConversationNotificationPolicyOptIn: - return notificationContentToNotificationType(settings.NotificationContent) + return notificationContentToNotificationType(gsettings.NotificationContent) } } } return constants.NotificationNone - case app.NotificationPolicyDefaultAll: + case settings.NotificationPolicyDefaultAll: if ci != nil { if policy, exists := ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.ConversationNotificationPolicy); exists { switch policy { @@ -34,11 +34,11 @@ func determineNotification(ci *model.Conversation, settings app.GlobalSettings) case constants.ConversationNotificationPolicyDefault: fallthrough case constants.ConversationNotificationPolicyOptIn: - return notificationContentToNotificationType(settings.NotificationContent) + return notificationContentToNotificationType(gsettings.NotificationContent) } } } - return notificationContentToNotificationType(settings.NotificationContent) + return notificationContentToNotificationType(gsettings.NotificationContent) } return constants.NotificationNone }