You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/db/relation/group_request_model.go

159 lines
5.8 KiB

2 years ago
package relation
3 years ago
//
//func UpdateGroupRequest(groupRequest GroupRequest) error {
// if groupRequest.HandledTime.Unix() < 0 {
// groupRequest.HandledTime = utils.UnixSecondToTime(0)
// }
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error
//}
//
2 years ago
//func InsertIntoGroupRequest(toInsertInfo GroupRequest) error {
// DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID)
// if toInsertInfo.HandledTime.Unix() < 0 {
// toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
// }
2 years ago
// u := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo)
2 years ago
// if u.RowsAffected != 0 {
// return nil
// }
//
// toInsertInfo.ReqTime = time.Now()
// if toInsertInfo.HandledTime.Unix() < 0 {
// toInsertInfo.HandledTime = utils.UnixSecondToTime(0)
// }
//
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error
2 years ago
// if err != nil {
// return err
// }
// return nil
//}
//
//func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*GroupRequest, error) {
// var groupRequest GroupRequest
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error
// if err != nil {
// return nil, err
// }
// return &groupRequest, nil
//}
//
//func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error {
2 years ago
// return DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(GroupRequest{}).Error
//}
//
//func GetGroupRequestByGroupID(groupID string) ([]GroupRequest, error) {
// var groupRequestList []GroupRequest
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error
// if err != nil {
// return nil, err
// }
// return groupRequestList, nil
//}
//
//received
2 years ago
//func GetRecvGroupApplicationList(userID string) ([]GroupRequest, error) {
// var groupRequestList []GroupRequest
// memberList, err := GetGroupMemberListByUserID(userID)
// if err != nil {
// return nil, utils.Wrap(err, utils.GetSelfFuncName())
// }
// for _, v := range memberList {
// if v.RoleLevel > constant.GroupOrdinaryUsers {
// list, err := GetGroupRequestByGroupID(v.GroupID)
// if err != nil {
// continue
// }
// groupRequestList = append(groupRequestList, list...)
// }
// }
// return groupRequestList, nil
//}
//
//func GetUserReqGroupByUserID(userID string) ([]GroupRequest, error) {
// var groupRequestList []GroupRequest
2 years ago
// err := DB.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error
2 years ago
// return groupRequestList, err
//}
//
3 years ago
//
//func GroupApplicationResponse(pb *group.GroupApplicationResponseReq) (*group.CommonResp, error) {
//
// ownerUser, err := FindGroupMemberInfoByGroupIdAndUserId(pb.GroupID, pb.OwnerID)
// if err != nil {
// log.ErrorByKv("FindGroupMemberInfoByGroupIdAndUserId failed", pb.OperationID, "groupId", pb.GroupID, "ownerID", pb.OwnerID)
// return nil, err
// }
// if ownerUser.AdministratorLevel <= 0 {
// return nil, errors.New("insufficient permissions")
// }
//
2 years ago
// dbConn, err := DB.DB.MysqlDB.DefaultGormDB()
3 years ago
// if err != nil {
// return nil, err
// }
// var groupRequest GroupRequest
// err = dbConn.Raw("select * from `group_request` where handled_user = ? and group_id = ? and from_user_id = ? and to_user_id = ?",
// "", pb.GroupID, pb.FromUserID, pb.ToUserID).Scan(&groupRequest).Error
// if err != nil {
// log.ErrorByKv("find group_request info failed", pb.OperationID, "groupId", pb.GroupID, "fromUserId", pb.FromUserID, "toUserId", pb.OwnerID)
// return nil, err
// }
//
// if groupRequest.Flag != 0 {
// return nil, errors.New("application has already handle")
// }
//
// var saveFlag int
// if pb.HandleResult == 0 {
// saveFlag = -1
// } else if pb.HandleResult == 1 {
// saveFlag = 1
// } else {
// return nil, errors.New("parma HandleResult error")
// }
// err = dbConn.Exec("update `group_request` set flag = ?, handled_msg = ?, handled_user = ? where group_id = ? and from_user_id = ? and to_user_id = ?",
// saveFlag, pb.HandledMsg, pb.OwnerID, groupRequest.GroupID, groupRequest.FromUserID, groupRequest.ToUserID).Error
// if err != nil {
// log.ErrorByKv("update group request failed", pb.OperationID, "groupID", pb.GroupID, "flag", saveFlag, "ownerId", pb.OwnerID, "fromUserId", pb.FromUserID, "toUserID", pb.ToUserID)
// return nil, err
// }
//
// if saveFlag == 1 {
// if groupRequest.ToUserID == "0" {
// err = InsertIntoGroupMember(pb.GroupID, pb.FromUserID, groupRequest.FromUserNickname, groupRequest.FromUserFaceUrl, 0)
// if err != nil {
// log.ErrorByKv("InsertIntoGroupMember failed", pb.OperationID, "groupID", pb.GroupID, "fromUserId", pb.FromUserID)
// return nil, err
// }
// } else {
// err = InsertIntoGroupMember(pb.GroupID, pb.ToUserID, groupRequest.ToUserNickname, groupRequest.ToUserFaceUrl, 0)
// if err != nil {
// log.ErrorByKv("InsertIntoGroupMember failed", pb.OperationID, "groupID", pb.GroupID, "fromUserId", pb.FromUserID)
// return nil, err
// }
// }
// }
//
// return &group.GroupApplicationResponseResp{}, nil
//}
//
3 years ago
//func FindGroupBeInvitedRequestInfoByUidAndGroupID(groupId, uid string) (*GroupRequest, error) {
2 years ago
// dbConn, err := DB.DB.MysqlDB.DefaultGormDB()
3 years ago
// if err != nil {
// return nil, err
// }
// var beInvitedRequestUserInfo GroupRequest
// err = dbConn.Table("group_request").Where("to_user_id=? and group_id=?", uid, groupId).Find(&beInvitedRequestUserInfo).Error
// if err != nil {
// return nil, err
// }
// return &beInvitedRequestUserInfo, nil
//
//}
//
3 years ago
//func InsertGroupRequest(groupId, fromUser, fromUserNickName, fromUserFaceUrl, toUser, requestMsg, handledMsg string, handleStatus int) error {
// return nil
//}