mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 02:26:00 +08:00
* feat: Add light mode and dark mode.(#89) Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: make file code len Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: fix scripts support win Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: make build issue Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: golint and format Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: add scripts sudo limits of authority Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: docker images fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: docker images fix Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
@@ -35,12 +35,12 @@ func (f *FriendGorm) NewTx(tx any) relation.FriendModelInterface {
|
||||
return &FriendGorm{NewMetaDB(tx.(*gorm.DB), &relation.FriendModel{})}
|
||||
}
|
||||
|
||||
// 插入多条记录
|
||||
// 插入多条记录.
|
||||
func (f *FriendGorm) Create(ctx context.Context, friends []*relation.FriendModel) (err error) {
|
||||
return utils.Wrap(f.db(ctx).Create(&friends).Error, "")
|
||||
}
|
||||
|
||||
// 删除ownerUserID指定的好友
|
||||
// 删除ownerUserID指定的好友.
|
||||
func (f *FriendGorm) Delete(ctx context.Context, ownerUserID string, friendUserIDs []string) (err error) {
|
||||
err = utils.Wrap(
|
||||
f.db(ctx).
|
||||
@@ -52,7 +52,7 @@ func (f *FriendGorm) Delete(ctx context.Context, ownerUserID string, friendUserI
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新ownerUserID单个好友信息 更新零值
|
||||
// 更新ownerUserID单个好友信息 更新零值.
|
||||
func (f *FriendGorm) UpdateByMap(
|
||||
ctx context.Context,
|
||||
ownerUserID string,
|
||||
@@ -65,12 +65,12 @@ func (f *FriendGorm) UpdateByMap(
|
||||
)
|
||||
}
|
||||
|
||||
// 更新好友信息的非零值
|
||||
// 更新好友信息的非零值.
|
||||
func (f *FriendGorm) Update(ctx context.Context, friends []*relation.FriendModel) (err error) {
|
||||
return utils.Wrap(f.db(ctx).Updates(&friends).Error, "")
|
||||
}
|
||||
|
||||
// 更新好友备注(也支持零值 )
|
||||
// 更新好友备注(也支持零值 ).
|
||||
func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID, remark string) (err error) {
|
||||
if remark != "" {
|
||||
return utils.Wrap(
|
||||
@@ -86,7 +86,7 @@ func (f *FriendGorm) UpdateRemark(ctx context.Context, ownerUserID, friendUserID
|
||||
return utils.Wrap(f.db(ctx).Where("owner_user_id = ?", ownerUserID).Updates(m).Error, "")
|
||||
}
|
||||
|
||||
// 获取单个好友信息,如没找到 返回错误
|
||||
// 获取单个好友信息,如没找到 返回错误.
|
||||
func (f *FriendGorm) Take(
|
||||
ctx context.Context,
|
||||
ownerUserID, friendUserID string,
|
||||
@@ -98,7 +98,7 @@ func (f *FriendGorm) Take(
|
||||
)
|
||||
}
|
||||
|
||||
// 查找好友关系,如果是双向关系,则都返回
|
||||
// 查找好友关系,如果是双向关系,则都返回.
|
||||
func (f *FriendGorm) FindUserState(
|
||||
ctx context.Context,
|
||||
userID1, userID2 string,
|
||||
@@ -112,7 +112,7 @@ func (f *FriendGorm) FindUserState(
|
||||
)
|
||||
}
|
||||
|
||||
// 获取 owner指定的好友列表 如果有friendUserIDs不存在,也不返回错误
|
||||
// 获取 owner指定的好友列表 如果有friendUserIDs不存在,也不返回错误.
|
||||
func (f *FriendGorm) FindFriends(
|
||||
ctx context.Context,
|
||||
ownerUserID string,
|
||||
@@ -124,7 +124,7 @@ func (f *FriendGorm) FindFriends(
|
||||
)
|
||||
}
|
||||
|
||||
// 获取哪些人添加了friendUserID 如果有ownerUserIDs不存在,也不返回错误
|
||||
// 获取哪些人添加了friendUserID 如果有ownerUserIDs不存在,也不返回错误.
|
||||
func (f *FriendGorm) FindReversalFriends(
|
||||
ctx context.Context,
|
||||
friendUserID string,
|
||||
@@ -136,7 +136,7 @@ func (f *FriendGorm) FindReversalFriends(
|
||||
)
|
||||
}
|
||||
|
||||
// 获取ownerUserID好友列表 支持翻页
|
||||
// 获取ownerUserID好友列表 支持翻页.
|
||||
func (f *FriendGorm) FindOwnerFriends(
|
||||
ctx context.Context,
|
||||
ownerUserID string,
|
||||
@@ -158,7 +158,7 @@ func (f *FriendGorm) FindOwnerFriends(
|
||||
return
|
||||
}
|
||||
|
||||
// 获取哪些人添加了friendUserID 支持翻页
|
||||
// 获取哪些人添加了friendUserID 支持翻页.
|
||||
func (f *FriendGorm) FindInWhoseFriends(
|
||||
ctx context.Context,
|
||||
friendUserID string,
|
||||
|
||||
@@ -35,12 +35,12 @@ func (f *FriendRequestGorm) NewTx(tx any) relation.FriendRequestModelInterface {
|
||||
return &FriendRequestGorm{NewMetaDB(tx.(*gorm.DB), &relation.FriendRequestModel{})}
|
||||
}
|
||||
|
||||
// 插入多条记录
|
||||
// 插入多条记录.
|
||||
func (f *FriendRequestGorm) Create(ctx context.Context, friendRequests []*relation.FriendRequestModel) (err error) {
|
||||
return utils.Wrap(f.db(ctx).Create(&friendRequests).Error, "")
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
// 删除记录.
|
||||
func (f *FriendRequestGorm) Delete(ctx context.Context, fromUserID, toUserID string) (err error) {
|
||||
return utils.Wrap(
|
||||
f.db(ctx).
|
||||
@@ -51,7 +51,7 @@ func (f *FriendRequestGorm) Delete(ctx context.Context, fromUserID, toUserID str
|
||||
)
|
||||
}
|
||||
|
||||
// 更新零值
|
||||
// 更新零值.
|
||||
func (f *FriendRequestGorm) UpdateByMap(
|
||||
ctx context.Context,
|
||||
fromUserID string,
|
||||
@@ -68,7 +68,7 @@ func (f *FriendRequestGorm) UpdateByMap(
|
||||
)
|
||||
}
|
||||
|
||||
// 更新记录 (非零值)
|
||||
// 更新记录 (非零值).
|
||||
func (f *FriendRequestGorm) Update(ctx context.Context, friendRequest *relation.FriendRequestModel) (err error) {
|
||||
return utils.Wrap(
|
||||
f.db(ctx).
|
||||
@@ -79,7 +79,7 @@ func (f *FriendRequestGorm) Update(ctx context.Context, friendRequest *relation.
|
||||
)
|
||||
}
|
||||
|
||||
// 获取来指定用户的好友申请 未找到 不返回错误
|
||||
// 获取来指定用户的好友申请 未找到 不返回错误.
|
||||
func (f *FriendRequestGorm) Find(
|
||||
ctx context.Context,
|
||||
fromUserID, toUserID string,
|
||||
@@ -104,7 +104,7 @@ func (f *FriendRequestGorm) Take(
|
||||
return friendRequest, err
|
||||
}
|
||||
|
||||
// 获取toUserID收到的好友申请列表
|
||||
// 获取toUserID收到的好友申请列表.
|
||||
func (f *FriendRequestGorm) FindToUserID(
|
||||
ctx context.Context,
|
||||
toUserID string,
|
||||
@@ -126,7 +126,7 @@ func (f *FriendRequestGorm) FindToUserID(
|
||||
return
|
||||
}
|
||||
|
||||
// 获取fromUserID发出去的好友申请列表
|
||||
// 获取fromUserID发出去的好友申请列表.
|
||||
func (f *FriendRequestGorm) FindFromUserID(
|
||||
ctx context.Context,
|
||||
fromUserID string,
|
||||
|
||||
@@ -16,9 +16,10 @@ package relation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/ormutil"
|
||||
@@ -67,6 +68,7 @@ func (g *GroupGorm) Search(ctx context.Context, keyword string, pageNumber, show
|
||||
db = db.WithContext(ctx).Where("status!=?", constant.GroupStatusDismissed)
|
||||
return ormutil.GormSearch[relation.GroupModel](db, []string{"name"}, keyword, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
func (g *GroupGorm) GetGroupIDsByGroupType(ctx context.Context, groupType int) (groupIDs []string, err error) {
|
||||
return groupIDs, utils.Wrap(g.DB.Model(&relation.GroupModel{}).Where("group_type = ? ", groupType).Pluck("group_id", &groupIDs).Error, "")
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
maxRetry = 100 //number of retries
|
||||
maxRetry = 100 // number of retries
|
||||
)
|
||||
|
||||
// newMysqlGormDB Initialize the database connection
|
||||
// newMysqlGormDB Initialize the database connection.
|
||||
func newMysqlGormDB() (*gorm.DB, error) {
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
config.Config.Mysql.Username, config.Config.Mysql.Password, config.Config.Mysql.Address[0], "mysql")
|
||||
@@ -84,7 +84,7 @@ func newMysqlGormDB() (*gorm.DB, error) {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// connectToDatabase Connection retry for mysql
|
||||
// connectToDatabase Connection retry for mysql.
|
||||
func connectToDatabase(dsn string, maxRetry int) (*gorm.DB, error) {
|
||||
var db *gorm.DB
|
||||
var err error
|
||||
@@ -101,7 +101,7 @@ func connectToDatabase(dsn string, maxRetry int) (*gorm.DB, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// NewGormDB gorm mysql
|
||||
// NewGormDB gorm mysql.
|
||||
func NewGormDB() (*gorm.DB, error) {
|
||||
specialerror.AddReplace(gorm.ErrRecordNotFound, errs.ErrRecordNotFound)
|
||||
specialerror.AddErrHandler(replaceDuplicateKey)
|
||||
|
||||
@@ -34,35 +34,35 @@ func NewUserGorm(db *gorm.DB) relation.UserModelInterface {
|
||||
return &UserGorm{NewMetaDB(db, &relation.UserModel{})}
|
||||
}
|
||||
|
||||
// 插入多条
|
||||
// 插入多条.
|
||||
func (u *UserGorm) Create(ctx context.Context, users []*relation.UserModel) (err error) {
|
||||
return utils.Wrap(u.db(ctx).Create(&users).Error, "")
|
||||
}
|
||||
|
||||
// 更新用户信息 零值
|
||||
// 更新用户信息 零值.
|
||||
func (u *UserGorm) UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error) {
|
||||
return utils.Wrap(u.db(ctx).Model(&relation.UserModel{}).Where("user_id = ?", userID).Updates(args).Error, "")
|
||||
}
|
||||
|
||||
// 更新多个用户信息 非零值
|
||||
// 更新多个用户信息 非零值.
|
||||
func (u *UserGorm) Update(ctx context.Context, user *relation.UserModel) (err error) {
|
||||
return utils.Wrap(u.db(ctx).Model(user).Updates(user).Error, "")
|
||||
}
|
||||
|
||||
// 获取指定用户信息 不存在,也不返回错误
|
||||
// 获取指定用户信息 不存在,也不返回错误.
|
||||
func (u *UserGorm) Find(ctx context.Context, userIDs []string) (users []*relation.UserModel, err error) {
|
||||
err = utils.Wrap(u.db(ctx).Where("user_id in (?)", userIDs).Find(&users).Error, "")
|
||||
return users, err
|
||||
}
|
||||
|
||||
// 获取某个用户信息 不存在,则返回错误
|
||||
// 获取某个用户信息 不存在,则返回错误.
|
||||
func (u *UserGorm) Take(ctx context.Context, userID string) (user *relation.UserModel, err error) {
|
||||
user = &relation.UserModel{}
|
||||
err = utils.Wrap(u.db(ctx).Where("user_id = ?", userID).Take(&user).Error, "")
|
||||
return user, err
|
||||
}
|
||||
|
||||
// 获取用户信息 不存在,不返回错误
|
||||
// 获取用户信息 不存在,不返回错误.
|
||||
func (u *UserGorm) Page(
|
||||
ctx context.Context,
|
||||
pageNumber, showNumber int32,
|
||||
|
||||
Reference in New Issue
Block a user