✨ Notification with avatar(only in APNs) and picture
This commit is contained in:
parent
282a0891d0
commit
8fcaf99103
55
.idea/workspace.xml
generated
55
.idea/workspace.xml
generated
@ -6,11 +6,6 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":arrow_up: Upgrade dealer">
|
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":arrow_up: Upgrade dealer">
|
||||||
<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$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/accounts.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/accounts.go" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/notifications.go" 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" />
|
||||||
@ -45,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": {
|
"keyToString": {
|
||||||
"DefaultGoTemplateProperty": "Go File",
|
"DefaultGoTemplateProperty": "Go File",
|
||||||
"Go Build.Backend.executor": "Run",
|
"Go Build.Backend.executor": "Run",
|
||||||
"Go 构建.Backend.executor": "Run",
|
"Go 构建.Backend.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||||
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
||||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||||
"git-widget-placeholder": "master",
|
"git-widget-placeholder": "master",
|
||||||
"go.import.settings.migrated": "true",
|
"go.import.settings.migrated": "true",
|
||||||
"go.sdk.automatically.set": "true",
|
"go.sdk.automatically.set": "true",
|
||||||
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/src/components/admin",
|
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/src/components/admin",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib",
|
"ts.external.directory.path": "/Users/littlesheep/Documents/Projects/Hydrogen/Passport/web/node_modules/typescript/lib",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
"DatabaseDriversLRU": [
|
"DatabaseDriversLRU": [
|
||||||
"postgresql"
|
"postgresql"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}]]></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" />
|
||||||
|
@ -12,6 +12,8 @@ type Notification struct {
|
|||||||
Subtitle *string `json:"subtitle"`
|
Subtitle *string `json:"subtitle"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Metadata datatypes.JSONMap `json:"metadata"`
|
Metadata datatypes.JSONMap `json:"metadata"`
|
||||||
|
Avatar *string `json:"avatar"`
|
||||||
|
Picture *string `json:"picture"`
|
||||||
AccountID uint `json:"account_id"`
|
AccountID uint `json:"account_id"`
|
||||||
SenderID *uint `json:"sender_id"`
|
SenderID *uint `json:"sender_id"`
|
||||||
|
|
||||||
@ -19,12 +21,6 @@ type Notification struct {
|
|||||||
IsForcePush bool `json:"is_force_push" gorm:"-"`
|
IsForcePush bool `json:"is_force_push" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotificationLink Used to embed into notify and render actions
|
|
||||||
type NotificationLink struct {
|
|
||||||
Label string `json:"label"`
|
|
||||||
Url string `json:"url"`
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NotifySubscriberFirebase = "firebase"
|
NotifySubscriberFirebase = "firebase"
|
||||||
NotifySubscriberAPNs = "apple"
|
NotifySubscriberAPNs = "apple"
|
||||||
|
@ -3,12 +3,13 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
|
||||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/gap"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/gap"
|
||||||
|
|
||||||
"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"
|
||||||
@ -112,10 +113,15 @@ func PushNotification(notification models.Notification) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var image string
|
||||||
|
if notification.Picture != nil {
|
||||||
|
image = *notification.Picture
|
||||||
|
}
|
||||||
message := &messaging.Message{
|
message := &messaging.Message{
|
||||||
Notification: &messaging.Notification{
|
Notification: &messaging.Notification{
|
||||||
Title: notification.Title,
|
Title: notification.Title,
|
||||||
Body: notification.Body,
|
Body: notification.Body,
|
||||||
|
ImageURL: image,
|
||||||
},
|
},
|
||||||
Token: subscriber.DeviceToken,
|
Token: subscriber.DeviceToken,
|
||||||
}
|
}
|
||||||
@ -131,13 +137,20 @@ func PushNotification(notification models.Notification) error {
|
|||||||
}
|
}
|
||||||
case models.NotifySubscriberAPNs:
|
case models.NotifySubscriberAPNs:
|
||||||
if ExtAPNS != nil {
|
if ExtAPNS != nil {
|
||||||
data, err := payload2.
|
data := payload2.
|
||||||
NewPayload().
|
NewPayload().
|
||||||
AlertTitle(notification.Title).
|
AlertTitle(notification.Title).
|
||||||
AlertBody(notification.Body).
|
AlertBody(notification.Body).
|
||||||
Sound("default").
|
Sound("default").
|
||||||
Category(notification.Topic).
|
Category(notification.Topic).
|
||||||
MarshalJSON()
|
MutableContent()
|
||||||
|
if notification.Avatar != nil {
|
||||||
|
data = data.Custom("avatar_url", *notification.Avatar)
|
||||||
|
}
|
||||||
|
if notification.Picture != nil {
|
||||||
|
data = data.Custom("picture_url", *notification.Picture)
|
||||||
|
}
|
||||||
|
rawData, err := data.MarshalJSON()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msg("An error occurred when preparing to notify subscriber via APNs...")
|
log.Warn().Err(err).Msg("An error occurred when preparing to notify subscriber via APNs...")
|
||||||
}
|
}
|
||||||
@ -145,7 +158,7 @@ func PushNotification(notification models.Notification) error {
|
|||||||
ApnsID: subscriber.DeviceID,
|
ApnsID: subscriber.DeviceID,
|
||||||
DeviceToken: subscriber.DeviceToken,
|
DeviceToken: subscriber.DeviceToken,
|
||||||
Topic: viper.GetString("apns_topic"),
|
Topic: viper.GetString("apns_topic"),
|
||||||
Payload: data,
|
Payload: rawData,
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp, err := ExtAPNS.Push(payload); err != nil {
|
if resp, err := ExtAPNS.Push(payload); err != nil {
|
||||||
|
@ -1,27 +1,38 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-navigation-drawer :model-value="props.open" @update:model-value="(val: any) => emits('update:open', val)" location="right"
|
<v-navigation-drawer
|
||||||
temporary order="0" width="400">
|
:model-value="props.open"
|
||||||
|
@update:model-value="(val: any) => emits('update:open', val)"
|
||||||
|
location="right"
|
||||||
|
temporary
|
||||||
|
order="0"
|
||||||
|
width="400"
|
||||||
|
>
|
||||||
<v-list-item prepend-icon="mdi-bell" title="Notifications" class="py-3"></v-list-item>
|
<v-list-item prepend-icon="mdi-bell" title="Notifications" class="py-3"></v-list-item>
|
||||||
|
|
||||||
<v-divider color="black" class="mb-1" />
|
<v-divider color="black" class="mb-1" />
|
||||||
|
|
||||||
<v-list v-if="notify.notifications.length <= 0" density="compact">
|
<v-list v-if="notify.notifications.length <= 0" density="compact">
|
||||||
<v-list-item color="secondary" prepend-icon="mdi-check" title="All notifications read"
|
<v-list-item
|
||||||
subtitle="There is no more new things for you..." />
|
color="secondary"
|
||||||
|
prepend-icon="mdi-check"
|
||||||
|
title="All notifications read"
|
||||||
|
subtitle="There is no more new things for you..."
|
||||||
|
/>
|
||||||
</v-list>
|
</v-list>
|
||||||
|
|
||||||
<v-list v-else density="compact" lines="three">
|
<v-list v-else density="compact" lines="three">
|
||||||
<v-list-item v-for="(item, idx) in notify.notifications" :key="idx">
|
<v-list-item v-for="(item, idx) in notify.notifications" :key="idx">
|
||||||
<template #title>{{ item.subject }}</template>
|
<template #title>{{ item.title }}</template>
|
||||||
<template #subtitle>{{ item.content }}</template>
|
<template #subtitle>{{ item.subtitle }}<br v-if="item.subtitle" />{{ item.body }}</template>
|
||||||
|
|
||||||
<template #append>
|
<template #append>
|
||||||
<v-btn icon="mdi-check" size="x-small" variant="text" :disabled="loading" @click="markAsRead(item, idx)" />
|
<v-btn icon="mdi-check" size="x-small" variant="text" :disabled="loading" @click="markAsRead(item, idx)" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="flex text-xs gap-1">
|
<div class="flex text-xs gap-1">
|
||||||
<a v-for="(link, idx) in item.links" :key="idx" class="mt-1 underline" target="_blank"
|
<a v-for="(link, idx) in item.links" :key="idx" class="mt-1 underline" target="_blank" :href="link.url">{{
|
||||||
:href="link.url">{{ link.label }}</a>
|
link.label
|
||||||
|
}}</a>
|
||||||
</div>
|
</div>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
|
Loading…
Reference in New Issue
Block a user