Compare commits

...

2 Commits

Author SHA1 Message Date
04d1970dc0 Reply will notify original poster 2024-02-08 18:47:29 +08:00
834c9de463 💄 Fix styles 2024-02-08 18:11:57 +08:00
7 changed files with 59 additions and 5 deletions

View File

@ -3,6 +3,9 @@ package services
import (
"code.smartsheep.studio/hydrogen/interactive/pkg/database"
"code.smartsheep.studio/hydrogen/interactive/pkg/models"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/spf13/viper"
)
func FollowAccount(followerId, followingId uint) error {
@ -28,3 +31,23 @@ func GetAccountFollowed(user models.Account, target models.Account) (models.Acco
Error
return relationship, err == nil
}
func NotifyAccount(user models.Account, subject, content string, links ...fiber.Map) error {
agent := fiber.Post(viper.GetString("passport.endpoint") + "/api/dev/notify")
agent.JSON(fiber.Map{
"client_id": viper.GetString("passport.client_id"),
"client_secret": viper.GetString("passport.client_secret"),
"subject": subject,
"content": content,
"links": links,
"user_id": user.ExternalID,
})
if status, body, errs := agent.Bytes(); len(errs) > 0 {
return errs[0]
} else if status != 200 {
return fmt.Errorf(string(body))
}
return nil
}

View File

@ -3,6 +3,8 @@ package services
import (
"errors"
"fmt"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
"time"
"code.smartsheep.studio/hydrogen/interactive/pkg/database"
@ -174,6 +176,26 @@ func NewPost(
return post, err
}
if post.ReplyID != nil {
var op models.Post
if err := database.C.Where(&models.Post{
BaseModel: models.BaseModel{ID: *post.ReplyID},
}).Preload("Author").First(&op).Error; err == nil {
if op.Author.ID != user.ID {
postUrl := fmt.Sprintf("https://%s/posts/%d", viper.GetString("domain"), post.ID)
err := NotifyAccount(
op.Author,
fmt.Sprintf("%s replied you", user.Name),
fmt.Sprintf("%s replied your post. Check it out!", user.Name),
fiber.Map{"label": "Related post", "url": postUrl},
)
if err != nil {
log.Error().Err(err).Msg("An error occurred when notifying user...")
}
}
}
}
return post, nil
}

View File

@ -43,7 +43,7 @@ export default function PostItem(props: {
);
return (
<div class="post-item max-w-screen">
<div class="post-item">
<Show when={!props.noAuthor}>
<a href={`/accounts/${props.post.author.name}`}>
<div class="flex bg-base-200">

View File

@ -13,4 +13,13 @@ html, body {
.medium-zoom-overlay {
z-index: 10;
}
.scrollbar-hidden {
scrollbar-width: none;
}
.scrollbar-hidden::-webkit-scrollbar {
display: none;
width: 0;
}

View File

@ -54,7 +54,7 @@ export default function RootLayout(props: any) {
<Navbar />
</Show>
<main class={mainContentStyles()}>{props.children}</main>
<main class={`${mainContentStyles()} scrollbar-hidden`}>{props.children}</main>
</Show>
);
}

View File

@ -1,12 +1,12 @@
.wrapper {
display: grid;
grid-template-columns: 1fr;
grid-template-columns: fit-content(100%);
column-gap: 20px;
max-height: calc(100vh - 64px);
}
@media (min-width: 768px) {
@media (min-width: 1024px) {
.wrapper {
grid-template-columns: 1fr 2fr 1fr;
}

View File

@ -5,7 +5,7 @@ export default function DashboardPage(props: any) {
<div class={`${styles.wrapper} container mx-auto`}>
<div id="trending" class="card shadow-xl h-fit"></div>
<div id="content" class="card shadow-xl">
<div id="content max-w-screen" class="card shadow-xl">
{props.children}
</div>