mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 02:55:58 +08:00
cms
This commit is contained in:
@@ -15,7 +15,7 @@ type Register struct {
|
||||
type Invitation struct {
|
||||
InvitationCode string `gorm:"column:invitation_code;primary_key;type:varchar(32)"`
|
||||
CreateTime time.Time `gorm:"column:create_time"`
|
||||
UserID string `gorm:"column:user_id"`
|
||||
UserID string `gorm:"column:user_id;index:userID"`
|
||||
LastTime time.Time `gorm:"column:last_time"`
|
||||
Status int32 `gorm:"column:status"`
|
||||
}
|
||||
@@ -179,8 +179,8 @@ type User struct {
|
||||
CreateTime time.Time `gorm:"column:create_time;index:create_time"`
|
||||
AppMangerLevel int32 `gorm:"column:app_manger_level"`
|
||||
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt"`
|
||||
InvitationCode string `gorm:"column:invitation_code"`
|
||||
status int32 `gorm:"column:status"`
|
||||
|
||||
status int32 `gorm:"column:status"`
|
||||
}
|
||||
|
||||
type UserIpRecord struct {
|
||||
|
||||
@@ -3,6 +3,7 @@ package im_mysql_model
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"errors"
|
||||
|
||||
_ "gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -74,3 +75,10 @@ func DeleteAllRegisterAddFriendIDList() error {
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Where("1 = 1").Delete(&db.RegisterAddFriend{}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
func GetUserIPLimit(userID string) (db.UserIpLimit, error) {
|
||||
var limit db.UserIpLimit
|
||||
limit.UserID = userID
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Model(&db.UserIpLimit{}).Take(&limit).Error
|
||||
return limit, err
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||
)
|
||||
|
||||
func InsertToFriend(toInsertFollow *db.Friend) error {
|
||||
@@ -51,3 +53,31 @@ func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
|
||||
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
|
||||
return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error
|
||||
}
|
||||
|
||||
type FriendUser struct {
|
||||
db.Friend
|
||||
Nickname string `gorm:"column:name;size:255"`
|
||||
}
|
||||
|
||||
func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, err error) {
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=?", ownerUserID).Limit(int(showNumber)).
|
||||
Joins("left join friends on friends.friend_user_id = users.user_id").
|
||||
Offset(int(showNumber * (pageNumber - 1)))
|
||||
if friendUserName != "" {
|
||||
db = db.Where("users.name like ?", fmt.Sprintf("%%%s%%", friendUserName))
|
||||
}
|
||||
err = db.Find(&friendUserList).Error
|
||||
return
|
||||
}
|
||||
|
||||
func GetFriendByIDCMS(ownerUserID, friendUserID string) (friendUser *FriendUser, err error) {
|
||||
friendUser = &FriendUser{}
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("friends").
|
||||
Select("friends.*, users.name").
|
||||
Where("friends.owner_user_id=? and friends.friend_user_id=?", ownerUserID, friendUserID).
|
||||
Joins("left join friends on friends.friend_user_id = users.user_id").
|
||||
Take(friendUser).Error
|
||||
return friendUser, err
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -54,7 +56,7 @@ type GroupWithNum struct {
|
||||
func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]GroupWithNum, error) {
|
||||
var groups []GroupWithNum
|
||||
err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Select("groups.*, (select count(*) from group_members where group_members.group_id=groups.group_id) as num").
|
||||
Where(" name like ? ", fmt.Sprintf("%%%s%%", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
|
||||
Where(" name like ? and status != ?", fmt.Sprintf("%%%s%%", groupName), constant.GroupStatusDismissed).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error
|
||||
return groups, err
|
||||
}
|
||||
|
||||
|
||||
@@ -11,16 +11,18 @@ import (
|
||||
func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) {
|
||||
var chatLogs []db.ChatLog
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)).
|
||||
Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1)))
|
||||
if chatLog.SessionType != 0 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" name like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
}
|
||||
if chatLog.ContentType == 1 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
} else if chatLog.ContentType == 2 {
|
||||
if chatLog.SessionType == 1 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
} else if chatLog.SessionType == 2 {
|
||||
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
}
|
||||
if chatLog.SendID != "" {
|
||||
db = db.Where("send_id = ?", chatLog.SendID)
|
||||
}
|
||||
@@ -37,13 +39,17 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
||||
func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
var chatLogs []db.ChatLog
|
||||
var count int64
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").
|
||||
Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content))
|
||||
db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs")
|
||||
if chatLog.Content != "" {
|
||||
db = db.Where(" name like ? ", fmt.Sprintf("%%%s%%", chatLog.Content))
|
||||
}
|
||||
if chatLog.SessionType != 0 {
|
||||
db = db.Where("session_type = ?", chatLog.SessionType)
|
||||
}
|
||||
if chatLog.ContentType != 0 {
|
||||
if chatLog.ContentType == 1 {
|
||||
db = db.Where("content_type = ?", chatLog.ContentType)
|
||||
} else if chatLog.ContentType == 2 {
|
||||
db = db.Where("content_type in (?)", []int{constant.GroupChatType, constant.SuperGroupChatType})
|
||||
}
|
||||
if chatLog.SendID != "" {
|
||||
db = db.Where("send_id = ?", chatLog.SendID)
|
||||
|
||||
@@ -130,21 +130,29 @@ func AddUser(userID string, phoneNumber string, name string, email string, gende
|
||||
_birth = time.Now()
|
||||
}
|
||||
user := db.User{
|
||||
UserID: userID,
|
||||
Nickname: name,
|
||||
FaceURL: faceURL,
|
||||
Gender: gender,
|
||||
PhoneNumber: phoneNumber,
|
||||
Birth: _birth,
|
||||
Email: email,
|
||||
Ex: "",
|
||||
CreateTime: time.Now(),
|
||||
InvitationCode: "",
|
||||
UserID: userID,
|
||||
Nickname: name,
|
||||
FaceURL: faceURL,
|
||||
Gender: gender,
|
||||
PhoneNumber: phoneNumber,
|
||||
Birth: _birth,
|
||||
Email: email,
|
||||
Ex: "",
|
||||
CreateTime: time.Now(),
|
||||
}
|
||||
result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user)
|
||||
return result.Error
|
||||
}
|
||||
|
||||
func UserIsBlock(userId string) (bool, error) {
|
||||
var user db.BlackList
|
||||
rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected
|
||||
if rows >= 1 {
|
||||
return user.EndDisableTime.After(time.Now()), nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func UsersIsBlock(userIDList []string) (inBlockUserIDList []string, err error) {
|
||||
err = db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid in (?) and end_disable_time > now()", userIDList).Pluck("uid", &inBlockUserIDList).Error
|
||||
return inBlockUserIDList, err
|
||||
|
||||
@@ -6,10 +6,8 @@ import (
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -36,38 +34,6 @@ const (
|
||||
conversationIDListCache = "CONVERSATION_ID_LIST_CACHE:"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fmt.Println("init to del old keys")
|
||||
for _, key := range []string{groupCache, friendRelationCache, blackListCache, userInfoCache, groupInfoCache, groupOwnerIDCache, joinedGroupListCache,
|
||||
groupMemberInfoCache, groupAllMemberInfoCache, allFriendInfoCache} {
|
||||
fName := utils.GetSelfFuncName()
|
||||
var cursor uint64
|
||||
var n int
|
||||
for {
|
||||
var keys []string
|
||||
var err error
|
||||
keys, cursor, err = db.DB.RDB.Scan(context.Background(), cursor, key+"*", 3000).Result()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
n += len(keys)
|
||||
// for each for redis cluster
|
||||
for _, key := range keys {
|
||||
if err = db.DB.RDB.Del(context.Background(), key).Err(); err != nil {
|
||||
log.NewError("", fName, key, err.Error())
|
||||
err = db.DB.RDB.Del(context.Background(), key).Err()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetFriendIDListFromCache(userID string) ([]string, error) {
|
||||
getFriendIDList := func() (string, error) {
|
||||
friendIDList, err := imdb.GetFriendIDListByUserID(userID)
|
||||
|
||||
Reference in New Issue
Block a user