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 }] // {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) log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)
//err := imdb.InsertFriendApplication(&friendRequest) //err := imdb.InsertFriendApplication(&friendRequest)
err := imdb.InsertFriendApplication(&friendRequest) err := imdb.InsertFriendApplication(&friendRequest, map[string]interface{}{"handle_result": 0})
if err != nil { if err != nil {
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest) 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 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 var appleUserList []*sdkws.FriendRequest
for _, applyUserInfo := range ApplyUsersInfo { for _, applyUserInfo := range ApplyUsersInfo {
var userInfo sdkws.FriendRequest var userInfo sdkws.FriendRequest
utils.CopyStructFields(&userInfo, applyUserInfo) cp.FriendRequestDBCopyOpenIM(&userInfo, &applyUserInfo)
u, err := imdb.GetUserByUserID(userInfo.FromUserID) // utils.CopyStructFields(&userInfo, applyUserInfo)
if err != nil { // u, err := imdb.GetUserByUserID(userInfo.FromUserID)
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID) // if err != nil {
continue // log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
} // continue
userInfo.FromNickname = u.Nickname // }
userInfo.FromFaceURL = u.FaceURL // userInfo.FromNickname = u.Nickname
userInfo.FromGender = u.Gender // userInfo.FromFaceURL = u.FaceURL
// userInfo.FromGender = u.Gender
u, err = imdb.GetUserByUserID(userInfo.ToUserID) //
if err != nil { // u, err = imdb.GetUserByUserID(userInfo.ToUserID)
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID) // if err != nil {
continue // log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
} // continue
userInfo.ToNickname = u.Nickname // }
userInfo.ToFaceURL = u.FaceURL // userInfo.ToNickname = u.Nickname
userInfo.ToGender = u.Gender // userInfo.ToFaceURL = u.FaceURL
// userInfo.ToGender = u.Gender
appleUserList = append(appleUserList, &userInfo) appleUserList = append(appleUserList, &userInfo)
} }
@ -448,23 +449,23 @@ func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetSe
for _, selfApplyOtherUserInfo := range usersInfo { for _, selfApplyOtherUserInfo := range usersInfo {
var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo
cp.FriendRequestDBCopyOpenIM(&userInfo, &selfApplyOtherUserInfo) cp.FriendRequestDBCopyOpenIM(&userInfo, &selfApplyOtherUserInfo)
u, err := imdb.GetUserByUserID(userInfo.FromUserID) //u, err := imdb.GetUserByUserID(userInfo.FromUserID)
if err != nil { //if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID) // log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
continue // continue
} //}
userInfo.FromNickname = u.Nickname //userInfo.FromNickname = u.Nickname
userInfo.FromFaceURL = u.FaceURL //userInfo.FromFaceURL = u.FaceURL
userInfo.FromGender = u.Gender //userInfo.FromGender = u.Gender
//
u, err = imdb.GetUserByUserID(userInfo.ToUserID) //u, err = imdb.GetUserByUserID(userInfo.ToUserID)
if err != nil { //if err != nil {
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID) // log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
continue // continue
} //}
userInfo.ToNickname = u.Nickname //userInfo.ToNickname = u.Nickname
userInfo.ToFaceURL = u.FaceURL //userInfo.ToFaceURL = u.FaceURL
userInfo.ToGender = u.Gender //userInfo.ToGender = u.Gender
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo) selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
} }

@ -3,7 +3,6 @@ package im_mysql_model
import ( import (
"Open_IM/pkg/common/db" "Open_IM/pkg/common/db"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"errors"
"time" "time"
) )
@ -72,7 +71,7 @@ func UpdateFriendApplication(friendRequest *db.FriendRequest) error {
friendRequest.FromUserID, friendRequest.ToUserID).Update(&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() dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil { if err != nil {
return err return err
@ -82,33 +81,32 @@ func InsertFriendApplication(friendRequest *db.FriendRequest) error {
return nil return nil
} }
t := dbConn.Debug().Table("friend_requests").Where("from_user_id = ? and to_user_id = ?", friendRequest.FromUserID, friendRequest.ToUserID).Select("*").Updates(*friendRequest) //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 { //if t.RowsAffected == 0 {
return utils.Wrap(errors.New("RowsAffected == 0"), "no update") // 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, "")
// if friendRequest.CreateTime.Unix() < 0 {
//friendRequest.CreateTime = time.Now() friendRequest.CreateTime = time.Now()
//args["create_time"] = friendRequest.CreateTime }
//u := dbConn.Model(friendRequest).Updates(args) if friendRequest.HandleTime.Unix() < 0 {
////u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", friendRequest.HandleTime = utils.UnixSecondToTime(0)
//// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest) }
////u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", err = dbConn.Table("friend_requests").Create(friendRequest).Error
//// friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest) if err != nil {
//if u.RowsAffected != 0 { return err
// return nil }
//} 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