mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 11:35:59 +08:00
opt
This commit is contained in:
@@ -22,7 +22,7 @@ var Config config
|
||||
type callBackConfig struct {
|
||||
Enable bool `yaml:"enable"`
|
||||
CallbackTimeOut int `yaml:"callbackTimeOut"`
|
||||
CallbackFailedContinue bool `CallbackFailedContinue`
|
||||
CallbackFailedContinue bool `callbackFailedContinue`
|
||||
}
|
||||
|
||||
type config struct {
|
||||
|
||||
@@ -213,6 +213,11 @@ type Conversation struct {
|
||||
UnreadCount int32 `gorm:"column:unread_count" json:"unreadCount"`
|
||||
DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"`
|
||||
IsPinned bool `gorm:"column:is_pinned" json:"isPinned"`
|
||||
IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"`
|
||||
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
}
|
||||
|
||||
func (Conversation) TableName() string {
|
||||
return "conversations"
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package im_mysql_model
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@@ -30,7 +32,6 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog,
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
|
||||
err = db.Find(&chatLogs).Error
|
||||
return chatLogs, err
|
||||
}
|
||||
@@ -58,6 +59,7 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) {
|
||||
db = db.Where("recv_id = ?", chatLog.RecvID)
|
||||
}
|
||||
if chatLog.SendTime.Unix() > 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1))
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -291,3 +292,56 @@ func GetBlockUsersNumCount() (int32, error) {
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func SetConversation(conversation db.Conversation) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
newConversation := conversation
|
||||
if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create")
|
||||
return dbConn.Model(&db.Conversation{}).Create(conversation).Error
|
||||
// if exist, then update record
|
||||
} else {
|
||||
log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update")
|
||||
//force update
|
||||
return dbConn.Model(&db.Conversation{}).Update(conversation).
|
||||
Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat}).Error
|
||||
}
|
||||
}
|
||||
|
||||
func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) {
|
||||
var conversations []db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversations, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
|
||||
func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error) {
|
||||
var conversation db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversation, err
|
||||
}
|
||||
err = dbConn.Model(&db.Conversation{
|
||||
OwnerUserID: OwnerUserID,
|
||||
ConversationID: conversationID,
|
||||
}).Find(&conversation).Error
|
||||
return conversation, err
|
||||
}
|
||||
|
||||
func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conversation, error) {
|
||||
var conversations []db.Conversation
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return conversations, err
|
||||
}
|
||||
err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error
|
||||
return conversations, err
|
||||
}
|
||||
@@ -111,12 +111,14 @@ func (d *DataBases) DeleteTokenByUidPid(userID string, platformID int32, fields
|
||||
_, err := d.Exec("HDEL", key, redis.Args{}.Add().AddFlat(fields)...)
|
||||
return err
|
||||
}
|
||||
func (d *DataBases) SetSingleConversationMsgOpt(userID, conversationID string, opt int) error {
|
||||
|
||||
func (d *DataBases) SetSingleConversationRecvMsgOpt(userID, conversationID string, opt int32) error {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
_, err := d.Exec("HSet", key, conversationID, opt)
|
||||
return err
|
||||
}
|
||||
func (d *DataBases) GetSingleConversationMsgOpt(userID, conversationID string) (int, error) {
|
||||
|
||||
func (d *DataBases) GetSingleConversationRecvMsgOpt(userID, conversationID string) (int, error) {
|
||||
key := conversationReceiveMessageOpt + userID
|
||||
return redis.Int(d.Exec("HGet", key, conversationID))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package log
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
@@ -33,13 +32,13 @@ func loggerInit(moduleName string) *Logger {
|
||||
//All logs will be printed
|
||||
logger.SetLevel(logrus.Level(config.Config.Log.RemainLogLevel))
|
||||
//Close std console output
|
||||
src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
writer := bufio.NewWriter(src)
|
||||
logger.SetOutput(writer)
|
||||
//logger.SetOutput(os.Stdout)
|
||||
//src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRONLY, os.ModeAppend)
|
||||
//if err != nil {
|
||||
// panic(err.Error())
|
||||
//}
|
||||
//writer := bufio.NewWriter(src)
|
||||
//logger.SetOutput(writer)
|
||||
logger.SetOutput(os.Stdout)
|
||||
//Log Console Print Style Setting
|
||||
logger.SetFormatter(&nested.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||
|
||||
Reference in New Issue
Block a user