pull/131/head
wenxu12345 3 years ago
parent 30b9ca7f37
commit 3d4e0a0479

@ -47,6 +47,7 @@ require (
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gorm.io/driver/mysql v1.2.2
sigs.k8s.io/yaml v1.2.0 // indirect
)

@ -151,8 +151,9 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@ -282,8 +283,9 @@ github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI=
github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
@ -876,6 +878,10 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.2.2 h1:2qoqhOun1maoJOfLtnzJwq+bZlHkEF34rGntgySqp48=
gorm.io/driver/mysql v1.2.2/go.mod h1:qsiz+XcAyMrS6QY+X3M9R6b/lKM1imKmcuK9kac5LTo=
gorm.io/gorm v1.22.4 h1:8aPcyEJhY0MAt8aY6Dc524Pn+pO29K+ydu+e/cXSpQM=
gorm.io/gorm v1.22.4/go.mod h1:1aeVC+pe9ZmvKZban/gW4QPra7PRoTEssyc922qCAkk=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

@ -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(&params); 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(&params); 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(&params); 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(&params); 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(&params); 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(&params); 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)
userBlackList = append(userBlackList, b)
}
resp := gin.H{
"errCode": RpcResp.ErrCode,
"errMsg": RpcResp.ErrMsg,
"data": userBlackList,
}
c.JSON(http.StatusOK, resp)
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)
} 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(&params); 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(&params); 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(&params); 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(&params); 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(&params); 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(&params); 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(&params); 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(&params); 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}
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, "IsFriend api return ", resp)
}
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList api return ", resp)
}

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{}

@ -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
)
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) 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
////
//}
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
}

@ -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)

@ -0,0 +1,155 @@
package base_info
import open_im_sdk "Open_IM/pkg/proto/sdk_ws"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
type paramsCommFriend struct {
OperationID string `json:"operationID" binding:"required"`
ToUserID string `json:"toUserID" binding:"required"`
FromUserID string `json:"fromUserID" binding:"required"`
}
type AddBlacklistReq struct {
paramsCommFriend
}
type AddBlacklistResp struct {
CommResp
}
type ImportFriendReq struct {
FriendUserIDList []string `json:"friendUserIDList" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
FromUserID string `json:"fromUserID" binding:"required"`
}
type ImportFriendResp struct {
CommResp
Data []string `json:"data"`
}
type AddFriendReq struct {
paramsCommFriend
ReqMsg string `json:"reqMsg"`
}
type AddFriendResp struct {
CommResp
}
type AddFriendResponseReq struct {
paramsCommFriend
Flag int32 `json:"flag" binding:"required"`
HandleMsg string `json:"handleMsg"`
}
type AddFriendResponseResp struct {
CommResp
}
type DeleteFriendReq struct {
paramsCommFriend
}
type DeleteFriendResp struct {
CommResp
}
type GetBlackListReq struct {
paramsCommFriend
}
type GetBlackListResp struct {
CommResp
BlackUserInfoList []*blackUserInfo `json:"data"`
}
//type PublicUserInfo struct {
// UserID string `json:"userID"`
// Nickname string `json:"nickname"`
// FaceUrl string `json:"faceUrl"`
// Gender int32 `json:"gender"`
//}
type blackUserInfo struct {
open_im_sdk.PublicUserInfo
}
type SetFriendCommentReq struct {
paramsCommFriend
Remark string `json:"remark" binding:"required"`
}
type SetFriendCommentResp struct {
CommResp
}
type RemoveBlackListReq struct {
paramsCommFriend
}
type RemoveBlackListResp struct {
CommResp
}
type IsFriendReq struct {
paramsCommFriend
}
type IsFriendResp struct {
CommResp
Response bool `json:"response"`
}
type GetFriendsInfoReq struct {
paramsCommFriend
}
type GetFriendsInfoResp struct {
CommResp
FriendInfoList []*open_im_sdk.FriendInfo `json:"data"`
}
type GetFriendListReq struct {
paramsCommFriend
}
type GetFriendListResp struct {
CommResp
FriendInfoList []*open_im_sdk.FriendInfo `json:"data"`
}
type GetFriendApplyListReq struct {
paramsCommFriend
}
type GetFriendApplyListResp struct {
CommResp
FriendRequestList open_im_sdk.FriendRequest `json:"data"`
}
type GetSelfApplyListReq struct {
paramsCommFriend
}
type GetSelfApplyListResp struct {
CommResp
FriendRequestList open_im_sdk.FriendRequest `json:"data"`
}

@ -0,0 +1,153 @@
package base_info
import (
pb "Open_IM/pkg/proto/group"
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
)
type CommResp struct {
ErrCode int32 `json:"errCode"`
ErrMsg string `json:"errMsg"`
}
type Id2Result struct {
UserID string `json:"userID"`
Result int32 `json:"result"`
}
type KickGroupMemberReq struct {
GroupID string `json:"groupID" binding:"required"`
KickedUserIDList []string `json:"kickedUserIDList" binding:"required"`
Reason string `json:"reason"`
OperationID string `json:"operationID" binding:"required"`
}
type KickGroupMemberResp struct {
CommResp
Data []*Id2Result `json:"data"`
}
type GetGroupMembersInfoReq struct {
GroupID string `json:"groupID" binding:"required"`
MemberList []string `json:"memberList" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetGroupMembersInfoResp struct {
CommResp
Data []*open_im_sdk.GroupMemberFullInfo `json:"data"`
}
type InviteUserToGroupReq struct {
GroupID string `json:"groupID" binding:"required"`
InvitedUserIDList []string `json:"uidList" binding:"required"`
Reason string `json:"reason"`
OperationID string `json:"operationID" binding:"required"`
}
type InviteUserToGroupResp struct {
CommResp
Data []Id2Result `json:"data"`
}
type GetJoinedGroupListReq struct {
OperationID string `json:"operationID" binding:"required"`
FromUserID string `json:"fromUserID" binding:"required"`
}
type GetJoinedGroupListResp struct {
CommResp
Data []*open_im_sdk.GroupInfo `json:"data"`
}
type GetGroupMemberListReq struct {
GroupID string `json:"groupID"`
Filter int32 `json:"filter"`
NextSeq int32 `json:"nextSeq"`
OperationID string `json:"operationID"`
}
type GetGroupMemberListResp struct {
CommResp
NextSeq int32 `json:"nextSeq"`
Data []*open_im_sdk.GroupMemberFullInfo `json:"data"`
}
type GetGroupAllMemberReq struct {
GroupID string `json:"groupID"`
OperationID string `json:"operationID"`
}
type GetGroupAllMemberResp struct {
CommResp
Data []*open_im_sdk.GroupMemberFullInfo `json:"data"`
}
type CreateGroupReq struct {
MemberList []*pb.GroupAddMemberInfo `json:"memberList"`
GroupName string `json:"groupName"`
Introduction string `json:"introduction"`
Notification string `json:"notification"`
FaceUrl string `json:"faceUrl"`
OperationID string `json:"operationID" binding:"required"`
GroupType int32 `json:"groupType"`
Ex string `json:"ex"`
}
type CreateGroupResp struct {
CommResp
Data open_im_sdk.GroupInfo `json:"data"`
}
type GetGroupApplicationListReq struct {
OperationID string `json:"operationID" binding:"required"`
FromUserID string `json:"fromUserID" binding:"required"` //my application
}
type GetGroupApplicationListResp struct {
CommResp
Data []*open_im_sdk.GroupRequest `json:"data"`
}
type GetGroupInfoReq struct {
GroupIDList []string `json:"groupIDList" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetGroupInfoResp struct {
CommResp
Data []open_im_sdk.GroupInfo `json:"data"`
}
type ApplicationGroupResponseReq struct {
OperationID string `json:"groupIDList" binding:"required"`
GroupID string `json:"groupIDList" binding:"required"`
FromUserID string `json:"groupIDList" binding:"required"`
HandledMsg string `json:"groupIDList" binding:"required"`
HandleResult int32 `json:"groupIDList" binding:"required"`
}
type ApplicationGroupResponseResp struct {
CommResp
}
type JoinGroupReq struct {
GroupID string `json:"groupID"`
ReqMessage string `json:"reqMessage"`
OperationID string `json:"operationID"`
}
type JoinGroupResp struct {
CommResp
}
type QuitGroupReq struct {
GroupID string `json:"groupID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type QuitGroupResp struct {
CommResp
}
type SetGroupInfoReq struct {
open_im_sdk.GroupInfo
OperationID string `json:"operationID" binding:"required"`
}
type SetGroupInfoResp struct {
CommResp
}
type TransferGroupOwnerReq struct {
GroupID string `json:"groupID" binding:"required"`
OldOwnerUserID string `json:"oldOwnerUserID" binding:"required"`
NewOwnerUserID string `json:"newOwnerUserID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}

@ -0,0 +1,95 @@
//package base_info
//
//type GroupInfo struct {
// GroupID string `json:"groupID"`
// GroupName string `json:"groupName"`
// Notification string `json:"notification"`
// Introduction string `json:"introduction"`
// FaceUrl string `json:"faceUrl"`
// OperationID string `json:"operationID"`
// OwnerUserID string `json:"ownerUserID"`
// CreateTime int64 `json:"createTime"`
// MemberCount uint32 `json:"memberCount"`
// Ex string `json:"ex"`
// Status int32 `json:"status"`
// CreatorUserID string `json:"creatorUserID"`
// GroupType int32 `json:"groupType"`
//}
//
//type GroupMemberFullInfo struct {
// GroupID string `json:"groupID"`
// UserID string `json:"userID"`
// RoleLevel int32 `json:"roleLevel"`
// JoinTime uint64 `json:"joinTime"`
// Nickname string `json:"nickname"`
// FaceUrl string `json:"faceUrl"`
// FriendRemark string `json:"friendRemark"`
// AppMangerLevel int32 `json:"appMangerLevel"`
// JoinSource int32 `json:"joinSource"`
// OperatorUserID string `json:"operatorUserID"`
// Ex string `json:"ex"`
//}
//
//type PublicUserInfo struct {
// UserID string `json:"userID"`
// Nickname string `json:"nickname"`
// FaceUrl string `json:"faceUrl"`
// Gender int32 `json:"gender"`
//}
//
//type UserInfo 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"`
// Ex string `json:"ex"`
//}
//
//type FriendInfo struct {
// OwnerUserID string `json:"ownerUserID"`
// Remark string `json:"remark"`
// CreateTime int64 `json:"createTime"`
// FriendUser UserInfo `json:"friendUser"`
// AddSource int32 `json:"addSource"`
// OperatorUserID string `json:"operatorUserID"`
// Ex string `json:"ex"`
//}
//
//type BlackInfo struct {
// OwnerUserID string `json:"ownerUserID"`
// CreateTime int64 `json:"createTime"`
// BlackUser PublicUserInfo `json:"friendUser"`
// AddSource int32 `json:"addSource"`
// OperatorUserID string `json:"operatorUserID"`
// Ex string `json:"ex"`
//}
//
//type GroupRequest struct {
// UserID string `json:"userID"`
// GroupID string `json:"groupID"`
// HandleResult string `json:"handleResult"`
// ReqMsg string `json:"reqMsg"`
// HandleMsg string `json:"handleMsg"`
// ReqTime int64 `json:"reqTime"`
// HandleUserID string `json:"handleUserID"`
// HandleTime int64 `json:"handleTime"`
// Ex string `json:"ex"`
//}
//
//type FriendRequest struct {
// FromUserID string `json:"fromUserID"`
// ToUserID string `json:"toUserID"`
// HandleResult int32 `json:"handleResult"`
// ReqMessage string `json:"reqMessage"`
// CreateTime int64 `json:"createTime"`
// HandlerUserID string `json:"handlerUserID"`
// HandleMsg string `json:"handleMsg"`
// HandleTime int64 `json:"handleTime"`
// Ex string `json:"ex"`
//}
//
//
//

@ -11,53 +11,60 @@ type ErrInfo struct {
var (
OK = ErrInfo{0, ""}
ErrMysql = ErrInfo{100, ""}
ErrMongo = ErrInfo{110, ""}
ErrRedis = ErrInfo{120, ""}
ErrParseToken = ErrInfo{200, "Parse token failed"}
ErrCreateToken = ErrInfo{201, "Create token failed"}
ErrAppServerKey = ErrInfo{300, "key error"}
ErrTencentCredential = ErrInfo{400, ""}
// ErrMysql = ErrInfo{100, ""}
// ErrMongo = ErrInfo{110, ""}
// ErrRedis = ErrInfo{120, ""}
ErrParseToken = ErrInfo{200, ParseTokenMsg.Error()}
// ErrCreateToken = ErrInfo{201, "Create token failed"}
// ErrAppServerKey = ErrInfo{300, "key error"}
ErrTencentCredential = ErrInfo{400, ThirdPartyMsg.Error()}
ErrorUserRegister = ErrInfo{600, "User registration failed"}
ErrAccountExists = ErrInfo{601, "The account is already registered and cannot be registered again"}
ErrUserPassword = ErrInfo{602, "User password error"}
ErrRefreshToken = ErrInfo{605, "Failed to refresh token"}
ErrAddFriend = ErrInfo{606, "Failed to add friends"}
ErrAgreeToAddFriend = ErrInfo{607, "Failed to agree application"}
ErrAddFriendToBlack = ErrInfo{608, "Failed to add friends to the blacklist"}
ErrGetBlackList = ErrInfo{609, "Failed to get blacklist"}
ErrDeleteFriend = ErrInfo{610, "Failed to delete friend"}
ErrGetFriendApplyList = ErrInfo{611, "Failed to get friend application list"}
ErrGetFriendList = ErrInfo{612, "Failed to get friend list"}
ErrRemoveBlackList = ErrInfo{613, "Failed to remove blacklist"}
ErrSearchUserInfo = ErrInfo{614, "Can't find the user information"}
ErrDelAppleDeviceToken = ErrInfo{615, ""}
ErrModifyUserInfo = ErrInfo{616, "update user some attribute failed"}
ErrSetFriendComment = ErrInfo{617, "set friend comment failed"}
ErrSearchUserInfoFromTheGroup = ErrInfo{618, "There is no such group or the user not in the group"}
ErrCreateGroup = ErrInfo{619, "create group chat failed"}
ErrJoinGroupApplication = ErrInfo{620, "Failed to apply to join the group"}
ErrQuitGroup = ErrInfo{621, "Failed to quit the group"}
ErrSetGroupInfo = ErrInfo{622, "Failed to set group info"}
ErrParam = ErrInfo{700, "param failed"}
ErrTokenExpired = ErrInfo{701, TokenExpired.Error()}
ErrTokenInvalid = ErrInfo{702, TokenInvalid.Error()}
ErrTokenMalformed = ErrInfo{703, TokenMalformed.Error()}
ErrTokenNotValidYet = ErrInfo{704, TokenNotValidYet.Error()}
ErrTokenUnknown = ErrInfo{705, TokenUnknown.Error()}
// ErrorUserRegister = ErrInfo{600, "User registration failed"}
// ErrAccountExists = ErrInfo{601, "The account is already registered and cannot be registered again"}
// ErrUserPassword = ErrInfo{602, "User password error"}
// ErrRefreshToken = ErrInfo{605, "Failed to refresh token"}
// ErrAddFriend = ErrInfo{606, "Failed to add friends"}
// ErrAgreeToAddFriend = ErrInfo{607, "Failed to agree application"}
// ErrAddFriendToBlack = ErrInfo{608, "Failed to add friends to the blacklist"}
// ErrGetBlackList = ErrInfo{609, "Failed to get blacklist"}
// ErrDeleteFriend = ErrInfo{610, "Failed to delete friend"}
// ErrGetFriendApplyList = ErrInfo{611, "Failed to get friend application list"}
// ErrGetFriendList = ErrInfo{612, "Failed to get friend list"}
// ErrRemoveBlackList = ErrInfo{613, "Failed to remove blacklist"}
// ErrSearchUserInfo = ErrInfo{614, "Can't find the user information"}
// ErrDelAppleDeviceToken = ErrInfo{615, ""}
// ErrModifyUserInfo = ErrInfo{616, "update user some attribute failed"}
// ErrSetFriendComment = ErrInfo{617, "set friend comment failed"}
// ErrSearchUserInfoFromTheGroup = ErrInfo{618, "There is no such group or the user not in the group"}
// ErrCreateGroup = ErrInfo{619, "create group chat failed"}
// ErrJoinGroupApplication = ErrInfo{620, "Failed to apply to join the group"}
// ErrQuitGroup = ErrInfo{621, "Failed to quit the group"}
// ErrSetGroupInfo = ErrInfo{622, "Failed to set group info"}
// ErrParam = ErrInfo{700, "param failed"}
ErrTokenExpired = ErrInfo{701, TokenExpiredMsg.Error()}
ErrTokenInvalid = ErrInfo{702, TokenInvalidMsg.Error()}
ErrTokenMalformed = ErrInfo{703, TokenMalformedMsg.Error()}
ErrTokenNotValidYet = ErrInfo{704, TokenNotValidYetMsg.Error()}
ErrTokenUnknown = ErrInfo{705, TokenUnknownMsg.Error()}
ErrAccess = ErrInfo{ErrCode: 800, ErrMsg: "no permission"}
ErrDb = ErrInfo{ErrCode: 900, ErrMsg: "db failed"}
ErrAccess = ErrInfo{ErrCode: 801, ErrMsg: AccessMsg.Error()}
ErrDB = ErrInfo{ErrCode: 802, ErrMsg: DBMsg.Error()}
ErrArgs = ErrInfo{ErrCode: 8003, ErrMsg: ArgsMsg.Error()}
)
var (
TokenExpired = errors.New("token is timed out, please log in again")
TokenInvalid = errors.New("token has been invalidated")
TokenNotValidYet = errors.New("token not active yet")
TokenMalformed = errors.New("that's not even a token")
TokenUnknown = errors.New("couldn't handle this token")
ParseTokenMsg = errors.New("parse token failed")
TokenExpiredMsg = errors.New("token is timed out, please log in again")
TokenInvalidMsg = errors.New("token has been invalidated")
TokenNotValidYetMsg = errors.New("token not active yet")
TokenMalformedMsg = errors.New("that's not even a token")
TokenUnknownMsg = errors.New("couldn't handle this token")
AccessMsg = errors.New("no permission")
DBMsg = errors.New("db failed")
ArgsMsg = errors.New("args failed")
ThirdPartyMsg = errors.New("third party error")
)
const (
@ -67,7 +74,7 @@ const (
LogicalError = 10003
ServerError = 10004
HttpError = 10005
IoErrot = 10006
IoError = 10006
IntentionalError = 10007
)

@ -6,17 +6,13 @@ import (
"time"
)
func InsertToFriend(ownerId, friendId string, flag int32) error {
func InsertToFriend(toInsertFollow *Friend) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
toInsertFollow := Friend{
OwnerUserID: ownerId,
FriendUserID: friendId,
FriendFlag: flag,
CreateTime: time.Now(),
}
toInsertFollow.CreateTime = time.Now()
err = dbConn.Table("friend").Create(toInsertFollow).Error
if err != nil {
return err
@ -24,46 +20,56 @@ func InsertToFriend(ownerId, friendId string, flag int32) error {
return nil
}
func FindFriendRelationshipFromFriend(ownerId, friendId string) (*Friend, error) {
func FindFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*Friend, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friend Friend
err = dbConn.Table("friend").Where("owner_id=? and friend_id=?", ownerId, friendId).Find(&friend).Error
err = dbConn.Table("friend").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Find(&friend).Error
if err != nil {
return nil, err
}
return &friend, err
}
func FindUserInfoFromFriend(ownerId string) ([]Friend, error) {
func FindUserInfoFromFriend(OwnerUserID string) ([]Friend, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friends []Friend
err = dbConn.Table("friend").Where("owner_id=?", ownerId).Find(&friends).Error
err = dbConn.Table("friend").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error
if err != nil {
return nil, err
}
return friends, nil
}
func UpdateFriendComment(ownerId, friendId, comment string) error {
func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Exec("update friend set comment=? where owner_id=? and friend_id=?", comment, ownerId, friendId).Error
err = dbConn.Exec("update friend set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error
return err
}
func DeleteSingleFriendInfo(ownerId, friendId string) error {
func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Table("friend").Where("owner_id=? and friend_id=?", ownerId, friendId).Delete(Friend{}).Error
err = dbConn.Table("friend").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(Friend{}).Error
return err
}
//type Friend struct {
// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
// FriendUserID string `gorm:"column:friend_user_id;primaryKey;"`
// Remark string `gorm:"column:remark"`
// CreateTime time.Time `gorm:"column:create_time"`
// AddSource int32 `gorm:"column:add_source"`
// OperatorUserID string `gorm:"column:operator_user_id"`
// Ex string `gorm:"column:ex"`
//}

@ -2,43 +2,42 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"time"
)
// reqId add userId
func ReplaceIntoFriendReq(reqId, userId string, flag int32, reqMessage string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Exec("replace into friend_request(req_id,user_id,flag,req_message,create_time) values(?,?,?,?,?)", reqId, userId, flag, reqMessage, time.Now()).Error
if err != nil {
return err
}
return nil
}
//type FriendRequest struct {
// FromUserID string `gorm:"column:from_user_id;primaryKey;"`
// ToUserID string `gorm:"column:to_user_id;primaryKey;"`
// HandleResult int32 `gorm:"column:handle_result"`
// ReqMessage string `gorm:"column:req_message"`
// CreateTime time.Time `gorm:"column:create_time"`
// HandlerUserID string `gorm:"column:handler_user_id"`
// HandleMsg string `gorm:"column:handle_msg"`
// HandleTime time.Time `gorm:"column:handle_time"`
// Ex string `gorm:"column:ex"`
//}
func FindFriendsApplyFromFriendReq(userId string) ([]FriendRequest, error) {
// who apply to add me
func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]FriendRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var usersInfo []FriendRequest
//dbConn.LogMode(true)
err = dbConn.Table("friend_request").Where("user_id=?", userId).Find(&usersInfo).Error
err = dbConn.Table("friend_request").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error
if err != nil {
return nil, err
}
return usersInfo, nil
}
func FindSelfApplyFromFriendReq(userId string) ([]FriendRequest, error) {
//I apply to add somebody
func GetSendFriendApplicationListByUserID(FromUserID string) ([]FriendRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var usersInfo []FriendRequest
err = dbConn.Table("friend_request").Where("req_id=?", userId).Find(&usersInfo).Error
err = dbConn.Table("friend_request").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error
if err != nil {
return nil, err
}
@ -46,26 +45,25 @@ func FindSelfApplyFromFriendReq(userId string) ([]FriendRequest, error) {
}
//reqId apply to add userId already
func FindFriendApplyFromFriendReqByUid(reqId, userId string) (*FriendRequest, error) {
func FindFriendApplicationByBothUserID(FromUserId, ToUserID string) (*FriendRequest, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var friendRequest FriendRequest
err = dbConn.Table("friend_request").Where("req_id=? and user_id=?", reqId, userId).Find(&friendRequest).Error
err = dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?", FromUserId, ToUserID).Find(&friendRequest).Error
if err != nil {
return nil, err
}
return &friendRequest, nil
}
//userId process reqId
func UpdateFriendRelationshipToFriendReq(reqId, userId string, flag int32) error {
func UpdateFriendApplication(friendRequest FriendRequest) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Exec("update friend_request set flag=? where req_id=? and user_id=?", flag, reqId, userId).Error
err = dbConn.Table("friend_request").Where("from_user_id=? and to_user_id=?", friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error
if err != nil {
return err
}

@ -2,15 +2,25 @@ package im_mysql_model
import (
"Open_IM/pkg/common/db"
"time"
)
func InsertIntoGroupMember(groupId, uid, nickName, userGroupFaceUrl string, administratorLevel int32) error {
//type GroupMember struct {
// GroupID string `gorm:"column:group_id;primaryKey;"`
// UserID string `gorm:"column:user_id;primaryKey;"`
// NickName string `gorm:"column:nickname"`
// FaceUrl string `gorm:"user_group_face_url"`
// RoleLevel int32 `gorm:"column:role_level"`
// JoinTime time.Time `gorm:"column:join_time"`
// JoinSource int32 `gorm:"column:join_source"`
// OperatorUserID string `gorm:"column:operator_user_id"`
// Ex string `gorm:"column:ex"`
//}
func InsertIntoGroupMember(toInsertInfo GroupMember) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
toInsertInfo := GroupMember{GroupID: groupId, UserID: uid, NickName: nickName, AdministratorLevel: administratorLevel, JoinTime: time.Now(), FaceUrl: userGroupFaceUrl}
err = dbConn.Table("group_member").Create(toInsertInfo).Error
if err != nil {
return err
@ -18,154 +28,154 @@ func InsertIntoGroupMember(groupId, uid, nickName, userGroupFaceUrl string, admi
return nil
}
func FindGroupMemberListByUserId(uid string) ([]GroupMember, error) {
func GetGroupMemberListByUserID(userID string) ([]GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMemberList []GroupMember
err = dbConn.Raw("select * from `group_member` where uid=?", uid).Find(&groupMemberList).Error
err = dbConn.Table("group_member").Where("user_id=?", userID).Find(&groupMemberList).Error
if err != nil {
return nil, err
}
return groupMemberList, nil
}
func FindGroupMemberListByGroupId(groupId string) ([]GroupMember, error) {
func GetGroupMemberListByGroupID(groupID string) ([]GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMemberList []GroupMember
err = dbConn.Raw("select * from `group_member` where group_id=?", groupId).Find(&groupMemberList).Error
err = dbConn.Table("group_member").Where("group_id=?", groupID).Find(&groupMemberList).Error
if err != nil {
return nil, err
}
return groupMemberList, nil
}
func FindGroupMemberListByGroupIdAndFilterInfo(groupId string, filter int32) ([]GroupMember, error) {
func GetGroupMemberListByGroupIDAndFilter(groupID string, filter int32) ([]GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
dbConn.LogMode(true)
if err != nil {
return nil, err
}
var groupMemberList []GroupMember
err = dbConn.Raw("select * from `group_member` where group_id=? and administrator_level=?", groupId, filter).Find(&groupMemberList).Error
err = dbConn.Table("group_member").Where("group_id=? and role_level=?", groupID, filter).Find(&groupMemberList).Error
if err != nil {
return nil, err
}
return groupMemberList, nil
}
func FindGroupMemberInfoByGroupIdAndUserId(groupId, uid string) (*GroupMember, error) {
func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return nil, err
}
var groupMember GroupMember
err = dbConn.Raw("select * from `group_member` where group_id=? and uid=? limit 1", groupId, uid).Find(&groupMember).Error
err = dbConn.Table("group_member").Where("group_id=? and user_id=? limit 1", groupID, userID).Find(&groupMember).Error
if err != nil {
return nil, err
}
return &groupMember, nil
}
func DeleteGroupMemberByGroupIdAndUserId(groupId, uid string) error {
func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Exec("delete from `group_member` where group_id=? and uid=?", groupId, uid).Error
err = dbConn.Table("group_member").Where("group_id=? and user_id=? limit 1", groupID, userID).Delete(&GroupMember{}).Error
if err != nil {
return err
}
return nil
}
func UpdateOwnerGroupNickName(groupId, userId, groupNickName string) error {
func UpdateGroupMemberInfo(groupMemberInfo GroupMember) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
err = dbConn.Exec("update `group_member` set nickname=? where group_id=? and uid=?", groupNickName, groupId, userId).Error
err = dbConn.Table("group_member").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Update(&groupMemberInfo).Error
if err != nil {
return err
}
return nil
}
func SelectGroupList(groupID string) ([]string, error) {
var groupUserID string
var groupList []string
func GetOwnerManagerByGroupID(groupID string) ([]GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return groupList, err
return nil, err
}
rows, err := dbConn.Model(&GroupMember{}).Where("group_id = ?", groupID).Select("user_id").Rows()
var groupMemberList []GroupMember
err = dbConn.Table("group_member").Where("group_id=? and role_level>0", groupID).Find(&groupMemberList).Error
if err != nil {
return groupList, err
}
defer rows.Close()
for rows.Next() {
rows.Scan(&groupUserID)
groupList = append(groupList, groupUserID)
return nil, err
}
return groupList, nil
return groupMemberList, nil
}
func UpdateTheUserAdministratorLevel(groupId, uid string, administratorLevel int64) error {
func GetGroupMemberNumByGroupID(groupID string) int32 {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
return 0
}
err = dbConn.Exec("update `group_member` set administrator_level=? where group_id=? and uid=?", administratorLevel, groupId, uid).Error
var number int32
err = dbConn.Table("group_member").Where("group_id=?", groupID).Count(&number).Error
if err != nil {
return err
return 0
}
return nil
return number
}
func GetOwnerManagerByGroupId(groupId string) ([]GroupMember, error) {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
func GetGroupOwnerInfoByGroupID(groupID string) (*GroupMember, error) {
omList, err := GetOwnerManagerByGroupID(groupID)
if err != nil {
return nil, err
}
var groupMemberList []GroupMember
err = dbConn.Raw("select * from `group_member` where group_id=? and administrator_level > 0", groupId).Find(&groupMemberList).Error
if err != nil {
return nil, err
for _, v := range omList {
if v.RoleLevel == 1 {
return &v, nil
}
return groupMemberList, nil
}
return nil, nil
}
func IsExistGroupMember(groupId, uid string) bool {
func IsExistGroupMember(groupID, userID string) bool {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return false
}
var number int32
err = dbConn.Raw("select count(*) from `group_member` where group_id = ? and uid = ?", groupId, uid).Count(&number).Error
err = dbConn.Table("group_member").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error
if err != nil {
return false
}
if number != 1 {
return false
}
return true
}
func RemoveGroupMember(groupId string, memberId string) error {
return DeleteGroupMemberByGroupIdAndUserId(groupId, memberId)
func RemoveGroupMember(groupID string, UserID string) error {
return DeleteGroupMemberByGroupIDAndUserID(groupID, UserID)
}
func GetMemberInfoById(groupId string, memberId string) (*GroupMember, error) {
return FindGroupMemberInfoByGroupIdAndUserId(groupId, memberId)
func GetMemberInfoByID(groupID string, userID string) (*GroupMember, error) {
return GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
}
func GetGroupMemberByGroupId(groupId string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
memberList, err := FindGroupMemberListByGroupId(groupId) //sorted by join time
func GetGroupMemberByGroupID(groupID string, filter int32, begin int32, maxNumber int32) ([]GroupMember, error) {
var memberList []GroupMember
var err error
if filter >= 0 {
memberList, err = GetGroupMemberListByGroupIDAndFilter(groupID, filter) //sorted by join time
} else {
memberList, err = GetGroupMemberListByGroupID(groupID)
}
if err != nil {
return nil, err
}
@ -182,49 +192,35 @@ func GetGroupMemberByGroupId(groupId string, filter int32, begin int32, maxNumbe
return memberList[begin:end], nil
}
func GetJoinedGroupIdListByMemberId(memberId string) ([]GroupMember, error) {
return FindGroupMemberListByUserId(memberId)
}
func GetGroupMemberNumByGroupId(groupId string) int32 {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return 0
}
var number int32
err = dbConn.Raw("select count(*) from `group_member` where group_id=? ", groupId).Count(&number).Error
if err != nil {
return 0
}
return number
}
func GetGroupOwnerByGroupId(groupId string) string {
omList, err := GetOwnerManagerByGroupId(groupId)
if err != nil {
return ""
}
for _, v := range omList {
if v.AdministratorLevel == 1 {
return v.UserID
}
}
return ""
}
func GetGroupOwnerInfoByGroupId(groupId string) (*GroupMember, error) {
omList, err := GetOwnerManagerByGroupId(groupId)
func GetJoinedGroupIDListByUserID(userID string) ([]string, error) {
memberList, err := GetGroupMemberListByUserID(userID)
if err != nil {
return nil, err
}
for _, v := range omList {
if v.AdministratorLevel == 1 {
return v, nil
}
}
return nil, nil
}
func InsertGroupMember(groupId, userId, nickName, userFaceUrl string, role int32) error {
return InsertIntoGroupMember(groupId, userId, nickName, userFaceUrl, role)
}
var groupIDList []string = make([]string, len(memberList))
for _, v := range memberList {
groupIDList = append(groupIDList, v.GroupID)
}
return groupIDList, nil
}
//
//func SelectGroupList(groupID string) ([]string, error) {
// var groupUserID string
// var groupList []string
// dbConn, err := db.DB.MysqlDB.DefaultGormDB()
// if err != nil {
// return groupList, err
// }
//
// rows, err := dbConn.Model(&GroupMember{}).Where("group_id = ?", groupID).Select("user_id").Rows()
// if err != nil {
// return groupList, err
// }
// defer rows.Close()
// for rows.Next() {
// rows.Scan(&groupUserID)
// groupList = append(groupList, groupUserID)
// }
// return groupList, nil
//}

@ -8,17 +8,16 @@ import (
"time"
)
func InsertIntoGroup(groupId, name, introduction, notification, faceUrl, ex string) error {
func InsertIntoGroup(groupInfo Group) error {
dbConn, err := db.DB.MysqlDB.DefaultGormDB()
if err != nil {
return err
}
//Default group name
if name == "" {
name = "Group Chat"
if groupInfo.GroupName == "" {
groupInfo.GroupName = "Group Chat"
}
toInsertInfo := Group{GroupID: groupId, GroupName: name, Introduction: introduction, Notification: notification, FaceUrl: faceUrl, CreateTime: time.Now(), Ex: ex}
err = dbConn.Table("group").Create(toInsertInfo).Error
groupInfo.CreateTime = time.Now()
err = dbConn.Table("group").Create(groupInfo).Error
if err != nil {
return err
}
@ -164,7 +163,7 @@ func GetGroupApplicationList(uid string) (*group.GetGroupApplicationListResp, er
return reply, nil
}
func TransferGroupOwner(pb *group.TransferGroupOwnerReq) (*group.CommonResp, error) {
func TransferGroupOwner(pb *group.TransferGroupOwnerReq) (*group.TransferGroupOwnerResp, error) {
oldOwner, err := FindGroupMemberInfoByGroupIdAndUserId(pb.GroupID, pb.OldOwnerUserID)
if err != nil {
return nil, err
@ -187,7 +186,7 @@ func TransferGroupOwner(pb *group.TransferGroupOwnerReq) (*group.CommonResp, err
return nil, err
}
return &group.CommonResp{}, nil
return &group.TransferGroupOwnerResp{CommonResp: &group.CommonResp{ErrCode: 0}}, nil
}
func GroupApplicationResponse(pb *group.GroupApplicationResponseReq) (*group.CommonResp, error) {

@ -2,69 +2,82 @@ package im_mysql_model
import "time"
type User struct {
UserID string `gorm:"column:uid;primaryKey;"`
Nickname string `gorm:"column:name"`
FaceUrl string `gorm:"column:icon"`
Gender int32 `gorm:"column:gender"`
Mobile string `gorm:"column:mobile"`
Birth string `gorm:"column:birth"`
Email string `gorm:"column:email"`
Ex string `gorm:"column:ex"`
CreateTime time.Time `gorm:"column:create_time"`
}
type Friend struct {
OwnerUserID string `gorm:"column:owner_id"`
FriendUserID string `gorm:"column:friend_id"`
Remark string `gorm:"column:comment"`
FriendFlag int32 `gorm:"column:friend_flag"`
OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
FriendUserID string `gorm:"column:friend_user_id;primaryKey;"`
Remark string `gorm:"column:remark"`
CreateTime time.Time `gorm:"column:create_time"`
AddSource int32 `gorm:"column:add_source"`
OperatorUserID string `gorm:"column:operator_user_id"`
Ex string `gorm:"column:ex"`
}
type FriendRequest struct {
ReqID string `gorm:"column:req_id"`
UserID string `gorm:"column:user_id"`
Flag int32 `gorm:"column:flag"`
FromUserID string `gorm:"column:from_user_id;primaryKey;"`
ToUserID string `gorm:"column:to_user_id;primaryKey;"`
HandleResult int32 `gorm:"column:handle_result"`
ReqMessage string `gorm:"column:req_message"`
CreateTime time.Time `gorm:"column:create_time"`
}
type BlackList struct {
OwnerUserID string `gorm:"column:owner_id"`
BlockUserID string `gorm:"column:block_id"`
CreateTime time.Time `gorm:"column:create_time"`
HandlerUserID string `gorm:"column:handler_user_id"`
HandleMsg string `gorm:"column:handle_msg"`
HandleTime time.Time `gorm:"column:handle_time"`
Ex string `gorm:"column:ex"`
}
type Group struct {
GroupID string `gorm:"column:group_id"`
GroupID string `gorm:"column:group_id;primaryKey;"`
GroupName string `gorm:"column:name"`
Introduction string `gorm:"column:introduction"`
Notification string `gorm:"column:notification"`
FaceUrl string `gorm:"column:face_url"`
CreateTime time.Time `gorm:"column:create_time"`
Ext string `gorm:"column:ex"`
Status int32 `gorm:"column:status"`
CreatorUserID string `gorm:"column:creator_user_id"`
GroupType int32 `gorm:"column:group_type"`
Ex string `gorm:"column:ex"`
}
type GroupMember struct {
GroupID string `gorm:"column:group_id"`
UserID string `gorm:"column:uid"`
GroupID string `gorm:"column:group_id;primaryKey;"`
UserID string `gorm:"column:user_id;primaryKey;"`
NickName string `gorm:"column:nickname"`
AdministratorLevel int32 `gorm:"column:administrator_level"`
JoinTime time.Time `gorm:"column:join_time"`
FaceUrl string `gorm:"user_group_face_url"`
RoleLevel int32 `gorm:"column:role_level"`
JoinTime time.Time `gorm:"column:join_time"`
JoinSource int32 `gorm:"column:join_source"`
OperatorUserID string `gorm:"column:operator_user_id"`
Ex string `gorm:"column:ex"`
}
type GroupRequest struct {
ID string `gorm:"column:id"`
GroupID string `gorm:"column:group_id"`
FromUserID string `gorm:"column:from_user_id"`
ToUserID string `gorm:"column:to_user_id"`
Flag int32 `gorm:"column:flag"`
UserID string `gorm:"column:user_id;primaryKey;"`
GroupID string `gorm:"column:group_id;primaryKey;"`
HandleResult string `gorm:"column:handle_result"`
ReqMsg string `gorm:"column:req_msg"`
HandledMsg string `gorm:"column:handled_msg"`
ReqTime time.Time `gorm:"column:req_time"`
HandleUserID string `gorm:"column:handle_user_id"`
HandledTime time.Time `gorm:"column:handle_time"`
Ex string `gorm:"column:ex"`
}
type User struct {
UserID string `gorm:"column:user_id;primaryKey;"`
Nickname string `gorm:"column:name"`
FaceUrl string `gorm:"column:icon"`
Gender int32 `gorm:"column:gender"`
PhoneNumber string `gorm:"column:phone_number"`
Birth string `gorm:"column:birth"`
Email string `gorm:"column:email"`
Ex string `gorm:"column:ex"`
CreateTime time.Time `gorm:"column:create_time"`
}
type BlackList struct {
OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"`
BlockUserID string `gorm:"column:block_user_id;primaryKey;"`
CreateTime time.Time `gorm:"column:create_time"`
FromUserNickname string `gorm:"from_user_nickname"`
ToUserNickname string `gorm:"to_user_nickname"`
FromUserFaceUrl string `gorm:"from_user_face_url"`
ToUserFaceUrl string `gorm:"to_user_face_url"`
HandledUser string `gorm:"handled_user"`
AddSource int32 `gorm:"column:add_source"`
OperatorUserID int32 `gorm:"column:operator_user_id"`
Ex string `gorm:"column:ex"`
}

@ -0,0 +1,5 @@
syntax = "proto3";
package base;

File diff suppressed because it is too large Load Diff

@ -15,138 +15,151 @@ message CommID{
string FromUserID = 5;
}
message GetFriendsInfoReq{
CommID CommID = 1;
}
message GetFriendInfoResp{
int32 ErrCode = 1;
string ErrMsg = 2;
FriendInfo Data = 3;
}
message FriendInfo{
string OwnerUserID = 1;
string Remark = 2;
uint64 CreateTime = 3;
open_im_sdk.UserInfo FriendUser = 4;
int32 IsBlack = 5;
repeated open_im_sdk.FriendInfo FriendInfoList = 3;
// int32 IsBlack = 4;
}
message AddFriendReq{
CommID CommID = 1;
string ReqMessage = 2;
string ReqMsg = 2;
}
message AddFriendResp{
CommonResp CommonResp = 1;
}
message ImportFriendReq{
repeated string FriendUserIDList = 1;
string OperationID = 2;
string FromUserID = 3;
string OpUserID = 4;
}
message ImportFriendResp{
CommonResp commonResp = 1;
repeated string failedUidList = 2;
CommonResp CommonResp = 1;
repeated string FailedFriendUserIDList = 2;
}
message GetFriendApplyReq{
message GetFriendApplyListReq{
CommID CommID = 1;
}
message GetFriendApplyResp{
message GetFriendApplyListResp{
int32 ErrCode = 1;
string ErrMsg = 2;
repeated ApplyUserInfo data = 4;
}
message ApplyUserInfo{
open_im_sdk.PublicUserInfo UserInfo = 1;
int64 applyTime = 2;
string reqMessage = 3;
int32 Flag = 4;
repeated open_im_sdk.FriendRequest FriendRequestList = 3;
}
message getFriendListReq{
message GetFriendListReq{
CommID CommID = 1;
}
message getFriendListResp{
message GetFriendListResp{
int32 ErrCode = 1;
string ErrMsg = 2;
repeated FriendInfo Data = 3;
repeated open_im_sdk.FriendInfo FriendInfoList = 3;
}
message AddBlacklistReq{
CommID CommID = 1;
}
message AddBlacklistResp{
CommonResp CommonResp = 1;
}
message RemoveBlacklistReq{
CommID CommID = 1;
}
message RemoveBlacklistResp{
CommonResp CommonResp = 1;
}
message GetBlacklistReq{
CommID CommID = 1;
}
message GetBlacklistResp{
int32 ErrCode = 1;
string ErrMsg = 2;
repeated open_im_sdk.PublicUserInfo data = 3;
repeated open_im_sdk.PublicUserInfo BlackUserInfoList = 3;
}
message IsFriendReq{
CommID CommID = 1;
}
message IsFriendResp{
int32 ErrCode = 1;
string ErrMsg = 2;
int32 ShipType = 3;
bool Response = 3;
}
message IsInBlackListReq{
CommID CommID = 1;
}
message IsInBlackListResp{
int32 ErrCode = 1;
string ErrMsg = 2;
bool Response = 3;
}
message DeleteFriendReq{
CommID CommID = 1;
}
message DeleteFriendResp{
CommonResp CommonResp = 1;
}
//process
message AddFriendResponseReq{
CommID CommID = 1;
int32 flag = 2;
string handleMsg = 3;
}
message AddFriendResponseResp{
CommonResp CommonResp = 1;
}
message SetFriendCommentReq{
CommID CommID = 1;
string Remark = 2;
}
message SetFriendCommentResp{
CommonResp CommonResp = 1;
}
message GetSelfApplyListReq{
CommID CommID = 1;
}
message GetSelfApplyListResp{
int32 ErrCode = 1;
string ErrMsg = 2;
repeated open_im_sdk.FriendRequest FriendRequestList = 3;
}
service friend{
rpc getFriendsInfo(GetFriendsInfoReq) returns(GetFriendInfoResp);
rpc addFriend(AddFriendReq) returns(CommonResp);
rpc getFriendApplyList(GetFriendApplyReq) returns(GetFriendApplyResp);
rpc getSelfApplyList(GetFriendApplyReq) returns(GetFriendApplyResp);
rpc getFriendList(getFriendListReq) returns(getFriendListResp);
rpc addBlacklist(AddBlacklistReq) returns(CommonResp);
rpc removeBlacklist(RemoveBlacklistReq) returns(CommonResp);
// rpc getFriendsInfo(GetFriendsInfoReq) returns(GetFriendInfoResp);
rpc addFriend(AddFriendReq) returns(AddFriendResp);
rpc getFriendApplyList(GetFriendApplyListReq) returns(GetFriendApplyListResp);
rpc getSelfApplyList(GetSelfApplyListReq) returns(GetSelfApplyListResp);
rpc getFriendList(GetFriendListReq) returns(GetFriendListResp);
rpc addBlacklist(AddBlacklistReq) returns(AddBlacklistResp);
rpc removeBlacklist(RemoveBlacklistReq) returns(RemoveBlacklistResp);
rpc isFriend(IsFriendReq) returns(IsFriendResp);
rpc isInBlackList(IsInBlackListReq) returns(IsInBlackListResp);
rpc getBlacklist(GetBlacklistReq) returns(GetBlacklistResp);
rpc deleteFriend(DeleteFriendReq) returns(CommonResp);
rpc addFriendResponse(AddFriendResponseReq) returns(CommonResp);
rpc setFriendComment(SetFriendCommentReq) returns(CommonResp);
rpc ImportFriend(ImportFriendReq) returns(ImportFriendResp);
rpc deleteFriend(DeleteFriendReq) returns(DeleteFriendResp);
rpc addFriendResponse(AddFriendResponseReq) returns(AddFriendResponseResp);
rpc setFriendComment(SetFriendCommentReq) returns(SetFriendCommentResp);
rpc importFriend(ImportFriendReq) returns(ImportFriendResp);
}

File diff suppressed because it is too large Load Diff

@ -10,33 +10,29 @@ message CommonResp{
message GroupAddMemberInfo{
string UserID = 1;
int32 Role = 2;
int32 RoleLevel = 2;
}
message CreateGroupReq{
repeated GroupAddMemberInfo InitMemberList = 1; //
string GroupName = 2;
string Introduction = 3;
string Notification = 4;
string FaceUrl = 5;
string Ext = 6;
string OperationID = 7;
string OpUserID = 8; //app manager or group owner
string FromUserID = 9;
repeated GroupAddMemberInfo InitMemberList = 1;
open_im_sdk.GroupInfo GroupInfo = 2;
string OperationID = 3;
string OpUserID = 4; //app manager or group owner
string OwnerUserID = 5; //owner
}
message CreateGroupResp{
int32 ErrCode = 1;
string ErrMsg = 2;
open_im_sdk.GroupInfo GroupInfo = 3;
}
message GetGroupsInfoReq{
repeated string GroupIDList = 1;
string OperationID = 2;
string OpUserID = 3; //No verification permission
}
message GetGroupsInfoResp{
int32 ErrCode = 1;
string ErrMsg = 2;
@ -49,44 +45,23 @@ message SetGroupInfoReq{
string OpUserID = 2; //app manager or group owner
string OperationID = 3;
}
message SetGroupInfoResp{
CommonResp CommonResp = 1;
}
message GetGroupApplicationListReq {
string OpUserID = 1; //app manager or group owner(manager)
string OperationID = 2;
string FromUserID = 3; //owner or manager (Received)
}
message GetGroupApplicationList_Data_User {
string ID = 1;
string GroupID = 2;
string FromUserID = 3;
string ToUserID = 4;
int32 Flag = 5;
string RequestMsg = 6;
string HandledMsg = 7;
int64 AddTime = 8;
string FromUserNickname = 9;
string ToUserNickname = 10;
string FromUserFaceUrl = 11;
string ToUserFaceUrl = 12;
string HandledUser = 13;
int32 Type = 14;
int32 HandleStatus = 15;
int32 HandleResult = 16;
string FromUserID = 3; //owner or manager
}
message GetGroupApplicationListData {
int32 Count = 1;
repeated GetGroupApplicationList_Data_User User = 2;
}
message GetGroupApplicationListResp {
int32 ErrCode = 1;
string ErrMsg = 2;
GetGroupApplicationListData Data = 3;
repeated open_im_sdk.GroupRequest GroupRequestList = 3;
}
message TransferGroupOwnerReq {
string GroupID = 1;
string OldOwnerUserID = 2;
@ -94,7 +69,9 @@ message TransferGroupOwnerReq {
string OperationID = 4;
string OpUserID = 5; //app manager or group owner
}
message TransferGroupOwnerResp{
CommonResp CommonResp = 1;
}
message JoinGroupReq{
string GroupID = 1;
@ -102,35 +79,33 @@ message JoinGroupReq{
string OpUserID = 3;
string OperationID = 4;
}
message JoinGroupResp{
CommonResp CommonResp = 1;
}
message GroupApplicationResponseReq{
string OperationID = 1;
string OpUserID = 2;
string GroupID = 3;
string FromUserID = 4; //::
string ToUserID = 5; //:0:
int64 AddTime = 6;
string HandledMsg = 7;
int32 HandleResult = 8;
string FromUserID = 4; //
string HandledMsg = 5;
int32 HandleResult = 6;
}
message SetOwnerGroupNickNameReq{
string GroupID = 1;
string Nickname = 2;
string OperationID = 3;
string FromUserID = 4;
string OpUserID = 5; //app manger or FromUserID
message GroupApplicationResponseResp{
CommonResp CommonResp = 1;
}
message QuitGroupReq{
string GroupID = 1;
string OperationID = 2;
string OpUserID = 3;
}
message QuitGroupResp{
CommonResp CommonResp = 1;
}
@ -150,7 +125,6 @@ message GetGroupMemberListResp {
}
message GetGroupMembersInfoReq {
string GroupID = 1;
repeated string memberList = 2;
@ -189,8 +163,6 @@ message GetJoinedGroupListReq {
string operationID = 2;
string OpUserID = 3; //app manager or FromUserID
}
message GetJoinedGroupListResp{
int32 ErrCode = 1;
string ErrMsg = 2;
@ -205,7 +177,6 @@ message InviteUserToGroupReq {
repeated string InvitedUserIDList = 5;
string OpUserID = 6; //group member or app manager
}
message InviteUserToGroupResp {
int32 ErrCode = 1;
string ErrMsg = 2;
@ -218,7 +189,6 @@ message GetGroupAllMemberReq {
string OpUserID = 2; //No verification permission
string OperationID = 3;
}
message GetGroupAllMemberResp {
int32 ErrCode = 1;
string ErrMsg = 2;
@ -229,20 +199,18 @@ message GetGroupAllMemberResp {
service group{
rpc createGroup(CreateGroupReq) returns(CreateGroupResp);
rpc joinGroup(JoinGroupReq) returns(CommonResp);
rpc quitGroup(QuitGroupReq) returns(CommonResp);
rpc joinGroup(JoinGroupReq) returns(JoinGroupResp);
rpc quitGroup(QuitGroupReq) returns(QuitGroupResp);
rpc getGroupsInfo(GetGroupsInfoReq) returns(GetGroupsInfoResp);
rpc setGroupInfo(SetGroupInfoReq) returns(CommonResp);
rpc setGroupInfo(SetGroupInfoReq) returns(SetGroupInfoResp);
rpc getGroupApplicationList(GetGroupApplicationListReq) returns(GetGroupApplicationListResp);
rpc transferGroupOwner(TransferGroupOwnerReq) returns(CommonResp);
rpc groupApplicationResponse(GroupApplicationResponseReq) returns(CommonResp);
// rpc setOwnerGroupNickName(SetOwnerGroupNickNameReq) returns(CommonResp);
rpc transferGroupOwner(TransferGroupOwnerReq) returns(TransferGroupOwnerResp);
rpc groupApplicationResponse(GroupApplicationResponseReq) returns(GroupApplicationResponseResp);
rpc getGroupMemberList(GetGroupMemberListReq) returns(GetGroupMemberListResp);
rpc getGroupMembersInfo(GetGroupMembersInfoReq) returns(GetGroupMembersInfoResp);
rpc kickGroupMember(KickGroupMemberReq) returns (KickGroupMemberResp);
rpc getJoinedGroupList(GetJoinedGroupListReq) returns (GetJoinedGroupListResp);
rpc inviteUserToGroup(InviteUserToGroupReq) returns (InviteUserToGroupResp);
rpc getGroupAllMember(GetGroupAllMemberReq) returns(GetGroupAllMemberResp);
}

File diff suppressed because it is too large Load Diff

@ -2,6 +2,102 @@ syntax = "proto3";
package open_im_sdk;//The package name to which the proto file belongs
//option go_package = "./sdk_ws;open_im_sdk";//The generated go pb file is in the current directory, and the package name is open_im_sdk
////////////////////////////////base///////////////////////////////
message GroupInfo{
string GroupID = 1;
string GroupName = 2;
string Notification = 3;
string Introduction = 4;
string FaceUrl = 5;
string OwnerUserID = 6;
int64 CreateTime = 7;
uint32 MemberCount = 8;
string Ex = 9;
int32 Status = 10;
string CreatorUserID = 11;
int32 GroupType = 12;
}
message GroupMemberFullInfo {
string GroupID = 1 ;
string UserID = 2 ;
int32 roleLevel = 3;
int64 JoinTime = 4;
string NickName = 5;
string FaceUrl = 6;
string FriendRemark = 7;
int32 AppMangerLevel = 8; //if >0
int32 JoinSource = 9;
string OperatorUserID = 10;
string Ex = 11;
}
message PublicUserInfo{
string UserID = 1;
string Nickname = 2;
string FaceUrl = 3;
int32 Gender = 4;
int32 AppMangerLevel = 5; //if >0
}
message UserInfo{
string UserID = 1;
string Nickname = 2;
string FaceUrl = 3;
int32 Gender = 4;
string PhoneNumber = 5;
string Birth = 6;
string Email = 7;
string Ex = 8;
}
message FriendInfo{
string OwnerUserID = 1;
string Remark = 2;
int64 CreateTime = 3;
UserInfo FriendUser = 4;
int32 AddSource = 5;
string OperatorUserID = 6;
string Ex = 7;
}
message BlackInfo{
string OwnerUserID = 1;
int64 CreateTime = 2;
PublicUserInfo BlackUserInfo = 4;
int32 AddSource = 5;
string OperatorUserID = 6;
string Ex = 7;
}
message GroupRequest{
string UserID = 1;
string GroupID = 2;
string HandleResult = 3;
string ReqMsg = 4;
string HandleMsg = 5;
int64 ReqTime = 6;
string HandleUserID = 7;
int64 HandleTime = 8;
string Ex = 9;
}
message FriendRequest{
string FromUserID = 1;
string ToUserID = 2;
int32 HandleResult = 3;
string ReqMsg = 4;
int64 CreateTime = 5;
string HandlerUserID = 6;
string HandleMsg = 7;
int64 HandleTime = 8;
string Ex = 9;
}
///////////////////////////////////base end/////////////////////////////////////
message PullMessageBySeqListResp {
int32 errCode = 1;
@ -14,7 +110,7 @@ message PullMessageBySeqListResp {
message PullMessageBySeqListReq{
string userID = 1;
string operationID = 2;
repeated int64 seqList =3;
repeated int64 seqList = 3;
}
message PullMessageReq {
string userID = 1;
@ -80,76 +176,38 @@ message MsgData {
string sendID = 1;
string recvID = 2;
string groupID = 3;
string clientMsgID =4;
string serverMsgID =5;
int32 senderPlatformID =6;
string senderNickName =7;
string senderFaceURL =8;
string clientMsgID = 4;
string serverMsgID = 5;
int32 senderPlatformID = 6;
string senderNickname = 7;
string senderFaceURL = 8;
int32 sessionType = 9;
int32 msgFrom = 10;
int32 contentType = 11;
bytes content =12;
bytes content = 12;
repeated string forceList = 13;
int64 seq =14;
int64 seq = 14;
int64 sendTime = 15;
int64 createTime = 16;
map<string,bool> Options= 17;
OfflinePushInfo offlinePushInfo =18;
map<string, bool> Options = 17;
OfflinePushInfo offlinePushInfo = 18;
}
message OfflinePushInfo{
string Title = 1;
string Desc = 2;
string Ext = 3;
string Ex = 3;
string iOSPushSound = 4;
bool iOSBadgeCount = 5;
}
//public
message GroupInfo{
string GroupID = 1;
string GroupName = 2;
string Notification = 3;
string Introduction = 4;
string FaceUrl = 5;
PublicUserInfo Owner = 6;
uint64 CreateTime = 7;
uint32 MemberCount = 8;
string Ext = 9;
}
//private, Group members have permission to view
message GroupMemberFullInfo {
string GroupID = 1 ;
string UserID = 2 ;
int32 AdministratorLevel = 3;
uint64 JoinTime = 4;
string NickName = 5;
string FaceUrl = 6;
string FriendRemark = 7;
int32 AppMangerLevel = 8; // >0
}
//private, Friends have permission to view
message UserInfo{
string UserID = 1;
string Nickname = 2;
string FaceUrl = 3;
int32 Gender = 4;
string Mobile = 5;
string Birth = 6;
string Email = 7;
string Ext = 8;
}
//No permissions required
message PublicUserInfo{
string UserID = 1;
string Nickname = 2;
string FaceUrl = 3;
int32 Gender = 4;
}
message TipsComm{
bytes Detail = 1;
@ -161,35 +219,35 @@ message TipsComm{
message MemberEnterTips{
GroupInfo Group = 1;
GroupMemberFullInfo EntrantUser = 2;
uint64 OperationTime = 3;
int64 OperationTime = 3;
}
//Actively leave the group
message MemberLeaveTips{
GroupInfo Group = 1;
GroupMemberFullInfo LeaverUser = 2;
uint64 OperationTime = 3;
int64 OperationTime = 3;
}
message MemberInvitedTips{
GroupInfo Group = 1;
GroupMemberFullInfo OpUser = 2;
repeated GroupMemberFullInfo InvitedUserList = 3;
uint64 OperationTime = 4;
int64 OperationTime = 4;
}
message MemberKickedTips{
GroupInfo Group = 1;
GroupMemberFullInfo OpUser = 2;
repeated GroupMemberFullInfo KickedUserList = 3;
uint64 OperationTime = 4;
int64 OperationTime = 4;
}
message MemberInfoChangedTips{
int32 ChangeType = 1; ///bitwise operators 0001:member info changed; 0010:mute ;
GroupMemberFullInfo OpUser = 2; //who do this
GroupMemberFullInfo FinalInfo = 3; //
uint64 MuteTime = 4;
int64 MuteTime = 4;
GroupInfo Group = 5;
}
@ -197,7 +255,7 @@ message GroupCreatedTips{
GroupInfo Group = 1;
GroupMemberFullInfo Creator = 2;
repeated GroupMemberFullInfo MemberList = 3;
uint64 OperationTime = 4;
int64 OperationTime = 4;
}
message GroupInfoChangedTips{
@ -220,15 +278,15 @@ message ApplicationProcessedTips{
}
//////////////////////friend/////////////////////
message FriendInfo{
UserInfo OwnerUser = 1;
string Remark = 2;
uint64 CreateTime = 3;
UserInfo FriendUser = 4;
}
//message FriendInfo{
// UserInfo OwnerUser = 1;
// string Remark = 2;
// uint64 CreateTime = 3;
// UserInfo FriendUser = 4;
//}
message FriendApplication{
uint64 AddTime = 1;
int64 AddTime = 1;
string AddSource = 2;
string AddWording = 3;
}
@ -251,7 +309,7 @@ message FriendApplicationProcessedTips{
// FromUserID Added a friend ToUserID
message FriendAddedTips{
FriendInfo Friend = 1;
uint64 OperationTime = 2;
int64 OperationTime = 2;
PublicUserInfo OpUser = 3; //who do this
}
@ -261,11 +319,7 @@ message FriendDeletedTips{
FromToUserID FromToUserID = 1;
}
//message BlackInfo{
// PublicUserInfo OwnerUser = 1;
// uint64 CreateTime = 3;
// PublicUserInfo BlackUser = 4;
//}
message BlackAddedTips{
FromToUserID FromToUserID = 1;

Loading…
Cancel
Save