✨ Allow user view and remove notification subscriptions
This commit is contained in:
parent
821e0c3e60
commit
bee9799415
@ -4,9 +4,10 @@
|
|||||||
<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=":recycle: Single table to store auth preferences">
|
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Trying to prevent send same notification to the same user in batch">
|
||||||
<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/grpc/notifier.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/notifier.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/index.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/notifications_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/notifications_api.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" />
|
||||||
@ -153,7 +154,6 @@
|
|||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
<MESSAGE value=":sparkles: Return affiliated to and automated by in userinfo grpc call" />
|
|
||||||
<MESSAGE value=":sparkles: Pagination bots api" />
|
<MESSAGE value=":sparkles: Pagination bots api" />
|
||||||
<MESSAGE value=":bug: Fix query issue" />
|
<MESSAGE value=":bug: Fix query issue" />
|
||||||
<MESSAGE value=":bug: Fix compare perm node panic" />
|
<MESSAGE value=":bug: Fix compare perm node panic" />
|
||||||
@ -178,7 +178,8 @@
|
|||||||
<MESSAGE value=":sparkles: Account deletion" />
|
<MESSAGE value=":sparkles: Account deletion" />
|
||||||
<MESSAGE value=":sparkles: Auth config to limit auth steps" />
|
<MESSAGE value=":sparkles: Auth config to limit auth steps" />
|
||||||
<MESSAGE value=":recycle: Single table to store auth preferences" />
|
<MESSAGE value=":recycle: Single table to store auth preferences" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value=":recycle: Single table to store auth preferences" />
|
<MESSAGE value=":bug: Trying to prevent send same notification to the same user in batch" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value=":bug: Trying to prevent send same notification to the same user in batch" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VgoProject">
|
<component name="VgoProject">
|
||||||
<settings-migrated>true</settings-migrated>
|
<settings-migrated>true</settings-migrated>
|
||||||
|
@ -18,8 +18,13 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
|||||||
|
|
||||||
notify := api.Group("/notifications").Name("Notifications API")
|
notify := api.Group("/notifications").Name("Notifications API")
|
||||||
{
|
{
|
||||||
notify.Get("/", getNotifications)
|
// Deprecated, use /subscription instead, will be removed in the future
|
||||||
notify.Post("/subscribe", addNotifySubscriber)
|
notify.Post("/subscribe", addNotifySubscriber)
|
||||||
|
|
||||||
|
notify.Get("/", getNotifications)
|
||||||
|
notify.Get("/subscription", getNotifySubscriber)
|
||||||
|
notify.Post("/subscription", addNotifySubscriber)
|
||||||
|
notify.Delete("/subscription/:deviceId", removeNotifySubscriber)
|
||||||
notify.Put("/read", markNotificationReadBatch)
|
notify.Put("/read", markNotificationReadBatch)
|
||||||
notify.Put("/read/:notificationId", markNotificationRead)
|
notify.Put("/read/:notificationId", markNotificationRead)
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,22 @@ func markNotificationReadBatch(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getNotifySubscriber(c *fiber.Ctx) error {
|
||||||
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
|
var subscribers []models.NotificationSubscriber
|
||||||
|
if err := database.C.Where(&models.NotificationSubscriber{
|
||||||
|
AccountID: user.ID,
|
||||||
|
}).Find(&subscribers).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusNotFound, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(subscribers)
|
||||||
|
}
|
||||||
|
|
||||||
func addNotifySubscriber(c *fiber.Ctx) error {
|
func addNotifySubscriber(c *fiber.Ctx) error {
|
||||||
if err := exts.EnsureAuthenticated(c); err != nil {
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -126,3 +142,21 @@ func addNotifySubscriber(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
return c.JSON(subscriber)
|
return c.JSON(subscriber)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeNotifySubscriber(c *fiber.Ctx) error {
|
||||||
|
if err := exts.EnsureAuthenticated(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
user := c.Locals("user").(models.Account)
|
||||||
|
|
||||||
|
device := c.Params("deviceId")
|
||||||
|
|
||||||
|
if err := database.C.Where(&models.NotificationSubscriber{
|
||||||
|
DeviceID: device,
|
||||||
|
AccountID: user.ID,
|
||||||
|
}).Delete(&models.NotificationSubscriber{}).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user