mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-12 13:05:58 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package controller
|
||||
|
||||
import "context"
|
||||
|
||||
type AuthInterface interface {
|
||||
GetTokens(ctx context.Context, userID, platform string) (map[string]int, error)
|
||||
DeleteToken(ctx context.Context, userID, platform string) error
|
||||
CreateToken(ctx context.Context, userID string, platformID int, ttl int64) (string, error)
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
"context"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -12,9 +13,9 @@ type BlackInterface interface {
|
||||
// Delete 删除黑名单
|
||||
Delete(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error)
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
|
||||
type BlackController struct {
|
||||
@@ -27,18 +28,22 @@ func NewBlackController(db *gorm.DB) *BlackController {
|
||||
|
||||
// Create 增加黑名单
|
||||
func (b *BlackController) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.database.Create(ctx, blacks)
|
||||
}
|
||||
|
||||
// Delete 删除黑名单
|
||||
func (b *BlackController) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.database.Delete(ctx, blacks)
|
||||
}
|
||||
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
func (b *BlackController) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error) {
|
||||
func (b *BlackController) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, total int64, err error) {
|
||||
return b.database.FindOwnerBlacks(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
func (b *BlackController) CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
func (b *BlackController) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
return b.database.CheckIn(ctx, userID1, userID2)
|
||||
}
|
||||
|
||||
type BlackDatabaseInterface interface {
|
||||
@@ -47,10 +52,9 @@ type BlackDatabaseInterface interface {
|
||||
// Delete 删除黑名单
|
||||
Delete(ctx context.Context, blacks []*relation.Black) (err error)
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error)
|
||||
FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error)
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error)
|
||||
}
|
||||
|
||||
type BlackDatabase struct {
|
||||
@@ -67,16 +71,40 @@ func NewBlackDatabase(db *gorm.DB) *BlackDatabase {
|
||||
|
||||
// Create 增加黑名单
|
||||
func (b *BlackDatabase) Create(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.sqlDB.Create(ctx, blacks)
|
||||
}
|
||||
|
||||
// Delete 删除黑名单
|
||||
func (b *BlackDatabase) Delete(ctx context.Context, blacks []*relation.Black) (err error) {
|
||||
return b.sqlDB.Delete(ctx, blacks)
|
||||
}
|
||||
|
||||
// FindOwnerBlacks 获取黑名单列表
|
||||
func (b *BlackDatabase) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blackList []*relation.Black, err error) {
|
||||
func (b *BlackDatabase) FindOwnerBlacks(ctx context.Context, ownerUserID string, pageNumber, showNumber int32) (blacks []*relation.Black, total int64, err error) {
|
||||
return b.sqlDB.FindOwnerBlacks(ctx, ownerUserID, pageNumber, showNumber)
|
||||
}
|
||||
|
||||
// CheckIn 检查user2是否在user1的黑名单列表中(inUser1Blacks==true) 检查user1是否在user2的黑名单列表中(inUser2Blacks==true)
|
||||
func (b *BlackDatabase) CheckIn(ctx context.Context, ownerUserID, blackUserID string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
func (b *BlackDatabase) CheckIn(ctx context.Context, userID1, userID2 string) (inUser1Blacks bool, inUser2Blacks bool, err error) {
|
||||
_, err = b.sqlDB.Take(ctx, userID1, userID2)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return
|
||||
}
|
||||
inUser1Blacks = false
|
||||
} else {
|
||||
inUser1Blacks = true
|
||||
}
|
||||
|
||||
inUser2Blacks = true
|
||||
_, err = b.sqlDB.Take(ctx, userID2, userID1)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != gorm.ErrRecordNotFound {
|
||||
return
|
||||
}
|
||||
inUser2Blacks = false
|
||||
} else {
|
||||
inUser2Blacks = true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
pbMsg "Open_IM/pkg/proto/msg"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ChatLogInterface interface {
|
||||
CreateChatLog(msg pbMsg.MsgDataToMQ) error
|
||||
GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
|
||||
}
|
||||
|
||||
func NewChatLogController(db *gorm.DB) ChatLogInterface {
|
||||
return &ChatLogController{database: NewChatLogDataBase(db)}
|
||||
}
|
||||
|
||||
type ChatLogController struct {
|
||||
database ChatLogDataBaseInterface
|
||||
}
|
||||
|
||||
func (c *ChatLogController) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
return c.database.CreateChatLog(msg)
|
||||
}
|
||||
|
||||
func (c *ChatLogController) GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
|
||||
return c.database.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
|
||||
}
|
||||
|
||||
type ChatLogDataBaseInterface interface {
|
||||
CreateChatLog(msg pbMsg.MsgDataToMQ) error
|
||||
GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error)
|
||||
}
|
||||
|
||||
type ChatLogDataBase struct {
|
||||
chatLogDB *relation.ChatLog
|
||||
}
|
||||
|
||||
func NewChatLogDataBase(db *gorm.DB) ChatLogDataBaseInterface {
|
||||
return &ChatLogDataBase{chatLogDB: relation.NewChatLog(db)}
|
||||
}
|
||||
|
||||
func (c *ChatLogDataBase) CreateChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
return c.chatLogDB.Create(msg)
|
||||
}
|
||||
|
||||
func (c *ChatLogDataBase) GetChatLog(chatLog *relation.ChatLog, pageNumber, showNumber int32, contentTypeList []int32) (int64, []relation.ChatLog, error) {
|
||||
return c.chatLogDB.GetChatLog(chatLog, pageNumber, showNumber, contentTypeList)
|
||||
}
|
||||
@@ -134,8 +134,8 @@ func (g *GroupController) AddUserToSuperGroup(ctx context.Context, groupID strin
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupInterface {
|
||||
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoDB)}
|
||||
func NewGroupController(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupInterface {
|
||||
groupController := &GroupController{database: newGroupDatabase(db, rdb, mgoClient)}
|
||||
return groupController
|
||||
}
|
||||
|
||||
@@ -182,23 +182,24 @@ type GroupDataBase struct {
|
||||
mongoDB *unrelation.SuperGroupMgoDB
|
||||
}
|
||||
|
||||
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoDB *mongo.Client) GroupDataBaseInterface {
|
||||
func newGroupDatabase(db *gorm.DB, rdb redis.UniversalClient, mgoClient *mongo.Client) GroupDataBaseInterface {
|
||||
groupDB := relation.NewGroupDB(db)
|
||||
groupMemberDB := relation.NewGroupMemberDB(db)
|
||||
groupRequestDB := relation.NewGroupRequest(db)
|
||||
newDB := db
|
||||
superGroupMgoDB := unrelation.NewSuperGroupMgoDB(mgoClient)
|
||||
database := &GroupDataBase{
|
||||
groupDB: groupDB,
|
||||
groupMemberDB: groupMemberDB,
|
||||
groupRequestDB: groupRequestDB,
|
||||
db: newDB,
|
||||
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, rockscache.Options{
|
||||
cache: cache.NewGroupCache(rdb, groupDB, groupMemberDB, groupRequestDB, superGroupMgoDB, rockscache.Options{
|
||||
RandomExpireAdjustment: 0.2,
|
||||
DisableCacheRead: false,
|
||||
DisableCacheDelete: false,
|
||||
StrongConsistency: true,
|
||||
}),
|
||||
mongoDB: unrelation.NewSuperGroupMgoDB(mgoDB),
|
||||
mongoDB: superGroupMgoDB,
|
||||
}
|
||||
return database
|
||||
}
|
||||
@@ -272,7 +273,7 @@ func (g *GroupDataBase) CreateSuperGroup(ctx context.Context, groupID string, in
|
||||
return err
|
||||
}
|
||||
|
||||
if err = g.cache.DelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
|
||||
if err = g.cache.BatchDelJoinedSuperGroupIDs(ctx, initMemberIDList); err != nil {
|
||||
_ = sess.AbortTransaction(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -7,14 +7,16 @@ import (
|
||||
)
|
||||
|
||||
type UserInterface interface {
|
||||
//获取指定用户的信息 如果有记录未找到 也返回错误
|
||||
Find(ctx context.Context, userIDs []string) (users []*relation.User, err error)
|
||||
Create(ctx context.Context, users []*relation.User) error
|
||||
Take(ctx context.Context, userID string) (user *relation.User, err error)
|
||||
Update(ctx context.Context, users []*relation.User) (err error)
|
||||
UpdateByMap(ctx context.Context, userID string, args map[string]interface{}) (err error)
|
||||
GetByName(ctx context.Context, userName string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
GetByNameAndID(ctx context.Context, content string, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
Get(ctx context.Context, showNumber, pageNumber int32) (users []*relation.User, count int64, err error)
|
||||
//userIDs是否存在 只要有一个存在就为true
|
||||
IsExist(ctx context.Context, userIDs []string) (exist bool, err error)
|
||||
}
|
||||
|
||||
type UserController struct {
|
||||
|
||||
Reference in New Issue
Block a user