mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-11 20:45:57 +08:00
conversation table
This commit is contained in:
@@ -32,17 +32,72 @@ type SetReceiveMessageOptResp struct {
|
||||
ConversationOptResultList []*OptResult `json:"data"`
|
||||
}
|
||||
|
||||
//type Conversation struct {
|
||||
// OwnerUserID string `gorm:"column:owner_user_id;primary_key;type:char(128)" json:"OwnerUserID"`
|
||||
// ConversationID string `gorm:"column:conversation_id;primary_key;type:char(128)" json:"conversationID"`
|
||||
// ConversationType int32 `gorm:"column:conversation_type" json:"conversationType"`
|
||||
// UserID string `gorm:"column:user_id;type:char(64)" json:"userID"`
|
||||
// GroupID string `gorm:"column:group_id;type:char(128)" json:"groupID"`
|
||||
// RecvMsgOpt int32 `gorm:"column:recv_msg_opt" json:"recvMsgOpt"`
|
||||
// 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"`
|
||||
// AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
|
||||
// Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
|
||||
//}
|
||||
type Conversation struct {
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
ConversationID string `json:"conversationID"`
|
||||
ConversationType int32 `json:"conversationType"`
|
||||
UserID string `json:"userID"`
|
||||
GroupID string `json:"groupID"`
|
||||
RecvMsgOpt int32 `json:"recvMsgOpt"`
|
||||
UnreadCount int32 `json:"unreadCount"`
|
||||
DraftTextTime int64 `json:"draftTextTime"`
|
||||
IsPinned bool `json:"isPinned"`
|
||||
IsPrivateChat bool `json:"isPrivateChat"`
|
||||
AttachedInfo string `json:"attachedInfo"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type SetConversationReq struct {
|
||||
Conversation
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type SetConversationResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type BatchSetConversationsReq struct {
|
||||
Conversations []Conversation `json:"conversations" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type BatchSetConversationsResp struct {
|
||||
CommResp
|
||||
Data struct{
|
||||
Success []string `json:"success"`
|
||||
Failed []string `json:"failed"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type GetConversationReq struct {
|
||||
ConversationID string `json:"conversationID" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetConversationResp struct {
|
||||
CommResp
|
||||
Conversation Conversation `json:"data"`
|
||||
}
|
||||
|
||||
type GetAllConversationsReq struct {
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetAllConversationsResp struct {
|
||||
CommResp
|
||||
Conversations []Conversation `json:"data"`
|
||||
}
|
||||
|
||||
type GetConversationsReq struct {
|
||||
ConversationIDs []string `json:"conversationIDs" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetConversationsResp struct {
|
||||
CommResp
|
||||
Conversations []Conversation `json:"data"`
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
+10
-11
@@ -1,15 +1,14 @@
|
||||
|
||||
all_proto=(
|
||||
message_cms/message_cms.proto
|
||||
admin_cms/admin_cms.proto
|
||||
statistics/statistics.proto
|
||||
auth/auth.proto
|
||||
friend/friend.proto
|
||||
group/group.proto
|
||||
#message_cms/message_cms.proto
|
||||
#admin_cms/admin_cms.proto
|
||||
#statistics/statistics.proto
|
||||
#auth/auth.proto
|
||||
#friend/friend.proto
|
||||
#group/group.proto
|
||||
user/user.proto
|
||||
chat/chat.proto
|
||||
push/push.proto
|
||||
relay/relay.proto
|
||||
sdk_ws/ws.proto
|
||||
|
||||
#chat/chat.proto
|
||||
#push/push.proto
|
||||
#relay/relay.proto
|
||||
#sdk_ws/ws.proto
|
||||
)
|
||||
|
||||
@@ -256,15 +256,6 @@ message MemberEnterTips{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////friend/////////////////////
|
||||
//message FriendInfo{
|
||||
// UserInfo OwnerUser = 1;
|
||||
|
||||
+1227
-763
File diff suppressed because it is too large
Load Diff
+63
-32
@@ -67,44 +67,72 @@ message UpdateUserInfoResp{
|
||||
CommonResp commonResp = 1;
|
||||
}
|
||||
|
||||
message Conversation{
|
||||
string OwnerUserID = 1;
|
||||
string ConversationID = 2;
|
||||
int32 RecvMsgOpt = 3;
|
||||
int32 ConversationType = 4;
|
||||
string UserID = 5;
|
||||
string GroupID = 6;
|
||||
int32 UnreadCount = 7;
|
||||
int64 DraftTextTime = 8;
|
||||
bool IsPinned = 9;
|
||||
string AttachedInfo = 10;
|
||||
bool IsPrivateChat = 11;
|
||||
string Ex = 12;
|
||||
}
|
||||
|
||||
message SetReceiveMessageOptReq{
|
||||
string FromUserID = 1;
|
||||
int32 opt = 2;
|
||||
repeated string conversationIDList = 3;
|
||||
string operationID = 4;
|
||||
string OpUserID = 5;
|
||||
message SetConversationReq{
|
||||
Conversation Conversation = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
message OptResult{
|
||||
string conversationID = 1;
|
||||
int32 result = 2; //-1: failed; 0:default; 1: not receive ; 2: not jpush
|
||||
}
|
||||
message SetReceiveMessageOptResp{
|
||||
|
||||
message SetConversationResp{
|
||||
CommonResp commonResp = 1;
|
||||
repeated OptResult conversationOptResultList = 2;
|
||||
}
|
||||
|
||||
|
||||
message GetReceiveMessageOptReq{
|
||||
string FromUserID = 1;
|
||||
repeated string conversationIDList = 2;
|
||||
string operationID = 3;
|
||||
string OpUserID = 4;
|
||||
message GetConversationReq{
|
||||
string ConversationID = 1;
|
||||
string OwnerUserID = 2;
|
||||
string OperationID = 3;
|
||||
}
|
||||
message GetReceiveMessageOptResp{
|
||||
|
||||
message GetConversationResp{
|
||||
CommonResp commonResp = 1;
|
||||
repeated OptResult conversationOptResultList = 3;
|
||||
Conversation Conversation = 2;
|
||||
}
|
||||
|
||||
|
||||
message GetAllConversationMsgOptReq{
|
||||
string FromUserID = 1;
|
||||
string operationID = 2;
|
||||
string OpUserID = 3;
|
||||
message GetConversationsReq{
|
||||
string OwnerUserID = 1;
|
||||
repeated string ConversationIDs = 2;
|
||||
string OperationID = 3;
|
||||
}
|
||||
message GetAllConversationMsgOptResp{
|
||||
|
||||
message GetConversationsResp{
|
||||
CommonResp commonResp = 1;
|
||||
repeated OptResult conversationOptResultList = 3;
|
||||
repeated Conversation Conversations = 2;
|
||||
}
|
||||
|
||||
message GetAllConversationsReq{
|
||||
string OwnerUserID = 1;
|
||||
string OperationID = 2;
|
||||
}
|
||||
|
||||
message GetAllConversationsResp{
|
||||
CommonResp commonResp = 1;
|
||||
repeated Conversation Conversations = 2;
|
||||
}
|
||||
|
||||
message BatchSetConversationsReq{
|
||||
repeated Conversation Conversations = 1;
|
||||
string OwnerUserID = 2;
|
||||
string OperationID = 3;
|
||||
}
|
||||
|
||||
message BatchSetConversationsResp{
|
||||
CommonResp commonResp = 1;
|
||||
repeated string Success = 2;
|
||||
repeated string Failed = 3;
|
||||
}
|
||||
|
||||
message ResignUserReq{
|
||||
@@ -130,7 +158,7 @@ message User{
|
||||
}
|
||||
|
||||
message GetUserByIdResp{
|
||||
CommonResp CommonResp = 1;
|
||||
CommonResp CommonResp = 1;
|
||||
User user = 2;
|
||||
}
|
||||
|
||||
@@ -241,7 +269,7 @@ message DeleteUserReq {
|
||||
}
|
||||
|
||||
message DeleteUserResp {
|
||||
|
||||
CommonResp CommonResp = 1;
|
||||
}
|
||||
|
||||
service user {
|
||||
@@ -249,10 +277,13 @@ service user {
|
||||
rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp);
|
||||
rpc DeleteUsers(DeleteUsersReq)returns(DeleteUsersResp);
|
||||
rpc GetAllUserID(GetAllUserIDReq)returns(GetAllUserIDResp);
|
||||
rpc SetReceiveMessageOpt(SetReceiveMessageOptReq)returns(SetReceiveMessageOptResp);
|
||||
rpc GetReceiveMessageOpt(GetReceiveMessageOptReq)returns(GetReceiveMessageOptResp);
|
||||
rpc GetAllConversationMsgOpt(GetAllConversationMsgOptReq)returns(GetAllConversationMsgOptResp);
|
||||
|
||||
rpc AccountCheck(AccountCheckReq)returns(AccountCheckResp);
|
||||
rpc GetConversation(GetConversationReq)returns(GetConversationResp);
|
||||
rpc GetAllConversations(GetAllConversationsReq)returns(GetAllConversationsResp);
|
||||
rpc GetConversations(GetConversationsReq)returns(GetConversationsResp);
|
||||
rpc BatchSetConversations(BatchSetConversationsReq)returns(BatchSetConversationsResp);
|
||||
rpc SetConversation(SetConversationReq)returns(SetConversationResp);
|
||||
|
||||
rpc GetUserById(GetUserByIdReq) returns (GetUserByIdResp);
|
||||
rpc GetUsersByName(GetUsersByNameReq) returns (GetUsersByNameResp);
|
||||
|
||||
Reference in New Issue
Block a user