Compare commits

...

5 Commits

Author SHA1 Message Date
25459cf429 💥 Attachments not found in singular field now remains string 2025-04-06 23:23:54 +08:00
c96e5bffa1 Allow user to embed live stream webpage 2025-04-06 22:54:21 +08:00
7dbb858d69 Ranked in mixed feed 2025-04-06 14:11:27 +08:00
ac30cb5e4d Community mod able to uncollapse post 2025-04-05 12:17:48 +08:00
d189c5a8d8 👔 Updated collapse post 2025-04-05 12:12:57 +08:00
8 changed files with 43 additions and 11 deletions

View File

@@ -67,6 +67,7 @@ func MapControllers(app *fiber.App, baseURL string) {
posts.Post("/:postId/flag", createFlag) posts.Post("/:postId/flag", createFlag)
posts.Post("/:postId/react", reactPost) posts.Post("/:postId/react", reactPost)
posts.Post("/:postId/pin", pinPost) posts.Post("/:postId/pin", pinPost)
posts.Post("/:postId/uncollapse", uncollapsePost)
posts.Delete("/:postId", deletePost) posts.Delete("/:postId", deletePost)
posts.Get("/:postId/replies", listPostReplies) posts.Get("/:postId/replies", listPostReplies)

View File

@@ -372,3 +372,17 @@ func pinPost(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusNoContent) return c.SendStatus(fiber.StatusNoContent)
} }
} }
func uncollapsePost(c *fiber.Ctx) error {
id, _ := c.ParamsInt("postId", 0)
if err := sec.EnsureGrantedPerm(c, "UncollapsePosts", true); err != nil {
return err
}
if err := database.C.Model(&models.Post{}).Where("id = ?", id).Update("is_collapsed", false).Error; err != nil {
return fiber.NewError(fiber.StatusBadRequest, err.Error())
}
return c.SendStatus(fiber.StatusOK)
}

View File

@@ -40,6 +40,8 @@ func createVideo(c *fiber.Ctx) error {
VisibleUsers []uint `json:"visible_users_list"` VisibleUsers []uint `json:"visible_users_list"`
InvisibleUsers []uint `json:"invisible_users_list"` InvisibleUsers []uint `json:"invisible_users_list"`
Visibility *int8 `json:"visibility"` Visibility *int8 `json:"visibility"`
Renderer *string `json:"renderer"`
IsLive bool `json:"is_live"`
IsDraft bool `json:"is_draft"` IsDraft bool `json:"is_draft"`
Realm *uint `json:"realm"` Realm *uint `json:"realm"`
} }
@@ -57,9 +59,11 @@ func createVideo(c *fiber.Ctx) error {
Thumbnail: data.Thumbnail, Thumbnail: data.Thumbnail,
Video: data.Video, Video: data.Video,
Title: data.Title, Title: data.Title,
Renderer: data.Renderer,
Description: data.Description, Description: data.Description,
Location: data.Location, Location: data.Location,
Subtitles: data.Subtitles, Subtitles: data.Subtitles,
IsLive: data.IsLive,
} }
var bodyMapping map[string]any var bodyMapping map[string]any
@@ -136,6 +140,8 @@ func editVideo(c *fiber.Ctx) error {
VisibleUsers []uint `json:"visible_users_list"` VisibleUsers []uint `json:"visible_users_list"`
InvisibleUsers []uint `json:"invisible_users_list"` InvisibleUsers []uint `json:"invisible_users_list"`
Visibility *int8 `json:"visibility"` Visibility *int8 `json:"visibility"`
Renderer *string `json:"renderer"`
IsLive bool `json:"is_live"`
IsDraft bool `json:"is_draft"` IsDraft bool `json:"is_draft"`
} }
@@ -178,6 +184,8 @@ func editVideo(c *fiber.Ctx) error {
Description: data.Description, Description: data.Description,
Location: data.Location, Location: data.Location,
Subtitles: data.Subtitles, Subtitles: data.Subtitles,
Renderer: data.Renderer,
IsLive: data.IsLive,
} }
var bodyMapping map[string]any var bodyMapping map[string]any

View File

@@ -102,6 +102,7 @@ type PostVideoBody struct {
Description *string `json:"description"` Description *string `json:"description"`
Location *string `json:"location"` Location *string `json:"location"`
Video string `json:"video"` Video string `json:"video"`
Renderer *string `json:"renderer"`
IsLive bool `json:"is_live"` IsLive bool `json:"is_live"`
IsLiveEnded bool `json:"is_live_ended"` IsLiveEnded bool `json:"is_live_ended"`
Subtitles map[string]string `json:"subtitles"` Subtitles map[string]string `json:"subtitles"`

View File

@@ -26,6 +26,10 @@ func NewFlag(post models.Post, account uint) (models.PostFlag, error) {
} }
func FlagCalculateCollapseStatus(post models.Post) error { func FlagCalculateCollapseStatus(post models.Post) error {
if post.TotalViews <= 2 {
return nil
}
collapseLimit := 0.5 collapseLimit := 0.5
var flagCount int64 var flagCount int64

View File

@@ -48,9 +48,6 @@ func UniversalPostFilter(c *fiber.Ctx, tx *gorm.DB, cfg ...UniversalPostFilterCo
if c.QueryBool("noReply", true) && !config.ShowReply { if c.QueryBool("noReply", true) && !config.ShowReply {
tx = FilterPostReply(tx) tx = FilterPostReply(tx)
} }
if c.QueryBool("noCollapse", true) && !config.ShowCollapsed {
tx = tx.Where("is_collapsed = ? OR is_collapsed IS NULL", false)
}
if len(c.Query("author")) > 0 { if len(c.Query("author")) > 0 {
var author models.Publisher var author models.Publisher

View File

@@ -33,8 +33,8 @@ func GetFeed(c *fiber.Ctx, limit int, user *uint, cursor *time.Time) ([]FeedEntr
// Planing the feed // Planing the feed
limitF := float64(limit) limitF := float64(limit)
interCount := int(math.Ceil(limitF * 0.5)) interCount := int(math.Ceil(limitF * 0.7))
readerCount := int(math.Ceil(limitF * 0.5)) readerCount := int(math.Ceil(limitF * 0.3))
// Internal posts // Internal posts
interTx, err := services.UniversalPostFilter(c, database.C) interTx, err := services.UniversalPostFilter(c, database.C)
@@ -55,7 +55,7 @@ func GetFeed(c *fiber.Ctx, limit int, user *uint, cursor *time.Time) ([]FeedEntr
}) })
// News today - from Reader // News today - from Reader
if news, err := ListNewsForFeed(readerCount, cursor); err != nil { if news, err := ListReaderPagesForFeed(readerCount, cursor); err != nil {
log.Error().Err(err).Msg("Failed to load news in getting feed...") log.Error().Err(err).Msg("Failed to load news in getting feed...")
} else { } else {
feed = append(feed, news...) feed = append(feed, news...)
@@ -70,10 +70,13 @@ func GetFeed(c *fiber.Ctx, limit int, user *uint, cursor *time.Time) ([]FeedEntr
func ListPostForFeed(tx *gorm.DB, limit int, user *uint, api string) ([]FeedEntry, error) { func ListPostForFeed(tx *gorm.DB, limit int, user *uint, api string) ([]FeedEntry, error) {
var posts []models.Post var posts []models.Post
var err error var err error
rankOrder := `(COALESCE(total_upvote, 0) - COALESCE(total_downvote, 0) +
LOG(1 + COALESCE(total_aggressive_views, 0))) /
POWER(EXTRACT(EPOCH FROM NOW() - published_at) / 3600 + 2, 1.5) DESC`
if api == "2" { if api == "2" {
posts, err = ListPost(tx, limit, -1, "published_at DESC", user) posts, err = ListPost(tx, limit, -1, rankOrder, user)
} else { } else {
posts, err = services.ListPost(tx, limit, -1, "published_at DESC", user) posts, err = services.ListPost(tx, limit, -1, rankOrder, user)
} }
if err != nil { if err != nil {
return nil, err return nil, err
@@ -88,7 +91,7 @@ func ListPostForFeed(tx *gorm.DB, limit int, user *uint, api string) ([]FeedEntr
return entries, nil return entries, nil
} }
func ListNewsForFeed(limit int, cursor *time.Time) ([]FeedEntry, error) { func ListReaderPagesForFeed(limit int, cursor *time.Time) ([]FeedEntry, error) {
conn, err := gap.Nx.GetClientGrpcConn("re") conn, err := gap.Nx.GetClientGrpcConn("re")
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get grpc connection with reader: %v", err) return nil, fmt.Errorf("failed to get grpc connection with reader: %v", err)

View File

@@ -2,6 +2,7 @@ package queries
import ( import (
"fmt" "fmt"
"strings"
"github.com/goccy/go-json" "github.com/goccy/go-json"
@@ -82,7 +83,7 @@ func CompletePostMeta(in ...models.Post) ([]models.Post, error) {
attachmentsRid = append(attachmentsRid, bodies[idx].Attachments...) attachmentsRid = append(attachmentsRid, bodies[idx].Attachments...)
for _, field := range singularAttachmentFields { for _, field := range singularAttachmentFields {
if raw, ok := info.Body[field]; ok { if raw, ok := info.Body[field]; ok {
if str, ok := raw.(string); ok { if str, ok := raw.(string); ok && !strings.HasPrefix(str, "http") {
attachmentsRid = append(attachmentsRid, str) attachmentsRid = append(attachmentsRid, str)
} }
} }
@@ -132,9 +133,12 @@ func CompletePostMeta(in ...models.Post) ([]models.Post, error) {
for _, field := range singularAttachmentFields { for _, field := range singularAttachmentFields {
if raw, ok := item.Body[field]; ok { if raw, ok := item.Body[field]; ok {
if str, ok := raw.(string); ok { if str, ok := raw.(string); ok {
item.Body[field] = lo.FindOrElse(this, fmodels.Attachment{}, func(item fmodels.Attachment) bool { result := lo.FindOrElse(this, fmodels.Attachment{}, func(item fmodels.Attachment) bool {
return item.Rid == str return item.Rid == str
}) })
if result.ID != 0 {
item.Body[field] = result
}
} }
} }
} }