This commit is contained in:
wangchuxiao
2023-02-02 19:40:54 +08:00
parent 174c3e5fae
commit 47b725ac69
7 changed files with 273 additions and 47 deletions
+6 -26
View File
@@ -1,35 +1,15 @@
package relation
import (
"Open_IM/pkg/common/db/table"
"gorm.io/gorm"
)
var ConversationDB *gorm.DB
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"`
IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"`
BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"`
GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"`
IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"`
UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"`
AttachedInfo string `gorm:"column:attached_info;type:varchar(1024)" json:"attachedInfo"`
Ex string `gorm:"column:ex;type:varchar(1024)" json:"ex"`
type ConversationGorm struct {
DB *gorm.DB
}
func (Conversation) TableName() string {
return "conversations"
}
func SetConversation(conversation Conversation) (bool, error) {
func SetConversation(conversation table.ConversationModel) (bool, error) {
var isUpdate bool
newConversation := conversation
if ConversationDB.Model(&Conversation{}).Find(&newConversation).RowsAffected == 0 {
@@ -93,7 +73,7 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str
return resultArr, nil
}
func GetConversation(OwnerUserID, conversationID string) (Conversation, error) {
func GetConversation(OwnerUserID, conversationID string) (table.ConversationModel, error) {
var conversation Conversation
err := ConversationDB.Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error
return conversation, err
@@ -116,7 +96,7 @@ func UpdateColumnsConversations(ownerUserIDList []string, conversationID string,
}
func GetConversationIDListByUserID(userID string) ([]string, error) {
func GetConversationIDsByUserID(userID string) ([]string, error) {
var IDList []string
err := ConversationDB.Model(&Conversation{}).Where("owner_user_id=?", userID).Pluck("conversation_id", &IDList).Error
return IDList, err