mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 10:35:59 +08:00
merge code
This commit is contained in:
@@ -5,60 +5,25 @@ import (
|
||||
_ "github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
type GetRegisterParams struct {
|
||||
Account string `json:"account"`
|
||||
}
|
||||
type Register struct {
|
||||
Account string `gorm:"column:account"`
|
||||
Password string `gorm:"column:password"`
|
||||
}
|
||||
|
||||
func GetRegister(params *GetRegisterParams) (Register, error, int64) {
|
||||
var r Register
|
||||
func GetRegister(account string) (*db.Register, error) {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return r, err, 0
|
||||
return nil, err
|
||||
}
|
||||
result := dbConn.
|
||||
Where(&Register{Account: params.Account}).
|
||||
Find(&r)
|
||||
return r, result.Error, result.RowsAffected
|
||||
var r db.Register
|
||||
return &r, dbConn.Table("registers").Where("account = ?",
|
||||
account).Take(&r).Error
|
||||
}
|
||||
|
||||
type SetPasswordParams struct {
|
||||
Account string `json:"account"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
func SetPassword(params *SetPasswordParams) (Register, error) {
|
||||
r := Register{
|
||||
Account: params.Account,
|
||||
Password: params.Password,
|
||||
func SetPassword(account, password, ex string) error {
|
||||
r := db.Register{
|
||||
Account: account,
|
||||
Password: password,
|
||||
Ex: ex,
|
||||
}
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return r, err
|
||||
return err
|
||||
}
|
||||
return dbConn.Table("registers").Create(&r).Error
|
||||
|
||||
result := dbConn.Create(&r)
|
||||
|
||||
return r, result.Error
|
||||
}
|
||||
|
||||
func Login(params *Register) int64 {
|
||||
var r Register
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return 3
|
||||
}
|
||||
result := dbConn.
|
||||
Where(&Register{Account: params.Account}).
|
||||
Find(&r)
|
||||
if result.Error != nil && result.RowsAffected == 0 {
|
||||
return 1
|
||||
}
|
||||
if r.Password != params.Password {
|
||||
return 2
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -71,11 +71,33 @@ func UpdateFriendApplication(friendRequest *db.FriendRequest) error {
|
||||
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
|
||||
}
|
||||
|
||||
func InsertFriendApplication(friendRequest *db.FriendRequest) error {
|
||||
func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]interface{}) error {
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = dbConn.Table("friend_requests").Create(friendRequest).Error; err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
//t := dbConn.Debug().Table("friend_requests").Where("from_user_id = ? and to_user_id = ?", friendRequest.FromUserID, friendRequest.ToUserID).Select("*").Updates(*friendRequest)
|
||||
//if t.RowsAffected == 0 {
|
||||
// return utils.Wrap(errors.New("RowsAffected == 0"), "no update")
|
||||
//}
|
||||
//return utils.Wrap(t.Error, "")
|
||||
|
||||
friendRequest.CreateTime = time.Now()
|
||||
args["create_time"] = friendRequest.CreateTime
|
||||
u := dbConn.Model(friendRequest).Updates(args)
|
||||
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
||||
//u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?",
|
||||
// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest)
|
||||
if u.RowsAffected != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if friendRequest.CreateTime.Unix() < 0 {
|
||||
friendRequest.CreateTime = time.Now()
|
||||
}
|
||||
|
||||
@@ -31,11 +31,20 @@ func UpdateGroupRequest(groupRequest db.GroupRequest) error {
|
||||
}
|
||||
|
||||
func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error {
|
||||
DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
}
|
||||
u := dbConn.Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Update(&toInsertInfo)
|
||||
if u.RowsAffected != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
toInsertInfo.ReqTime = time.Now()
|
||||
if toInsertInfo.HandledTime.Unix() < 0 {
|
||||
toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
|
||||
@@ -108,6 +117,18 @@ func GetGroupApplicationList(userID string) ([]db.GroupRequest, error) {
|
||||
return groupRequestList, nil
|
||||
}
|
||||
|
||||
func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) {
|
||||
var groupRequestList []db.GroupRequest
|
||||
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dbConn.LogMode(true)
|
||||
err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
|
||||
return groupRequestList, err
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
//func GroupApplicationResponse(pb *group.GroupApplicationResponseReq) (*group.CommonResp, error) {
|
||||
//
|
||||
|
||||
@@ -10,7 +10,10 @@ import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
"Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
@@ -27,7 +30,19 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error {
|
||||
case constant.SingleChatType:
|
||||
chatLog.RecvID = msg.MsgData.RecvID
|
||||
}
|
||||
chatLog.Content = string(msg.MsgData.Content)
|
||||
if msg.MsgData.ContentType >= constant.NotificationBegin && msg.MsgData.ContentType <= constant.NotificationEnd {
|
||||
var tips server_api_params.TipsComm
|
||||
_ = proto.Unmarshal(msg.MsgData.Content, &tips)
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
chatLog.Content, _ = marshaler.MarshalToString(&tips)
|
||||
|
||||
} else {
|
||||
chatLog.Content = string(msg.MsgData.Content)
|
||||
}
|
||||
chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime)
|
||||
chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime)
|
||||
return dbConn.Table("chat_logs").Create(chatLog).Error
|
||||
|
||||
Reference in New Issue
Block a user