🐛 Fix push notifications wont work

This commit is contained in:
LittleSheep 2024-07-10 17:38:39 +08:00
parent 77c1a029bd
commit e5bdb23c09
4 changed files with 37 additions and 35 deletions

58
.idea/workspace.xml generated
View File

@ -4,10 +4,8 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":poop: Remove mis-imported cgo"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Bug fixes">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/server/admin/users_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/admin/users_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/web/src/views/admin/users.vue" beforeDir="false" afterPath="$PROJECT_DIR$/web/src/views/admin/users.vue" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -42,34 +40,34 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"DefaultGoTemplateProperty": "Go File", &quot;DefaultGoTemplateProperty&quot;: &quot;Go File&quot;,
"Go Build.Backend.executor": "Run", &quot;Go Build.Backend.executor&quot;: &quot;Run&quot;,
"Go 构建.Backend.executor": "Run", &quot;Go 构建.Backend.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.go.formatter.settings.were.checked": "true", &quot;RunOnceActivity.go.formatter.settings.were.checked&quot;: &quot;true&quot;,
"RunOnceActivity.go.migrated.go.modules.settings": "true", &quot;RunOnceActivity.go.migrated.go.modules.settings&quot;: &quot;true&quot;,
"RunOnceActivity.go.modules.automatic.dependencies.download": "true", &quot;RunOnceActivity.go.modules.automatic.dependencies.download&quot;: &quot;true&quot;,
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true", &quot;RunOnceActivity.go.modules.go.list.on.any.changes.was.set&quot;: &quot;true&quot;,
"git-widget-placeholder": "master", &quot;git-widget-placeholder&quot;: &quot;master&quot;,
"go.import.settings.migrated": "true", &quot;go.import.settings.migrated&quot;: &quot;true&quot;,
"go.sdk.automatically.set": "true", &quot;go.sdk.automatically.set&quot;: &quot;true&quot;,
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/src/components/admin", &quot;last_opened_file_path&quot;: &quot;/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/src/components/admin&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"run.code.analysis.last.selected.profile": "pProject Default", &quot;run.code.analysis.last.selected.profile&quot;: &quot;pProject Default&quot;,
"settings.editor.selected.configurable": "preferences.pluginManager", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib", &quot;ts.external.directory.path&quot;: &quot;/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}, },
"keyToStringList": { &quot;keyToStringList&quot;: {
"DatabaseDriversLRU": [ &quot;DatabaseDriversLRU&quot;: [
"postgresql" &quot;postgresql&quot;
] ]
} }
}]]></component> }</component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/web/src/components/admin" /> <recent name="$PROJECT_DIR$/web/src/components/admin" />
@ -153,7 +151,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":bug: Invisible status is visible to others" />
<MESSAGE value=":ambulance: Fix nil pointer panic" /> <MESSAGE value=":ambulance: Fix nil pointer panic" />
<MESSAGE value=":bug: Not supposed to appear to status at the same time" /> <MESSAGE value=":bug: Not supposed to appear to status at the same time" />
<MESSAGE value=":ambulance: Fix getting user panic again..." /> <MESSAGE value=":ambulance: Fix getting user panic again..." />
@ -178,7 +175,8 @@
<MESSAGE value=":sparkles: View auth factors in admin panel" /> <MESSAGE value=":sparkles: View auth factors in admin panel" />
<MESSAGE value=":rotating_light: Fix ts lint issue" /> <MESSAGE value=":rotating_light: Fix ts lint issue" />
<MESSAGE value=":poop: Remove mis-imported cgo" /> <MESSAGE value=":poop: Remove mis-imported cgo" />
<option name="LAST_COMMIT_MESSAGE" value=":poop: Remove mis-imported cgo" /> <MESSAGE value=":bug: Bug fixes" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Bug fixes" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

View File

@ -2,6 +2,8 @@ package services
import ( import (
"context" "context"
"reflect"
"firebase.google.com/go/messaging" "firebase.google.com/go/messaging"
"git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models" "git.solsynth.dev/hydrogen/passport/pkg/internal/models"
@ -9,7 +11,6 @@ import (
"github.com/sideshow/apns2" "github.com/sideshow/apns2"
payload2 "github.com/sideshow/apns2/payload" payload2 "github.com/sideshow/apns2/payload"
"github.com/spf13/viper" "github.com/spf13/viper"
"reflect"
) )
func AddNotifySubscriber(user models.Account, provider, id, tk, ua string) (models.NotificationSubscriber, error) { func AddNotifySubscriber(user models.Account, provider, id, tk, ua string) (models.NotificationSubscriber, error) {

View File

@ -2,10 +2,11 @@ package services
import ( import (
"fmt" "fmt"
"time"
"git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models" "git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"github.com/samber/lo" "github.com/samber/lo"
"time"
) )
var statusCache = make(map[uint]models.Status) var statusCache = make(map[uint]models.Status)
@ -30,15 +31,17 @@ func GetStatus(uid uint) (models.Status, error) {
return status, nil return status, nil
} }
func GetUserOnline(uid uint) bool {
return wsConn[uid] != nil && len(wsConn[uid]) > 0
}
func GetStatusDisturbable(uid uint) error { func GetStatusDisturbable(uid uint) error {
status, err := GetStatus(uid) status, err := GetStatus(uid)
isOnline := wsConn[uid] != nil && len(wsConn[uid]) > 0 isOnline := GetUserOnline(uid)
if isOnline && err != nil { if isOnline && err != nil {
return nil return nil
} else if err == nil && status.IsNoDisturb { } else if err == nil && status.IsNoDisturb {
return fmt.Errorf("do not disturb") return fmt.Errorf("do not disturb")
} else if !isOnline {
return fmt.Errorf("offline")
} else { } else {
return nil return nil
} }

BIN
web/bun.lockb Executable file

Binary file not shown.