Implement friend APIs and target profile support
- Add friend search/list/request/requestCancel/response/expel handlers and schemas - Store friend relationships in user_friend and backfill default friend links at startup - Auto-add the default user as a friend for newly created accounts - Support target user_id in /api profile requests and return target profile data - Make profile accessory_info optional to avoid zero-value accessory payloads - Update login topInfo friend counters from friend relationship state Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package startup
|
||||
|
||||
import (
|
||||
usermodel "honoka-chan/internal/model/user"
|
||||
"honoka-chan/pkg/db"
|
||||
"log"
|
||||
)
|
||||
|
||||
func EnsureDefaultFriends() {
|
||||
session := db.UserEng.NewSession()
|
||||
defer session.Close()
|
||||
|
||||
if err := session.Begin(); err != nil {
|
||||
log.Fatalln("初始化默认好友失败:", err.Error())
|
||||
}
|
||||
|
||||
userIDs := []int{}
|
||||
err := session.Table(new(usermodel.Users)).
|
||||
Cols("user_id").
|
||||
Find(&userIDs)
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
log.Fatalln("初始化默认好友失败:", err.Error())
|
||||
}
|
||||
|
||||
for _, userID := range userIDs {
|
||||
err = usermodel.EnsureDefaultFriendship(session, userID)
|
||||
if err != nil {
|
||||
session.Rollback()
|
||||
log.Fatalln("初始化默认好友失败:", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if err := session.Commit(); err != nil {
|
||||
session.Rollback()
|
||||
log.Fatalln("初始化默认好友失败:", err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user