mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-20 00:39:01 +08:00
tidy code
This commit is contained in:
+103
-271
@@ -1,11 +1,12 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
rpc "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -13,20 +14,14 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsCommFriend struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
ToUserID string `json:"toUserID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
|
||||
func AddBlacklist(c *gin.Context) {
|
||||
params := paramsCommFriend{}
|
||||
params := api.AddBlacklistReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
return
|
||||
}
|
||||
req := &pbFriend.AddBlacklistReq{}
|
||||
req := &rpc.AddBlacklistReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -38,36 +33,26 @@ func AddBlacklist(c *gin.Context) {
|
||||
log.NewInfo(params.OperationID, "AddBlacklist args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.AddBlacklist(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "AddBlacklist failed ", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add blacklist rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
resp := api.AddBlacklistResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist api return ", resp)
|
||||
}
|
||||
|
||||
type paramsImportFriendReq struct {
|
||||
FriendUserIDList []string `json:"friendUserIDList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
Token string `json:"token"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
OpUserID string `json:"opUserID" binding:"required"`
|
||||
}
|
||||
|
||||
func ImportFriend(c *gin.Context) {
|
||||
params := paramsImportFriendReq{}
|
||||
params := api.ImportFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
req := &pbFriend.ImportFriendReq{}
|
||||
req := &rpc.ImportFriendReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -76,10 +61,10 @@ func ImportFriend(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "ImportFriend args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.ImportFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "ImportFriend failed", err.Error(), req.String())
|
||||
@@ -87,28 +72,19 @@ func ImportFriend(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
failedUidList := make([]string, 0)
|
||||
for _, v := range RpcResp.FailedUidList {
|
||||
failedUidList = append(failedUidList, v)
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.CommonResp.ErrCode, "errMsg": RpcResp.CommonResp.ErrMsg, "failedUidList": failedUidList}
|
||||
resp := api.ImportFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, Data: RpcResp.FailedFriendUserIDList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.OperationID, "AddBlacklist api return ", resp)
|
||||
}
|
||||
|
||||
type paramsAddFriend struct {
|
||||
paramsCommFriend
|
||||
ReqMessage string `json:"reqMessage"`
|
||||
log.NewInfo(req.OperationID, "ImportFriend api return ", resp)
|
||||
}
|
||||
|
||||
func AddFriend(c *gin.Context) {
|
||||
params := paramsAddFriend{}
|
||||
params := api.AddFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.AddFriendReq{}
|
||||
req := &rpc.AddFriendReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -117,11 +93,10 @@ func AddFriend(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
req.ReqMessage = params.ReqMessage
|
||||
log.NewInfo("AddFriend args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.AddFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "AddFriend failed ", err.Error(), req.String())
|
||||
@@ -129,24 +104,19 @@ func AddFriend(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
resp := api.AddFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriend api return ", resp)
|
||||
}
|
||||
|
||||
type paramsAddFriendResponse struct {
|
||||
paramsCommFriend
|
||||
Flag int32 `json:"flag" binding:"required"`
|
||||
}
|
||||
|
||||
func AddFriendResponse(c *gin.Context) {
|
||||
params := paramsAddFriendResponse{}
|
||||
params := api.AddFriendResponseReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.AddFriendResponseReq{}
|
||||
req := &rpc.AddFriendResponseReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -155,11 +125,11 @@ func AddFriendResponse(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
req.Flag = params.Flag
|
||||
|
||||
utils.CopyStructFields(&req, params)
|
||||
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)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.AddFriendResponse(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "AddFriendResponse failed ", err.Error(), req.String())
|
||||
@@ -167,23 +137,19 @@ func AddFriendResponse(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
resp := api.AddFriendResponseResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriendResponse api return ", resp)
|
||||
}
|
||||
|
||||
type paramsDeleteFriend struct {
|
||||
paramsCommFriend
|
||||
}
|
||||
|
||||
func DeleteFriend(c *gin.Context) {
|
||||
params := paramsDeleteFriend{}
|
||||
params := api.DeleteFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.DeleteFriendReq{}
|
||||
req := &rpc.DeleteFriendReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -195,7 +161,7 @@ func DeleteFriend(c *gin.Context) {
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.DeleteFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "DeleteFriend failed ", err, req.String())
|
||||
@@ -203,34 +169,19 @@ func DeleteFriend(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
resp := api.DeleteFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriendResponse api return ", resp)
|
||||
}
|
||||
|
||||
type paramsGetBlackList struct {
|
||||
paramsCommFriend
|
||||
}
|
||||
|
||||
type PublicUserInfo struct {
|
||||
UserID string `json:"userID"`
|
||||
Nickname string `json:"nickname"`
|
||||
FaceUrl string `json:"faceUrl"`
|
||||
Gender int32 `json:"gender"`
|
||||
}
|
||||
|
||||
type blackUserInfo struct {
|
||||
PublicUserInfo
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend api return ", resp)
|
||||
}
|
||||
|
||||
func GetBlacklist(c *gin.Context) {
|
||||
params := paramsGetBlackList{}
|
||||
params := api.GetBlackListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetBlacklistReq{}
|
||||
req := &rpc.GetBlacklistReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -239,10 +190,10 @@ func GetBlacklist(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "GetBlacklist args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.GetBlacklist(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetBlacklist failed ", err.Error(), req.String())
|
||||
@@ -250,42 +201,22 @@ func GetBlacklist(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if RpcResp.ErrCode == 0 {
|
||||
userBlackList := make([]blackUserInfo, 0)
|
||||
for _, friend := range RpcResp.Data {
|
||||
var b blackUserInfo
|
||||
utils.CopyStructFields(&b, friend)
|
||||
resp := api.GetBlackListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
utils.CopyStructFields(&resp.BlackUserInfoList, RpcResp.BlackUserInfoList)
|
||||
log.NewInfo(req.CommID.OperationID, "GetBlacklist api return ", resp)
|
||||
|
||||
userBlackList = append(userBlackList, b)
|
||||
}
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrCode,
|
||||
"errMsg": RpcResp.ErrMsg,
|
||||
"data": userBlackList,
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "GetBlacklist api return ", resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewError(req.CommID.OperationID, "GetBlacklist api return ", resp)
|
||||
}
|
||||
}
|
||||
|
||||
type paramsSetFriendComment struct {
|
||||
paramsCommFriend
|
||||
remark string `json:"remark" binding:"required"`
|
||||
}
|
||||
|
||||
func SetFriendComment(c *gin.Context) {
|
||||
params := paramsSetFriendComment{}
|
||||
params := api.SetFriendCommentReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.SetFriendCommentReq{}
|
||||
req := &rpc.SetFriendCommentReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
req.Remark = params.Remark
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
@@ -293,34 +224,29 @@ func SetFriendComment(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
req.Remark = params.remark
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "SetFriendComment args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.SetFriendComment(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "SetFriendComment failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call set friend comment rpc server failed"})
|
||||
return
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
resp := api.SetFriendCommentResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "SetFriendComment api return ", resp)
|
||||
}
|
||||
|
||||
type paramsRemoveBlackList struct {
|
||||
paramsCommFriend
|
||||
}
|
||||
|
||||
func RemoveBlacklist(c *gin.Context) {
|
||||
params := paramsRemoveBlackList{}
|
||||
params := api.RemoveBlackListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.RemoveBlacklistReq{}
|
||||
req := &rpc.RemoveBlacklistReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -332,31 +258,26 @@ func RemoveBlacklist(c *gin.Context) {
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist args ", req.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.RemoveBlacklist(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "RemoveBlacklist failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call remove blacklist rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.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, "SetFriendComment api return ", resp)
|
||||
}
|
||||
|
||||
type paramsIsFriend struct {
|
||||
paramsCommFriend
|
||||
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist api return ", resp)
|
||||
}
|
||||
|
||||
func IsFriend(c *gin.Context) {
|
||||
params := paramsIsFriend{}
|
||||
params := api.IsFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.IsFriendReq{}
|
||||
req := &rpc.IsFriendReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -368,96 +289,60 @@ func IsFriend(c *gin.Context) {
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.IsFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "IsFriend failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg, "isFriend": RpcResp.ShipType}
|
||||
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)
|
||||
}
|
||||
|
||||
type paramsSearchFriend struct {
|
||||
paramsCommFriend
|
||||
}
|
||||
|
||||
func GetFriendsInfo(c *gin.Context) {
|
||||
params := paramsSearchFriend{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendsInfoReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.GetFriendsInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetFriendsInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
if RpcResp.ErrCode == 0 {
|
||||
var fi friendInfo
|
||||
utils.CopyStructFields(&fi, RpcResp.Data.FriendUser)
|
||||
utils.CopyStructFields(&fi, RpcResp.Data)
|
||||
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrCode,
|
||||
"errMsg": RpcResp.ErrMsg,
|
||||
"data": fi,
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrCode,
|
||||
"errMsg": RpcResp.ErrMsg,
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
}
|
||||
|
||||
type paramsGetFriendList struct {
|
||||
paramsCommFriend
|
||||
}
|
||||
|
||||
type friendInfo struct {
|
||||
UserID string `json:"userID"`
|
||||
Nickname string `json:"nickname"`
|
||||
FaceUrl string `json:"faceUrl"`
|
||||
Gender int32 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
Birth string `json:"birth"`
|
||||
Email string `json:"email"`
|
||||
Ext string `json:"ext"`
|
||||
Remark string `json:"remark"`
|
||||
IsBlack int32 `json:"isBlack"`
|
||||
}
|
||||
//
|
||||
//func GetFriendsInfo(c *gin.Context) {
|
||||
// params := api.GetFriendsInfoReq{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// log.NewError("0", "BindJSON failed ", err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// req := &rpc.GetFriendsInfoReq{}
|
||||
// utils.CopyStructFields(req.CommID, params)
|
||||
// var ok bool
|
||||
// ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
// if !ok {
|
||||
// log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
// return
|
||||
// }
|
||||
// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
|
||||
//
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
// client := rpc.NewFriendClient(etcdConn)
|
||||
// RpcResp, err := client.GetFriendsInfo(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(req.CommID.OperationID, "GetFriendsInfo failed ", err.Error(), req.String())
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// resp := api.GetFriendsInfoResp{CommResp:api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
// utils.CopyStructFields(&resp, RpcResp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo api return ", resp)
|
||||
//}
|
||||
|
||||
func GetFriendList(c *gin.Context) {
|
||||
params := paramsGetFriendList{}
|
||||
params := api.GetFriendListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendListReq{}
|
||||
req := &rpc.GetFriendListReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -469,7 +354,7 @@ func GetFriendList(c *gin.Context) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendList args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.GetFriendList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetFriendList failed ", err.Error(), req.String())
|
||||
@@ -477,49 +362,19 @@ func GetFriendList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if RpcResp.ErrCode == 0 {
|
||||
friendsInfo := make([]friendInfo, 0)
|
||||
for _, friend := range RpcResp.Data {
|
||||
|
||||
var fi friendInfo
|
||||
utils.CopyStructFields(&fi, friend.FriendUser)
|
||||
utils.CopyStructFields(&fi, RpcResp.Data)
|
||||
friendsInfo = append(friendsInfo, fi)
|
||||
}
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrCode,
|
||||
"errMsg": RpcResp.ErrMsg,
|
||||
"data": friendsInfo,
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type paramsGetApplyList struct {
|
||||
paramsCommFriend
|
||||
}
|
||||
|
||||
type FriendApplicationUserInfo struct {
|
||||
PublicUserInfo
|
||||
ApplyTime int64 `json:"applyTime"`
|
||||
ReqMessage string `json:"reqMessage`
|
||||
Flag int32 `json:"flag"`
|
||||
resp := api.GetFriendListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
utils.CopyStructFields(&resp, RpcResp)
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendList api return ", resp)
|
||||
}
|
||||
|
||||
func GetFriendApplyList(c *gin.Context) {
|
||||
params := paramsGetApplyList{}
|
||||
params := api.GetFriendApplyListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendApplyReq{}
|
||||
req := &rpc.GetFriendApplyListReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -531,7 +386,7 @@ func GetFriendApplyList(c *gin.Context) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
|
||||
RpcResp, err := client.GetFriendApplyList(context.Background(), req)
|
||||
if err != nil {
|
||||
@@ -540,32 +395,20 @@ func GetFriendApplyList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if RpcResp.ErrCode == 0 {
|
||||
userInfoList := make([]FriendApplicationUserInfo, 0)
|
||||
for _, applyUserinfo := range RpcResp.Data {
|
||||
var un FriendApplicationUserInfo
|
||||
utils.CopyStructFields(&un, applyUserinfo.UserInfo)
|
||||
utils.CopyStructFields(&un, applyUserinfo)
|
||||
userInfoList = append(userInfoList, un)
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg, "data": userInfoList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
}
|
||||
resp := api.GetFriendApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
utils.CopyStructFields(&resp, RpcResp)
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList api return ", resp)
|
||||
|
||||
}
|
||||
|
||||
func GetSelfApplyList(c *gin.Context) {
|
||||
params := paramsGetApplyList{}
|
||||
params := api.GetSelfApplyListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendApplyReq{}
|
||||
req := &rpc.GetSelfApplyListReq{}
|
||||
utils.CopyStructFields(req.CommID, params)
|
||||
var ok bool
|
||||
ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
@@ -577,7 +420,7 @@ func GetSelfApplyList(c *gin.Context) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
client := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.GetSelfApplyList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetSelfApplyList failed ", err.Error(), req.String())
|
||||
@@ -585,20 +428,9 @@ func GetSelfApplyList(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if RpcResp.ErrCode == 0 {
|
||||
userInfoList := make([]FriendApplicationUserInfo, 0)
|
||||
for _, applyUserinfo := range RpcResp.Data {
|
||||
var un FriendApplicationUserInfo
|
||||
utils.CopyStructFields(&un, applyUserinfo.UserInfo)
|
||||
utils.CopyStructFields(&un, applyUserinfo)
|
||||
userInfoList = append(userInfoList, un)
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg, "data": userInfoList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrCode, "errMsg": RpcResp.ErrMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
}
|
||||
resp := api.GetSelfApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
utils.CopyStructFields(resp, RpcResp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList api return ", resp)
|
||||
|
||||
}
|
||||
|
||||
+256
-569
File diff suppressed because it is too large
Load Diff
@@ -65,7 +65,7 @@ func Login(c *gin.Context) {
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
log.ErrorByKv("Failed to read file", account, "err", err.Error())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoErrot, "errMsg": err.Error()})
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
imRep := IMRegisterResp{}
|
||||
|
||||
@@ -86,7 +86,7 @@ openIMRegisterTab:
|
||||
response, err := ioutil.ReadAll(resp.Body)
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoErrot, "errMsg": err.Error()})
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": constant.IoError, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
imrep := IMRegisterResp{}
|
||||
|
||||
+123
-147
@@ -9,10 +9,9 @@ import (
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
@@ -37,17 +36,17 @@ func NewFriendServer(port int) *friendServer {
|
||||
}
|
||||
|
||||
func (s *friendServer) Run() {
|
||||
log.Info("", "", fmt.Sprintf("rpc friend init...."))
|
||||
log.NewInfo("0", "friendServer run...")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs(fmt.Sprintf("Failed to listen rpc friend network,err=%s", err.Error()))
|
||||
log.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
log.NewInfo("0", "listen ok ", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
@@ -56,62 +55,59 @@ func (s *friendServer) Run() {
|
||||
pbFriend.RegisterFriendServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("register rpc fiend service to etcd failed,err=%s", err.Error())
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error(), s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName)
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen rpc friend error,err=%s", err.Error())
|
||||
log.NewError("0", "Serve failed ", err.Error(), listener)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendInfoResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
|
||||
var (
|
||||
isInBlackList int32
|
||||
// isFriend int32
|
||||
comment string
|
||||
)
|
||||
////
|
||||
//func (s *friendServer) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendInfoResp, error) {
|
||||
// return nil, nil
|
||||
//// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
|
||||
//// var (
|
||||
//// isInBlackList int32
|
||||
//// // isFriend int32
|
||||
//// comment string
|
||||
//// )
|
||||
////
|
||||
//// friendShip, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
//// if err != nil {
|
||||
//// log.NewError(req.CommID.OperationID, "FindFriendRelationshipFromFriend failed ", err.Error())
|
||||
//// return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
//// // isFriend = constant.FriendFlag
|
||||
//// }
|
||||
//// comment = friendShip.Remark
|
||||
////
|
||||
//// friendUserInfo, err := imdb.FindUserByUID(req.CommID.ToUserID)
|
||||
//// if err != nil {
|
||||
//// log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error())
|
||||
//// return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
//// }
|
||||
////
|
||||
//// err = imdb.FindRelationshipFromBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
//// if err == nil {
|
||||
//// isInBlackList = constant.BlackListFlag
|
||||
//// }
|
||||
////
|
||||
//// resp := pbFriend.GetFriendInfoResp{ErrCode: 0, ErrMsg: "",}
|
||||
////
|
||||
//// utils.CopyStructFields(resp.FriendInfoList, friendUserInfo)
|
||||
//// resp.Data.IsBlack = isInBlackList
|
||||
//// resp.Data.OwnerUserID = req.CommID.FromUserID
|
||||
//// resp.Data.Remark = comment
|
||||
//// resp.Data.CreateTime = friendUserInfo.CreateTime
|
||||
////
|
||||
//// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo ok ", resp)
|
||||
//// return &resp, nil
|
||||
////
|
||||
//}
|
||||
|
||||
friendShip, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindFriendRelationshipFromFriend failed ", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
// isFriend = constant.FriendFlag
|
||||
}
|
||||
comment = friendShip.Remark
|
||||
|
||||
friendUserInfo, err := imdb.FindUserByUID(req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = imdb.FindRelationshipFromBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
isInBlackList = constant.BlackListFlag
|
||||
}
|
||||
|
||||
resp := pbFriend.GetFriendInfoResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
Data: &pbFriend.FriendInfo{
|
||||
IsBlack: isInBlackList,
|
||||
},
|
||||
}
|
||||
utils.CopyStructFields(resp.Data.FriendUser, friendUserInfo)
|
||||
resp.Data.IsBlack = isInBlackList
|
||||
resp.Data.OwnerUserID = req.CommID.FromUserID
|
||||
resp.Data.Remark = comment
|
||||
resp.Data.CreateTime = friendUserInfo.CreateTime
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendsInfo ok ", resp)
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.AddBlacklistResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist args ", req.String())
|
||||
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
if !ok {
|
||||
@@ -121,15 +117,14 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl
|
||||
err := imdb.InsertInToUserBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "InsertInToUserBlackList ok ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
chat.BlackAddedNotification(req)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.CommonResp, error) {
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.AddFriendResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriend args ", req.String())
|
||||
ok := token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
if !ok {
|
||||
@@ -138,18 +133,18 @@ func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq
|
||||
//Cannot add non-existent users
|
||||
if _, err := imdb.FindUserByUID(req.CommID.ToUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAddFriend.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
//Establish a latest relationship in the friend request table
|
||||
err := imdb.ReplaceIntoFriendReq(req.CommID.FromUserID, req.CommID.ToUserID, constant.ApplicationFriendFlag, req.ReqMessage)
|
||||
err := imdb.ReplaceIntoFriendReq(req.CommID.FromUserID, req.CommID.ToUserID, constant.ApplicationFriendFlag, req.ReqMsg)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "ReplaceIntoFriendReq failed ", err.Error())
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAddFriend.ErrCode, ErrMsg: constant.ErrAddFriend.ErrMsg}, nil
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
chat.FriendApplicationAddedNotification(req)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||
@@ -159,29 +154,29 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
|
||||
|
||||
if !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
log.NewError(req.OperationID, "not authorized", req.OpUserID)
|
||||
c.ErrCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrMsg = "not authorized"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.FriendUserIDList}, nil
|
||||
c.ErrCode = constant.ErrAccess.ErrCode
|
||||
c.ErrMsg = constant.ErrAccess.ErrMsg
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedFriendUserIDList: req.FriendUserIDList}, nil
|
||||
}
|
||||
|
||||
if _, err := imdb.FindUserByUID(req.FromUserID); err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.FromUserID)
|
||||
c.ErrCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrCode = constant.ErrDB.ErrCode
|
||||
c.ErrMsg = "this user not exists,cant not add friend"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.FriendUserIDList}, nil
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedFriendUserIDList: req.FriendUserIDList}, nil
|
||||
}
|
||||
|
||||
for _, v := range req.FriendUserIDList {
|
||||
if _, fErr := imdb.FindUserByUID(v); fErr != nil {
|
||||
c.ErrMsg = "some uid establish failed"
|
||||
c.ErrCode = 408
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
resp.FailedFriendUserIDList = append(resp.FailedFriendUserIDList, v)
|
||||
} else {
|
||||
if _, err := imdb.FindFriendRelationshipFromFriend(req.FromUserID, v); err != nil {
|
||||
//Establish two single friendship
|
||||
err1 := imdb.InsertToFriend(req.FromUserID, v, 1)
|
||||
if err1 != nil {
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
resp.FailedFriendUserIDList = append(resp.FailedFriendUserIDList, v)
|
||||
log.NewError(req.OperationID, "InsertToFriend failed", req.FromUserID, v, err1.Error())
|
||||
c.ErrMsg = "some uid establish failed"
|
||||
c.ErrCode = 408
|
||||
@@ -189,7 +184,7 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
|
||||
}
|
||||
err2 := imdb.InsertToFriend(v, req.FromUserID, 1)
|
||||
if err2 != nil {
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
resp.FailedFriendUserIDList = append(resp.FailedFriendUserIDList, v)
|
||||
log.NewError(req.OperationID, "InsertToFriend failed", v, req.FromUserID, err2.Error())
|
||||
c.ErrMsg = "some uid establish failed"
|
||||
c.ErrCode = 408
|
||||
@@ -208,26 +203,26 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri
|
||||
}
|
||||
|
||||
//process Friend application
|
||||
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.CommonResp, error) {
|
||||
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.AddFriendResponseResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriendResponse args ", req.String())
|
||||
|
||||
if !token_verify.CheckAccess(req.CommID.FromUserID, req.CommID.ToUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess failed ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
//Check there application before agreeing or refuse to a friend's application
|
||||
//req.CommID.FromUserID process req.CommID.ToUserID
|
||||
if _, err := imdb.FindFriendApplyFromFriendReqByUid(req.CommID.ToUserID, req.CommID.FromUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindFriendApplyFromFriendReqByUid failed ", err.Error(), req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
//Change friend request status flag
|
||||
err := imdb.UpdateFriendRelationshipToFriendReq(req.CommID.ToUserID, req.CommID.FromUserID, req.Flag)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendRelationshipToFriendReq failed ", err.Error(), req.CommID.ToUserID, req.CommID.FromUserID, req.Flag)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc AddFriendResponse ok")
|
||||
//Change the status of the friend request form
|
||||
@@ -241,43 +236,43 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF
|
||||
err = imdb.InsertToFriend(req.CommID.FromUserID, req.CommID.ToUserID, req.Flag)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID, req.Flag)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
_, err = imdb.FindFriendRelationshipFromFriend(req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
if err == nil {
|
||||
log.NewWarn(req.CommID.OperationID, "FindFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
err = imdb.InsertToFriend(req.CommID.ToUserID, req.CommID.FromUserID, req.Flag)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID, req.Flag)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrAgreeToAddFriend.ErrCode, ErrMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
chat.FriendApplicationProcessedNotification(req)
|
||||
chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.CommonResp, error) {
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.DeleteFriendResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
err := imdb.DeleteSingleFriendInfo(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "DeleteSingleFriendInfo failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend rpc ok")
|
||||
chat.FriendDeletedNotification(req)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
|
||||
@@ -286,20 +281,20 @@ func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlackl
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess failed", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
blackListInfo, err := imdb.GetBlackListByUID(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetBlackListByUID failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrGetBlackList.ErrCode, ErrMsg: constant.ErrGetBlackList.ErrMsg}, nil
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var (
|
||||
userInfoList []*sdk_ws.PublicUserInfo
|
||||
userInfoList []*sdkws.PublicUserInfo
|
||||
)
|
||||
for _, blackUser := range blackListInfo {
|
||||
var blackUserInfo sdk_ws.PublicUserInfo
|
||||
var blackUserInfo sdkws.PublicUserInfo
|
||||
//Find black user information
|
||||
us, err := imdb.FindUserByUID(blackUser.BlockUserID)
|
||||
if err != nil {
|
||||
@@ -310,49 +305,50 @@ func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlackl
|
||||
userInfoList = append(userInfoList, &blackUserInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok")
|
||||
return &pbFriend.GetBlacklistResp{Data: userInfoList}, nil
|
||||
return &pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) SetFriendComment(ctx context.Context, req *pbFriend.SetFriendCommentReq) (*pbFriend.CommonResp, error) {
|
||||
func (s *friendServer) SetFriendComment(ctx context.Context, req *pbFriend.SetFriendCommentReq) (*pbFriend.SetFriendCommentResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "SetFriendComment args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.SetFriendCommentResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.OpUserID, req.Remark)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", err.Error(), req.CommID.FromUserID, req.CommID.OpUserID, req.Remark)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrSetFriendComment.ErrCode, ErrMsg: constant.ErrSetFriendComment.ErrMsg}, nil
|
||||
return &pbFriend.SetFriendCommentResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok")
|
||||
chat.FriendInfoChangedNotification(req)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
return &pbFriend.SetFriendCommentResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlacklistReq) (*pbFriend.RemoveBlacklistResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist args ", req.String())
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
err := imdb.RemoveBlackList(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "RemoveBlackList failed", err.Error(), req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.CommonResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok")
|
||||
chat.BlackDeletedNotification(req)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlackListReq) (*pbFriend.IsInBlackListResp, error) {
|
||||
log.NewInfo("IsInBlackList args ", req.String())
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var isInBlacklist = false
|
||||
@@ -366,44 +362,44 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac
|
||||
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||
log.NewInfo("IsFriend args ", req.String())
|
||||
var isFriend int32
|
||||
var isFriend bool
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.IsFriendResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.IsFriendResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
_, err := imdb.FindFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
isFriend = constant.FriendFlag
|
||||
isFriend = true
|
||||
} else {
|
||||
isFriend = constant.ApplicationFriendFlag
|
||||
isFriend = false
|
||||
}
|
||||
log.NewInfo("IsFriend rpc ok")
|
||||
return &pbFriend.IsFriendResp{ShipType: isFriend}, nil
|
||||
return &pbFriend.IsFriendResp{Response: isFriend}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
|
||||
log.NewInfo("GetFriendList args ", req.String())
|
||||
var userInfoList []*pbFriend.FriendInfo
|
||||
var userInfoList []*sdkws.FriendInfo
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
friends, err := imdb.FindUserInfoFromFriend(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
for _, friendUser := range friends {
|
||||
var friendUserInfo pbFriend.FriendInfo
|
||||
var friendUserInfo sdkws.FriendInfo
|
||||
//find user is in blackList
|
||||
err = imdb.FindRelationshipFromBlackList(req.CommID.FromUserID, friendUser.FriendUserID)
|
||||
if err == nil {
|
||||
friendUserInfo.IsBlack = constant.BlackListFlag
|
||||
} else {
|
||||
friendUserInfo.IsBlack = 0
|
||||
}
|
||||
//if err == nil {
|
||||
// friendUserInfo.IsBlack = constant.BlackListFlag
|
||||
//} else {
|
||||
// friendUserInfo.IsBlack = 0
|
||||
//}
|
||||
//Find user information
|
||||
us, err := imdb.FindUserByUID(friendUser.FriendUserID)
|
||||
if err != nil {
|
||||
@@ -416,77 +412,57 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien
|
||||
friendUserInfo.CreateTime = friendUser.CreateTime
|
||||
userInfoList = append(userInfoList, &friendUserInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetFriendList ok", pbFriend.GetFriendListResp{Data: userInfoList})
|
||||
return &pbFriend.GetFriendListResp{Data: userInfoList}, nil
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetFriendList ok", pbFriend.GetFriendListResp{FriendInfoList: userInfoList})
|
||||
return &pbFriend.GetFriendListResp{FriendInfoList: userInfoList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyListReq) (*pbFriend.GetFriendApplyListResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList args ", req.String())
|
||||
var appleUserList []*pbFriend.ApplyUserInfo
|
||||
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.GetFriendApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
// Find the current user friend applications received
|
||||
ApplyUsersInfo, err := imdb.FindFriendsApplyFromFriendReq(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindFriendsApplyFromFriendReq ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
return &pbFriend.GetFriendApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var appleUserList []*sdkws.FriendRequest
|
||||
for _, applyUserInfo := range ApplyUsersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = applyUserInfo.Flag
|
||||
userInfo.ReqMessage = applyUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = applyUserInfo.CreateTime
|
||||
|
||||
//Find user information
|
||||
us, err := imdb.FindUserByUID(applyUserInfo.ReqID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed ", err.Error(), applyUserInfo.ReqID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(userInfo.UserInfo, us)
|
||||
var userInfo sdkws.FriendRequest
|
||||
utils.CopyStructFields(&userInfo, applyUserInfo)
|
||||
appleUserList = append(appleUserList, &userInfo)
|
||||
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetFriendApplyList ok", pbFriend.GetFriendApplyResp{Data: appleUserList})
|
||||
return &pbFriend.GetFriendApplyResp{Data: appleUserList}, nil
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetFriendApplyList ok", pbFriend.GetFriendApplyListResp{FriendRequestList: appleUserList})
|
||||
return &pbFriend.GetFriendApplyListResp{FriendRequestList: appleUserList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetSelfApplyListReq) (*pbFriend.GetSelfApplyListResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList args ", req.String())
|
||||
var selfApplyOtherUserList []*pbFriend.ApplyUserInfo
|
||||
var selfApplyOtherUserList []*sdkws.FriendRequest
|
||||
//Parse token, to find current user information
|
||||
if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbFriend.GetSelfApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
// Find the self add other userinfo
|
||||
usersInfo, err := imdb.FindSelfApplyFromFriendReq(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindSelfApplyFromFriendReq failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyResp{ErrCode: constant.ErrMysql.ErrCode, ErrMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
return &pbFriend.GetSelfApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
for _, selfApplyOtherUserInfo := range usersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = selfApplyOtherUserInfo.Flag
|
||||
userInfo.ReqMessage = selfApplyOtherUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = selfApplyOtherUserInfo.CreateTime
|
||||
//Find user information
|
||||
us, err := imdb.FindUserByUID(selfApplyOtherUserInfo.UserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserByUID failed", err.Error(), selfApplyOtherUserInfo.UserID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(userInfo.UserInfo, us)
|
||||
var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo
|
||||
utils.CopyStructFields(&userInfo, selfApplyOtherUserInfo)
|
||||
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetSelfApplyList ok", pbFriend.GetFriendApplyResp{Data: selfApplyOtherUserList})
|
||||
return &pbFriend.GetFriendApplyResp{Data: selfApplyOtherUserList}, nil
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetSelfApplyList ok", pbFriend.GetSelfApplyListResp{FriendRequestList: selfApplyOtherUserList})
|
||||
return &pbFriend.GetSelfApplyListResp{FriendRequestList: selfApplyOtherUserList}, nil
|
||||
}
|
||||
|
||||
+42
-43
@@ -71,36 +71,36 @@ func (s *groupServer) Run() {
|
||||
|
||||
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "CreateGroup, args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.FromUserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.OwnerUserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.OwnerUserID)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
var okUserIDList []string
|
||||
//Time stamp + MD5 to generate group chat id
|
||||
groupId := utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
//to group
|
||||
err := im_mysql_model.InsertIntoGroup(groupId, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, req.Ext)
|
||||
err := im_mysql_model.InsertIntoGroup(groupId, req.GroupInfo.GroupName, req.GroupInfo.Introduction, req.GroupInfo.Notification, req.GroupInfo.FaceUrl, req.GroupInfo.Ex, req.GroupInfo.GroupType)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupId, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, req.Ext)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
log.NewError(req.OperationID, "InsertIntoGroup failed, ", err.Error(), groupId, req.GroupInfo.GroupName, req.GroupInfo.Introduction, req.GroupInfo.Notification, req.GroupInfo.FaceUrl, req.GroupInfo.Ex, req.GroupInfo.GroupType)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
us, err := im_mysql_model.FindUserByUID(req.FromUserID)
|
||||
us, err := im_mysql_model.FindUserByUID(req.OwnerUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.FromUserID)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OwnerUserID)
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//to group member
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, us.UserID, us.Nickname, us.FaceUrl, constant.GroupOwner)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.AddGroupMember(groupId, req.FromUserID)
|
||||
err = db.DB.AddGroupMember(groupId, req.OwnerUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), groupId, req.FromUserID)
|
||||
log.NewError(req.OperationID, "AddGroupMember failed ", err.Error(), groupId, req.OwnerUserID)
|
||||
// return &pbGroup.CreateGroupResp{ErrCode: constant.ErrCreateGroup.ErrCode, ErrMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
@@ -111,13 +111,13 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), user.UserID)
|
||||
continue
|
||||
}
|
||||
if user.Role == 1 {
|
||||
if user.RoleLevel == 1 {
|
||||
log.NewError(req.OperationID, "only one owner, failed ", user)
|
||||
continue
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, user.UserID, us.Nickname, us.FaceUrl, user.Role)
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, user.UserID, us.Nickname, us.FaceUrl, user.RoleLevel)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", groupId, user.UserID, us.Nickname, us.FaceUrl, user.Role)
|
||||
log.NewError(req.OperationID, "InsertIntoGroupMember failed ", groupId, user.UserID, us.Nickname, us.FaceUrl, user.RoleLevel)
|
||||
}
|
||||
okUserIDList = append(okUserIDList, user.UserID)
|
||||
err = db.DB.AddGroupMember(groupId, user.UserID)
|
||||
@@ -130,11 +130,11 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR
|
||||
group, err := im_mysql_model.FindGroupInfoByGroupId(groupId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", err.Error(), groupId)
|
||||
resp.ErrCode = constant.ErrCreateGroup.ErrCode
|
||||
resp.ErrMsg = constant.ErrCreateGroup.ErrMsg
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, req.FromUserID, groupId, okUserIDList)
|
||||
chat.GroupCreatedNotification(req.OperationID, req.OpUserID, req.OwnerUserID, groupId, okUserIDList)
|
||||
utils.CopyStructFields(resp.GroupInfo, group)
|
||||
log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String())
|
||||
return resp, nil
|
||||
@@ -144,14 +144,14 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList, args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.FromUserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID)
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrParseToken.ErrCode, ErrMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//group list
|
||||
joinedGroupList, err := imdb.GetJoinedGroupIdListByMemberId(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetJoinedGroupIdListByMemberId failed ", err.Error(), req.FromUserID)
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrParam.ErrCode, ErrMsg: constant.ErrParam.ErrMsg}, nil
|
||||
return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var resp pbGroup.GetJoinedGroupListResp
|
||||
@@ -163,7 +163,6 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
if num > 0 && owner != nil && err2 == nil && group != nil && err == nil {
|
||||
utils.CopyStructFields(&groupNode, group)
|
||||
groupNode.CreateTime = group.CreateTime
|
||||
utils.CopyStructFields(groupNode.Owner, owner)
|
||||
groupNode.MemberCount = uint32(num)
|
||||
resp.GroupList = append(resp.GroupList, &groupNode)
|
||||
} else {
|
||||
@@ -241,8 +240,8 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro
|
||||
resp.ErrCode = 0
|
||||
memberList, err := imdb.FindGroupMemberListByGroupId(req.GroupID)
|
||||
if err != nil {
|
||||
resp.ErrCode = constant.ErrDb.ErrCode
|
||||
resp.ErrMsg = constant.ErrDb.ErrMsg
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = constant.ErrDB.ErrMsg
|
||||
log.NewError(req.OperationID, "FindGroupMemberListByGroupId failed,", err.Error(), req.GroupID)
|
||||
return &resp, nil
|
||||
}
|
||||
@@ -273,7 +272,7 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr
|
||||
resp.ErrCode = 0
|
||||
memberList, err := imdb.GetGroupMemberByGroupId(req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
if err != nil {
|
||||
resp.ErrCode = constant.ErrDb.ErrCode
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
log.NewError(req.OperationID, "GetGroupMemberByGroupId failed,", req.GroupID, req.Filter, req.NextSeq, 30)
|
||||
return &resp, nil
|
||||
@@ -301,7 +300,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
ownerList, err := imdb.GetOwnerManagerByGroupId(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrParam.ErrCode, ErrMsg: constant.ErrParam.ErrMsg}, nil
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
//op is group owner?
|
||||
var flag = 0
|
||||
@@ -328,7 +327,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou
|
||||
|
||||
if len(req.KickedUserIDList) == 0 {
|
||||
log.NewError(req.OperationID, "failed, kick list 0")
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrParam.ErrCode, ErrMsg: constant.ErrParam.ErrMsg}, nil
|
||||
return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}, nil
|
||||
}
|
||||
|
||||
groupOwnerUserID := ""
|
||||
@@ -422,12 +421,12 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.CommonResp, error) {
|
||||
func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) {
|
||||
log.NewInfo(req.OperationID, "GroupApplicationResponse args ", req.String())
|
||||
reply, err := imdb.GroupApplicationResponse(req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.String())
|
||||
return &pbGroup.CommonResp{ErrCode: 702, ErrMsg: err.Error()}, nil
|
||||
return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: 702, ErrMsg: err.Error()}}, nil
|
||||
}
|
||||
|
||||
if req.HandleResult == 1 {
|
||||
@@ -471,13 +470,13 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G
|
||||
return reply, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.CommonResp, error) {
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
|
||||
|
||||
applicationUserInfo, err := im_mysql_model.FindUserByUID(req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", err.Error(), req.OpUserID)
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrSearchUserInfo.ErrCode, ErrMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
_, err = im_mysql_model.FindGroupRequestUserInfoByGroupIDAndUid(req.GroupID, req.OpUserID)
|
||||
@@ -487,34 +486,34 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq)
|
||||
|
||||
if err = im_mysql_model.InsertIntoGroupRequest(req.GroupID, req.OpUserID, "0", req.ReqMessage, applicationUserInfo.Nickname, applicationUserInfo.FaceUrl); err != nil {
|
||||
log.NewError(req.OperationID, "InsertIntoGroupRequest ", err.Error(), req.GroupID, req.OpUserID, "0", req.ReqMessage, applicationUserInfo.Nickname, applicationUserInfo.FaceUrl)
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrJoinGroupApplication.ErrCode, ErrMsg: constant.ErrJoinGroupApplication.ErrMsg}, nil
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
memberList, err := im_mysql_model.FindGroupMemberListByGroupIdAndFilterInfo(req.GroupID, constant.GroupOwner)
|
||||
if len(memberList) == 0 {
|
||||
log.NewError(req.OperationID, "FindGroupMemberListByGroupIdAndFilterInfo failed ", req.GroupID, constant.GroupOwner, err)
|
||||
return &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}, nil
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
}
|
||||
|
||||
chat.JoinApplicationNotification(req)
|
||||
|
||||
log.NewInfo(req.OperationID, "ReceiveJoinApplicationNotification rpc return ")
|
||||
return &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}, nil
|
||||
return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.CommonResp, error) {
|
||||
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.QuitGroupResp, error) {
|
||||
log.NewError("QuitGroup args ", req.String())
|
||||
|
||||
_, err := im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindGroupMemberInfoByGroupIdAndUserId failed", err.Error(), req.GroupID, req.OpUserID)
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrQuitGroup.ErrCode, ErrMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
err = im_mysql_model.DeleteGroupMemberByGroupIdAndUserId(req.GroupID, req.OpUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "DeleteGroupMemberByGroupIdAndUserId failed ", err.Error(), req.GroupID, req.OpUserID)
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrQuitGroup.ErrCode, ErrMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, req.OpUserID)
|
||||
@@ -525,7 +524,7 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq)
|
||||
|
||||
chat.MemberLeaveNotification(req)
|
||||
log.NewInfo(req.OperationID, "rpc QuitGroup return ")
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil
|
||||
}
|
||||
|
||||
func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
||||
@@ -543,17 +542,17 @@ func hasAccess(req *pbGroup.SetGroupInfoReq) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.CommonResp, error) {
|
||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.SetGroupInfoResp, error) {
|
||||
log.NewInfo(req.OperationID, "SetGroupInfo args ", req.String())
|
||||
if !hasAccess(req) {
|
||||
log.NewError(req.OperationID, "no access ")
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrSetGroupInfo.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
group, err := im_mysql_model.FindGroupInfoByGroupId(req.GroupInfo.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed, ", err.Error(), req.GroupInfo.GroupID)
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrSetGroupInfo.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
////bitwise operators: 0001:groupName; 0010:Notification 0100:Introduction; 1000:FaceUrl; 10000:owner
|
||||
@@ -572,7 +571,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
}
|
||||
//only administrators can set group information
|
||||
if err = im_mysql_model.SetGroupInfo(req.GroupInfo.GroupID, req.GroupInfo.GroupName, req.GroupInfo.Introduction, req.GroupInfo.Notification, req.GroupInfo.FaceUrl, ""); err != nil {
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrSetGroupInfo.ErrCode, ErrMsg: constant.ErrSetGroupInfo.ErrMsg}, nil
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
if changedType != 0 {
|
||||
@@ -582,13 +581,13 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.CommonResp, error) {
|
||||
func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.TransferGroupOwnerReq) (*pbGroup.TransferGroupOwnerResp, error) {
|
||||
log.NewInfo(req.OperationID, "TransferGroupOwner ", req.String())
|
||||
|
||||
reply, err := im_mysql_model.TransferGroupOwner(req)
|
||||
if err != nil {
|
||||
log.NewError("TransferGroupOwner ", req.String())
|
||||
return &pbGroup.CommonResp{ErrCode: constant.ErrDb.ErrCode, ErrMsg: constant.ErrDb.ErrMsg}, nil
|
||||
return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
changedType := int32(1) << 4
|
||||
chat.GroupInfoChangedNotification(req.OperationID, req.OpUserID, req.GroupID, changedType)
|
||||
|
||||
Reference in New Issue
Block a user