Merge remote-tracking branch 'origin/tuoyun' into tuoyun

pull/141/head
Gordon 3 years ago
commit 6bfbf37749

@ -106,7 +106,7 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
// {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }]
log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)
//err := imdb.InsertFriendApplication(&friendRequest)
err := imdb.InsertFriendApplication(&friendRequest)
err := imdb.InsertFriendApplication(&friendRequest, map[string]interface{}{"handle_result": 0})
if err != nil {
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
@ -405,24 +405,25 @@ func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.Get
var appleUserList []*sdkws.FriendRequest
for _, applyUserInfo := range ApplyUsersInfo {
var userInfo sdkws.FriendRequest
utils.CopyStructFields(&userInfo, applyUserInfo)
u, err := imdb.GetUserByUserID(userInfo.FromUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
continue
}
userInfo.FromNickname = u.Nickname
userInfo.FromFaceURL = u.FaceURL
userInfo.FromGender = u.Gender
u, err = imdb.GetUserByUserID(userInfo.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
continue
}
userInfo.ToNickname = u.Nickname
userInfo.ToFaceURL = u.FaceURL
userInfo.ToGender = u.Gender
cp.FriendRequestDBCopyOpenIM(&userInfo, &applyUserInfo)
// utils.CopyStructFields(&userInfo, applyUserInfo)
// u, err := imdb.GetUserByUserID(userInfo.FromUserID)
// if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
// continue
// }
// userInfo.FromNickname = u.Nickname
// userInfo.FromFaceURL = u.FaceURL
// userInfo.FromGender = u.Gender
//
// u, err = imdb.GetUserByUserID(userInfo.ToUserID)
// if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
// continue
// }
// userInfo.ToNickname = u.Nickname
// userInfo.ToFaceURL = u.FaceURL
// userInfo.ToGender = u.Gender
appleUserList = append(appleUserList, &userInfo)
}
@ -448,23 +449,23 @@ func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetSe
for _, selfApplyOtherUserInfo := range usersInfo {
var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo
cp.FriendRequestDBCopyOpenIM(&userInfo, &selfApplyOtherUserInfo)
u, err := imdb.GetUserByUserID(userInfo.FromUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
continue
}
userInfo.FromNickname = u.Nickname
userInfo.FromFaceURL = u.FaceURL
userInfo.FromGender = u.Gender
u, err = imdb.GetUserByUserID(userInfo.ToUserID)
if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
continue
}
userInfo.ToNickname = u.Nickname
userInfo.ToFaceURL = u.FaceURL
userInfo.ToGender = u.Gender
//u, err := imdb.GetUserByUserID(userInfo.FromUserID)
//if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
// continue
//}
//userInfo.FromNickname = u.Nickname
//userInfo.FromFaceURL = u.FaceURL
//userInfo.FromGender = u.Gender
//
//u, err = imdb.GetUserByUserID(userInfo.ToUserID)
//if err != nil {
// log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
// continue
//}
//userInfo.ToNickname = u.Nickname
//userInfo.ToFaceURL = u.FaceURL
//userInfo.ToGender = u.Gender
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
}

@ -3,7 +3,6 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"Open_IM/pkg/utils"
"errors"
"time"
)
@ -72,7 +71,7 @@ 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
@ -82,33 +81,32 @@ func InsertFriendApplication(friendRequest *db.FriendRequest) error {
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")
//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
}
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()
//}
//if friendRequest.HandleTime.Unix() < 0 {
// friendRequest.HandleTime = utils.UnixSecondToTime(0)
//}
//err = dbConn.Table("friend_requests").Create(friendRequest).Error
//if err != nil {
// return err
//}
//return nil
if friendRequest.CreateTime.Unix() < 0 {
friendRequest.CreateTime = time.Now()
}
if friendRequest.HandleTime.Unix() < 0 {
friendRequest.HandleTime = utils.UnixSecondToTime(0)
}
err = dbConn.Table("friend_requests").Create(friendRequest).Error
if err != nil {
return err
}
return nil
}

Loading…
Cancel
Save