mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-25 22:49:19 +08:00
Merge remote-tracking branch 'origin/tuoyun' into tuoyun
This commit is contained in:
commit
bd1af2223d
@ -31,9 +31,9 @@ func main() {
|
|||||||
friendRouterGroup := r.Group("/friend")
|
friendRouterGroup := r.Group("/friend")
|
||||||
{
|
{
|
||||||
// friendRouterGroup.POST("/get_friends_info", friend.GetFriendsInfo)
|
// friendRouterGroup.POST("/get_friends_info", friend.GetFriendsInfo)
|
||||||
friendRouterGroup.POST("/add_friend", friend.AddFriend)
|
friendRouterGroup.POST("/add_friend", friend.AddFriend) //1
|
||||||
friendRouterGroup.POST("/get_friend_apply_list", friend.GetFriendApplyList)
|
friendRouterGroup.POST("/get_friend_apply_list", friend.GetFriendApplyList)
|
||||||
friendRouterGroup.POST("/get_self_apply_list", friend.GetSelfApplyList)
|
friendRouterGroup.POST("/get_self_apply_list", friend.GetSelfApplyList) //1
|
||||||
friendRouterGroup.POST("/get_friend_list", friend.GetFriendList)
|
friendRouterGroup.POST("/get_friend_list", friend.GetFriendList)
|
||||||
friendRouterGroup.POST("/add_blacklist", friend.AddBlacklist)
|
friendRouterGroup.POST("/add_blacklist", friend.AddBlacklist)
|
||||||
friendRouterGroup.POST("/get_blacklist", friend.GetBlacklist)
|
friendRouterGroup.POST("/get_blacklist", friend.GetBlacklist)
|
||||||
|
@ -21,7 +21,7 @@ func AddBlacklist(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.AddBlacklistReq{}
|
req := &rpc.AddBlacklistReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, ¶ms)
|
utils.CopyStructFields(req.CommID, ¶ms)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
@ -84,8 +84,9 @@ func AddFriend(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.AddFriendReq{}
|
req := &rpc.AddFriendReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, params)
|
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||||
|
req.ReqMsg = params.ReqMsg
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -93,7 +94,7 @@ func AddFriend(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.NewInfo("AddFriend args ", req.String())
|
log.NewInfo(req.CommID.OperationID, "AddFriend args ", req.String())
|
||||||
|
|
||||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
client := rpc.NewFriendClient(etcdConn)
|
client := rpc.NewFriendClient(etcdConn)
|
||||||
@ -116,8 +117,8 @@ func AddFriendResponse(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.AddFriendResponseReq{}
|
req := &rpc.AddFriendResponseReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, ¶ms)
|
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -125,7 +126,7 @@ func AddFriendResponse(c *gin.Context) {
|
|||||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
utils.CopyStructFields(&req, ¶ms)
|
utils.CopyStructFields(req, ¶ms)
|
||||||
log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String())
|
log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String())
|
||||||
|
|
||||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||||
@ -149,8 +150,8 @@ func DeleteFriend(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.DeleteFriendReq{}
|
req := &rpc.DeleteFriendReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, ¶ms)
|
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -181,7 +182,7 @@ func GetBlacklist(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.GetBlacklistReq{}
|
req := &rpc.GetBlacklistReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, ¶ms)
|
utils.CopyStructFields(req.CommID, ¶ms)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
@ -218,8 +219,8 @@ func SetFriendComment(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.SetFriendCommentReq{}
|
req := &rpc.SetFriendCommentReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, params)
|
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||||
req.Remark = params.Remark
|
req.Remark = params.Remark
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
@ -251,8 +252,8 @@ func RemoveBlacklist(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.RemoveBlacklistReq{}
|
req := &rpc.RemoveBlacklistReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, params)
|
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -271,8 +272,8 @@ func RemoveBlacklist(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp := api.RemoveBlackListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
resp := api.RemoveBlackListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||||
c.JSON(http.StatusOK, resp)
|
|
||||||
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist api return ", resp)
|
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist api return ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsFriend(c *gin.Context) {
|
func IsFriend(c *gin.Context) {
|
||||||
@ -282,8 +283,8 @@ func IsFriend(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.IsFriendReq{}
|
req := &rpc.IsFriendReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, params)
|
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -302,8 +303,8 @@ func IsFriend(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp := api.IsFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, Response: RpcResp.Response}
|
resp := api.IsFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, Response: RpcResp.Response}
|
||||||
c.JSON(http.StatusOK, resp)
|
|
||||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -347,8 +348,8 @@ func GetFriendList(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.GetFriendListReq{}
|
req := &rpc.GetFriendListReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, params)
|
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -367,9 +368,9 @@ func GetFriendList(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := api.GetFriendListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
resp := api.GetFriendListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendInfoList: RpcResp.FriendInfoList}
|
||||||
utils.CopyStructFields(&resp, RpcResp)
|
|
||||||
log.NewInfo(req.CommID.OperationID, "GetFriendList api return ", resp)
|
log.NewInfo(req.CommID.OperationID, "GetFriendList api return ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFriendApplyList(c *gin.Context) {
|
func GetFriendApplyList(c *gin.Context) {
|
||||||
@ -379,8 +380,8 @@ func GetFriendApplyList(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.GetFriendApplyListReq{}
|
req := &rpc.GetFriendApplyListReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, params)
|
utils.CopyStructFields(req.CommID, ¶ms)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -400,10 +401,9 @@ func GetFriendApplyList(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := api.GetFriendApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
resp := api.GetFriendApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
|
||||||
utils.CopyStructFields(&resp, RpcResp)
|
|
||||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList api return ", resp)
|
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList api return ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSelfApplyList(c *gin.Context) {
|
func GetSelfApplyList(c *gin.Context) {
|
||||||
@ -413,8 +413,8 @@ func GetSelfApplyList(c *gin.Context) {
|
|||||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
req := &rpc.GetSelfApplyListReq{}
|
req := &rpc.GetSelfApplyListReq{CommID: &rpc.CommID{}}
|
||||||
utils.CopyStructFields(req.CommID, params)
|
utils.CopyStructFields(req.CommID, ¶ms)
|
||||||
var ok bool
|
var ok bool
|
||||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -433,9 +433,7 @@ func GetSelfApplyList(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := api.GetSelfApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
resp := api.GetSelfApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
|
||||||
utils.CopyStructFields(resp, RpcResp)
|
|
||||||
c.JSON(http.StatusOK, resp)
|
|
||||||
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList api return ", resp)
|
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList api return ", resp)
|
||||||
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,8 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
|||||||
//Establish a latest relationship in the friend request table
|
//Establish a latest relationship in the friend request table
|
||||||
friendRequest := imdb.FriendRequest{ReqMsg: req.ReqMsg}
|
friendRequest := imdb.FriendRequest{ReqMsg: req.ReqMsg}
|
||||||
utils.CopyStructFields(&friendRequest, req.CommID)
|
utils.CopyStructFields(&friendRequest, req.CommID)
|
||||||
|
// {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.UpdateFriendApplication(&friendRequest)
|
err := imdb.UpdateFriendApplication(&friendRequest)
|
||||||
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)
|
||||||
|
@ -94,7 +94,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
}
|
}
|
||||||
|
|
||||||
//to group member
|
//to group member
|
||||||
groupMember := imdb.GroupMember{GroupID: groupId, RoleLevel: 1}
|
groupMember := imdb.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner}
|
||||||
utils.CopyStructFields(&groupMember, us)
|
utils.CopyStructFields(&groupMember, us)
|
||||||
err = im_mysql_model.InsertIntoGroupMember(groupMember)
|
err = im_mysql_model.InsertIntoGroupMember(groupMember)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -114,7 +114,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
|||||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), user.UserID)
|
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), user.UserID)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if user.RoleLevel == 1 {
|
if user.RoleLevel == constant.GroupOwner {
|
||||||
log.NewError(req.OperationID, "only one owner, failed ", user)
|
log.NewError(req.OperationID, "only one owner, failed ", user)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -224,7 +224,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
|||||||
var toInsertInfo imdb.GroupMember
|
var toInsertInfo imdb.GroupMember
|
||||||
utils.CopyStructFields(&toInsertInfo, toUserInfo)
|
utils.CopyStructFields(&toInsertInfo, toUserInfo)
|
||||||
toInsertInfo.GroupID = req.GroupID
|
toInsertInfo.GroupID = req.GroupID
|
||||||
toInsertInfo.RoleLevel = 0
|
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||||
err = imdb.InsertIntoGroupMember(toInsertInfo)
|
err = imdb.InsertIntoGroupMember(toInsertInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceUrl)
|
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceUrl)
|
||||||
@ -331,7 +331,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
|||||||
|
|
||||||
groupOwnerUserID := ""
|
groupOwnerUserID := ""
|
||||||
for _, v := range ownerList {
|
for _, v := range ownerList {
|
||||||
if v.RoleLevel == 1 {
|
if v.RoleLevel == constant.GroupOwner {
|
||||||
groupOwnerUserID = v.UserID
|
groupOwnerUserID = v.UserID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -513,7 +513,7 @@ func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
}
|
}
|
||||||
if groupUserInfo.RoleLevel == constant.OrdinaryMember {
|
if groupUserInfo.RoleLevel == constant.GroupAdmin {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -2,14 +2,14 @@ package base_info
|
|||||||
|
|
||||||
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||||
|
|
||||||
type paramsCommFriend struct {
|
type ParamsCommFriend struct {
|
||||||
OperationID string `json:"operationID" binding:"required"`
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
ToUserID string `json:"toUserID" binding:"required"`
|
ToUserID string `json:"toUserID" binding:"required"`
|
||||||
FromUserID string `json:"fromUserID" binding:"required"`
|
FromUserID string `json:"fromUserID" binding:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddBlacklistReq struct {
|
type AddBlacklistReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
}
|
}
|
||||||
type AddBlacklistResp struct {
|
type AddBlacklistResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
@ -26,7 +26,7 @@ type ImportFriendResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AddFriendReq struct {
|
type AddFriendReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
ReqMsg string `json:"reqMsg"`
|
ReqMsg string `json:"reqMsg"`
|
||||||
}
|
}
|
||||||
type AddFriendResp struct {
|
type AddFriendResp struct {
|
||||||
@ -34,7 +34,7 @@ type AddFriendResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AddFriendResponseReq struct {
|
type AddFriendResponseReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
Flag int32 `json:"flag" binding:"required"`
|
Flag int32 `json:"flag" binding:"required"`
|
||||||
HandleMsg string `json:"handleMsg"`
|
HandleMsg string `json:"handleMsg"`
|
||||||
}
|
}
|
||||||
@ -43,14 +43,15 @@ type AddFriendResponseResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DeleteFriendReq struct {
|
type DeleteFriendReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
}
|
}
|
||||||
type DeleteFriendResp struct {
|
type DeleteFriendResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetBlackListReq struct {
|
type GetBlackListReq struct {
|
||||||
paramsCommFriend
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
FromUserID string `json:"fromUserID" binding:"required"`
|
||||||
}
|
}
|
||||||
type GetBlackListResp struct {
|
type GetBlackListResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
@ -69,7 +70,7 @@ type BlackUserInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SetFriendCommentReq struct {
|
type SetFriendCommentReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
Remark string `json:"remark" binding:"required"`
|
Remark string `json:"remark" binding:"required"`
|
||||||
}
|
}
|
||||||
type SetFriendCommentResp struct {
|
type SetFriendCommentResp struct {
|
||||||
@ -77,14 +78,14 @@ type SetFriendCommentResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RemoveBlackListReq struct {
|
type RemoveBlackListReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
}
|
}
|
||||||
type RemoveBlackListResp struct {
|
type RemoveBlackListResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
}
|
}
|
||||||
|
|
||||||
type IsFriendReq struct {
|
type IsFriendReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
}
|
}
|
||||||
type IsFriendResp struct {
|
type IsFriendResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
@ -92,7 +93,7 @@ type IsFriendResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetFriendsInfoReq struct {
|
type GetFriendsInfoReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
}
|
}
|
||||||
type GetFriendsInfoResp struct {
|
type GetFriendsInfoResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
@ -100,7 +101,7 @@ type GetFriendsInfoResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetFriendListReq struct {
|
type GetFriendListReq struct {
|
||||||
paramsCommFriend
|
ParamsCommFriend
|
||||||
}
|
}
|
||||||
type GetFriendListResp struct {
|
type GetFriendListResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
@ -108,17 +109,19 @@ type GetFriendListResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GetFriendApplyListReq struct {
|
type GetFriendApplyListReq struct {
|
||||||
paramsCommFriend
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
FromUserID string `json:"fromUserID" binding:"required"`
|
||||||
}
|
}
|
||||||
type GetFriendApplyListResp struct {
|
type GetFriendApplyListResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
FriendRequestList open_im_sdk.FriendRequest `json:"data"`
|
FriendRequestList []*open_im_sdk.FriendRequest `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetSelfApplyListReq struct {
|
type GetSelfApplyListReq struct {
|
||||||
paramsCommFriend
|
OperationID string `json:"operationID" binding:"required"`
|
||||||
|
FromUserID string `json:"fromUserID" binding:"required"`
|
||||||
}
|
}
|
||||||
type GetSelfApplyListResp struct {
|
type GetSelfApplyListResp struct {
|
||||||
CommResp
|
CommResp
|
||||||
FriendRequestList open_im_sdk.FriendRequest `json:"data"`
|
FriendRequestList []*open_im_sdk.FriendRequest `json:"data"`
|
||||||
}
|
}
|
||||||
|
@ -3,12 +3,12 @@ package constant
|
|||||||
const (
|
const (
|
||||||
|
|
||||||
//group admin
|
//group admin
|
||||||
OrdinaryMember = 0
|
// OrdinaryMember = 0
|
||||||
GroupOwner = 1
|
// GroupOwner = 1
|
||||||
Administrator = 2
|
// Administrator = 2
|
||||||
//group application
|
//group application
|
||||||
Application = 0
|
// Application = 0
|
||||||
AgreeApplication = 1
|
// AgreeApplication = 1
|
||||||
|
|
||||||
//friend related
|
//friend related
|
||||||
BlackListFlag = 1
|
BlackListFlag = 1
|
||||||
@ -117,4 +117,16 @@ var ContentType2PushContent = map[int64]string{
|
|||||||
Common: "你收到一条新消息",
|
Common: "你收到一条新消息",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
AppOrdinaryUsers = 1
|
||||||
|
AppAdmin = 2
|
||||||
|
|
||||||
|
GroupOrdinaryUsers = 1
|
||||||
|
GroupOwner = 2
|
||||||
|
GroupAdmin = 3
|
||||||
|
|
||||||
|
Male = 1
|
||||||
|
Female = 2
|
||||||
|
)
|
||||||
|
|
||||||
const FriendAcceptTip = "You have successfully become friends, so start chatting"
|
const FriendAcceptTip = "You have successfully become friends, so start chatting"
|
||||||
|
@ -2,6 +2,7 @@ package im_mysql_model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
|
"Open_IM/pkg/utils"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,11 +66,12 @@ func UpdateFriendApplication(friendRequest *FriendRequest) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
friendRequest.CreateTime = time.Now()
|
friendRequest.CreateTime = time.Now()
|
||||||
err = dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?", friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
|
if dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?",
|
||||||
if err != nil {
|
friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).RowsAffected == 0 {
|
||||||
return err
|
return InsertFriendApplication(friendRequest)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func InsertFriendApplication(friendRequest *FriendRequest) error {
|
func InsertFriendApplication(friendRequest *FriendRequest) error {
|
||||||
@ -77,6 +79,12 @@ func InsertFriendApplication(friendRequest *FriendRequest) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if friendRequest.CreateTime.Unix() < 0 {
|
||||||
|
friendRequest.CreateTime = time.Now()
|
||||||
|
}
|
||||||
|
if friendRequest.HandleTime.Unix() < 0 {
|
||||||
|
friendRequest.HandleTime = utils.UnixSecondToTime(0)
|
||||||
|
}
|
||||||
err = dbConn.Table("friend_request").Create(friendRequest).Error
|
err = dbConn.Table("friend_request").Create(friendRequest).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package im_mysql_model
|
package im_mysql_model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -22,7 +23,10 @@ func InsertIntoGroupMember(toInsertInfo GroupMember) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
toInsertInfo.JoinSource = time.Now()
|
toInsertInfo.JoinTime = time.Now()
|
||||||
|
if toInsertInfo.RoleLevel == 0 {
|
||||||
|
toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers
|
||||||
|
}
|
||||||
err = dbConn.Table("group_member").Create(toInsertInfo).Error
|
err = dbConn.Table("group_member").Create(toInsertInfo).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -138,7 +142,7 @@ func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, v := range omList {
|
for _, v := range omList {
|
||||||
if v.RoleLevel == 1 {
|
if v.RoleLevel == constant.GroupOwner {
|
||||||
return &v, nil
|
return &v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package im_mysql_model
|
package im_mysql_model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -88,7 +89,7 @@ func GetGroupApplicationList(userID string) ([]GroupRequest, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, v := range memberList {
|
for _, v := range memberList {
|
||||||
if v.RoleLevel > 0 {
|
if v.RoleLevel > constant.GroupOrdinaryUsers {
|
||||||
list, err := GetGroupRequestByGroupID(v.GroupID)
|
list, err := GetGroupRequestByGroupID(v.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -95,7 +95,7 @@ type GroupMember struct {
|
|||||||
JoinTime time.Time `gorm:"column:join_time"`
|
JoinTime time.Time `gorm:"column:join_time"`
|
||||||
Nickname string `gorm:"column:nickname"`
|
Nickname string `gorm:"column:nickname"`
|
||||||
FaceUrl string `gorm:"user_group_face_url"`
|
FaceUrl string `gorm:"user_group_face_url"`
|
||||||
JoinSource time.Time `gorm:"column:join_source"`
|
JoinSource int32 `gorm:"column:join_source"`
|
||||||
OperatorUserID string `gorm:"column:operator_user_id"`
|
OperatorUserID string `gorm:"column:operator_user_id"`
|
||||||
Ex string `gorm:"column:ex"`
|
Ex string `gorm:"column:ex"`
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package im_mysql_model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/db"
|
"Open_IM/pkg/common/db"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -15,13 +16,16 @@ func init() {
|
|||||||
user, err := GetUserByUserID(v)
|
user, err := GetUserByUserID(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("GetUserByUserID failed ", err.Error(), v, user)
|
fmt.Println("GetUserByUserID failed ", err.Error(), v, user)
|
||||||
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var appMgr User
|
var appMgr User
|
||||||
|
appMgr.UserID = v
|
||||||
appMgr.Nickname = "AppManager" + utils.IntToString(k+1)
|
appMgr.Nickname = "AppManager" + utils.IntToString(k+1)
|
||||||
|
appMgr.AppMangerLevel = constant.AppAdmin
|
||||||
err = UserRegister(appMgr)
|
err = UserRegister(appMgr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("AppManager insert error", err.Error())
|
fmt.Println("AppManager insert error", err.Error(), appMgr, "time: ", appMgr.Birth.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -33,7 +37,12 @@ func UserRegister(user User) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
user.CreateTime = time.Now()
|
user.CreateTime = time.Now()
|
||||||
|
if user.AppMangerLevel == 0 {
|
||||||
|
user.AppMangerLevel = constant.AppOrdinaryUsers
|
||||||
|
}
|
||||||
|
if user.Birth.Unix() < 0 {
|
||||||
|
user.Birth = utils.UnixSecondToTime(0)
|
||||||
|
}
|
||||||
err = dbConn.Table("user").Create(&user).Error
|
err = dbConn.Table("user").Create(&user).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1,49 +1,10 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/jinzhu/copier"
|
"github.com/jinzhu/copier"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// copy a by b b->a
|
// copy a by b b->a
|
||||||
func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error) {
|
func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error) {
|
||||||
return copier.Copy(a, b)
|
return copier.Copy(a, b)
|
||||||
|
|
||||||
at := reflect.TypeOf(a)
|
|
||||||
av := reflect.ValueOf(a)
|
|
||||||
bt := reflect.TypeOf(b)
|
|
||||||
bv := reflect.ValueOf(b)
|
|
||||||
|
|
||||||
if at.Kind() != reflect.Ptr {
|
|
||||||
err = fmt.Errorf("a must be a struct pointer")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
av = reflect.ValueOf(av.Interface())
|
|
||||||
|
|
||||||
_fields := make([]string, 0)
|
|
||||||
if len(fields) > 0 {
|
|
||||||
_fields = fields
|
|
||||||
} else {
|
|
||||||
for i := 0; i < bv.NumField(); i++ {
|
|
||||||
_fields = append(_fields, bt.Field(i).Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(_fields) == 0 {
|
|
||||||
err = fmt.Errorf("no fields to copy")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < len(_fields); i++ {
|
|
||||||
name := _fields[i]
|
|
||||||
|
|
||||||
f := av.Elem().FieldByName(name)
|
|
||||||
bValue := bv.FieldByName(name)
|
|
||||||
|
|
||||||
if f.IsValid() && f.Kind() == bValue.Kind() {
|
|
||||||
f.Set(bValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user