package logic import ( "sort" "strconv" "time" "juwan-backend/app/community/rpc/pb" ) func nowUnix(in int64) int64 { if in > 0 { return in } return time.Now().Unix() } func postLikeKey(postID, userID int64) string { return strconv.FormatInt(postID, 10) + ":" + strconv.FormatInt(userID, 10) } func commentLikeKey(commentID, userID int64) string { return strconv.FormatInt(commentID, 10) + ":" + strconv.FormatInt(userID, 10) } func sortPostsDesc(posts []*pb.Posts) { sort.Slice(posts, func(i, j int) bool { if posts[i].Pinned != posts[j].Pinned { return posts[i].Pinned } if posts[i].CreatedAt == posts[j].CreatedAt { return posts[i].Id > posts[j].Id } return posts[i].CreatedAt > posts[j].CreatedAt }) } func sortCommentsAsc(comments []*pb.Comments) { sort.Slice(comments, func(i, j int) bool { if comments[i].CreatedAt == comments[j].CreatedAt { return comments[i].Id < comments[j].Id } return comments[i].CreatedAt < comments[j].CreatedAt }) }