mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-03 08:35:59 +08:00
Merge branch 'tuoyun' of github.com:OpenIMSDK/Open-IM-Server into tuoyun
This commit is contained in:
@@ -45,6 +45,17 @@ type config struct {
|
||||
SecretID string `yaml:"secretID"`
|
||||
SecretKey string `yaml:"secretKey"`
|
||||
}
|
||||
Ali struct {
|
||||
RegionID string `yaml:"regionID"`
|
||||
AccessKeyID string `yaml:"accessKeyID"`
|
||||
AccessKeySecret string `yaml:"accessKeySecret"`
|
||||
StsEndpoint string `yaml:"stsEndpoint"`
|
||||
OssEndpoint string `yaml:"ossEndpoint"`
|
||||
Bucket string `yaml:"bucket"`
|
||||
FinalHost string `yaml:"finalHost"`
|
||||
StsDurationSeconds int64 `yaml:"stsDurationSeconds"`
|
||||
OssRoleArn string `yaml:"OssRoleArn"`
|
||||
}
|
||||
Minio struct {
|
||||
Bucket string `yaml:"bucket"`
|
||||
Location string `yaml:"location"`
|
||||
@@ -66,6 +77,7 @@ type config struct {
|
||||
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
|
||||
}
|
||||
Mongo struct {
|
||||
DBUri string `yaml:"dbUri"` // 当dbUri值不为空则直接使用该值
|
||||
DBAddress []string `yaml:"dbAddress"`
|
||||
DBDirect bool `yaml:"dbDirect"`
|
||||
DBTimeout int `yaml:"dbTimeout"`
|
||||
|
||||
@@ -79,6 +79,7 @@ const (
|
||||
MemberInvitedNotification = 1509
|
||||
MemberEnterNotification = 1510
|
||||
GroupDismissedNotification = 1511
|
||||
GroupMemberInfoChangedNotification = 1512
|
||||
|
||||
SignalingNotificationBegin = 1600
|
||||
SignalingNotification = 1601
|
||||
@@ -138,6 +139,7 @@ const (
|
||||
GroupOk = 0
|
||||
GroupBanChat = 1
|
||||
GroupStatusDismissed = 2
|
||||
GroupStatusMuted = 3
|
||||
|
||||
GroupBaned = 3
|
||||
GroupBanPrivateChat = 4
|
||||
|
||||
@@ -41,12 +41,17 @@ func init() {
|
||||
// mongo init
|
||||
// "mongodb://sysop:moon@localhost/records"
|
||||
uri := "mongodb://sample.host:27017/?maxPoolSize=20&w=majority"
|
||||
uri = fmt.Sprintf("mongodb://%s/%s/?connect=direct&maxPoolSize=%d",
|
||||
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
||||
config.Config.Mongo.DBMaxPoolSize)
|
||||
if config.Config.Mongo.DBUri != "" {
|
||||
// example: mongodb://$user:$password@mongo1.mongo:27017,mongo2.mongo:27017,mongo3.mongo:27017/$DBDatabase/?replicaSet=rs0&readPreference=secondary&authSource=admin&maxPoolSize=$DBMaxPoolSize
|
||||
uri = config.Config.Mongo.DBUri
|
||||
} else {
|
||||
uri = fmt.Sprintf("mongodb://%s/%s/?maxPoolSize=%d",
|
||||
config.Config.Mongo.DBAddress[0], config.Config.Mongo.DBDatabase,
|
||||
config.Config.Mongo.DBMaxPoolSize)
|
||||
}
|
||||
|
||||
mongoClient, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||
if err != nil {
|
||||
if err != nil{
|
||||
log.NewError(" mongo.Connect failed, try ", utils.GetSelfFuncName(), err.Error(), uri)
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
mongoClient, err1 = mongo.Connect(context.TODO(), options.Client().ApplyURI(uri))
|
||||
|
||||
@@ -30,6 +30,9 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error {
|
||||
if toInsertInfo.RoleLevel == 0 {
|
||||
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||
}
|
||||
if toInsertInfo.MuteEndTime.Unix() == 0 {
|
||||
toInsertInfo.MuteEndTime = time.Unix(0, 0)
|
||||
}
|
||||
err = dbConn.Table("group_members").Create(toInsertInfo).Error
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -281,6 +284,14 @@ func GetGroupMembersCount(groupId, userName string) (int32, error) {
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func UpdateGroupMemberInfoDefaultZero(groupMemberInfo db.GroupMember, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Model(groupMemberInfo).Updates(args).Error
|
||||
}
|
||||
|
||||
//
|
||||
//func SelectGroupList(groupID string) ([]string, error) {
|
||||
// var groupUserID string
|
||||
|
||||
@@ -57,7 +57,6 @@ func SetGroupInfo(groupInfo db.Group) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
err = dbConn.Table("groups").Where("group_id=?", groupInfo.GroupID).Update(&groupInfo).Error
|
||||
return err
|
||||
}
|
||||
@@ -68,7 +67,7 @@ func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]db.Group
|
||||
if err != nil {
|
||||
return groups, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
err = dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error
|
||||
return groups, err
|
||||
}
|
||||
@@ -79,7 +78,7 @@ func GetGroups(pageNumber, showNumber int) ([]db.Group, error) {
|
||||
if err != nil {
|
||||
return groups, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
if err = dbConn.Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil {
|
||||
return groups, err
|
||||
}
|
||||
@@ -102,7 +101,7 @@ func DeleteGroup(groupId string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
var group db.Group
|
||||
var groupMembers []db.GroupMember
|
||||
if err := dbConn.Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil {
|
||||
@@ -119,7 +118,6 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string,
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
groupMember := db.GroupMember{
|
||||
UserID: userId,
|
||||
GroupID: groupId,
|
||||
@@ -182,7 +180,7 @@ func GetGroupsCountNum(group db.Group) (int32, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
var count int32
|
||||
if err := dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
@@ -198,7 +196,7 @@ func GetGroupById(groupId string) (db.Group, error) {
|
||||
if err != nil {
|
||||
return group, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
if err := dbConn.Table("groups").Find(&group).Error; err != nil {
|
||||
return group, err
|
||||
}
|
||||
@@ -211,9 +209,17 @@ func GetGroupMaster(groupId string) (db.GroupMember, error) {
|
||||
if err != nil {
|
||||
return groupMember, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
|
||||
if err := dbConn.Table("group_members").Where("role_level=? and group_id=?", constant.GroupOwner, groupId).Find(&groupMember).Error; err != nil {
|
||||
return groupMember, err
|
||||
}
|
||||
return groupMember, nil
|
||||
}
|
||||
|
||||
func UpdateGroupInfoDefaultZero(groupInfo db.Group, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return dbConn.Model(groupInfo).Updates(args).Error
|
||||
}
|
||||
|
||||
@@ -118,6 +118,10 @@ func GroupMemberDBCopyOpenIM(dst *open_im_sdk.GroupMemberFullInfo, src *db.Group
|
||||
dst.AppMangerLevel = 1
|
||||
}
|
||||
dst.JoinTime = int32(src.JoinTime.Unix())
|
||||
dst.MuteEndTime = uint32(src.JoinTime.Unix())
|
||||
if dst.MuteEndTime < uint32(time.Now().Unix()) {
|
||||
dst.MuteEndTime = 0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user