# Conflicts: # config/config.yaml # internal/rpc/chat/send_msg.go # internal/rpc/group/create_group.go # pkg/common/config/config.go # pkg/proto/sdk_ws/ws.pb.go # pkg/proto/sdk_ws/ws.protopull/141/head
commit
fca092d392
@ -0,0 +1,85 @@
|
||||
package apiAuth
|
||||
|
||||
import (
|
||||
api "Open_IM/pkg/base_info"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
rpc "Open_IM/pkg/proto/auth"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func UserRegister(c *gin.Context) {
|
||||
params := api.UserRegisterReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if params.Secret != config.Config.Secret {
|
||||
log.NewError(params.OperationID, "params.Secret != config.Config.Secret", params.Secret, config.Config.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||
return
|
||||
}
|
||||
req := &rpc.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}}
|
||||
utils.CopyStructFields(req.UserInfo, ¶ms)
|
||||
//copier.Copy(req.UserInfo, ¶ms)
|
||||
req.OperationID = params.OperationID
|
||||
log.NewInfo(req.OperationID, "UserRegister args ", req.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := rpc.NewAuthClient(etcdConn)
|
||||
reply, err := client.UserRegister(context.Background(), req)
|
||||
if err != nil || reply.CommonResp.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "UserRegister failed ", err, reply.CommonResp.ErrCode)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": reply.CommonResp.ErrMsg})
|
||||
return
|
||||
}
|
||||
|
||||
pbDataToken := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
||||
replyToken, err := client.UserToken(context.Background(), pbDataToken)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UserToken failed ", err.Error(), pbDataToken)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp := api.UserRegisterResp{CommResp: api.CommResp{ErrCode: replyToken.CommonResp.ErrCode, ErrMsg: replyToken.CommonResp.ErrMsg},
|
||||
UserToken: api.UserTokenInfo{UserID: req.UserInfo.UserID, Token: replyToken.Token, ExpiredTime: replyToken.ExpiredTime}}
|
||||
log.NewInfo(req.OperationID, "UserRegister return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
|
||||
func UserToken(c *gin.Context) {
|
||||
params := api.UserTokenReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if params.Secret != config.Config.Secret {
|
||||
log.NewError(params.OperationID, "params.Secret != config.Config.Secret", params.Secret, config.Config.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||
return
|
||||
}
|
||||
req := &rpc.UserTokenReq{Platform: params.Platform, FromUserID: params.UserID, OperationID: params.OperationID}
|
||||
log.NewInfo(req.OperationID, "UserToken args ", req.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := rpc.NewAuthClient(etcdConn)
|
||||
reply, err := client.UserToken(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UserToken failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
resp := api.UserTokenResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg},
|
||||
UserToken: api.UserTokenInfo{UserID: req.FromUserID, Token: reply.Token, ExpiredTime: reply.ExpiredTime}}
|
||||
log.NewInfo(req.OperationID, "UserRegister return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
package apiAuth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsUserRegister struct {
|
||||
Secret string `json:"secret" binding:"required,max=32"`
|
||||
Platform int32 `json:"platform" binding:"required,min=1,max=7"`
|
||||
UID string `json:"uid" binding:"required,min=1,max=64"`
|
||||
Name string `json:"name" binding:"required,min=1,max=64"`
|
||||
Icon string `json:"icon" binding:"omitempty,max=1024"`
|
||||
Gender int32 `json:"gender" binding:"omitempty,oneof=0 1 2"`
|
||||
Mobile string `json:"mobile" binding:"omitempty,max=32"`
|
||||
Birth string `json:"birth" binding:"omitempty,max=16"`
|
||||
Email string `json:"email" binding:"omitempty,max=64"`
|
||||
Ex string `json:"ex" binding:"omitempty,max=1024"`
|
||||
}
|
||||
|
||||
func newUserRegisterReq(params *paramsUserRegister) *pbAuth.UserRegisterReq {
|
||||
pbData := pbAuth.UserRegisterReq{
|
||||
UID: params.UID,
|
||||
Name: params.Name,
|
||||
Icon: params.Icon,
|
||||
Gender: params.Gender,
|
||||
Mobile: params.Mobile,
|
||||
Birth: params.Birth,
|
||||
Email: params.Email,
|
||||
Ex: params.Ex,
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
|
||||
func UserRegister(c *gin.Context) {
|
||||
log.Info("", "", "api user_register init ....")
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := pbAuth.NewAuthClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsUserRegister{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
if params.Secret != config.Config.Secret {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||
return
|
||||
}
|
||||
pbData := newUserRegisterReq(¶ms)
|
||||
|
||||
log.Info("", "", "api user_register is server, [data: %s]", pbData.String())
|
||||
reply, err := client.UserRegister(context.Background(), pbData)
|
||||
if err != nil || !reply.Success {
|
||||
log.Error("", "", "api user_register call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "api user_register call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
pbDataToken := &pbAuth.UserTokenReq{
|
||||
Platform: params.Platform,
|
||||
UID: params.UID,
|
||||
}
|
||||
replyToken, err := client.UserToken(context.Background(), pbDataToken)
|
||||
if err != nil {
|
||||
log.Error("", "", "api user_register call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "api user_register call success, [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
if replyToken.ErrCode == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": replyToken.ErrCode,
|
||||
"errMsg": replyToken.ErrMsg,
|
||||
"data": gin.H{
|
||||
"uid": pbData.UID,
|
||||
"token": replyToken.Token,
|
||||
"expiredTime": replyToken.ExpiredTime,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": replyToken.ErrCode,
|
||||
"errMsg": replyToken.ErrMsg,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,72 +0,0 @@
|
||||
package apiAuth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsUserToken struct {
|
||||
Secret string `json:"secret" binding:"required,max=32"`
|
||||
Platform int32 `json:"platform" binding:"required,min=1,max=8"`
|
||||
UID string `json:"uid" binding:"required,min=1,max=64"`
|
||||
}
|
||||
|
||||
func newUserTokenReq(params *paramsUserToken) *pbAuth.UserTokenReq {
|
||||
pbData := pbAuth.UserTokenReq{
|
||||
Platform: params.Platform,
|
||||
UID: params.UID,
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
|
||||
func UserToken(c *gin.Context) {
|
||||
log.Info("", "", "api user_token init ....")
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName)
|
||||
client := pbAuth.NewAuthClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsUserToken{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.Error("", "", params.UID, params.Platform, params.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
if params.Secret != config.Config.Secret {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"})
|
||||
return
|
||||
}
|
||||
pbData := newUserTokenReq(¶ms)
|
||||
|
||||
log.Info("", "", "api user_token is server, [data: %s]", pbData.String())
|
||||
reply, err := client.UserToken(context.Background(), pbData)
|
||||
if err != nil {
|
||||
log.Error("", "", "api user_token call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "api user_token call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
if reply.ErrCode == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
"data": gin.H{
|
||||
"uid": pbData.UID,
|
||||
"token": reply.Token,
|
||||
"expiredTime": reply.ExpiredTime,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
type paramsAddBlackList struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
}*/
|
||||
|
||||
func AddBlacklist(c *gin.Context) {
|
||||
log.Info("", "", "api add blacklist init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsSearchFriend{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.AddBlacklistReq{
|
||||
Uid: params.UID,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
OwnerUid: params.OwnerUid,
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api add blacklist is server:userID=%s", req.Uid)
|
||||
RpcResp, err := client.AddBlacklist(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call add blacklist rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add blacklist rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call add blacklist rpc server success,args=%s", RpcResp.String())
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.InfoByArgs("api add blacklist success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,88 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsImportFriendReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UIDList []string `json:"uidList" binding:"required"`
|
||||
OwnerUid string `json:"ownerUid" binding:"required"`
|
||||
}
|
||||
|
||||
type paramsAddFriend struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
ReqMessage string `json:"reqMessage"`
|
||||
}
|
||||
|
||||
//
|
||||
func ImportFriend(c *gin.Context) {
|
||||
log.Info("", "", "ImportFriend init ....")
|
||||
log.NewDebug("", "api importFriend start")
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
|
||||
params := paramsImportFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.ImportFriendReq{
|
||||
UidList: params.UIDList,
|
||||
OperationID: params.OperationID,
|
||||
OwnerUid: params.OwnerUid,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.NewDebug(req.OperationID, "args is ", req.String())
|
||||
RpcResp, err := client.ImportFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "rpc importFriend failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed " + err.Error()})
|
||||
return
|
||||
}
|
||||
failedUidList := make([]string, 0)
|
||||
for _, v := range RpcResp.FailedUidList {
|
||||
failedUidList = append(failedUidList, v)
|
||||
}
|
||||
log.NewDebug(req.OperationID, "rpc importFriend success", RpcResp.CommonResp.ErrorMsg, RpcResp.CommonResp.ErrorCode, RpcResp.FailedUidList)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": failedUidList})
|
||||
}
|
||||
|
||||
func AddFriend(c *gin.Context) {
|
||||
log.Info("", "", "api add friend init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
|
||||
params := paramsAddFriend{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.AddFriendReq{
|
||||
Uid: params.UID,
|
||||
OperationID: params.OperationID,
|
||||
ReqMessage: params.ReqMessage,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api add friend is server")
|
||||
RpcResp, err := client.AddFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call add friend rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call add friend rpc server success,args=%s", RpcResp.String())
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
})
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsAddFriendResponse struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
Flag int32 `json:"flag" binding:"required"`
|
||||
}
|
||||
|
||||
func AddFriendResponse(c *gin.Context) {
|
||||
log.Info("", "", fmt.Sprintf("api add friend response init ...."))
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsAddFriendResponse{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.AddFriendResponseReq{
|
||||
Uid: params.UID,
|
||||
Flag: params.Flag,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api add friend response is server:userID=%s", req.Uid)
|
||||
RpcResp, err := client.AddFriendResponse(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call add_friend_response rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add_friend_response rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call add friend response rpc server success,args=%s", RpcResp.String())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
log.InfoByArgs("api add friend response success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsDeleteFriend struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
}
|
||||
|
||||
func DeleteFriend(c *gin.Context) {
|
||||
log.Info("", "", fmt.Sprintf("api delete_friend init ...."))
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsDeleteFriend{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.DeleteFriendReq{
|
||||
Uid: params.UID,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api delete_friend is server:%s", req.Uid)
|
||||
RpcResp, err := client.DeleteFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call delete_friend rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete_friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call delete_friend rpc server,args=%s", RpcResp.String())
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.InfoByArgs("api delete_friend success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -0,0 +1,456 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
jsonData "Open_IM/internal/utils"
|
||||
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"
|
||||
rpc "Open_IM/pkg/proto/friend"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func AddBlack(c *gin.Context) {
|
||||
params := api.AddBlacklistReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.AddBlacklistReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms)
|
||||
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(params.OperationID, "AddBlacklist 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.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 := api.AddBlacklistResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func ImportFriend(c *gin.Context) {
|
||||
params := api.ImportFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.ImportFriendReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
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 := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.ImportFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "ImportFriend failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "ImportFriend failed "})
|
||||
return
|
||||
}
|
||||
resp := api.ImportFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
if resp.ErrCode == 0 {
|
||||
for _, v := range RpcResp.UserIDResultList {
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, api.UserIDResult{UserID: v.UserID, Result: v.Result})
|
||||
}
|
||||
}
|
||||
if len(resp.UserIDResultList) == 0 {
|
||||
resp.UserIDResultList = []api.UserIDResult{}
|
||||
}
|
||||
log.NewInfo(req.OperationID, "ImportFriend api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func AddFriend(c *gin.Context) {
|
||||
params := api.AddFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.AddFriendReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||
req.ReqMsg = params.ReqMsg
|
||||
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, "AddFriend 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.AddFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "AddFriend failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call AddFriend rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.AddFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriend api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func AddFriendResponse(c *gin.Context) {
|
||||
params := api.AddFriendResponseReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.AddFriendResponseReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||
req.HandleMsg = params.HandleMsg
|
||||
req.HandleResult = params.Flag
|
||||
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
|
||||
}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
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 := rpc.NewFriendClient(etcdConn)
|
||||
RpcResp, err := client.AddFriendResponse(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "AddFriendResponse failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add_friend_response rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.AddFriendResponseResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.CommID.OperationID, "AddFriendResponse api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func DeleteFriend(c *gin.Context) {
|
||||
params := api.DeleteFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.DeleteFriendReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||
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, "DeleteFriend 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.DeleteFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "DeleteFriend failed ", err, req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete_friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.DeleteFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.CommID.OperationID, "DeleteFriend api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetBlacklist(c *gin.Context) {
|
||||
params := api.GetBlackListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetBlacklistReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms)
|
||||
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, "GetBlacklist 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.GetBlacklist(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetBlacklist failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get blacklist rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.GetBlackListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
for _, v := range RpcResp.BlackUserInfoList {
|
||||
black := open_im_sdk.PublicUserInfo{}
|
||||
utils.CopyStructFields(&black, v)
|
||||
resp.BlackUserInfoList = append(resp.BlackUserInfoList, &black)
|
||||
}
|
||||
resp.Data = jsonData.JsonDataList(resp.BlackUserInfoList)
|
||||
log.NewInfo(req.CommID.OperationID, "GetBlacklist api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func SetFriendRemark(c *gin.Context) {
|
||||
params := api.SetFriendRemarkReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.SetFriendRemarkReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||
req.Remark = params.Remark
|
||||
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, "SetFriendComment 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.SetFriendRemark(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 := api.SetFriendRemarkResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "SetFriendComment api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func RemoveBlack(c *gin.Context) {
|
||||
params := api.RemoveBlackListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.RemoveBlacklistReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||
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, "RemoveBlacklist 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.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 := api.RemoveBlackListResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.CommID.OperationID, "RemoveBlacklist api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func IsFriend(c *gin.Context) {
|
||||
params := api.IsFriendReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.IsFriendReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms.ParamsCommFriend)
|
||||
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, "IsFriend 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.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 := api.IsFriendResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
resp.Response.Friend = RpcResp.Response
|
||||
|
||||
log.NewInfo(req.CommID.OperationID, "IsFriend api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
//
|
||||
//func GetFriendsInfo(c *gin.Context) {
|
||||
// params := api.GetFriendsInfoReq{}
|
||||
// if err := c.BindJSON(¶ms); err != nil {
|
||||
// log.NewError("0", "BindJSON failed ", err.Error())
|
||||
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
// return
|
||||
// }
|
||||
// req := &rpc.GetFriendsInfoReq{}
|
||||
// utils.CopyStructFields(req.CommID, params)
|
||||
// var ok bool
|
||||
// ok, req.CommID.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
// if !ok {
|
||||
// log.NewError(req.CommID.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
// return
|
||||
// }
|
||||
// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo args ", req.String())
|
||||
//
|
||||
// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
// client := rpc.NewFriendClient(etcdConn)
|
||||
// RpcResp, err := client.GetFriendsInfo(context.Background(), req)
|
||||
// if err != nil {
|
||||
// log.NewError(req.CommID.OperationID, "GetFriendsInfo failed ", err.Error(), req.String())
|
||||
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// resp := api.GetFriendsInfoResp{CommResp:api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
// utils.CopyStructFields(&resp, RpcResp)
|
||||
// c.JSON(http.StatusOK, resp)
|
||||
// log.NewInfo(req.CommID.OperationID, "GetFriendsInfo api return ", resp)
|
||||
//}
|
||||
|
||||
func GetFriendList(c *gin.Context) {
|
||||
params := api.GetFriendListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetFriendListReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms)
|
||||
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, "GetFriendList 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.GetFriendList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetFriendList failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend list rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.GetFriendListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendInfoList: RpcResp.FriendInfoList}
|
||||
resp.Data = jsonData.JsonDataList(resp.FriendInfoList)
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendList api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
//c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetFriendApplyList(c *gin.Context) {
|
||||
params := api.GetFriendApplyListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetFriendApplyListReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms)
|
||||
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, "GetFriendApplyList 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.GetFriendApplyList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetFriendApplyList failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend apply list rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
resp := api.GetFriendApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
|
||||
resp.Data = jsonData.JsonDataList(resp.FriendRequestList)
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetSelfFriendApplyList(c *gin.Context) {
|
||||
params := api.GetSelfApplyListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetSelfApplyListReq{CommID: &rpc.CommID{}}
|
||||
utils.CopyStructFields(req.CommID, ¶ms)
|
||||
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, "GetSelfApplyList 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.GetSelfApplyList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetSelfApplyList failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get self apply list rpc server failed"})
|
||||
return
|
||||
}
|
||||
resp := api.GetSelfApplyListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, FriendRequestList: RpcResp.FriendRequestList}
|
||||
resp.Data = jsonData.JsonDataList(resp.FriendRequestList)
|
||||
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsGetBlackList struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type blackListUserInfo struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
Gender int32 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
Birth string `json:"birth"`
|
||||
Email string `json:"email"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
func GetBlacklist(c *gin.Context) {
|
||||
log.Info("", "", "api get blacklist init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsGetBlackList{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetBlacklistReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("api get blacklist is server"))
|
||||
RpcResp, err := client.GetBlacklist(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get_friend_list rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get blacklist rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call get blacklist rpc server success,args=%s", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
userBlackList := make([]blackListUserInfo, 0)
|
||||
for _, friend := range RpcResp.Data {
|
||||
var fi blackListUserInfo
|
||||
fi.UID = friend.Uid
|
||||
fi.Name = friend.Name
|
||||
fi.Icon = friend.Icon
|
||||
fi.Gender = friend.Gender
|
||||
fi.Mobile = friend.Mobile
|
||||
fi.Birth = friend.Birth
|
||||
fi.Email = friend.Email
|
||||
fi.Ex = friend.Ex
|
||||
userBlackList = append(userBlackList, fi)
|
||||
}
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
"data": userBlackList,
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByArgs("api get black list success return,get args=%s,return=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,129 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsGetApplyList struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type UserInfo struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
Gender int32 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
Birth string `json:"birth"`
|
||||
Email string `json:"email"`
|
||||
Ex string `json:"ex"`
|
||||
ReqMessage string `json:"reqMessage"`
|
||||
ApplyTime string `json:"applyTime"`
|
||||
Flag int32 `json:"flag"`
|
||||
}
|
||||
|
||||
func GetFriendApplyList(c *gin.Context) {
|
||||
log.Info("", "", "api get_friend_apply_list init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsGetApplyList{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendApplyReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api get friend apply list is server")
|
||||
RpcResp, err := client.GetFriendApplyList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get friend apply list rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend apply list rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call get friend apply list rpc server success,args=%s", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
userInfoList := make([]UserInfo, 0)
|
||||
for _, applyUserinfo := range RpcResp.Data {
|
||||
var un UserInfo
|
||||
un.UID = applyUserinfo.Uid
|
||||
un.Name = applyUserinfo.Name
|
||||
un.Icon = applyUserinfo.Icon
|
||||
un.Gender = applyUserinfo.Gender
|
||||
un.Mobile = applyUserinfo.Mobile
|
||||
un.Birth = applyUserinfo.Birth
|
||||
un.Email = applyUserinfo.Email
|
||||
un.Ex = applyUserinfo.Ex
|
||||
un.Flag = applyUserinfo.Flag
|
||||
un.ApplyTime = applyUserinfo.ApplyTime
|
||||
un.ReqMessage = applyUserinfo.ReqMessage
|
||||
userInfoList = append(userInfoList, un)
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": userInfoList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByArgs("api get friend apply list success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
|
||||
func GetSelfApplyList(c *gin.Context) {
|
||||
log.Info("", "", "api get self friend apply list init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsGetApplyList{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendApplyReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api get self apply list is server")
|
||||
RpcResp, err := client.GetSelfApplyList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get self apply list rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get self apply list rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call get self apply list rpc server success,args=%s", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
userInfoList := make([]UserInfo, 0)
|
||||
for _, selfApplyOtherUserinfo := range RpcResp.Data {
|
||||
var un UserInfo
|
||||
un.UID = selfApplyOtherUserinfo.Uid
|
||||
un.Name = selfApplyOtherUserinfo.Name
|
||||
un.Icon = selfApplyOtherUserinfo.Icon
|
||||
un.Gender = selfApplyOtherUserinfo.Gender
|
||||
un.Mobile = selfApplyOtherUserinfo.Mobile
|
||||
un.Birth = selfApplyOtherUserinfo.Birth
|
||||
un.Email = selfApplyOtherUserinfo.Email
|
||||
un.Ex = selfApplyOtherUserinfo.Ex
|
||||
un.Flag = selfApplyOtherUserinfo.Flag
|
||||
un.ApplyTime = selfApplyOtherUserinfo.ApplyTime
|
||||
un.ReqMessage = selfApplyOtherUserinfo.ReqMessage
|
||||
userInfoList = append(userInfoList, un)
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": userInfoList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByArgs("api get self apply list success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsGetFriendLIst struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type friendInfo struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
Gender int32 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
Birth string `json:"birth"`
|
||||
Email string `json:"email"`
|
||||
Ex string `json:"ex"`
|
||||
Comment string `json:"comment"`
|
||||
IsInBlackList int32 `json:"isInBlackList"`
|
||||
}
|
||||
|
||||
func GetFriendList(c *gin.Context) {
|
||||
log.Info("", "", fmt.Sprintf("api get_friendlist init ...."))
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsGetFriendLIst{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendListReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api get friend list is server")
|
||||
RpcResp, err := client.GetFriendList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get friend list rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call get friend list rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call get friend list rpc server success,args=%s", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
friendsInfo := make([]friendInfo, 0)
|
||||
for _, friend := range RpcResp.Data {
|
||||
var fi friendInfo
|
||||
fi.UID = friend.Uid
|
||||
fi.Name = friend.Name
|
||||
fi.Icon = friend.Icon
|
||||
fi.Gender = friend.Gender
|
||||
fi.Mobile = friend.Mobile
|
||||
fi.Birth = friend.Birth
|
||||
fi.Email = friend.Email
|
||||
fi.Ex = friend.Ex
|
||||
fi.Comment = friend.Comment
|
||||
fi.IsInBlackList = friend.IsInBlackList
|
||||
friendsInfo = append(friendsInfo, fi)
|
||||
}
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
"data": friendsInfo,
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByArgs("api get friend list success return,get args=%s,return=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsSearchFriend struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
OwnerUid string `json:"ownerUid"`
|
||||
}
|
||||
|
||||
func GetFriendsInfo(c *gin.Context) {
|
||||
log.Info("", "", fmt.Sprintf("api search friend init ...."))
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsSearchFriend{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.GetFriendsInfoReq{
|
||||
Uid: params.UID,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api search_friend is server")
|
||||
RpcResp, err := client.GetFriendsInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call search friend rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call search friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call search friend rpc server success,args=%s", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
"data": gin.H{
|
||||
"uid": RpcResp.Data.Uid,
|
||||
"icon": RpcResp.Data.Icon,
|
||||
"name": RpcResp.Data.Name,
|
||||
"gender": RpcResp.Data.Gender,
|
||||
"mobile": RpcResp.Data.Mobile,
|
||||
"birth": RpcResp.Data.Birth,
|
||||
"email": RpcResp.Data.Email,
|
||||
"ex": RpcResp.Data.Ex,
|
||||
"comment": RpcResp.Data.Comment,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByArgs("api search_friend success return,get args=%s,return=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsIsFriend struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
ReceiveUid string `json:"receive_uid"`
|
||||
}
|
||||
|
||||
func IsFriend(c *gin.Context) {
|
||||
log.Info("", "", "api is friend init....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsIsFriend{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.IsFriendReq{
|
||||
OperationID: params.OperationID,
|
||||
ReceiveUid: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api is friend is server")
|
||||
RpcResp, err := client.IsFriend(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call add friend rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call add friend rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call is friend rpc server success,args=%s", RpcResp.String())
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "isFriend": RpcResp.ShipType}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.InfoByArgs("api is friend success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsRemoveBlackList struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
}
|
||||
|
||||
func RemoveBlacklist(c *gin.Context) {
|
||||
log.Info("", "", "api remove_blacklist init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsRemoveBlackList{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.RemoveBlacklistReq{
|
||||
Uid: params.UID,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api remove blacklist is server:userID=%s", req.Uid)
|
||||
RpcResp, err := client.RemoveBlacklist(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call remove blacklist rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call remove blacklist rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call remove blacklist rpc server success,args=%s", RpcResp.String())
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.InfoByArgs("api remove blacklist success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsSetFriendComment struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
Comment string `json:"comment"`
|
||||
}
|
||||
|
||||
func SetFriendComment(c *gin.Context) {
|
||||
log.Info("", "", "api set friend comment init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsSetFriendComment{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbFriend.SetFriendCommentReq{
|
||||
Uid: params.UID,
|
||||
OperationID: params.OperationID,
|
||||
Comment: params.Comment,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api set friend comment is server")
|
||||
RpcResp, err := client.SetFriendComment(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call set friend comment rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call set friend comment rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "call set friend comment rpc server success,args=%s", RpcResp.String())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
log.Info("", "", "api set friend comment success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,61 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pb "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsCreateGroupStruct 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"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
func CreateGroup(c *gin.Context) {
|
||||
log.Info("", "", "api create group init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsCreateGroupStruct{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.CreateGroupReq{
|
||||
MemberList: params.MemberList,
|
||||
GroupName: params.GroupName,
|
||||
Introduction: params.Introduction,
|
||||
Notification: params.Notification,
|
||||
FaceUrl: params.FaceUrl,
|
||||
OperationID: params.OperationID,
|
||||
Ex: params.Ex,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api create group is server,params=%s", req.String())
|
||||
RpcResp, err := client.CreateGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call create group rpc server failed", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call create group rpc server success,args=%s", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": gin.H{"groupID": RpcResp.GroupID}}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
}
|
||||
log.InfoByArgs("api create group success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsGroupApplicationList struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
func newUserRegisterReq(params *paramsGroupApplicationList) *group.GetGroupApplicationListReq {
|
||||
pbData := group.GetGroupApplicationListReq{
|
||||
OperationID: params.OperationID,
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
|
||||
type paramsGroupApplicationListRet struct {
|
||||
ID string `json:"id"`
|
||||
GroupID string `json:"groupID"`
|
||||
FromUserID string `json:"fromUserID"`
|
||||
ToUserID string `json:"toUserID"`
|
||||
Flag int32 `json:"flag"`
|
||||
RequestMsg string `json:"reqMsg"`
|
||||
HandledMsg string `json:"handledMsg"`
|
||||
AddTime int64 `json:"createTime"`
|
||||
FromUserNickname string `json:"fromUserNickName"`
|
||||
ToUserNickname string `json:"toUserNickName"`
|
||||
FromUserFaceUrl string `json:"fromUserFaceURL"`
|
||||
ToUserFaceUrl string `json:"toUserFaceURL"`
|
||||
HandledUser string `json:"handledUser"`
|
||||
Type int32 `json:"type"`
|
||||
HandleStatus int32 `json:"handleStatus"`
|
||||
HandleResult int32 `json:"handleResult"`
|
||||
}
|
||||
|
||||
func GetGroupApplicationList(c *gin.Context) {
|
||||
log.Info("", "", "api GetGroupApplicationList init ....")
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := group.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsGroupApplicationList{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
pbData := newUserRegisterReq(¶ms)
|
||||
|
||||
token := c.Request.Header.Get("token")
|
||||
if claims, err := token_verify.ParseToken(token); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
|
||||
return
|
||||
} else {
|
||||
pbData.UID = claims.UID
|
||||
}
|
||||
|
||||
log.Info("", "", "api GetGroupApplicationList is server, [data: %s]", pbData.String())
|
||||
reply, err := client.GetGroupApplicationList(context.Background(), pbData)
|
||||
if err != nil {
|
||||
log.Error("", "", "api GetGroupApplicationList call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "api GetGroupApplicationList call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
unProcessCount := 0
|
||||
userReq := make([]paramsGroupApplicationListRet, 0)
|
||||
if reply != nil && reply.Data != nil && reply.Data.User != nil {
|
||||
for i := 0; i < len(reply.Data.User); i++ {
|
||||
req := paramsGroupApplicationListRet{}
|
||||
req.ID = reply.Data.User[i].ID
|
||||
req.GroupID = reply.Data.User[i].GroupID
|
||||
req.FromUserID = reply.Data.User[i].FromUserID
|
||||
req.ToUserID = reply.Data.User[i].ToUserID
|
||||
req.Flag = reply.Data.User[i].Flag
|
||||
req.RequestMsg = reply.Data.User[i].RequestMsg
|
||||
req.HandledMsg = reply.Data.User[i].HandledMsg
|
||||
req.AddTime = reply.Data.User[i].AddTime
|
||||
req.FromUserNickname = reply.Data.User[i].FromUserNickname
|
||||
req.ToUserNickname = reply.Data.User[i].ToUserNickname
|
||||
req.FromUserFaceUrl = reply.Data.User[i].FromUserFaceUrl
|
||||
req.ToUserFaceUrl = reply.Data.User[i].ToUserFaceUrl
|
||||
req.HandledUser = reply.Data.User[i].HandledUser
|
||||
req.Type = reply.Data.User[i].Type
|
||||
req.HandleStatus = reply.Data.User[i].HandleStatus
|
||||
req.HandleResult = reply.Data.User[i].HandleResult
|
||||
userReq = append(userReq, req)
|
||||
|
||||
if req.Flag == 0 {
|
||||
unProcessCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
"data": gin.H{
|
||||
"count": unProcessCount,
|
||||
"user": userReq,
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
@ -1,67 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pb "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsGetGroupInfo struct {
|
||||
GroupIDList []string `json:"groupIDList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
func GetGroupsInfo(c *gin.Context) {
|
||||
log.Info("", "", "api get groups info init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsGetGroupInfo{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.GetGroupsInfoReq{
|
||||
GroupIDList: params.GroupIDList,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
OperationID: params.OperationID,
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "get groups info is server,params=%s", req.String())
|
||||
RpcResp, err := client.GetGroupsInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "call get groups info rpc server failed,err=%s", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call get groups info rpc server success", RpcResp.String())
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
groupsInfo := make([]pb.GroupInfo, 0)
|
||||
for _, v := range RpcResp.Data {
|
||||
var groupInfo pb.GroupInfo
|
||||
groupInfo.GroupId = v.GroupId
|
||||
groupInfo.GroupName = v.GroupName
|
||||
groupInfo.Notification = v.Notification
|
||||
groupInfo.Introduction = v.Introduction
|
||||
groupInfo.FaceUrl = v.FaceUrl
|
||||
groupInfo.CreateTime = v.CreateTime
|
||||
groupInfo.OwnerId = v.OwnerId
|
||||
groupInfo.MemberCount = v.MemberCount
|
||||
|
||||
groupsInfo = append(groupsInfo, groupInfo)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": RpcResp.ErrorCode,
|
||||
"errMsg": RpcResp.ErrorMsg,
|
||||
"data": groupsInfo,
|
||||
})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
}
|
||||
}
|
||||
@ -1,351 +1,508 @@
|
||||
package group
|
||||
|
||||
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"
|
||||
pb "Open_IM/pkg/proto/group"
|
||||
rpc "Open_IM/pkg/proto/group"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type InviteUserToGroupReq struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
UidList []string `json:"uidList" binding:"required"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type GetJoinedGroupListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type KickGroupMemberReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
UidListInfo []*pb.GroupMemberFullInfo `json:"uidListInfo" binding:"required"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
jsonData "Open_IM/internal/utils"
|
||||
)
|
||||
|
||||
func KickGroupMember(c *gin.Context) {
|
||||
log.Info("", "", "KickGroupMember start....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
|
||||
params := KickGroupMemberReq{}
|
||||
params := api.KickGroupMemberReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
req := &pb.KickGroupMemberReq{
|
||||
OperationID: params.OperationID,
|
||||
GroupID: params.GroupID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
|
||||
UidListInfo: params.UidListInfo,
|
||||
req := &rpc.KickGroupMemberReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "recv req: ", req.String())
|
||||
|
||||
log.NewInfo(req.OperationID, "KickGroupMember args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.KickGroupMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "GetGroupMemberList failed, err: ", err.Error())
|
||||
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
type KickGroupMemberResp struct {
|
||||
ErrorCode int32 `json:"errCode"`
|
||||
ErrorMsg string `json:"errMsg"`
|
||||
Data []Id2Result `json:"data"`
|
||||
var memberListResp api.KickGroupMemberResp
|
||||
memberListResp.ErrMsg = RpcResp.ErrMsg
|
||||
memberListResp.ErrCode = RpcResp.ErrCode
|
||||
for _, v := range RpcResp.Id2ResultList {
|
||||
memberListResp.UserIDResultList = append(memberListResp.UserIDResultList, &api.UserIDResult{UserID: v.UserID, Result: v.Result})
|
||||
}
|
||||
|
||||
var memberListResp KickGroupMemberResp
|
||||
memberListResp.ErrorMsg = RpcResp.ErrorMsg
|
||||
memberListResp.ErrorCode = RpcResp.ErrorCode
|
||||
for _, v := range RpcResp.Id2Result {
|
||||
memberListResp.Data = append(memberListResp.Data,
|
||||
Id2Result{UId: v.UId,
|
||||
Result: v.Result})
|
||||
if len(memberListResp.UserIDResultList) == 0 {
|
||||
memberListResp.UserIDResultList = []*api.UserIDResult{}
|
||||
}
|
||||
c.JSON(http.StatusOK, memberListResp)
|
||||
}
|
||||
|
||||
type GetGroupMembersInfoReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
MemberList []string `json:"memberList"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
type GetGroupMembersInfoResp struct {
|
||||
ErrorCode int32 `json:"errCode"`
|
||||
ErrorMsg string `json:"errMsg"`
|
||||
Data []MemberResult `json:"data"`
|
||||
log.NewInfo(req.OperationID, "KickGroupMember api return ", memberListResp)
|
||||
c.JSON(http.StatusOK, memberListResp)
|
||||
}
|
||||
|
||||
func GetGroupMembersInfo(c *gin.Context) {
|
||||
log.Info("", "", "GetGroupMembersInfo start....")
|
||||
params := api.GetGroupMembersInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetGroupMembersInfoReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
//c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
api.SetErrCodeMsg(c, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
|
||||
RpcResp, err := client.GetGroupMembersInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupMemberList failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
memberListResp := api.GetGroupMembersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList}
|
||||
memberListResp.Data = jsonData.JsonDataList(RpcResp.MemberList)
|
||||
log.NewInfo(req.OperationID, "GetGroupMembersInfo api return ", memberListResp)
|
||||
c.JSON(http.StatusOK, memberListResp)
|
||||
}
|
||||
|
||||
params := GetGroupMembersInfoReq{}
|
||||
func GetGroupMemberList(c *gin.Context) {
|
||||
params := api.GetGroupMemberListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
req := &pb.GetGroupMembersInfoReq{
|
||||
OperationID: params.OperationID,
|
||||
GroupID: params.GroupID,
|
||||
MemberList: params.MemberList,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
req := &rpc.GetGroupMemberListReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "recv req: ", len(params.MemberList))
|
||||
log.NewInfo(req.OperationID, "GetGroupMemberList args ", req.String())
|
||||
|
||||
RpcResp, err := client.GetGroupMembersInfo(context.Background(), req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
|
||||
RpcResp, err := client.GetGroupMemberList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "GetGroupMemberList failed, err: ", err.Error())
|
||||
log.NewError(req.OperationID, "GetGroupMemberList failed, ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var memberListResp GetGroupMembersInfoResp
|
||||
memberListResp.ErrorMsg = RpcResp.ErrorMsg
|
||||
memberListResp.ErrorCode = RpcResp.ErrorCode
|
||||
for _, v := range RpcResp.MemberList {
|
||||
memberListResp.Data = append(memberListResp.Data,
|
||||
MemberResult{GroupId: req.GroupID,
|
||||
UserId: v.UserId,
|
||||
Role: v.Role,
|
||||
JoinTime: uint64(v.JoinTime),
|
||||
Nickname: v.NickName,
|
||||
FaceUrl: v.FaceUrl})
|
||||
}
|
||||
memberListResp := api.GetGroupMemberListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList, NextSeq: RpcResp.NextSeq}
|
||||
memberListResp.Data = jsonData.JsonDataList(memberListResp.MemberList)
|
||||
|
||||
log.NewInfo(req.OperationID, "GetGroupMemberList api return ", memberListResp)
|
||||
c.JSON(http.StatusOK, memberListResp)
|
||||
}
|
||||
|
||||
type GetGroupMemberListReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
Filter int32 `json:"filter"`
|
||||
NextSeq int32 `json:"nextSeq"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
type getGroupAllMemberReq struct {
|
||||
GroupID string `json:"groupID"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
func GetGroupAllMemberList(c *gin.Context) {
|
||||
params := api.GetGroupAllMemberReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetGroupAllMemberReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetGroupAllMember args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.GetGroupAllMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupAllMember failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
type MemberResult struct {
|
||||
GroupId string `json:"groupID"`
|
||||
UserId string `json:"userId"`
|
||||
Role int32 `json:"role"`
|
||||
JoinTime uint64 `json:"joinTime"`
|
||||
Nickname string `json:"nickName"`
|
||||
FaceUrl string `json:"faceUrl"`
|
||||
memberListResp := api.GetGroupAllMemberResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, MemberList: RpcResp.MemberList}
|
||||
memberListResp.Data = jsonData.JsonDataList(memberListResp.MemberList)
|
||||
log.NewInfo(req.OperationID, "GetGroupAllMember api return ", memberListResp)
|
||||
c.JSON(http.StatusOK, memberListResp)
|
||||
}
|
||||
|
||||
func GetGroupMemberList(c *gin.Context) {
|
||||
log.Info("", "", "GetGroupMemberList start....")
|
||||
func GetJoinedGroupList(c *gin.Context) {
|
||||
params := api.GetJoinedGroupListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetJoinedGroupListReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.GetJoinedGroupList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetJoinedGroupList failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
GroupListResp := api.GetJoinedGroupListResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, GroupInfoList: RpcResp.GroupList}
|
||||
GroupListResp.Data = jsonData.JsonDataList(GroupListResp.GroupInfoList)
|
||||
log.NewInfo(req.OperationID, "GetJoinedGroupList api return ", GroupListResp)
|
||||
c.JSON(http.StatusOK, GroupListResp)
|
||||
}
|
||||
|
||||
params := GetGroupMemberListReq{}
|
||||
func InviteUserToGroup(c *gin.Context) {
|
||||
params := api.InviteUserToGroupReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.GetGroupMemberListReq{
|
||||
OperationID: params.OperationID,
|
||||
Filter: params.Filter,
|
||||
NextSeq: params.NextSeq,
|
||||
GroupID: params.GroupID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
req := &rpc.InviteUserToGroupReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "recv req: ", req.String())
|
||||
RpcResp, err := client.GetGroupMemberList(context.Background(), req)
|
||||
log.NewInfo(req.OperationID, "InviteUserToGroup args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.InviteUserToGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "GetGroupMemberList failed, err: ", err.Error())
|
||||
log.NewError(req.OperationID, "InviteUserToGroup failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
type GetGroupMemberListResp struct {
|
||||
ErrorCode int32 `json:"errCode"`
|
||||
ErrorMsg string `json:"errMsg"`
|
||||
NextSeq int32 `json:"nextSeq"`
|
||||
Data []MemberResult `json:"data"`
|
||||
resp := api.InviteUserToGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
for _, v := range RpcResp.Id2ResultList {
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &api.UserIDResult{UserID: v.UserID, Result: v.Result})
|
||||
}
|
||||
|
||||
var memberListResp GetGroupMemberListResp
|
||||
memberListResp.ErrorMsg = RpcResp.ErrorMsg
|
||||
memberListResp.ErrorCode = RpcResp.ErrorCode
|
||||
memberListResp.NextSeq = RpcResp.NextSeq
|
||||
for _, v := range RpcResp.MemberList {
|
||||
memberListResp.Data = append(memberListResp.Data,
|
||||
MemberResult{GroupId: req.GroupID,
|
||||
UserId: v.UserId,
|
||||
Role: v.Role,
|
||||
JoinTime: uint64(v.JoinTime),
|
||||
Nickname: v.NickName,
|
||||
FaceUrl: v.FaceUrl})
|
||||
if len(resp.UserIDResultList) == 0 {
|
||||
resp.UserIDResultList = *new([]*api.UserIDResult)
|
||||
}
|
||||
c.JSON(http.StatusOK, memberListResp)
|
||||
|
||||
log.NewInfo(req.OperationID, "InviteUserToGroup api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetGroupAllMember(c *gin.Context) {
|
||||
log.Info("", "", "GetGroupAllMember start....")
|
||||
func CreateGroup(c *gin.Context) {
|
||||
params := api.CreateGroupReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.CreateGroupReq{GroupInfo: &open_im_sdk.GroupInfo{}}
|
||||
utils.CopyStructFields(req.GroupInfo, ¶ms)
|
||||
|
||||
for _, v := range params.MemberList {
|
||||
req.InitMemberList = append(req.InitMemberList, &rpc.GroupAddMemberInfo{UserID: v.UserID, RoleLevel: v.RoleLevel})
|
||||
}
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
req.OwnerUserID = req.OpUserID
|
||||
req.OperationID = params.OperationID
|
||||
log.NewInfo(req.OperationID, "CreateGroup args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.CreateGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "CreateGroup failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
|
||||
params := getGroupAllMemberReq{}
|
||||
resp := api.CreateGroupResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}}
|
||||
if RpcResp.ErrCode == 0 {
|
||||
utils.CopyStructFields(&resp.GroupInfo, RpcResp.GroupInfo)
|
||||
resp.Data = jsonData.JsonDataOne(&resp.GroupInfo)
|
||||
}
|
||||
log.NewInfo(req.OperationID, "CreateGroup api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// 群主或管理员收到的
|
||||
func GetRecvGroupApplicationList(c *gin.Context) {
|
||||
params := api.GetGroupApplicationListReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.GetGroupAllMemberReq{
|
||||
GroupID: params.GroupID,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
req := &rpc.GetGroupApplicationListReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "recv req: ", req.String())
|
||||
RpcResp, err := client.GetGroupAllMember(context.Background(), req)
|
||||
log.NewInfo(req.OperationID, "GetGroupApplicationList args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.GetGroupApplicationList(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "GetGroupAllMember failed, err: ", err.Error())
|
||||
log.NewError(req.OperationID, "GetGroupApplicationList failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
type GetGroupMemberListResp struct {
|
||||
ErrorCode int32 `json:"errCode"`
|
||||
ErrorMsg string `json:"errMsg"`
|
||||
Data []MemberResult `json:"data"`
|
||||
resp := api.GetGroupApplicationListResp{CommResp: api.CommResp{ErrCode: reply.ErrCode, ErrMsg: reply.ErrMsg}, GroupRequestList: reply.GroupRequestList}
|
||||
resp.Data = jsonData.JsonDataList(resp.GroupRequestList)
|
||||
log.NewInfo(req.OperationID, "GetGroupApplicationList api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetGroupsInfo(c *gin.Context) {
|
||||
params := api.GetGroupInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetGroupsInfoReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String())
|
||||
|
||||
var memberListResp GetGroupMemberListResp
|
||||
memberListResp.ErrorMsg = RpcResp.ErrorMsg
|
||||
memberListResp.ErrorCode = RpcResp.ErrorCode
|
||||
for _, v := range RpcResp.MemberList {
|
||||
memberListResp.Data = append(memberListResp.Data,
|
||||
MemberResult{GroupId: req.GroupID,
|
||||
UserId: v.UserId,
|
||||
Role: v.Role,
|
||||
JoinTime: uint64(v.JoinTime),
|
||||
Nickname: v.NickName,
|
||||
FaceUrl: v.FaceUrl})
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.GetGroupsInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupsInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, memberListResp)
|
||||
}
|
||||
|
||||
type groupResult struct {
|
||||
GroupId string `json:"groupId"`
|
||||
GroupName string `json:"groupName"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
FaceUrl string `json:"faceUrl"`
|
||||
OwnerId string `json:"ownerId"`
|
||||
CreateTime uint64 `json:"createTime"`
|
||||
MemberCount uint32 `json:"memberCount"`
|
||||
resp := api.GetGroupInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.ErrCode, ErrMsg: RpcResp.ErrMsg}, GroupInfoList: RpcResp.GroupInfoList}
|
||||
resp.Data = jsonData.JsonDataList(resp.GroupInfoList)
|
||||
log.NewInfo(req.OperationID, "GetGroupsInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetJoinedGroupList(c *gin.Context) {
|
||||
log.Info("", "", "GetJoinedGroupList start....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
fmt.Println("config: ", etcdConn, config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
|
||||
params := GetJoinedGroupListReq{}
|
||||
//process application
|
||||
func ApplicationGroupResponse(c *gin.Context) {
|
||||
params := api.ApplicationGroupResponseReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.GetJoinedGroupListReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
req := &rpc.GroupApplicationResponseReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "recv req: ", req.String())
|
||||
log.NewInfo(req.OperationID, "ApplicationGroupResponse args ", req.String())
|
||||
|
||||
RpcResp, err := client.GetJoinedGroupList(context.Background(), req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.GroupApplicationResponse(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "GetJoinedGroupList failed, err: ", err.Error())
|
||||
log.NewError(req.OperationID, "GroupApplicationResponse failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "GetJoinedGroupList: ", RpcResp)
|
||||
|
||||
type GetJoinedGroupListResp struct {
|
||||
ErrorCode int32 `json:"errCode"`
|
||||
ErrorMsg string `json:"errMsg"`
|
||||
Data []groupResult `json:"data"`
|
||||
resp := api.ApplicationGroupResponseResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, "ApplicationGroupResponse api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func JoinGroup(c *gin.Context) {
|
||||
params := api.JoinGroupReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.JoinGroupReq{}
|
||||
utils.CopyStructFields(req, params)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "JoinGroup args ", req.String())
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
|
||||
var GroupListResp GetJoinedGroupListResp
|
||||
GroupListResp.ErrorCode = RpcResp.ErrorCode
|
||||
GroupListResp.ErrorMsg = RpcResp.ErrorMsg
|
||||
for _, v := range RpcResp.GroupList {
|
||||
GroupListResp.Data = append(GroupListResp.Data,
|
||||
groupResult{GroupId: v.GroupId, GroupName: v.GroupName,
|
||||
Notification: v.Notification,
|
||||
Introduction: v.Introduction,
|
||||
FaceUrl: v.FaceUrl,
|
||||
OwnerId: v.OwnerId,
|
||||
CreateTime: v.CreateTime,
|
||||
MemberCount: v.MemberCount})
|
||||
RpcResp, err := client.JoinGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "JoinGroup failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, GroupListResp)
|
||||
resp := api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}
|
||||
log.NewInfo(req.OperationID, "JoinGroup api return", RpcResp.String())
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
type Id2Result struct {
|
||||
UId string `json:"uid"`
|
||||
Result int32 `json:"result"`
|
||||
}
|
||||
func QuitGroup(c *gin.Context) {
|
||||
params := api.QuitGroupReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.QuitGroupReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "QuitGroup args ", req.String())
|
||||
|
||||
func InviteUserToGroup(c *gin.Context) {
|
||||
log.Info("", "", "InviteUserToGroup start....")
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.QuitGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "call quit group rpc server failed,err=%s", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
resp := api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}
|
||||
log.NewInfo(req.OperationID, "QuitGroup api return", RpcResp.String())
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
params := InviteUserToGroupReq{}
|
||||
func SetGroupInfo(c *gin.Context) {
|
||||
params := api.SetGroupInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.InviteUserToGroupReq{
|
||||
OperationID: params.OperationID,
|
||||
GroupID: params.GroupID,
|
||||
Reason: params.Reason,
|
||||
UidList: params.UidList,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
req := &rpc.SetGroupInfoReq{GroupInfo: &open_im_sdk.GroupInfo{}}
|
||||
utils.CopyStructFields(req.GroupInfo, ¶ms)
|
||||
req.OperationID = params.OperationID
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "recv req: ", req.String())
|
||||
log.NewInfo(req.OperationID, "SetGroupInfo args ", req.String())
|
||||
|
||||
RpcResp, err := client.InviteUserToGroup(context.Background(), req)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
RpcResp, err := client.SetGroupInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "InviteUserToGroup failed, err: ", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
resp := api.SetGroupInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
log.NewInfo(req.OperationID, "SetGroupInfo api return ", resp)
|
||||
}
|
||||
|
||||
type InviteUserToGroupResp struct {
|
||||
ErrorCode int32 `json:"errCode"`
|
||||
ErrorMsg string `json:"errMsg"`
|
||||
I2R []Id2Result `json:"data"`
|
||||
func TransferGroupOwner(c *gin.Context) {
|
||||
params := api.TransferGroupOwnerReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.TransferGroupOwnerReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(req.OperationID, "TransferGroupOwner args ", req.String())
|
||||
|
||||
var iResp InviteUserToGroupResp
|
||||
iResp.ErrorMsg = RpcResp.ErrorMsg
|
||||
iResp.ErrorCode = RpcResp.ErrorCode
|
||||
for _, v := range RpcResp.Id2Result {
|
||||
iResp.I2R = append(iResp.I2R, Id2Result{UId: v.UId, Result: v.Result})
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := rpc.NewGroupClient(etcdConn)
|
||||
reply, err := client.TransferGroupOwner(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "TransferGroupOwner failed ", req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
//resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": RpcResp.Id2Result}
|
||||
c.JSON(http.StatusOK, iResp)
|
||||
resp := api.TransferGroupOwnerResp{CommResp: api.CommResp{ErrCode: reply.CommonResp.ErrCode, ErrMsg: reply.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, "TransferGroupOwner api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
|
||||
}
|
||||
|
||||
@ -1,87 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsGroupApplicationResponse struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
FromUserNickName string `json:"fromUserNickName"`
|
||||
FromUserFaceUrl string `json:"fromUserFaceUrl"`
|
||||
ToUserID string `json:"toUserID" binding:"required"`
|
||||
ToUserNickName string `json:"toUserNickName"`
|
||||
ToUserFaceUrl string `json:"toUserFaceUrl"`
|
||||
AddTime int64 `json:"addTime"`
|
||||
RequestMsg string `json:"requestMsg"`
|
||||
HandledMsg string `json:"handledMsg"`
|
||||
Type int32 `json:"type"`
|
||||
HandleStatus int32 `json:"handleStatus"`
|
||||
HandleResult int32 `json:"handleResult"`
|
||||
}
|
||||
|
||||
func newGroupApplicationResponse(params *paramsGroupApplicationResponse) *group.GroupApplicationResponseReq {
|
||||
pbData := group.GroupApplicationResponseReq{
|
||||
OperationID: params.OperationID,
|
||||
GroupID: params.GroupID,
|
||||
FromUserID: params.FromUserID,
|
||||
FromUserNickName: params.FromUserNickName,
|
||||
FromUserFaceUrl: params.FromUserFaceUrl,
|
||||
ToUserID: params.ToUserID,
|
||||
ToUserNickName: params.ToUserNickName,
|
||||
ToUserFaceUrl: params.ToUserFaceUrl,
|
||||
AddTime: params.AddTime,
|
||||
RequestMsg: params.RequestMsg,
|
||||
HandledMsg: params.HandledMsg,
|
||||
Type: params.Type,
|
||||
HandleStatus: params.HandleStatus,
|
||||
HandleResult: params.HandleResult,
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
|
||||
func ApplicationGroupResponse(c *gin.Context) {
|
||||
log.Info("", "", "api GroupApplicationResponse init ....")
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := group.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsGroupApplicationResponse{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
pbData := newGroupApplicationResponse(¶ms)
|
||||
|
||||
token := c.Request.Header.Get("token")
|
||||
if claims, err := token_verify.ParseToken(token); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
|
||||
return
|
||||
} else {
|
||||
pbData.OwnerID = claims.UID
|
||||
}
|
||||
|
||||
log.Info("", "", "api GroupApplicationResponse is server, [data: %s]", pbData.String())
|
||||
reply, err := client.GroupApplicationResponse(context.Background(), pbData)
|
||||
if err != nil {
|
||||
log.Error("", "", "api GroupApplicationResponse call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "api GroupApplicationResponse call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
})
|
||||
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pb "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsJoinGroup struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
Message string `json:"message"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
func JoinGroup(c *gin.Context) {
|
||||
log.Info("", "", "api join group init....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsJoinGroup{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.JoinGroupReq{
|
||||
GroupID: params.GroupID,
|
||||
Message: params.Message,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
OperationID: params.OperationID,
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api join group is server,params=%s", req.String())
|
||||
RpcResp, err := client.JoinGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "call join group rpc server failed,err=%s", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call join group rpc server success,args=%s", RpcResp.String())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pb "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsQuitGroup struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
func QuitGroup(c *gin.Context) {
|
||||
log.Info("", "", "api quit group init ....")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsQuitGroup{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.QuitGroupReq{
|
||||
GroupID: params.GroupID,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api quit group is server,params=%s", req.String())
|
||||
RpcResp, err := client.QuitGroup(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "call quit group rpc server failed,err=%s", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call quit group rpc server success,args=%s", RpcResp.String())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
log.InfoByArgs("api quit group success return,get args=%s,return args=%s", req.String(), RpcResp.String())
|
||||
}
|
||||
@ -1,53 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pb "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsSetGroupInfo struct {
|
||||
GroupID string `json:"groupId" binding:"required"`
|
||||
GroupName string `json:"groupName"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
FaceUrl string `json:"faceUrl"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
func SetGroupInfo(c *gin.Context) {
|
||||
log.Info("", "", "api set group info init...")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pb.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsSetGroupInfo{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pb.SetGroupInfoReq{
|
||||
GroupID: params.GroupID,
|
||||
GroupName: params.GroupName,
|
||||
Notification: params.Notification,
|
||||
Introduction: params.Introduction,
|
||||
FaceUrl: params.FaceUrl,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
OperationID: params.OperationID,
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "api set group info is server,params=%s", req.String())
|
||||
RpcResp, err := client.SetGroupInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "call set group info rpc server failed,err=%s", err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByArgs("call set group info rpc server success,args=%s", RpcResp.String())
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsTransferGroupOwner struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
UID string `json:"uid" binding:"required"`
|
||||
}
|
||||
|
||||
func newTransferGroupOwnerReq(params *paramsTransferGroupOwner) *group.TransferGroupOwnerReq {
|
||||
pbData := group.TransferGroupOwnerReq{
|
||||
OperationID: params.OperationID,
|
||||
GroupID: params.GroupID,
|
||||
NewOwner: params.UID,
|
||||
}
|
||||
return &pbData
|
||||
}
|
||||
|
||||
func TransferGroupOwner(c *gin.Context) {
|
||||
log.Info("", "", "api TransferGroupOwner init ....")
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := group.NewGroupClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsTransferGroupOwner{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
pbData := newTransferGroupOwnerReq(¶ms)
|
||||
|
||||
token := c.Request.Header.Get("token")
|
||||
if claims, err := token_verify.ParseToken(token); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": "token validate err"})
|
||||
return
|
||||
} else {
|
||||
pbData.OldOwner = claims.UID
|
||||
}
|
||||
|
||||
log.Info("", "", "api TransferGroupOwner is server, [data: %s]", pbData.String())
|
||||
reply, err := client.TransferGroupOwner(context.Background(), pbData)
|
||||
if err != nil {
|
||||
log.Error("", "", "api TransferGroupOwner call rpc fail, [data: %s] [err: %s]", pbData.String(), err.Error())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
log.Info("", "", "api TransferGroupOwner call rpc success, [data: %s] [reply: %s]", pbData.String(), reply.String())
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"errCode": reply.ErrCode,
|
||||
"errMsg": reply.ErrMsg,
|
||||
})
|
||||
|
||||
}
|
||||
@ -1,142 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbRelay "Open_IM/pkg/proto/relay"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type userInfo struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
Gender int32 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
Birth string `json:"birth"`
|
||||
Email string `json:"email"`
|
||||
Ex string `json:"ex"`
|
||||
}
|
||||
|
||||
type paramsGetUsersOnlineStatus struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UserIDList []string `json:"userIDList" binding:"required,lte=200"`
|
||||
Secret string `json:"secret" binding:"required,max=32"`
|
||||
}
|
||||
|
||||
func GetUsersOnlineStatus(c *gin.Context) {
|
||||
params := paramsGetUsersOnlineStatus{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError(params.OperationID, "bind json failed ", err.Error(), c)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if params.Secret != config.Config.Secret {
|
||||
log.NewError(params.OperationID, "parse token failed ", params.Secret, config.Config.Secret)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "secret failed"})
|
||||
return
|
||||
}
|
||||
|
||||
req := &pbRelay.GetUsersOnlineStatusReq{
|
||||
OperationID: params.OperationID,
|
||||
UserIDList: params.UserIDList,
|
||||
}
|
||||
var wsResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
var respResult []*pbRelay.GetUsersOnlineStatusResp_SuccessResult
|
||||
flag := false
|
||||
log.NewDebug(params.OperationID, "GetUsersOnlineStatus req come here", params.UserIDList)
|
||||
|
||||
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
||||
for _, v := range grpcCons {
|
||||
client := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
||||
reply, err := client.GetUsersOnlineStatus(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(params.OperationID, "GetUsersOnlineStatus rpc err", req.String(), err.Error())
|
||||
continue
|
||||
} else {
|
||||
if reply.ErrCode == 0 {
|
||||
wsResult = append(wsResult, reply.SuccessResult...)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.NewDebug(params.OperationID, "call GetUsersOnlineStatus rpc server is success", wsResult)
|
||||
//Online data merge of each node
|
||||
for _, v1 := range params.UserIDList {
|
||||
flag = false
|
||||
temp := new(pbRelay.GetUsersOnlineStatusResp_SuccessResult)
|
||||
for _, v2 := range wsResult {
|
||||
if v2.UserID == v1 {
|
||||
flag = true
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OnlineStatus
|
||||
temp.DetailPlatformStatus = append(temp.DetailPlatformStatus, v2.DetailPlatformStatus...)
|
||||
}
|
||||
}
|
||||
if !flag {
|
||||
temp.UserID = v1
|
||||
temp.Status = constant.OfflineStatus
|
||||
}
|
||||
respResult = append(respResult, temp)
|
||||
}
|
||||
log.NewDebug(params.OperationID, "Finished merged data", respResult)
|
||||
resp := gin.H{"errCode": 0, "errMsg": "", "successResult": respResult}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetUserInfo(c *gin.Context) {
|
||||
log.InfoByKv("api get userinfo init...", "")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsStruct{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbUser.GetUserInfoReq{
|
||||
UserIDList: params.UIDList,
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
}
|
||||
log.InfoByKv("api get user info is server", c.PostForm("OperationID"), c.Request.Header.Get("token"))
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get user info rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"errorCode": 500,
|
||||
"errorMsg": "call rpc server failed",
|
||||
})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("call get user info rpc server success", params.OperationID)
|
||||
if RpcResp.ErrorCode == 0 {
|
||||
userInfoList := make([]userInfo, 0)
|
||||
for _, user := range RpcResp.Data {
|
||||
var ui userInfo
|
||||
ui.UID = user.Uid
|
||||
ui.Name = user.Name
|
||||
ui.Icon = user.Icon
|
||||
ui.Gender = user.Gender
|
||||
ui.Mobile = user.Mobile
|
||||
ui.Birth = user.Birth
|
||||
ui.Email = user.Email
|
||||
ui.Ex = user.Ex
|
||||
userInfoList = append(userInfoList, ui)
|
||||
}
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg, "data": userInfoList}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
log.InfoByKv("api get user info return success", params.OperationID, "args=%s", RpcResp.String())
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type paramsStruct struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
UIDList []string `json:"uidList"`
|
||||
Platform int32 `json:"platform"`
|
||||
Name string `json:"name"`
|
||||
Icon string `json:"icon"`
|
||||
Gender int32 `json:"gender"`
|
||||
Mobile string `json:"mobile"`
|
||||
Birth string `json:"birth"`
|
||||
Email string `json:"email"`
|
||||
Ex string `json:"ex"`
|
||||
Uid string `json:"uid"`
|
||||
}
|
||||
|
||||
func UpdateUserInfo(c *gin.Context) {
|
||||
log.InfoByKv("api update userinfo init...", "")
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
//defer etcdConn.Close()
|
||||
|
||||
params := paramsStruct{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &pbUser.UpdateUserInfoReq{
|
||||
OperationID: params.OperationID,
|
||||
Token: c.Request.Header.Get("token"),
|
||||
Name: params.Name,
|
||||
Icon: params.Icon,
|
||||
Gender: params.Gender,
|
||||
Mobile: params.Mobile,
|
||||
Birth: params.Birth,
|
||||
Email: params.Email,
|
||||
Ex: params.Ex,
|
||||
Uid: params.Uid,
|
||||
}
|
||||
log.InfoByKv("api update user info is server", req.OperationID, req.Token)
|
||||
RpcResp, err := client.UpdateUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,call get user info rpc server failed", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
log.InfoByKv("call update user info rpc server success", params.OperationID)
|
||||
c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.ErrorCode, "errMsg": RpcResp.ErrorMsg})
|
||||
log.InfoByKv("api update user info return success", params.OperationID, "args=%s", RpcResp.String())
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
jsonData "Open_IM/internal/utils"
|
||||
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"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
rpc "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUsersInfo(c *gin.Context) {
|
||||
params := api.GetUsersInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetUserInfoReq{}
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(params.OperationID, "GetUserInfo args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := rpc.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
var publicUserInfoList []*open_im_sdk.PublicUserInfo
|
||||
for _, v := range RpcResp.UserInfoList {
|
||||
publicUserInfoList = append(publicUserInfoList,
|
||||
&open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, AppMangerLevel: v.AppMangerLevel})
|
||||
}
|
||||
|
||||
resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList}
|
||||
resp.Data = jsonData.JsonDataList(resp.UserInfoList)
|
||||
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func UpdateUserInfo(c *gin.Context) {
|
||||
params := api.UpdateSelfUserInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.UpdateUserInfoReq{UserInfo: &open_im_sdk.UserInfo{}}
|
||||
utils.CopyStructFields(req.UserInfo, ¶ms)
|
||||
|
||||
req.OperationID = params.OperationID
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
log.NewInfo(params.OperationID, "UpdateUserInfo args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := rpc.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.UpdateUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
func GetSelfUserInfo(c *gin.Context) {
|
||||
params := api.GetSelfUserInfoReq{}
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
log.NewError("0", "BindJSON failed ", err.Error())
|
||||
c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()})
|
||||
return
|
||||
}
|
||||
req := &rpc.GetUserInfoReq{}
|
||||
|
||||
utils.CopyStructFields(req, ¶ms)
|
||||
var ok bool
|
||||
ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"))
|
||||
if !ok {
|
||||
log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token"))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"})
|
||||
return
|
||||
}
|
||||
req.UserIDList = append(req.UserIDList, req.OpUserID)
|
||||
log.NewInfo(params.OperationID, "GetUserInfo args ", req.String())
|
||||
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := rpc.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String())
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"})
|
||||
return
|
||||
}
|
||||
if len(RpcResp.UserInfoList) == 1 {
|
||||
resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfo: RpcResp.UserInfoList[0]}
|
||||
resp.Data = jsonData.JsonDataOne(resp.UserInfo)
|
||||
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
} else {
|
||||
resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}}
|
||||
log.NewInfo(req.OperationID, "GetUserInfo api return ", resp)
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"Open_IM/pkg/common/config"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserRegister(_ context.Context, req *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
||||
log.NewInfo(req.OperationID, "UserRegister args ", req.String())
|
||||
var user db.User
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
if req.UserInfo.Birth != 0 {
|
||||
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
||||
}
|
||||
err := imdb.UserRegister(user)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UserRegister failed ", err.Error(), user)
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc UserRegister return")
|
||||
return &pbAuth.UserRegisterResp{CommonResp: &pbAuth.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.NewInfo(req.OperationID, "UserToken args ", req.String())
|
||||
|
||||
_, err := imdb.GetUserByUserID(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
tokens, expTime, err := token_verify.CreateToken(req.FromUserID, req.Platform)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "CreateToken failed ", err.Error(), req.FromUserID, req.Platform)
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "rpc UserToken return ")
|
||||
return &pbAuth.UserTokenResp{CommonResp: &pbAuth.CommonResp{}, Token: tokens, ExpiredTime: expTime}, nil
|
||||
}
|
||||
|
||||
type rpcAuth struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
log.NewPrivateLog("auth")
|
||||
return &rpcAuth{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) Run() {
|
||||
log.NewInfo("0", "rpc auth start...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.NewError("0", "listen network failed ", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, ", address, listener)
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
pbAuth.RegisterAuthServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.NewError("0", "RegisterEtcd failed ", err.Error(),
|
||||
rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "RegisterAuthServer ok ", rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName)
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "rpc auth ok")
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"Open_IM/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type rpcAuth struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewRpcAuthServer(port int) *rpcAuth {
|
||||
log.NewPrivateLog("auth")
|
||||
return &rpcAuth{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImAuthName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcAuth) Run() {
|
||||
log.Info("", "", "rpc get_token init...")
|
||||
|
||||
address := utils.ServerIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.Error("", "", "listen network failed, err = %s, address = %s", err.Error(), address)
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", address)
|
||||
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
|
||||
//service registers with etcd
|
||||
|
||||
pbAuth.RegisterAuthServer(srv, rpc)
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), utils.ServerIP, rpc.rpcPort, rpc.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.Error("", "", "register rpc get_token to etcd failed, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.Info("", "", "rpc get_token fail, err = %s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "rpc get_token init success")
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserRegister(_ context.Context, pb *pbAuth.UserRegisterReq) (*pbAuth.UserRegisterResp, error) {
|
||||
log.Info("", "", "rpc user_register start, [data: %s]", pb.String())
|
||||
|
||||
//if len(pb.UID) == 0 {
|
||||
// pb.UID = utils.GenID()
|
||||
//}
|
||||
if err := im_mysql_model.UserRegister(pb); err != nil {
|
||||
log.Error("", "", "rpc user_register error, [data: %s] [err: %s]", pb.String(), err.Error())
|
||||
return &pbAuth.UserRegisterResp{Success: false}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_register success return")
|
||||
|
||||
return &pbAuth.UserRegisterResp{Success: true}, nil
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbAuth "Open_IM/pkg/proto/auth"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (rpc *rpcAuth) UserToken(_ context.Context, pb *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) {
|
||||
log.Info("", "", "rpc user_token call start..., [pbTokenReq: %s]", pb.String())
|
||||
|
||||
_, err := im_mysql_model.FindUserByUID(pb.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &pbAuth.UserTokenResp{ErrCode: 500, ErrMsg: err.Error()}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_token call..., im_mysql_model.AppServerFindFromUserByUserID")
|
||||
|
||||
tokens, expTime, err := token_verify.CreateToken(pb.UID, pb.Platform)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc user_token call..., utils.CreateToken fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &pbAuth.UserTokenResp{ErrCode: 500, ErrMsg: err.Error()}, err
|
||||
}
|
||||
log.Info("", "", "rpc user_token success return, [uid: %s] [tokens: %s]", pb.UID, tokens)
|
||||
|
||||
return &pbAuth.UserTokenResp{Token: tokens, ExpiredTime: expTime}, nil
|
||||
}
|
||||
@ -1,159 +0,0 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *pbMsg.GetMaxAndMinSeqReq) (*pbMsg.GetMaxAndMinSeqResp, error) {
|
||||
log.InfoByKv("rpc getMaxAndMinSeq is arriving", in.OperationID, in.String())
|
||||
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
|
||||
maxSeq, err1 := commonDB.DB.GetUserMaxSeq(in.UserID)
|
||||
minSeq, err2 := commonDB.DB.GetUserMinSeq(in.UserID)
|
||||
resp := new(pbMsg.GetMaxAndMinSeqResp)
|
||||
if err1 == nil {
|
||||
resp.MaxSeq = maxSeq
|
||||
} else if err1 == redis.ErrNil {
|
||||
resp.MaxSeq = 0
|
||||
} else {
|
||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err1.Error())
|
||||
resp.MaxSeq = -1
|
||||
resp.ErrCode = 200
|
||||
resp.ErrMsg = "redis get err"
|
||||
}
|
||||
if err2 == nil {
|
||||
resp.MinSeq = minSeq
|
||||
} else if err2 == redis.ErrNil {
|
||||
resp.MinSeq = 0
|
||||
} else {
|
||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error())
|
||||
resp.MinSeq = -1
|
||||
resp.ErrCode = 201
|
||||
resp.ErrMsg = "redis get err"
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
func (rpc *rpcChat) PullMessage(_ context.Context, in *pbMsg.PullMessageReq) (*pbMsg.PullMessageResp, error) {
|
||||
log.InfoByKv("rpc pullMessage is arriving", in.OperationID, "args", in.String())
|
||||
resp := new(pbMsg.PullMessageResp)
|
||||
var respSingleMsgFormat []*pbMsg.GatherFormat
|
||||
var respGroupMsgFormat []*pbMsg.GatherFormat
|
||||
SingleMsgFormat, GroupMsgFormat, MaxSeq, MinSeq, err := commonDB.DB.GetMsgBySeqRange(in.UserID, in.SeqBegin, in.SeqEnd)
|
||||
if err != nil {
|
||||
log.ErrorByKv("pullMsg data error", in.OperationID, in.String())
|
||||
resp.ErrCode = 1
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
respSingleMsgFormat = singleMsgHandleByUser(SingleMsgFormat, in.UserID)
|
||||
respGroupMsgFormat = groupMsgHandleByUser(GroupMsgFormat)
|
||||
return &pbMsg.PullMessageResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
MaxSeq: MaxSeq,
|
||||
MinSeq: MinSeq,
|
||||
SingleUserMsg: respSingleMsgFormat,
|
||||
GroupUserMsg: respGroupMsgFormat,
|
||||
}, nil
|
||||
}
|
||||
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *pbMsg.PullMessageBySeqListReq) (*pbMsg.PullMessageResp, error) {
|
||||
log.NewInfo(in.OperationID, "rpc PullMessageBySeqList is arriving", in.String())
|
||||
resp := new(pbMsg.PullMessageResp)
|
||||
var respSingleMsgFormat []*pbMsg.GatherFormat
|
||||
var respGroupMsgFormat []*pbMsg.GatherFormat
|
||||
SingleMsgFormat, GroupMsgFormat, MaxSeq, MinSeq, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList)
|
||||
if err != nil {
|
||||
log.ErrorByKv("PullMessageBySeqList data error", in.OperationID, in.String())
|
||||
resp.ErrCode = 1
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
respSingleMsgFormat = singleMsgHandleByUser(SingleMsgFormat, in.UserID)
|
||||
respGroupMsgFormat = groupMsgHandleByUser(GroupMsgFormat)
|
||||
return &pbMsg.PullMessageResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
MaxSeq: MaxSeq,
|
||||
MinSeq: MinSeq,
|
||||
SingleUserMsg: respSingleMsgFormat,
|
||||
GroupUserMsg: respGroupMsgFormat,
|
||||
}, nil
|
||||
}
|
||||
func singleMsgHandleByUser(allMsg []*pbMsg.MsgFormat, ownerId string) []*pbMsg.GatherFormat {
|
||||
var userid string
|
||||
var respMsgFormat []*pbMsg.GatherFormat
|
||||
m := make(map[string]MsgFormats)
|
||||
//Gather messages in the dimension of users
|
||||
for _, v := range allMsg {
|
||||
if v.RecvID != ownerId {
|
||||
userid = v.RecvID
|
||||
} else {
|
||||
userid = v.SendID
|
||||
}
|
||||
if value, ok := m[userid]; !ok {
|
||||
var t MsgFormats
|
||||
m[userid] = append(t, v)
|
||||
} else {
|
||||
m[userid] = append(value, v)
|
||||
}
|
||||
}
|
||||
//Return in pb format
|
||||
for user, msg := range m {
|
||||
tempUserMsg := new(pbMsg.GatherFormat)
|
||||
tempUserMsg.ID = user
|
||||
tempUserMsg.List = msg
|
||||
sort.Sort(msg)
|
||||
respMsgFormat = append(respMsgFormat, tempUserMsg)
|
||||
}
|
||||
return respMsgFormat
|
||||
}
|
||||
func groupMsgHandleByUser(allMsg []*pbMsg.MsgFormat) []*pbMsg.GatherFormat {
|
||||
var respMsgFormat []*pbMsg.GatherFormat
|
||||
m := make(map[string]MsgFormats)
|
||||
//Gather messages in the dimension of users
|
||||
for _, v := range allMsg {
|
||||
//Get group ID
|
||||
groupID := strings.Split(v.RecvID, " ")[1]
|
||||
if value, ok := m[groupID]; !ok {
|
||||
var t MsgFormats
|
||||
m[groupID] = append(t, v)
|
||||
} else {
|
||||
m[groupID] = append(value, v)
|
||||
}
|
||||
|
||||
}
|
||||
//Return in pb format
|
||||
for groupID, msg := range m {
|
||||
tempUserMsg := new(pbMsg.GatherFormat)
|
||||
tempUserMsg.ID = groupID
|
||||
tempUserMsg.List = msg
|
||||
sort.Sort(msg)
|
||||
respMsgFormat = append(respMsgFormat, tempUserMsg)
|
||||
}
|
||||
return respMsgFormat
|
||||
}
|
||||
|
||||
type MsgFormats []*pbMsg.MsgFormat
|
||||
|
||||
// Implement the sort.Interface interface to get the number of elements method
|
||||
func (s MsgFormats) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
//Implement the sort.Interface interface comparison element method
|
||||
func (s MsgFormats) Less(i, j int) bool {
|
||||
return s[i].SendTime < s[j].SendTime
|
||||
}
|
||||
|
||||
//Implement the sort.Interface interface exchange element method
|
||||
func (s MsgFormats) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
@ -1,280 +0,0 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"Open_IM/internal/api/group"
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
http2 "Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MsgCallBackReq struct {
|
||||
SendID string `json:"sendID"`
|
||||
RecvID string `json:"recvID"`
|
||||
Content string `json:"content"`
|
||||
SendTime int64 `json:"sendTime"`
|
||||
MsgFrom int32 `json:"msgFrom"`
|
||||
ContentType int32 `json:"contentType"`
|
||||
SessionType int32 `json:"sessionType"`
|
||||
PlatformID int32 `json:"senderPlatformID"`
|
||||
MsgID string `json:"msgID"`
|
||||
IsOnlineOnly bool `json:"isOnlineOnly"`
|
||||
}
|
||||
type MsgCallBackResp struct {
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
ResponseErrCode int32 `json:"responseErrCode"`
|
||||
ResponseResult struct {
|
||||
ModifiedMsg string `json:"modifiedMsg"`
|
||||
Ext string `json:"ext"`
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*pbChat.UserSendMsgResp, error) {
|
||||
replay := pbChat.UserSendMsgResp{}
|
||||
log.NewDebug(pb.OperationID, "rpc sendMsg come here", pb.String())
|
||||
//if !utils.VerifyToken(pb.Token, pb.SendID) {
|
||||
// return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
|
||||
serverMsgID := GetMsgID(pb.SendID)
|
||||
pbData := pbChat.WSToMsgSvrChatMsg{}
|
||||
pbData.MsgFrom = pb.MsgFrom
|
||||
pbData.SessionType = pb.SessionType
|
||||
pbData.ContentType = pb.ContentType
|
||||
pbData.Content = pb.Content
|
||||
pbData.RecvID = pb.RecvID
|
||||
pbData.ForceList = pb.ForceList
|
||||
pbData.OfflineInfo = pb.OffLineInfo
|
||||
pbData.Options = pb.Options
|
||||
pbData.PlatformID = pb.PlatformID
|
||||
pbData.ClientMsgID = pb.ClientMsgID
|
||||
pbData.SendID = pb.SendID
|
||||
pbData.SenderNickName = pb.SenderNickName
|
||||
pbData.SenderFaceURL = pb.SenderFaceURL
|
||||
pbData.MsgID = serverMsgID
|
||||
pbData.OperationID = pb.OperationID
|
||||
pbData.Token = pb.Token
|
||||
if pb.SendTime == 0 {
|
||||
pbData.SendTime = utils.GetCurrentTimestampByNano()
|
||||
} else {
|
||||
pbData.SendTime = pb.SendTime
|
||||
}
|
||||
options := utils.JsonStringToMap(pbData.Options)
|
||||
isHistory := utils.GetSwitchFromOptions(options, "history")
|
||||
mReq := MsgCallBackReq{
|
||||
SendID: pb.SendID,
|
||||
RecvID: pb.RecvID,
|
||||
Content: pb.Content,
|
||||
SendTime: pbData.SendTime,
|
||||
MsgFrom: pbData.MsgFrom,
|
||||
ContentType: pb.ContentType,
|
||||
SessionType: pb.SessionType,
|
||||
PlatformID: pb.PlatformID,
|
||||
MsgID: pb.ClientMsgID,
|
||||
}
|
||||
if !isHistory {
|
||||
mReq.IsOnlineOnly = true
|
||||
}
|
||||
mResp := MsgCallBackResp{}
|
||||
if config.Config.MessageCallBack.CallbackSwitch {
|
||||
bMsg, err := http2.Post(config.Config.MessageCallBack.CallbackUrl, mReq, config.Config.MessageCallBack.CallBackTimeOut)
|
||||
if err != nil {
|
||||
log.ErrorByKv("callback to Business server err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
||||
return returnMsg(&replay, pb, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), "", 0)
|
||||
} else if err = json.Unmarshal(bMsg, &mResp); err != nil {
|
||||
log.ErrorByKv("ws json Unmarshal err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
if mResp.ErrCode != 0 {
|
||||
return returnMsg(&replay, pb, mResp.ResponseErrCode, mResp.ErrMsg, "", 0)
|
||||
} else {
|
||||
pbData.Content = mResp.ResponseResult.ModifiedMsg
|
||||
}
|
||||
}
|
||||
}
|
||||
switch pbData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(pbData.RecvID, pbData.SendID, constant.SingleChatType, &pbData)
|
||||
if isSend {
|
||||
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
||||
if err1 != nil {
|
||||
log.NewError(pbData.OperationID, "kafka send msg err:RecvID", pbData.RecvID, pbData.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
||||
if err2 != nil {
|
||||
log.NewError(pbData.OperationID, "kafka send msg err:SendID", pbData.SendID, pbData.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
case constant.GroupChatType:
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
req := &pbGroup.GetGroupAllMemberReq{
|
||||
GroupID: pbData.RecvID,
|
||||
Token: pbData.Token,
|
||||
OperationID: pbData.OperationID,
|
||||
}
|
||||
reply, err := client.GetGroupAllMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", err.Error())
|
||||
return returnMsg(&replay, pb, 201, err.Error(), "", 0)
|
||||
}
|
||||
if reply.ErrorCode != 0 {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrorMsg)
|
||||
return returnMsg(&replay, pb, reply.ErrorCode, reply.ErrorMsg, "", 0)
|
||||
}
|
||||
var addUidList []string
|
||||
switch pbData.ContentType {
|
||||
case constant.KickGroupMemberTip:
|
||||
var notification content_struct.NotificationContent
|
||||
var kickContent group.KickGroupMemberReq
|
||||
err := utils.JsonStringToStruct(pbData.Content, ¬ification)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
err := utils.JsonStringToStruct(notification.Detail, &kickContent)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
}
|
||||
for _, v := range kickContent.UidListInfo {
|
||||
addUidList = append(addUidList, v.UserId)
|
||||
}
|
||||
}
|
||||
case constant.QuitGroupTip:
|
||||
addUidList = append(addUidList, pbData.SendID)
|
||||
default:
|
||||
}
|
||||
groupID := pbData.RecvID
|
||||
for i, v := range reply.MemberList {
|
||||
pbData.RecvID = v.UserId + " " + groupID
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(v.UserId, groupID, constant.GroupChatType, &pbData)
|
||||
if isSend {
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i))
|
||||
if err != nil {
|
||||
log.NewError(pbData.OperationID, "kafka send msg err:UserId", v.UserId, pbData.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for i, v := range addUidList {
|
||||
pbData.RecvID = v + " " + groupID
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, &pbData)
|
||||
if isSend {
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i+1))
|
||||
if err != nil {
|
||||
log.NewError(pbData.OperationID, "kafka send msg err:UserId", v, pbData.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
default:
|
||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type WSToMsgSvrChatMsg struct {
|
||||
SendID string `protobuf:"bytes,1,opt,name=SendID" json:"SendID,omitempty"`
|
||||
RecvID string `protobuf:"bytes,2,opt,name=RecvID" json:"RecvID,omitempty"`
|
||||
Content string `protobuf:"bytes,3,opt,name=Content" json:"Content,omitempty"`
|
||||
MsgFrom int32 `protobuf:"varint,5,opt,name=MsgFrom" json:"MsgFrom,omitempty"`
|
||||
ContentType int32 `protobuf:"varint,8,opt,name=ContentType" json:"ContentType,omitempty"`
|
||||
SessionType int32 `protobuf:"varint,9,opt,name=SessionType" json:"SessionType,omitempty"`
|
||||
OperationID string `protobuf:"bytes,10,opt,name=OperationID" json:"OperationID,omitempty"`
|
||||
}
|
||||
|
||||
func CreateGroupNotification(sendID string, creator im_mysql_model.User, group im_mysql_model.Group, memberList []im_mysql_model.GroupMember) {
|
||||
var msg WSToMsgSvrChatMsg
|
||||
msg.OperationID = utils.OperationIDGenerator()
|
||||
msg.SendID = sendID
|
||||
msg.RecvID = group.GroupId
|
||||
msg.ContentType = constant.CreateGroupTip
|
||||
msg.SessionType = constant.GroupChatType
|
||||
msg.MsgFrom = constant.SysMsgType
|
||||
|
||||
var groupCreated open_im_sdk.GroupCreatedTips
|
||||
groupCreated.Group = &open_im_sdk.GroupInfo{}
|
||||
utils.CopyStructFields(groupCreated.Group, group)
|
||||
groupCreated.Creator = &open_im_sdk.GroupMemberFullInfo{}
|
||||
utils.CopyStructFields(groupCreated.Creator, creator)
|
||||
for _, v := range memberList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
utils.CopyStructFields(&groupMemberInfo, v)
|
||||
groupCreated.MemberList = append(groupCreated.MemberList, &groupMemberInfo)
|
||||
}
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail = utils.StructToJsonString(groupCreated)
|
||||
tips.DefaultTips = creator.Name + " " + config.Config.DefaultTips.GroupCreatedTips
|
||||
msg.Content = utils.StructToJsonString(tips)
|
||||
Notification(&msg, false)
|
||||
}
|
||||
|
||||
func Notification(m *WSToMsgSvrChatMsg, onlineUserOnly bool) {
|
||||
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) sendMsgToKafka(m *pbChat.WSToMsgSvrChatMsg, key string) error {
|
||||
pid, offset, err := rpc.producer.SendMessage(m, key)
|
||||
if err != nil {
|
||||
log.ErrorByKv("kafka send failed", m.OperationID, "send data", m.String(), "pid", pid, "offset", offset, "err", err.Error(), "key", key)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func GetMsgID(sendID string) string {
|
||||
t := time.Now().Format("2006-01-02 15:04:05")
|
||||
return t + "-" + sendID + "-" + strconv.Itoa(rand.Int())
|
||||
}
|
||||
func returnMsg(replay *pbChat.UserSendMsgResp, pb *pbChat.UserSendMsgReq, errCode int32, errMsg, serverMsgID string, sendTime int64) (*pbChat.UserSendMsgResp, error) {
|
||||
replay.ErrCode = errCode
|
||||
replay.ErrMsg = errMsg
|
||||
replay.ReqIdentifier = pb.ReqIdentifier
|
||||
replay.ClientMsgID = pb.ClientMsgID
|
||||
replay.ServerMsgID = serverMsgID
|
||||
replay.SendTime = sendTime
|
||||
return replay, nil
|
||||
}
|
||||
func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType int, msg *pbChat.WSToMsgSvrChatMsg) bool {
|
||||
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
|
||||
opt, err := db.DB.GetSingleConversationMsgOpt(userID, conversationID)
|
||||
if err != nil {
|
||||
log.NewError(msg.OperationID, "GetSingleConversationMsgOpt from redis err", msg.String())
|
||||
return true
|
||||
}
|
||||
switch opt {
|
||||
case constant.ReceiveMessage:
|
||||
return true
|
||||
case constant.NotReceiveMessage:
|
||||
return false
|
||||
case constant.ReceiveNotNotifyMessage:
|
||||
options := utils.JsonStringToMap(msg.Options)
|
||||
if options == nil {
|
||||
options = make(map[string]int32, 2)
|
||||
}
|
||||
utils.SetSwitchFromOptions(options, "offlinePush", 0)
|
||||
msg.Options = utils.MapIntToJsonString(options)
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist is server,args=%s", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
|
||||
isMagagerFlag := 0
|
||||
tokenUid := claims.UID
|
||||
|
||||
if utils.IsContain(tokenUid, config.Config.Manager.AppManagerUid) {
|
||||
isMagagerFlag = 1
|
||||
}
|
||||
|
||||
if isMagagerFlag == 0 {
|
||||
err = im_mysql_model.InsertInToUserBlackList(claims.UID, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
err = im_mysql_model.InsertInToUserBlackList(req.OwnerUid, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,Failed to add blacklist", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add blacklist success return,uid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@ -1,133 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) AddFriend(ctx context.Context, req *pbFriend.AddFriendReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend is server,userid=%s", req.Uid)
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//Cannot add non-existent users
|
||||
if _, err = im_mysql_model.FindUserByUID(req.Uid); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "this user not exists,cant not add friend")
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrAddFriend.ErrCode, ErrorMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//Establish a latest relationship in the friend request table
|
||||
err = im_mysql_model.ReplaceIntoFriendReq(claims.UID, req.Uid, constant.ApplicationFriendFlag, req.ReqMessage)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friend request record failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrAddFriend.ErrCode, ErrorMsg: constant.ErrAddFriend.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend is success return,uid=%s", req.Uid)
|
||||
//Push message when add friend successfully
|
||||
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||
receiverInfo, errReceive := im_mysql_model.FindUserByUID(req.Uid)
|
||||
if errSend == nil && errReceive == nil {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: senderInfo.UID,
|
||||
RecvID: receiverInfo.UID,
|
||||
Content: content_struct.NewContentStructString(0, "", senderInfo.Name+" asked to add you as a friend"),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.AddFriendTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "ImportFriend come here,args=%s", req.String())
|
||||
var resp pbFriend.ImportFriendResp
|
||||
var c pbFriend.CommonResp
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "parse token failed", err.Error())
|
||||
c.ErrorCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrorMsg = constant.ErrParseToken.ErrMsg
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
|
||||
if !utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.NewError(req.OperationID, "not manager uid", claims.UID)
|
||||
c.ErrorCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrorMsg = "not authorized"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
if _, err = im_mysql_model.FindUserByUID(req.OwnerUid); err != nil {
|
||||
log.NewError(req.OperationID, "this user not exists,cant not add friend", req.OwnerUid)
|
||||
c.ErrorCode = constant.ErrAddFriend.ErrCode
|
||||
c.ErrorMsg = "this user not exists,cant not add friend"
|
||||
return &pbFriend.ImportFriendResp{CommonResp: &c, FailedUidList: req.UidList}, nil
|
||||
}
|
||||
for _, v := range req.UidList {
|
||||
if _, fErr := im_mysql_model.FindUserByUID(v); fErr != nil {
|
||||
c.ErrorMsg = "some uid establish failed"
|
||||
c.ErrorCode = 408
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
} else {
|
||||
if _, err = im_mysql_model.FindFriendRelationshipFromFriend(req.OwnerUid, v); err != nil {
|
||||
//Establish two single friendship
|
||||
err1 := im_mysql_model.InsertToFriend(req.OwnerUid, v, 1)
|
||||
if err1 != nil {
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
log.NewError(req.OperationID, "err1,create friendship failed", req.OwnerUid, v, err1.Error())
|
||||
}
|
||||
err2 := im_mysql_model.InsertToFriend(v, req.OwnerUid, 1)
|
||||
if err2 != nil {
|
||||
log.NewError(req.OperationID, "err2,create friendship failed", v, req.OwnerUid, err2.Error())
|
||||
}
|
||||
if err1 == nil && err2 == nil {
|
||||
var name, faceUrl string
|
||||
n := content_struct.NotificationContent{IsDisplay: 1, DefaultTips: constant.FriendAcceptTip}
|
||||
r, err := im_mysql_model.FindUserByUID(v)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "get info failed", err.Error(), v)
|
||||
}
|
||||
if r != nil {
|
||||
name, faceUrl = r.Name, r.Icon
|
||||
}
|
||||
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: v,
|
||||
RecvID: req.OwnerUid,
|
||||
SenderFaceURL: faceUrl,
|
||||
SenderNickName: name,
|
||||
Content: n.ContentToString(),
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||
ContentType: constant.AcceptFriendApplicationTip, //Add friend flag
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
} else {
|
||||
c.ErrorMsg = "some uid establish failed"
|
||||
c.ErrorCode = 408
|
||||
resp.FailedUidList = append(resp.FailedUidList, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.CommonResp = &c
|
||||
log.NewDebug(req.OperationID, "rpc come end", resp.CommonResp.ErrorCode, resp.CommonResp.ErrorMsg, resp.FailedUidList)
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
@ -1,84 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/content_struct"
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddFriendResponseReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend response is server,args=%s", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//Check there application before agreeing or refuse to a friend's application
|
||||
if _, err = im_mysql_model.FindFriendApplyFromFriendReqByUid(req.Uid, claims.UID); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "No such application record")
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrAgreeToAddFriend.ErrCode, ErrorMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
//Change friend request status flag
|
||||
err = im_mysql_model.UpdateFriendRelationshipToFriendReq(req.Uid, claims.UID, req.Flag)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,update friend request table failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrAgreeToAddFriend.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc add friend response success return,userid=%s,flag=%d", req.Uid, req.Flag)
|
||||
//Change the status of the friend request form
|
||||
if req.Flag == constant.FriendFlag {
|
||||
//Establish friendship after find friend relationship not exists
|
||||
_, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
|
||||
//fixme If there is an error, it means that there is no friend record or database err, if no friend record should be inserted,Continue down execution
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, err.Error())
|
||||
}
|
||||
//Establish two single friendship
|
||||
err = im_mysql_model.InsertToFriend(claims.UID, req.Uid, req.Flag)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
err = im_mysql_model.InsertToFriend(req.Uid, claims.UID, req.Flag)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,create friendship failed", err.Error())
|
||||
}
|
||||
//Push message when establish friends successfully
|
||||
//senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||
//if errSend == nil {
|
||||
// logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: req.Uid,
|
||||
// Content: content_struct.NewContentStructString(1, "", senderInfo.Name+" agreed to add you as a friend."),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.UserMsgType, //Notification message identification
|
||||
// ContentType: constant.AcceptFriendApplicationTip, //Add friend flag
|
||||
// SessionType: constant.SingleChatType,
|
||||
// OperationID: req.OperationID,
|
||||
// })
|
||||
//}
|
||||
}
|
||||
if req.Flag == constant.RefuseFriendFlag {
|
||||
senderInfo, errSend := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if errSend == nil {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: claims.UID,
|
||||
RecvID: req.Uid,
|
||||
Content: content_struct.NewContentStructString(0, "", senderInfo.Name+" refuse to add you as a friend."),
|
||||
SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
MsgFrom: constant.UserMsgType, //Notification message identification
|
||||
ContentType: constant.RefuseFriendApplicationTip, //Add friend flag
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
})
|
||||
}
|
||||
}
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFriendReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc delete friend is server,args=%s", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.DeleteSingleFriendInfo(claims.UID, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,delete friend failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc delete friend success return")
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@ -0,0 +1,514 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
cp "Open_IM/pkg/common/utils"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type friendServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog("friend")
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) Run() {
|
||||
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.NewError("0", "Listen failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen ok ", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//User friend related services register to etcd
|
||||
pbFriend.RegisterFriendServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
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.NewError("0", "Serve failed ", err.Error(), listener)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
black := db.Black{OwnerUserID: req.CommID.FromUserID, BlockUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
|
||||
err := imdb.InsertInToUserBlackList(black)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error())
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
chat.BlackAddedNotification(req)
|
||||
return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
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 {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
//Cannot add non-existent users
|
||||
if _, err := imdb.GetUserByUserID(req.CommID.ToUserID); err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), req.CommID.ToUserID)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
//Establish a latest relationship in the friend request table
|
||||
friendRequest := db.FriendRequest{ReqMsg: req.ReqMsg}
|
||||
utils.CopyStructFields(&friendRequest, req.CommID)
|
||||
// {openIM001 openIM002 0 test add friend 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC }]
|
||||
log.NewDebug(req.CommID.OperationID, "UpdateFriendApplication args ", friendRequest)
|
||||
err := imdb.InsertFriendApplication(&friendRequest)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
chat.FriendApplicationNotification(req)
|
||||
return &pbFriend.AddFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFriendReq) (*pbFriend.ImportFriendResp, error) {
|
||||
log.NewInfo(req.OperationID, "ImportFriend args ", req.String())
|
||||
resp := pbFriend.ImportFriendResp{CommonResp: &pbFriend.CommonResp{}}
|
||||
var c pbFriend.CommonResp
|
||||
|
||||
if !utils.IsContain(req.OpUserID, config.Config.Manager.AppManagerUid) {
|
||||
log.NewError(req.OperationID, "not authorized", req.OpUserID, config.Config.Manager.AppManagerUid)
|
||||
c.ErrCode = constant.ErrAccess.ErrCode
|
||||
c.ErrMsg = constant.ErrAccess.ErrMsg
|
||||
for _, v := range req.FriendUserIDList {
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
}
|
||||
resp.CommonResp = &c
|
||||
return &resp, nil
|
||||
}
|
||||
if _, err := imdb.GetUserByUserID(req.FromUserID); err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.FromUserID)
|
||||
c.ErrCode = constant.ErrDB.ErrCode
|
||||
c.ErrMsg = "this user not exists,cant not add friend"
|
||||
for _, v := range req.FriendUserIDList {
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
}
|
||||
resp.CommonResp = &c
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
for _, v := range req.FriendUserIDList {
|
||||
log.NewDebug(req.OperationID, "FriendUserIDList ", v)
|
||||
if _, fErr := imdb.GetUserByUserID(v); fErr != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", fErr.Error(), v)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
} else {
|
||||
if _, err := imdb.GetFriendRelationshipFromFriend(req.FromUserID, v); err != nil {
|
||||
//Establish two single friendship
|
||||
toInsertFollow := db.Friend{OwnerUserID: req.FromUserID, FriendUserID: v}
|
||||
err1 := imdb.InsertToFriend(&toInsertFollow)
|
||||
if err1 != nil {
|
||||
log.NewError(req.OperationID, "InsertToFriend failed ", err1.Error(), toInsertFollow)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
continue
|
||||
}
|
||||
toInsertFollow = db.Friend{OwnerUserID: v, FriendUserID: req.FromUserID}
|
||||
err2 := imdb.InsertToFriend(&toInsertFollow)
|
||||
if err2 != nil {
|
||||
log.NewError(req.OperationID, "InsertToFriend failed ", err2.Error(), toInsertFollow)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: -1})
|
||||
continue
|
||||
}
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: 0})
|
||||
log.NewDebug(req.OperationID, "UserIDResultList ", resp.UserIDResultList)
|
||||
chat.FriendAddedNotification(req.OperationID, req.OpUserID, req.FromUserID, v)
|
||||
} else {
|
||||
log.NewWarn(req.OperationID, "GetFriendRelationshipFromFriend ok", req.FromUserID, v)
|
||||
resp.UserIDResultList = append(resp.UserIDResultList, &pbFriend.UserIDResult{UserID: v, Result: 0})
|
||||
}
|
||||
}
|
||||
}
|
||||
resp.CommonResp.ErrCode = 0
|
||||
log.NewInfo(req.OperationID, "ImportFriend rpc ok ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
//process Friend application
|
||||
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.OpUserID, req.CommID.FromUserID) {
|
||||
log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID)
|
||||
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
|
||||
friendRequest, err := imdb.GetFriendApplicationByBothUserID(req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetFriendApplicationByBothUserID failed ", err.Error(), req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
friendRequest.HandleResult = req.HandleResult
|
||||
friendRequest.HandleTime = time.Now()
|
||||
//friendRequest.HandleTime.Unix()
|
||||
friendRequest.HandleMsg = req.HandleMsg
|
||||
friendRequest.HandlerUserID = req.CommID.OpUserID
|
||||
err = imdb.UpdateFriendApplication(friendRequest)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendApplication failed ", err.Error(), friendRequest)
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
//Change the status of the friend request form
|
||||
if req.HandleResult == constant.FriendFlag {
|
||||
//Establish friendship after find friend relationship not exists
|
||||
_, err := imdb.GetFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
} else {
|
||||
//Establish two single friendship
|
||||
toInsertFollow := db.Friend{OwnerUserID: req.CommID.FromUserID, FriendUserID: req.CommID.ToUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
err = imdb.InsertToFriend(&toInsertFollow)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
}
|
||||
|
||||
_, err = imdb.GetFriendRelationshipFromFriend(req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
if err == nil {
|
||||
log.NewWarn(req.CommID.OperationID, "GetFriendRelationshipFromFriend exist", req.CommID.ToUserID, req.CommID.FromUserID)
|
||||
} else {
|
||||
toInsertFollow := db.Friend{OwnerUserID: req.CommID.ToUserID, FriendUserID: req.CommID.FromUserID, OperatorUserID: req.CommID.OpUserID}
|
||||
err = imdb.InsertToFriend(&toInsertFollow)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "InsertToFriend failed ", err.Error(), toInsertFollow)
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
}
|
||||
}
|
||||
if req.HandleResult == constant.FriendResponseAgree {
|
||||
chat.FriendApplicationApprovedNotification(req)
|
||||
} else if req.HandleResult == constant.FriendResponseRefuse {
|
||||
chat.FriendApplicationRejectedNotification(req)
|
||||
} else {
|
||||
log.Error(req.CommID.OperationID, "HandleResult failed ", req.HandleResult)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc AddFriendResponse ok")
|
||||
return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
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.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.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.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetBlacklist 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.GetBlacklistResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
blackListInfo, err := imdb.GetBlackListByUserID(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetBlackListByUID failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var (
|
||||
userInfoList []*sdkws.PublicUserInfo
|
||||
)
|
||||
for _, blackUser := range blackListInfo {
|
||||
var blackUserInfo sdkws.PublicUserInfo
|
||||
//Find black user information
|
||||
us, err := imdb.GetUserByUserID(blackUser.BlockUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), blackUser.BlockUserID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(&blackUserInfo, us)
|
||||
userInfoList = append(userInfoList, &blackUserInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok ", pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList})
|
||||
return &pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFriendRemarkReq) (*pbFriend.SetFriendRemarkResp, 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.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.ToUserID, req.Remark)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark)
|
||||
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok")
|
||||
chat.FriendRemarkSetNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{}}, nil
|
||||
}
|
||||
|
||||
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.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.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.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.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var isInBlacklist = false
|
||||
err := imdb.CheckBlack(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
isInBlacklist = true
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok ", pbFriend.IsInBlackListResp{Response: isInBlacklist})
|
||||
return &pbFriend.IsInBlackListResp{Response: isInBlacklist}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||
log.NewInfo("IsFriend args ", req.String())
|
||||
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.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
_, err := imdb.GetFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID)
|
||||
if err == nil {
|
||||
isFriend = true
|
||||
} else {
|
||||
isFriend = false
|
||||
}
|
||||
log.NewInfo("IsFriend rpc ok ", pbFriend.IsFriendResp{Response: isFriend})
|
||||
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())
|
||||
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.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
friends, err := imdb.GetFriendListByUserID(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
var userInfoList []*sdkws.FriendInfo
|
||||
for _, friendUser := range friends {
|
||||
friendUserInfo := sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}}
|
||||
cp.FriendDBCopyOpenIM(&friendUserInfo, &friendUser)
|
||||
log.NewDebug(req.CommID.OperationID, "friends : ", friendUser, "openim friends: ", friendUserInfo)
|
||||
userInfoList = append(userInfoList, &friendUserInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetFriendList ok", pbFriend.GetFriendListResp{FriendInfoList: userInfoList})
|
||||
return &pbFriend.GetFriendListResp{FriendInfoList: userInfoList}, nil
|
||||
}
|
||||
|
||||
//received
|
||||
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyListReq) (*pbFriend.GetFriendApplyListResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetFriendApplyList 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.GetFriendApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
// Find the current user friend applications received
|
||||
ApplyUsersInfo, err := imdb.GetReceivedFriendsApplicationListByUserID(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetReceivedFriendsApplicationListByUserID ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetFriendApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
|
||||
var appleUserList []*sdkws.FriendRequest
|
||||
for _, applyUserInfo := range ApplyUsersInfo {
|
||||
var userInfo sdkws.FriendRequest
|
||||
utils.CopyStructFields(&userInfo, applyUserInfo)
|
||||
u, err := imdb.GetUserByUserID(userInfo.FromUserID)
|
||||
if err != nil {
|
||||
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
|
||||
continue
|
||||
}
|
||||
userInfo.FromNickname = u.Nickname
|
||||
userInfo.FromFaceURL = u.FaceURL
|
||||
userInfo.FromGender = u.Gender
|
||||
|
||||
u, err = imdb.GetUserByUserID(userInfo.ToUserID)
|
||||
if err != nil {
|
||||
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
|
||||
continue
|
||||
}
|
||||
userInfo.ToNickname = u.Nickname
|
||||
userInfo.ToFaceURL = u.FaceURL
|
||||
userInfo.ToGender = u.Gender
|
||||
appleUserList = append(appleUserList, &userInfo)
|
||||
}
|
||||
|
||||
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.GetSelfApplyListReq) (*pbFriend.GetSelfApplyListResp, error) {
|
||||
log.NewInfo(req.CommID.OperationID, "GetSelfApplyList 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.GetSelfApplyListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
// Find the self add other userinfo
|
||||
usersInfo, err := imdb.GetSendFriendApplicationListByUserID(req.CommID.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.CommID.OperationID, "GetSendFriendApplicationListByUserID failed ", err.Error(), req.CommID.FromUserID)
|
||||
return &pbFriend.GetSelfApplyListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil
|
||||
}
|
||||
var selfApplyOtherUserList []*sdkws.FriendRequest
|
||||
for _, selfApplyOtherUserInfo := range usersInfo {
|
||||
var userInfo sdkws.FriendRequest // pbFriend.ApplyUserInfo
|
||||
cp.FriendRequestDBCopyOpenIM(&userInfo, &selfApplyOtherUserInfo)
|
||||
u, err := imdb.GetUserByUserID(userInfo.FromUserID)
|
||||
if err != nil {
|
||||
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.FromUserID)
|
||||
continue
|
||||
}
|
||||
userInfo.FromNickname = u.Nickname
|
||||
userInfo.FromFaceURL = u.FaceURL
|
||||
userInfo.FromGender = u.Gender
|
||||
|
||||
u, err = imdb.GetUserByUserID(userInfo.ToUserID)
|
||||
if err != nil {
|
||||
log.Error(req.CommID.OperationID, "GetUserByUserID", userInfo.ToUserID)
|
||||
continue
|
||||
}
|
||||
userInfo.ToNickname = u.Nickname
|
||||
userInfo.ToFaceURL = u.FaceURL
|
||||
userInfo.ToGender = u.Gender
|
||||
|
||||
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
|
||||
}
|
||||
log.NewInfo(req.CommID.OperationID, "rpc GetSelfApplyList ok", pbFriend.GetSelfApplyListResp{FriendRequestList: selfApplyOtherUserList})
|
||||
return &pbFriend.GetSelfApplyListResp{FriendRequestList: selfApplyOtherUserList}, nil
|
||||
}
|
||||
|
||||
////
|
||||
//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
|
||||
////
|
||||
//}
|
||||
@ -1,55 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get blacklist is server,args=%s", req.String())
|
||||
var (
|
||||
userInfoList []*pbFriend.UserInfo
|
||||
comment string
|
||||
)
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetBlacklistResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
blackListInfo, err := im_mysql_model.GetBlackListByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s get blacklist failed", err.Error())
|
||||
return &pbFriend.GetBlacklistResp{ErrorCode: constant.ErrGetBlackList.ErrCode, ErrorMsg: constant.ErrGetBlackList.ErrMsg}, nil
|
||||
}
|
||||
for _, blackUser := range blackListInfo {
|
||||
var blackUserInfo pbFriend.UserInfo
|
||||
//Find black user information
|
||||
us, err := im_mysql_model.FindUserByUID(blackUser.BlockId)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s search black list userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, blackUser.BlockId)
|
||||
if err == nil {
|
||||
comment = friendShip.Comment
|
||||
}
|
||||
blackUserInfo.Uid = us.UID
|
||||
blackUserInfo.Icon = us.Icon
|
||||
blackUserInfo.Name = us.Name
|
||||
blackUserInfo.Gender = us.Gender
|
||||
blackUserInfo.Mobile = us.Mobile
|
||||
blackUserInfo.Birth = us.Birth
|
||||
blackUserInfo.Email = us.Email
|
||||
blackUserInfo.Ex = us.Ex
|
||||
blackUserInfo.Comment = comment
|
||||
|
||||
userInfoList = append(userInfoList, &blackUserInfo)
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc get blacklist success return")
|
||||
return &pbFriend.GetBlacklistResp{Data: userInfoList}, nil
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"fmt"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type friendServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewFriendServer(port int) *friendServer {
|
||||
log.NewPrivateLog("friend")
|
||||
return &friendServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImFriendName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) Run() {
|
||||
log.Info("", "", fmt.Sprintf("rpc friend init...."))
|
||||
|
||||
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()))
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//User friend related services register to etcd
|
||||
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())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen rpc friend error,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s *friendServer) GetFriendsInfo(ctx context.Context, req *pbFriend.GetFriendsInfoReq) (*pbFriend.GetFriendInfoResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc search user is server,args=%s", req.String())
|
||||
var (
|
||||
isInBlackList int32
|
||||
isFriend int32
|
||||
comment string
|
||||
)
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
friendShip, err := im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.Uid)
|
||||
if err == nil {
|
||||
isFriend = constant.FriendFlag
|
||||
comment = friendShip.Comment
|
||||
}
|
||||
friendUserInfo, err := im_mysql_model.FindUserByUID(req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,no this user", err.Error())
|
||||
return &pbFriend.GetFriendInfoResp{ErrorCode: constant.ErrSearchUserInfo.ErrCode, ErrorMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.FindRelationshipFromBlackList(claims.UID, req.Uid)
|
||||
if err == nil {
|
||||
isInBlackList = constant.BlackListFlag
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc search friend success return")
|
||||
return &pbFriend.GetFriendInfoResp{
|
||||
ErrorCode: 0,
|
||||
ErrorMsg: "",
|
||||
Data: &pbFriend.GetFriendData{
|
||||
Uid: friendUserInfo.UID,
|
||||
Icon: friendUserInfo.Icon,
|
||||
Name: friendUserInfo.Name,
|
||||
Gender: friendUserInfo.Gender,
|
||||
Mobile: friendUserInfo.Mobile,
|
||||
Birth: friendUserInfo.Birth,
|
||||
Email: friendUserInfo.Email,
|
||||
Ex: friendUserInfo.Ex,
|
||||
Comment: comment,
|
||||
IsFriend: isFriend,
|
||||
IsInBlackList: isInBlackList,
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (s *friendServer) GetFriendApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get friend apply list is server,args=%s", req.String())
|
||||
var appleUserList []*pbFriend.ApplyUserInfo
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
// Find the current user friend applications received
|
||||
ApplyUsersInfo, err := im_mysql_model.FindFriendsApplyFromFriendReq(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search applyInfo failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
for _, applyUserInfo := range ApplyUsersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = applyUserInfo.Flag
|
||||
userInfo.ReqMessage = applyUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = strconv.FormatInt(applyUserInfo.CreateTime.Unix(), 10)
|
||||
//Find user information
|
||||
us, err := im_mysql_model.FindUserByUID(applyUserInfo.ReqId)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
userInfo.Uid = us.UID
|
||||
userInfo.Icon = us.Icon
|
||||
userInfo.Name = us.Name
|
||||
userInfo.Gender = us.Gender
|
||||
userInfo.Mobile = us.Mobile
|
||||
userInfo.Birth = us.Birth
|
||||
userInfo.Email = us.Email
|
||||
userInfo.Ex = us.Ex
|
||||
appleUserList = append(appleUserList, &userInfo)
|
||||
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get friendapplylist success return"))
|
||||
return &pbFriend.GetFriendApplyResp{Data: appleUserList}, nil
|
||||
}
|
||||
|
||||
func (s *friendServer) GetSelfApplyList(ctx context.Context, req *pbFriend.GetFriendApplyReq) (*pbFriend.GetFriendApplyResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get self apply list is server,args=%s", req.String())
|
||||
var selfApplyOtherUserList []*pbFriend.ApplyUserInfo
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
// Find the self add other userinfo
|
||||
usersInfo, err := im_mysql_model.FindSelfApplyFromFriendReq(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search self to other user Info failed", err.Error())
|
||||
return &pbFriend.GetFriendApplyResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
for _, selfApplyOtherUserInfo := range usersInfo {
|
||||
var userInfo pbFriend.ApplyUserInfo
|
||||
//Find friend application status
|
||||
userInfo.Flag = selfApplyOtherUserInfo.Flag
|
||||
userInfo.ReqMessage = selfApplyOtherUserInfo.ReqMessage
|
||||
userInfo.ApplyTime = strconv.FormatInt(selfApplyOtherUserInfo.CreateTime.Unix(), 10)
|
||||
//Find user information
|
||||
us, err := im_mysql_model.FindUserByUID(selfApplyOtherUserInfo.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,search userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
userInfo.Uid = us.UID
|
||||
userInfo.Icon = us.Icon
|
||||
userInfo.Name = us.Name
|
||||
userInfo.Gender = us.Gender
|
||||
userInfo.Mobile = us.Mobile
|
||||
userInfo.Birth = us.Birth
|
||||
userInfo.Email = us.Email
|
||||
userInfo.Ex = us.Ex
|
||||
selfApplyOtherUserList = append(selfApplyOtherUserList, &userInfo)
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, fmt.Sprintf("rpc get self apply list success return"))
|
||||
return &pbFriend.GetFriendApplyResp{Data: selfApplyOtherUserList}, nil
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFriendListReq) (*pbFriend.GetFriendListResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get friend list is server,args=%s", req.String())
|
||||
var userInfoList []*pbFriend.UserInfo
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.GetFriendListResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
friends, err := im_mysql_model.FindUserInfoFromFriend(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s search friendInfo failed", err.Error())
|
||||
return &pbFriend.GetFriendListResp{ErrorCode: constant.ErrSearchUserInfo.ErrCode, ErrorMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
for _, friendUser := range friends {
|
||||
var friendUserInfo pbFriend.UserInfo
|
||||
|
||||
//find user is in blackList
|
||||
err = im_mysql_model.FindRelationshipFromBlackList(claims.UID, friendUser.FriendId)
|
||||
if err == nil {
|
||||
friendUserInfo.IsInBlackList = constant.BlackListFlag
|
||||
} else {
|
||||
friendUserInfo.IsInBlackList = 0
|
||||
}
|
||||
//Find user information
|
||||
us, err := im_mysql_model.FindUserByUID(friendUser.FriendId)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s search userInfo failed", err.Error())
|
||||
continue
|
||||
}
|
||||
friendUserInfo.Uid = friendUser.FriendId
|
||||
friendUserInfo.Comment = friendUser.Comment
|
||||
friendUserInfo.Icon = us.Icon
|
||||
friendUserInfo.Name = us.Name
|
||||
friendUserInfo.Gender = us.Gender
|
||||
friendUserInfo.Mobile = us.Mobile
|
||||
friendUserInfo.Birth = us.Birth
|
||||
friendUserInfo.Email = us.Email
|
||||
friendUserInfo.Ex = us.Ex
|
||||
|
||||
userInfoList = append(userInfoList, &friendUserInfo)
|
||||
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc get friend list success return")
|
||||
return &pbFriend.GetFriendListResp{Data: userInfoList}, nil
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) {
|
||||
log.InfoByArgs("rpc is friend is server,args=%s", req.String())
|
||||
var isFriend int32
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.IsFriendResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
_, err = im_mysql_model.FindFriendRelationshipFromFriend(claims.UID, req.ReceiveUid)
|
||||
if err == nil {
|
||||
isFriend = constant.FriendFlag
|
||||
} else {
|
||||
isFriend = constant.ApplicationFriendFlag
|
||||
}
|
||||
log.InfoByArgs(fmt.Sprintf("rpc is friend success return"))
|
||||
return &pbFriend.IsFriendResp{ShipType: isFriend}, nil
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlackListReq) (*pbFriend.IsInBlackListResp, error) {
|
||||
log.InfoByArgs("rpc is in blacklist is server,args=%s", req.String())
|
||||
var isInBlacklist = false
|
||||
err := im_mysql_model.FindRelationshipFromBlackList(req.ReceiveUid, req.SendUid)
|
||||
if err == nil {
|
||||
isInBlacklist = true
|
||||
}
|
||||
log.InfoByArgs(fmt.Sprintf("rpc is in blackList success return"))
|
||||
return &pbFriend.IsInBlackListResp{Response: isInBlacklist}, nil
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.RemoveBlacklistReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc remove blacklist is server,userid=%s", req.Uid)
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.RemoveBlackList(claims.UID, req.Uid)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,remove blacklist failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: constant.ErrMysql.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc remove blacklist success return,userid=%s", req.Uid)
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *friendServer) SetFriendComment(ctx context.Context, req *pbFriend.SetFriendCommentReq) (*pbFriend.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc set friend comment is server,params=%s", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.UpdateFriendComment(claims.UID, req.Uid, req.Comment)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "set friend comment failed,err=%s", err.Error())
|
||||
return &pbFriend.CommonResp{ErrorCode: constant.ErrSetFriendComment.ErrCode, ErrorMsg: constant.ErrSetFriendComment.ErrMsg}, nil
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc set friend comment is success return")
|
||||
return &pbFriend.CommonResp{}, nil
|
||||
}
|
||||
@ -1,152 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/internal/rpc/chat"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type groupServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewGroupServer(port int) *groupServer {
|
||||
log.NewPrivateLog("group")
|
||||
return &groupServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImGroupName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
func (s *groupServer) Run() {
|
||||
log.Info("", "", "rpc group init....")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs("listen network failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbGroup.RegisterGroupServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("get etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen rpc_group error,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "rpc create group init success")
|
||||
}
|
||||
|
||||
func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (*pbGroup.CreateGroupResp, error) {
|
||||
log.NewInfo(req.OperationID, "rpc create group is server,args=%s", req.String())
|
||||
var (
|
||||
groupId string
|
||||
)
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
//Time stamp + MD5 to generate group chat id
|
||||
groupId = utils.Md5(strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
err = im_mysql_model.InsertIntoGroup(groupId, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, req.Ex)
|
||||
if err != nil {
|
||||
log.ErrorByKv("create group chat failed", req.OperationID, "err=%s", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: constant.ErrCreateGroup.ErrCode, ErrorMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
isMagagerFlag := 0
|
||||
tokenUid := claims.UID
|
||||
|
||||
if utils.IsContain(tokenUid, config.Config.Manager.AppManagerUid) {
|
||||
isMagagerFlag = 1
|
||||
}
|
||||
|
||||
if isMagagerFlag == 0 {
|
||||
//Add the group owner to the group first, otherwise the group creation will fail
|
||||
us, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: constant.ErrCreateGroup.ErrCode, ErrorMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, claims.UID, us.Name, us.Icon, constant.GroupOwner)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "create group chat failed,err=%s", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: constant.ErrCreateGroup.ErrCode, ErrorMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.AddGroupMember(groupId, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "create mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: constant.ErrCreateGroup.ErrCode, ErrorMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
}
|
||||
|
||||
//Binding group id and member id
|
||||
for _, user := range req.MemberList {
|
||||
us, err := im_mysql_model.FindUserByUID(user.Uid)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "find userInfo failed,uid=%s", user.Uid, err.Error())
|
||||
continue
|
||||
}
|
||||
err = im_mysql_model.InsertIntoGroupMember(groupId, user.Uid, us.Name, us.Icon, user.SetRole)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("pull %s to group %s failed,err=%s", user.Uid, groupId, err.Error())
|
||||
}
|
||||
err = db.DB.AddGroupMember(groupId, user.Uid)
|
||||
if err != nil {
|
||||
log.Error("", "", "add mongo group member failed, db.DB.AddGroupMember fail [err: %s]", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
groupInfo, err := im_mysql_model.FindGroupInfoByGroupId(groupId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindGroupInfoByGroupId failed ", groupId)
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: constant.ErrCreateGroup.ErrCode, ErrorMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
creatorInfo, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindUserByUID failed ", claims.UID)
|
||||
return &pbGroup.CreateGroupResp{ErrorCode: constant.ErrCreateGroup.ErrCode, ErrorMsg: constant.ErrCreateGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
memberList, err := im_mysql_model.FindGroupMemberListByGroupId(groupId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "FindGroupMemberListByGroupId failed ", groupId)
|
||||
}
|
||||
|
||||
log.NewInfo(req.OperationID, "creator, group, member list: ", *creatorInfo, *groupInfo, memberList)
|
||||
chat.CreateGroupNotification(claims.UID, *creatorInfo, *groupInfo, memberList)
|
||||
return &pbGroup.CreateGroupResp{GroupID: groupId}, nil
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) GetGroupApplicationList(_ context.Context, pb *group.GetGroupApplicationListReq) (*group.GetGroupApplicationListResp, error) {
|
||||
log.Info("", "", "rpc GetGroupApplicationList call start..., [pb: %s]", pb.String())
|
||||
|
||||
reply, err := im_mysql_model.GetGroupApplicationList(pb.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList fail [uid: %s] [err: %s]", pb.UID, err.Error())
|
||||
return &group.GetGroupApplicationListResp{ErrCode: 701, ErrMsg: "GetGroupApplicationList failed"}, nil
|
||||
}
|
||||
log.Info("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList")
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsInfoReq) (*pbGroup.GetGroupsInfoResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc get group info is server,args=%s", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.GetGroupsInfoResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.Info("", req.OperationID, "args:", req.GroupIDList, claims.UID)
|
||||
groupsInfoList := make([]*pbGroup.GroupInfo, 0)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
groupInfoFromMysql, err := im_mysql_model.FindGroupInfoByGroupId(groupID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "find group info failed,err=%s", err.Error())
|
||||
continue
|
||||
}
|
||||
var groupInfo pbGroup.GroupInfo
|
||||
groupInfo.GroupId = groupID
|
||||
groupInfo.GroupName = groupInfoFromMysql.Name
|
||||
groupInfo.Introduction = groupInfoFromMysql.Introduction
|
||||
groupInfo.Notification = groupInfoFromMysql.Notification
|
||||
groupInfo.FaceUrl = groupInfoFromMysql.FaceUrl
|
||||
groupInfo.OwnerId = im_mysql_model.GetGroupOwnerByGroupId(groupID)
|
||||
groupInfo.MemberCount = uint32(im_mysql_model.GetGroupMemberNumByGroupId(groupID))
|
||||
groupInfo.CreateTime = uint64(groupInfoFromMysql.CreateTime.Unix())
|
||||
|
||||
groupsInfoList = append(groupsInfoList, &groupInfo)
|
||||
}
|
||||
log.Info(req.Token, req.OperationID, "rpc get groupsInfo success return")
|
||||
return &pbGroup.GetGroupsInfoResp{Data: groupsInfoList}, nil
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) GroupApplicationResponse(_ context.Context, pb *group.GroupApplicationResponseReq) (*group.GroupApplicationResponseResp, error) {
|
||||
log.Info("", "", "rpc GroupApplicationResponse call start..., [pb: %s]", pb.String())
|
||||
|
||||
reply, err := im_mysql_model.GroupApplicationResponse(pb)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return &group.GroupApplicationResponseResp{ErrCode: 702, ErrMsg: "rpc GroupApplicationResponse failed"}, nil
|
||||
}
|
||||
|
||||
if pb.HandleResult == 1 {
|
||||
if pb.ToUserID == "0" {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.FromUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
err = db.DB.AddGroupMember(pb.GroupID, pb.ToUserID)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc GroupApplicationResponse call..., db.DB.AddGroupMember fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse")
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc join group is server,args=%s", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
applicationUserInfo, err := im_mysql_model.FindUserByUID(claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "No this user,err=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrSearchUserInfo.ErrCode, ErrorMsg: constant.ErrSearchUserInfo.ErrMsg}, nil
|
||||
}
|
||||
|
||||
_, err = im_mysql_model.FindGroupRequestUserInfoByGroupIDAndUid(req.GroupID, claims.UID)
|
||||
if err == nil {
|
||||
err = im_mysql_model.DelGroupRequest(req.GroupID, claims.UID, "0")
|
||||
}
|
||||
|
||||
log.Info(req.Token, req.OperationID, "args: ", req.GroupID, claims.UID, "0", req.Message, applicationUserInfo.Name, applicationUserInfo.Icon)
|
||||
|
||||
if err = im_mysql_model.InsertIntoGroupRequest(req.GroupID, claims.UID, "0", req.Message, applicationUserInfo.Name, applicationUserInfo.Icon); err != nil {
|
||||
log.Error(req.Token, req.OperationID, "Insert into group request failed,er=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrJoinGroupApplication.ErrCode, ErrorMsg: constant.ErrJoinGroupApplication.ErrMsg}, nil
|
||||
}
|
||||
////Find the the group owner
|
||||
//groupCreatorInfo, err := im_mysql_model.FindGroupMemberListByGroupIdAndFilterInfo(req.GroupID, constant.GroupCreator)
|
||||
//if err != nil {
|
||||
// log.Error(req.Token, req.OperationID, "find group creator failed", err.Error())
|
||||
//} else {
|
||||
// //Push message when join group chat
|
||||
// logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: groupCreatorInfo[0].Uid,
|
||||
// Content: content_struct.NewContentStructString(0, "", req.String()),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.SysMsgType,
|
||||
// ContentType: constant.JoinGroupTip,
|
||||
// SessionType: constant.SingleChatType,
|
||||
// OperationID: req.OperationID,
|
||||
// })
|
||||
//}
|
||||
|
||||
log.Info(req.Token, req.OperationID, "rpc join group success return")
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) (*pbGroup.CommonResp, error) {
|
||||
log.InfoByArgs("rpc quit group is server,args:", req.String())
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
log.InfoByKv("args:", req.OperationID, req.GetGroupID(), claims.UID)
|
||||
//Check to see whether there is a user in the group.
|
||||
_, err = im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "no such group or you are not in the group,err=%s", err.Error(), req.OperationID, req.GroupID, claims.UID)
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrQuitGroup.ErrCode, ErrorMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
//After the user's verification is successful, user will quit the group chat.
|
||||
err = im_mysql_model.DeleteGroupMemberByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("this user exit the group failed,err=%s", err.Error(), req.OperationID, req.GroupID, claims.UID)
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrQuitGroup.ErrCode, ErrorMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
|
||||
err = db.DB.DelGroupMember(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", "", "delete mongo group member failed, db.DB.DelGroupMember fail [err: %s]", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrQuitGroup.ErrCode, ErrorMsg: constant.ErrQuitGroup.ErrMsg}, nil
|
||||
}
|
||||
////Push message when quit group chat
|
||||
//jsonInfo, _ := json.Marshal(req)
|
||||
//logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: req.GroupID,
|
||||
// Content: string(jsonInfo),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.SysMsgType,
|
||||
// ContentType: constant.QuitGroupTip,
|
||||
// SessionType: constant.GroupChatType,
|
||||
// OperationID: req.OperationID,
|
||||
//})
|
||||
log.Info(req.Token, req.OperationID, "rpc quit group is success return")
|
||||
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInfoReq) (*pbGroup.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc set group info is server,args=%s", req.String())
|
||||
|
||||
//Parse token, to find current user information
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: constant.ErrParseToken.ErrMsg}, nil
|
||||
}
|
||||
groupUserInfo, err := im_mysql_model.FindGroupMemberInfoByGroupIdAndUserId(req.GroupID, claims.UID)
|
||||
if err != nil {
|
||||
log.Error("", req.OperationID, "your are not in the group,can not change this group info,err=%s", err.Error())
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrSetGroupInfo.ErrCode, ErrorMsg: constant.ErrSetGroupInfo.ErrMsg}, nil
|
||||
}
|
||||
if groupUserInfo.AdministratorLevel == constant.OrdinaryMember {
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrSetGroupInfo.ErrCode, ErrorMsg: constant.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
//only administrators can set group information
|
||||
if err = im_mysql_model.SetGroupInfo(req.GroupID, req.GroupName, req.Introduction, req.Notification, req.FaceUrl, ""); err != nil {
|
||||
return &pbGroup.CommonResp{ErrorCode: constant.ErrSetGroupInfo.ErrCode, ErrorMsg: constant.ErrSetGroupInfo.ErrMsg}, nil
|
||||
}
|
||||
////Push message when set group info
|
||||
//jsonInfo, _ := json.Marshal(req)
|
||||
//logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
// SendID: claims.UID,
|
||||
// RecvID: req.GroupID,
|
||||
// Content: string(jsonInfo),
|
||||
// SendTime: utils.GetCurrentTimestampBySecond(),
|
||||
// MsgFrom: constant.SysMsgType,
|
||||
// ContentType: constant.SetGroupInfoTip,
|
||||
// SessionType: constant.GroupChatType,
|
||||
// OperationID: req.OperationID,
|
||||
//})
|
||||
return &pbGroup.CommonResp{}, nil
|
||||
}
|
||||
@ -1,21 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *groupServer) TransferGroupOwner(_ context.Context, pb *group.TransferGroupOwnerReq) (*group.TransferGroupOwnerResp, error) {
|
||||
log.Info("", "", "rpc TransferGroupOwner call start..., [pb: %s]", pb.String())
|
||||
|
||||
reply, err := im_mysql_model.TransferGroupOwner(pb)
|
||||
if err != nil {
|
||||
log.Error("", "", "rpc TransferGroupOwner call..., im_mysql_model.TransferGroupOwner fail [pb: %s] [err: %s]", pb.String(), err.Error())
|
||||
return nil, err
|
||||
}
|
||||
log.Info("", "", "rpc TransferGroupOwner call..., im_mysql_model.TransferGroupOwner")
|
||||
|
||||
return reply, nil
|
||||
}
|
||||
@ -0,0 +1,155 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func getFromToUserNickname(fromUserID, toUserID string) (string, string, error) {
|
||||
from, err := imdb.GetUserByUserID(fromUserID)
|
||||
if err != nil {
|
||||
return "", "", utils.Wrap(err, "")
|
||||
}
|
||||
to, err := imdb.GetUserByUserID(toUserID)
|
||||
if err != nil {
|
||||
return "", "", utils.Wrap(err, "")
|
||||
}
|
||||
return from.Nickname, to.Nickname, nil
|
||||
}
|
||||
|
||||
func friendNotification(commID *pbFriend.CommID, contentType int32, m proto.Message) {
|
||||
log.Info(commID.OperationID, utils.GetSelfFuncName(), "args: ", commID, contentType)
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(commID.OperationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
|
||||
fromUserNickname, toUserNickname, err := getFromToUserNickname(commID.FromUserID, commID.ToUserID)
|
||||
if err != nil {
|
||||
log.Error(commID.OperationID, "getFromToUserNickname failed ", err.Error(), commID.FromUserID, commID.ToUserID)
|
||||
return
|
||||
}
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.FriendApplicationNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplication.DefaultTips.Tips
|
||||
case constant.FriendApplicationApprovedNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplicationApproved.DefaultTips.Tips
|
||||
case constant.FriendApplicationRejectedNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendApplicationRejected.DefaultTips.Tips
|
||||
case constant.FriendAddedNotification:
|
||||
tips.DefaultTips = cn.FriendAdded.DefaultTips.Tips
|
||||
case constant.FriendDeletedNotification:
|
||||
tips.DefaultTips = cn.FriendDeleted.DefaultTips.Tips + toUserNickname
|
||||
case constant.FriendRemarkSetNotification:
|
||||
tips.DefaultTips = fromUserNickname + cn.FriendRemarkSet.DefaultTips.Tips
|
||||
case constant.BlackAddedNotification:
|
||||
tips.DefaultTips = cn.BlackAdded.DefaultTips.Tips + toUserNickname
|
||||
case constant.BlackDeletedNotification:
|
||||
tips.DefaultTips = cn.BlackDeleted.DefaultTips.Tips + toUserNickname
|
||||
default:
|
||||
log.Error(commID.OperationID, "contentType failed ", contentType)
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = commID.FromUserID
|
||||
n.RecvID = commID.ToUserID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = commID.OperationID
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(commID.OperationID, "Marshal failed ", err.Error(), tips.String())
|
||||
return
|
||||
}
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
func FriendApplicationNotification(req *pbFriend.AddFriendReq) {
|
||||
FriendApplicationTips := open_im_sdk.FriendApplicationTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.FriendApplicationNotification, &FriendApplicationTips)
|
||||
}
|
||||
|
||||
func FriendApplicationApprovedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
friendNotification(req.CommID, constant.FriendApplicationApprovedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func FriendApplicationRejectedNotification(req *pbFriend.AddFriendResponseReq) {
|
||||
FriendApplicationApprovedTips := open_im_sdk.FriendApplicationApprovedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
FriendApplicationApprovedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
FriendApplicationApprovedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
FriendApplicationApprovedTips.HandleMsg = req.HandleMsg
|
||||
friendNotification(req.CommID, constant.FriendApplicationRejectedNotification, &FriendApplicationApprovedTips)
|
||||
}
|
||||
|
||||
func FriendAddedNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
return
|
||||
friendAddedTips := open_im_sdk.FriendAddedTips{Friend: &open_im_sdk.FriendInfo{}, OpUser: &open_im_sdk.PublicUserInfo{}}
|
||||
user, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetUserByUserID failed ", err.Error(), opUserID)
|
||||
return
|
||||
}
|
||||
utils2.UserDBCopyOpenIMPublicUser(friendAddedTips.OpUser, user)
|
||||
friend, err := imdb.GetFriendRelationshipFromFriend(fromUserID, toUserID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetFriendRelationshipFromFriend failed ", err.Error(), fromUserID, toUserID)
|
||||
return
|
||||
}
|
||||
utils2.FriendDBCopyOpenIM(friendAddedTips.Friend, friend)
|
||||
commID := pbFriend.CommID{FromUserID: fromUserID, ToUserID: toUserID, OpUserID: opUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.FriendAddedNotification, &friendAddedTips)
|
||||
}
|
||||
|
||||
func FriendDeletedNotification(req *pbFriend.DeleteFriendReq) {
|
||||
friendDeletedTips := open_im_sdk.FriendDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
friendDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
friendDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.FriendDeletedNotification, &friendDeletedTips)
|
||||
}
|
||||
|
||||
func FriendRemarkSetNotification(operationID, opUserID, fromUserID, toUserID string) {
|
||||
friendInfoChangedTips := open_im_sdk.FriendInfoChangedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
friendInfoChangedTips.FromToUserID.FromUserID = fromUserID
|
||||
friendInfoChangedTips.FromToUserID.ToUserID = toUserID
|
||||
commID := pbFriend.CommID{FromUserID: fromUserID, ToUserID: toUserID, OpUserID: opUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.FriendRemarkSetNotification, &friendInfoChangedTips)
|
||||
}
|
||||
|
||||
func BlackAddedNotification(req *pbFriend.AddBlacklistReq) {
|
||||
blackAddedTips := open_im_sdk.BlackAddedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
blackAddedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
blackAddedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.BlackAddedNotification, &blackAddedTips)
|
||||
}
|
||||
|
||||
func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) {
|
||||
blackDeletedTips := open_im_sdk.BlackDeletedTips{FromToUserID: &open_im_sdk.FromToUserID{}}
|
||||
blackDeletedTips.FromToUserID.FromUserID = req.CommID.FromUserID
|
||||
blackDeletedTips.FromToUserID.ToUserID = req.CommID.ToUserID
|
||||
friendNotification(req.CommID, constant.BlackDeletedNotification, &blackDeletedTips)
|
||||
}
|
||||
|
||||
func UserInfoUpdatedNotification(operationID, userID string, needNotifiedUserID string) {
|
||||
selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: userID}
|
||||
commID := pbFriend.CommID{FromUserID: userID, ToUserID: userID, OpUserID: needNotifiedUserID, OperationID: operationID}
|
||||
friendNotification(&commID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
}
|
||||
@ -0,0 +1,368 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
//message GroupCreatedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo Creator = 2;
|
||||
// repeated GroupMemberFullInfo MemberList = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//} creator->group
|
||||
|
||||
func setOpUserInfo(opUserID, groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
|
||||
if token_verify.IsMangerUserID(opUserID) {
|
||||
u, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetUserByUserID failed")
|
||||
}
|
||||
utils.CopyStructFields(groupMemberInfo, u)
|
||||
groupMemberInfo.GroupID = groupID
|
||||
} else {
|
||||
u, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, opUserID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupMemberInfoByGroupIDAndUserID failed")
|
||||
}
|
||||
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, u); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupInfo(groupID string, groupInfo *open_im_sdk.GroupInfo) error {
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupInfoByGroupID failed")
|
||||
}
|
||||
err = utils2.GroupDBCopyOpenIM(groupInfo, group)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupMemberNumByGroupID failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupMemberInfo(groupID, userID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
|
||||
groupMember, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupOwnerInfo(groupID string, groupMemberInfo *open_im_sdk.GroupMemberFullInfo) error {
|
||||
groupMember, err := imdb.GetGroupOwnerInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setPublicUserInfo(userID string, publicUserInfo *open_im_sdk.PublicUserInfo) error {
|
||||
user, err := imdb.GetUserByUserID(userID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
utils2.UserDBCopyOpenIMPublicUser(publicUserInfo, user)
|
||||
return nil
|
||||
}
|
||||
|
||||
func groupNotification(contentType int32, m proto.Message, sendID, groupID, recvUserID, operationID string) {
|
||||
log.Info(operationID, utils.GetSelfFuncName(), "args: ", contentType)
|
||||
|
||||
var err error
|
||||
var tips open_im_sdk.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.GroupCreatedNotification:
|
||||
tips.DefaultTips = cn.GroupCreated.DefaultTips.Tips
|
||||
case constant.GroupInfoSetNotification:
|
||||
case constant.JoinGroupApplicationNotification:
|
||||
case constant.MemberQuitNotification:
|
||||
case constant.GroupApplicationAcceptedNotification:
|
||||
case constant.GroupApplicationRejectedNotification:
|
||||
case constant.GroupOwnerTransferredNotification:
|
||||
case constant.MemberKickedNotification:
|
||||
case constant.MemberInvitedNotification:
|
||||
default:
|
||||
log.Error(operationID, "contentType failed ", contentType)
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
if groupID != "" {
|
||||
n.RecvID = groupID
|
||||
n.SessionType = constant.GroupChatType
|
||||
} else {
|
||||
n.RecvID = recvUserID
|
||||
n.SessionType = constant.SingleChatType
|
||||
}
|
||||
n.ContentType = contentType
|
||||
n.OperationID = operationID
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
|
||||
return
|
||||
}
|
||||
Notification(&n)
|
||||
}
|
||||
|
||||
//创建群后调用
|
||||
func GroupCreatedNotification(operationID, opUserID, groupID string, initMemberList []string) {
|
||||
GroupCreatedTips := open_im_sdk.GroupCreatedTips{Group: &open_im_sdk.GroupInfo{},
|
||||
OpUser: &open_im_sdk.GroupMemberFullInfo{}, GroupOwnerUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setOpUserInfo(opUserID, groupID, GroupCreatedTips.OpUser); err != nil {
|
||||
log.NewError(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID, GroupCreatedTips.OpUser)
|
||||
return
|
||||
}
|
||||
err := setGroupInfo(groupID, GroupCreatedTips.Group)
|
||||
if err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", groupID, GroupCreatedTips.Group)
|
||||
return
|
||||
}
|
||||
imdb.GetGroupOwnerInfoByGroupID(groupID)
|
||||
if err := setGroupOwnerInfo(groupID, GroupCreatedTips.GroupOwnerUser); err != nil {
|
||||
log.Error(operationID, "setGroupOwnerInfo failed", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
for _, v := range initMemberList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
if err := setGroupMemberInfo(groupID, v, &groupMemberInfo); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, v)
|
||||
continue
|
||||
}
|
||||
GroupCreatedTips.MemberList = append(GroupCreatedTips.MemberList, &groupMemberInfo)
|
||||
}
|
||||
groupNotification(constant.GroupCreatedNotification, &GroupCreatedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//群信息改变后掉用
|
||||
func GroupInfoSetNotification(operationID, opUserID, groupID string) {
|
||||
GroupInfoChangedTips := open_im_sdk.GroupInfoSetTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, GroupInfoChangedTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, GroupInfoChangedTips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupInfoSetNotification, &GroupInfoChangedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//message ReceiveJoinApplicationTips{
|
||||
// GroupInfo Group = 1;
|
||||
// PublicUserInfo Applicant = 2;
|
||||
// string Reason = 3;
|
||||
//} apply->all managers GroupID string `protobuf:"bytes,1,opt,name=GroupID" json:"GroupID,omitempty"`
|
||||
// ReqMessage string `protobuf:"bytes,2,opt,name=ReqMessage" json:"ReqMessage,omitempty"`
|
||||
// OpUserID string `protobuf:"bytes,3,opt,name=OpUserID" json:"OpUserID,omitempty"`
|
||||
// OperationID string `protobuf:"bytes,4,opt,name=OperationID" json:"OperationID,omitempty"`
|
||||
//申请进群后调用
|
||||
func JoinGroupApplicationNotification(req *pbGroup.JoinGroupReq) {
|
||||
JoinGroupApplicationTips := open_im_sdk.JoinGroupApplicationTips{Group: &open_im_sdk.GroupInfo{}, Applicant: &open_im_sdk.PublicUserInfo{}}
|
||||
err := setGroupInfo(req.GroupID, JoinGroupApplicationTips.Group)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err = setPublicUserInfo(req.OpUserID, JoinGroupApplicationTips.Applicant); err != nil {
|
||||
log.Error(req.OperationID, "setPublicUserInfo failed ", err.Error(), req.OpUserID)
|
||||
return
|
||||
}
|
||||
JoinGroupApplicationTips.ReqMsg = req.ReqMessage
|
||||
|
||||
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
for _, v := range managerList {
|
||||
groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, req.OpUserID, "", v.UserID, req.OperationID)
|
||||
log.NewInfo(req.OperationID, "Notification ", v)
|
||||
}
|
||||
}
|
||||
|
||||
func MemberQuitNotification(req *pbGroup.QuitGroupReq) {
|
||||
MemberQuitTips := open_im_sdk.MemberQuitTips{Group: &open_im_sdk.GroupInfo{}, QuitUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberQuitTips.Group); err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberQuitTips.QuitUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID)
|
||||
return
|
||||
}
|
||||
|
||||
groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, "", req.OpUserID, req.OperationID)
|
||||
|
||||
}
|
||||
|
||||
//message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
//}
|
||||
//处理进群请求后调用
|
||||
func GroupApplicationAcceptedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationAcceptedTips := open_im_sdk.GroupApplicationAcceptedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := setGroupInfo(req.GroupID, GroupApplicationAcceptedTips.Group); err != nil {
|
||||
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, GroupApplicationAcceptedTips.Group)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, GroupApplicationAcceptedTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID, GroupApplicationAcceptedTips.OpUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, req.OpUserID, "", req.FromUserID, req.OperationID)
|
||||
}
|
||||
|
||||
func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationRejectedTips := open_im_sdk.GroupApplicationRejectedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := setGroupInfo(req.GroupID, GroupApplicationRejectedTips.Group); err != nil {
|
||||
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, GroupApplicationRejectedTips.Group)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, GroupApplicationRejectedTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID, GroupApplicationRejectedTips.OpUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, req.OpUserID, "", req.FromUserID, req.OperationID)
|
||||
}
|
||||
|
||||
func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {
|
||||
GroupOwnerTransferredTips := open_im_sdk.GroupOwnerTransferredTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}, NewGroupOwner: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, GroupOwnerTransferredTips.Group); err != nil {
|
||||
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, GroupOwnerTransferredTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(req.GroupID, req.NewOwnerUserID, GroupOwnerTransferredTips.NewGroupOwner); err != nil {
|
||||
log.Error(req.OperationID, "setGroupMemberInfo failed", req.GroupID, req.NewOwnerUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, req.OpUserID, "", req.NewOwnerUserID, req.OperationID)
|
||||
}
|
||||
|
||||
//message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被踢后调用
|
||||
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
MemberKickedTips := open_im_sdk.MemberKickedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberKickedTips.Group); err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberKickedTips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID)
|
||||
return
|
||||
}
|
||||
for _, v := range kickedUserIDList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
if err := setGroupMemberInfo(req.GroupID, v, &groupMemberInfo); err != nil {
|
||||
log.Error(req.OperationID, "setGroupMemberInfo failed ", err.Error(), req.GroupID, v)
|
||||
continue
|
||||
}
|
||||
MemberKickedTips.KickedUserList = append(MemberKickedTips.KickedUserList, &groupMemberInfo)
|
||||
}
|
||||
groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
|
||||
for _, v := range kickedUserIDList {
|
||||
groupNotification(constant.MemberKickedNotification, &MemberKickedTips, req.OpUserID, "", v, req.OperationID)
|
||||
}
|
||||
}
|
||||
|
||||
//message MemberInvitedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo InvitedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//}
|
||||
//被邀请进群后调用
|
||||
func MemberInvitedNotification(operationID, groupID, opUserID, reason string, invitedUserIDList []string) {
|
||||
MemberInvitedTips := open_im_sdk.MemberInvitedTips{Group: &open_im_sdk.GroupInfo{}, OpUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, MemberInvitedTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, MemberInvitedTips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
for _, v := range invitedUserIDList {
|
||||
var groupMemberInfo open_im_sdk.GroupMemberFullInfo
|
||||
if err := setGroupMemberInfo(groupID, v, &groupMemberInfo); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID)
|
||||
continue
|
||||
}
|
||||
MemberInvitedTips.InvitedUserList = append(MemberInvitedTips.InvitedUserList, &groupMemberInfo)
|
||||
}
|
||||
|
||||
groupNotification(constant.MemberInvitedNotification, &MemberInvitedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
//message GroupInfoChangedTips{
|
||||
// int32 ChangedType = 1; //bitwise operators: 1:groupName; 10:Notification 100:Introduction; 1000:FaceUrl
|
||||
// GroupInfo Group = 2;
|
||||
// GroupMemberFullInfo OpUser = 3;
|
||||
//}
|
||||
|
||||
//message MemberLeaveTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo LeaverUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
|
||||
//群成员退群后调用
|
||||
|
||||
//message MemberEnterTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo EntrantUser = 2;
|
||||
// uint64 OperationTime = 3;
|
||||
//}
|
||||
//群成员主动申请进群,管理员同意后调用,
|
||||
func MemberEnterNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
MemberEnterTips := open_im_sdk.MemberEnterTips{Group: &open_im_sdk.GroupInfo{}, EntrantUser: &open_im_sdk.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, MemberEnterTips.Group); err != nil {
|
||||
log.Error(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID, MemberEnterTips.Group)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, MemberEnterTips.EntrantUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed ", err.Error(), req.OpUserID, req.GroupID, MemberEnterTips.EntrantUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.MemberEnterNotification, &MemberEnterTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
|
||||
}
|
||||
@ -0,0 +1,73 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbMsg "Open_IM/pkg/proto/chat"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *pbMsg.GetMaxAndMinSeqReq) (*pbMsg.GetMaxAndMinSeqResp, error) {
|
||||
log.InfoByKv("rpc getMaxAndMinSeq is arriving", in.OperationID, in.String())
|
||||
//seq, err := model.GetBiggestSeqFromReceive(in.UserID)
|
||||
maxSeq, err1 := commonDB.DB.GetUserMaxSeq(in.UserID)
|
||||
minSeq, err2 := commonDB.DB.GetUserMinSeq(in.UserID)
|
||||
resp := new(pbMsg.GetMaxAndMinSeqResp)
|
||||
if err1 == nil {
|
||||
resp.MaxSeq = uint32(maxSeq)
|
||||
} else if err1 == redis.ErrNil {
|
||||
resp.MaxSeq = 0
|
||||
} else {
|
||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err1.Error())
|
||||
resp.ErrCode = 200
|
||||
resp.ErrMsg = "redis get err"
|
||||
}
|
||||
if err2 == nil {
|
||||
resp.MinSeq = uint32(minSeq)
|
||||
} else if err2 == redis.ErrNil {
|
||||
resp.MinSeq = 0
|
||||
} else {
|
||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String(), err2.Error())
|
||||
resp.ErrCode = 201
|
||||
resp.ErrMsg = "redis get err"
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *open_im_sdk.PullMessageBySeqListReq) (*open_im_sdk.PullMessageBySeqListResp, error) {
|
||||
log.NewInfo(in.OperationID, "rpc PullMessageBySeqList is arriving", in.String())
|
||||
resp := new(open_im_sdk.PullMessageBySeqListResp)
|
||||
msgList, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList, in.OperationID)
|
||||
if err != nil {
|
||||
log.ErrorByKv("PullMessageBySeqList data error", in.OperationID, in.String())
|
||||
resp.ErrCode = 201
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
//respSingleMsgFormat = singleMsgHandleByUser(SingleMsgFormat, in.UserID)
|
||||
//respGroupMsgFormat = groupMsgHandleByUser(GroupMsgFormat)
|
||||
resp.ErrCode = 0
|
||||
resp.ErrMsg = ""
|
||||
resp.List = msgList
|
||||
return resp, nil
|
||||
|
||||
}
|
||||
|
||||
type MsgFormats []*open_im_sdk.MsgData
|
||||
|
||||
// Implement the sort.Interface interface to get the number of elements method
|
||||
func (s MsgFormats) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
//Implement the sort.Interface interface comparison element method
|
||||
func (s MsgFormats) Less(i, j int) bool {
|
||||
return s[i].SendTime < s[j].SendTime
|
||||
}
|
||||
|
||||
//Implement the sort.Interface interface exchange element method
|
||||
func (s MsgFormats) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package chat
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
@ -0,0 +1,302 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
http2 "Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
sdk_ws "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MsgCallBackReq struct {
|
||||
SendID string `json:"sendID"`
|
||||
RecvID string `json:"recvID"`
|
||||
Content string `json:"content"`
|
||||
SendTime int64 `json:"sendTime"`
|
||||
MsgFrom int32 `json:"msgFrom"`
|
||||
ContentType int32 `json:"contentType"`
|
||||
SessionType int32 `json:"sessionType"`
|
||||
PlatformID int32 `json:"senderPlatformID"`
|
||||
MsgID string `json:"msgID"`
|
||||
IsOnlineOnly bool `json:"isOnlineOnly"`
|
||||
}
|
||||
type MsgCallBackResp struct {
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
ResponseErrCode int32 `json:"responseErrCode"`
|
||||
ResponseResult struct {
|
||||
ModifiedMsg string `json:"modifiedMsg"`
|
||||
Ext string `json:"ext"`
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) encapsulateMsgData(msg *sdk_ws.MsgData) {
|
||||
msg.ServerMsgID = GetMsgID(msg.SendID)
|
||||
if msg.SendTime == 0 {
|
||||
msg.SendTime = utils.GetCurrentTimestampByMill()
|
||||
}
|
||||
switch msg.ContentType {
|
||||
case constant.Text:
|
||||
fallthrough
|
||||
case constant.Picture:
|
||||
fallthrough
|
||||
case constant.Voice:
|
||||
fallthrough
|
||||
case constant.Video:
|
||||
fallthrough
|
||||
case constant.File:
|
||||
fallthrough
|
||||
case constant.AtText:
|
||||
fallthrough
|
||||
case constant.Merger:
|
||||
fallthrough
|
||||
case constant.Card:
|
||||
fallthrough
|
||||
case constant.Location:
|
||||
fallthrough
|
||||
case constant.Custom:
|
||||
fallthrough
|
||||
case constant.Quote:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, true)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, true)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderSync, true)
|
||||
case constant.Revoke:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
case constant.HasReadReceipt:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
case constant.Typing:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderSync, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
|
||||
}
|
||||
}
|
||||
func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.SendMsgResp, error) {
|
||||
replay := pbChat.SendMsgResp{}
|
||||
log.NewDebug(pb.OperationID, "rpc sendMsg come here", pb.String())
|
||||
//if !utils.VerifyToken(pb.Token, pb.SendID) {
|
||||
// return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
|
||||
rpc.encapsulateMsgData(pb.MsgData)
|
||||
msgToMQ := pbChat.MsgDataToMQ{Token: pb.Token, OperationID: pb.OperationID}
|
||||
//options := utils.JsonStringToMap(pbData.Options)
|
||||
isHistory := utils.GetSwitchFromOptions(pb.MsgData.Options, constant.IsHistory)
|
||||
mReq := MsgCallBackReq{
|
||||
SendID: pb.MsgData.SendID,
|
||||
RecvID: pb.MsgData.RecvID,
|
||||
Content: string(pb.MsgData.Content),
|
||||
SendTime: pb.MsgData.SendTime,
|
||||
MsgFrom: pb.MsgData.MsgFrom,
|
||||
ContentType: pb.MsgData.ContentType,
|
||||
SessionType: pb.MsgData.SessionType,
|
||||
PlatformID: pb.MsgData.SenderPlatformID,
|
||||
MsgID: pb.MsgData.ClientMsgID,
|
||||
}
|
||||
if !isHistory {
|
||||
mReq.IsOnlineOnly = true
|
||||
}
|
||||
mResp := MsgCallBackResp{}
|
||||
if config.Config.MessageCallBack.CallbackSwitch {
|
||||
bMsg, err := http2.Post(config.Config.MessageCallBack.CallbackUrl, mReq, config.Config.MessageCallBack.CallBackTimeOut)
|
||||
if err != nil {
|
||||
log.ErrorByKv("callback to Business server err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
||||
return returnMsg(&replay, pb, http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError), "", 0)
|
||||
} else if err = json.Unmarshal(bMsg, &mResp); err != nil {
|
||||
log.ErrorByKv("ws json Unmarshal err", pb.OperationID, "args", pb.String(), "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
if mResp.ErrCode != 0 {
|
||||
return returnMsg(&replay, pb, mResp.ResponseErrCode, mResp.ErrMsg, "", 0)
|
||||
} else {
|
||||
pb.MsgData.Content = []byte(mResp.ResponseResult.ModifiedMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
switch pb.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(pb.MsgData.RecvID, pb.MsgData.SendID, constant.SingleChatType, pb)
|
||||
if isSend {
|
||||
msgToMQ.MsgData = pb.MsgData
|
||||
err1 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.RecvID)
|
||||
if err1 != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:RecvID", msgToMQ.MsgData.RecvID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
if msgToMQ.MsgData.SendID != msgToMQ.MsgData.RecvID { //Filter messages sent to yourself
|
||||
err2 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.SendID)
|
||||
if err2 != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:SendID", msgToMQ.MsgData.SendID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||
case constant.GroupChatType:
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
req := &pbGroup.GetGroupAllMemberReq{
|
||||
GroupID: pb.MsgData.GroupID,
|
||||
OperationID: pb.OperationID,
|
||||
}
|
||||
reply, err := client.GetGroupAllMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(pb.Token, pb.OperationID, "rpc send_msg getGroupInfo failed, err = %s", err.Error())
|
||||
return returnMsg(&replay, pb, 201, err.Error(), "", 0)
|
||||
}
|
||||
if reply.ErrCode != 0 {
|
||||
log.Error(pb.Token, pb.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrMsg)
|
||||
return returnMsg(&replay, pb, reply.ErrCode, reply.ErrMsg, "", 0)
|
||||
}
|
||||
groupID := pb.MsgData.GroupID
|
||||
for _, v := range reply.MemberList {
|
||||
pb.MsgData.RecvID = v.UserID
|
||||
isSend := modifyMessageByUserMessageReceiveOpt(v.UserID, groupID, constant.GroupChatType, pb)
|
||||
if isSend {
|
||||
msgToMQ.MsgData = pb.MsgData
|
||||
err := rpc.sendMsgToKafka(&msgToMQ, v.UserID)
|
||||
if err != nil {
|
||||
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v.UserID, msgToMQ.String())
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
||||
default:
|
||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) sendMsgToKafka(m *pbChat.MsgDataToMQ, key string) error {
|
||||
pid, offset, err := rpc.producer.SendMessage(m, key)
|
||||
if err != nil {
|
||||
log.ErrorByKv("kafka send failed", m.OperationID, "send data", m.String(), "pid", pid, "offset", offset, "err", err.Error(), "key", key)
|
||||
}
|
||||
return err
|
||||
}
|
||||
func GetMsgID(sendID string) string {
|
||||
t := time.Now().Format("2006-01-02 15:04:05")
|
||||
return t + "-" + sendID + "-" + strconv.Itoa(rand.Int())
|
||||
}
|
||||
|
||||
func returnMsg(replay *pbChat.SendMsgResp, pb *pbChat.SendMsgReq, errCode int32, errMsg, serverMsgID string, sendTime int64) (*pbChat.SendMsgResp, error) {
|
||||
replay.ErrCode = errCode
|
||||
replay.ErrMsg = errMsg
|
||||
replay.ServerMsgID = serverMsgID
|
||||
replay.ClientMsgID = pb.MsgData.ClientMsgID
|
||||
replay.SendTime = sendTime
|
||||
return replay, nil
|
||||
}
|
||||
|
||||
func modifyMessageByUserMessageReceiveOpt(userID, sourceID string, sessionType int, pb *pbChat.SendMsgReq) bool {
|
||||
conversationID := utils.GetConversationIDBySessionType(sourceID, sessionType)
|
||||
opt, err := db.DB.GetSingleConversationMsgOpt(userID, conversationID)
|
||||
if err != nil || err != redis.ErrNil {
|
||||
log.NewError(pb.OperationID, "GetSingleConversationMsgOpt from redis err", conversationID, pb.String(), err.Error())
|
||||
return true
|
||||
}
|
||||
switch opt {
|
||||
case constant.ReceiveMessage:
|
||||
return true
|
||||
case constant.NotReceiveMessage:
|
||||
return false
|
||||
case constant.ReceiveNotNotifyMessage:
|
||||
if pb.MsgData.Options == nil {
|
||||
pb.MsgData.Options = make(map[string]bool, 10)
|
||||
}
|
||||
utils.SetSwitchFromOptions(pb.MsgData.Options, constant.IsOfflinePush, false)
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
type NotificationMsg struct {
|
||||
SendID string
|
||||
RecvID string
|
||||
Content []byte // open_im_sdk.TipsComm
|
||||
MsgFrom int32
|
||||
ContentType int32
|
||||
SessionType int32
|
||||
OperationID string
|
||||
}
|
||||
|
||||
func Notification(n *NotificationMsg) {
|
||||
return
|
||||
var req pbChat.SendMsgReq
|
||||
var msg sdk_ws.MsgData
|
||||
var offlineInfo sdk_ws.OfflinePushInfo
|
||||
var title, desc, ex string
|
||||
var pushSwitch bool
|
||||
req.OperationID = n.OperationID
|
||||
msg.SendID = n.SendID
|
||||
msg.RecvID = n.RecvID
|
||||
msg.Content = n.Content
|
||||
msg.MsgFrom = n.MsgFrom
|
||||
msg.ContentType = n.ContentType
|
||||
msg.SessionType = n.SessionType
|
||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
msg.ClientMsgID = utils.GetMsgID(n.SendID)
|
||||
switch n.SessionType {
|
||||
case constant.GroupChatType:
|
||||
msg.RecvID = ""
|
||||
msg.GroupID = n.RecvID
|
||||
}
|
||||
if true {
|
||||
msg.Options = make(map[string]bool, 10)
|
||||
//utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
}
|
||||
offlineInfo.IOSBadgeCount = config.Config.IOSPush.BadgeCount
|
||||
offlineInfo.IOSPushSound = config.Config.IOSPush.PushSound
|
||||
//switch msg.ContentType {
|
||||
//case constant.GroupCreatedNotification:
|
||||
// pushSwitch = config.Config.Notification.GroupCreated.OfflinePush.PushSwitch
|
||||
// title = config.Config.Notification.GroupCreated.OfflinePush.Title
|
||||
// desc = config.Config.Notification.GroupCreated.OfflinePush.Desc
|
||||
// ex = config.Config.Notification.GroupCreated.OfflinePush.Ext
|
||||
//case constant.GroupInfoChangedNotification:
|
||||
// pushSwitch = config.Config.Notification.GroupInfoChanged.OfflinePush.PushSwitch
|
||||
// title = config.Config.Notification.GroupInfoChanged.OfflinePush.Title
|
||||
// desc = config.Config.Notification.GroupInfoChanged.OfflinePush.Desc
|
||||
// ex = config.Config.Notification.GroupInfoChanged.OfflinePush.Ext
|
||||
//case constant.JoinApplicationNotification:
|
||||
// pushSwitch = config.Config.Notification.ApplyJoinGroup.OfflinePush.PushSwitch
|
||||
// title = config.Config.Notification.ApplyJoinGroup.OfflinePush.Title
|
||||
// desc = config.Config.Notification.ApplyJoinGroup.OfflinePush.Desc
|
||||
// ex = config.Config.Notification.ApplyJoinGroup.OfflinePush.Ext
|
||||
//}
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, pushSwitch)
|
||||
offlineInfo.Title = title
|
||||
offlineInfo.Desc = desc
|
||||
offlineInfo.Ex = ex
|
||||
msg.OfflinePushInfo = &offlineInfo
|
||||
req.MsgData = &msg
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
reply, err := client.SendMsg(context.Background(), &req)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String(), err.Error())
|
||||
} else if reply.ErrCode != 0 {
|
||||
log.NewError(req.OperationID, "SendMsg rpc failed, ", req.String())
|
||||
}
|
||||
}
|
||||
@ -1,59 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) {
|
||||
m := make(map[string]int, len(req.ConversationId))
|
||||
for _, v := range req.ConversationId {
|
||||
m[v] = int(req.Opt)
|
||||
}
|
||||
err := db.DB.SetMultiConversationMsgOpt(req.UId, m)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SetMultiConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.SetReceiveMessageOptResp{ErrCode: constant.DatabaseError, ErrMsg: err.Error()}, nil
|
||||
}
|
||||
var resp pbUser.SetReceiveMessageOptResp
|
||||
resp.ErrCode = 0
|
||||
|
||||
for _, v := range req.ConversationId {
|
||||
resp.OptResult = append(resp.OptResult, &pbUser.OptResult{ConversationId: v, Result: 0})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt req, resp ", req, resp)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetReceiveMessageOpt(ctx context.Context, req *pbUser.GetReceiveMessageOptReq) (*pbUser.GetReceiveMessageOptResp, error) {
|
||||
m, err := db.DB.GetMultiConversationMsgOpt(req.UId, req.ConversationId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetMultiConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.GetReceiveMessageOptResp{ErrCode: constant.DatabaseError, ErrMsg: err.Error()}, nil
|
||||
}
|
||||
var resp pbUser.GetReceiveMessageOptResp
|
||||
resp.ErrCode = 0
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResult = append(resp.ConversationOptResult, &pbUser.OptResult{ConversationId: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOpt, req, resp", req, resp)
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllConversationMsgOpt(ctx context.Context, req *pbUser.GetAllConversationMsgOptReq) (*pbUser.GetAllConversationMsgOptResp, error) {
|
||||
m, err := db.DB.GetAllConversationMsgOpt(req.UId)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetAllConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.GetAllConversationMsgOptResp{ErrCode: constant.DatabaseError, ErrMsg: err.Error()}, nil
|
||||
}
|
||||
var resp pbUser.GetAllConversationMsgOptResp
|
||||
resp.ErrCode = 0
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResult = append(resp.ConversationOptResult, &pbUser.OptResult{ConversationId: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt, req, resp", req, resp)
|
||||
return &resp, nil
|
||||
}
|
||||
@ -1,97 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewUserServer(port int) *userServer {
|
||||
log.NewPrivateLog("user")
|
||||
return &userServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userServer) Run() {
|
||||
log.Info("", "", "rpc user init....")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.InfoByArgs("listen network failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "listen network success, address = %s", registerAddress)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbUser.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("register rpc token to etcd failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.ErrorByArgs("listen token failed,err=%s", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "", "rpc token init success")
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.InfoByKv("rpc get_user_info is server", req.OperationID)
|
||||
|
||||
var userInfoList []*pbUser.UserInfo
|
||||
//Obtain user information according to userID
|
||||
if len(req.UserIDList) > 0 {
|
||||
for _, userID := range req.UserIDList {
|
||||
var userInfo pbUser.UserInfo
|
||||
user, err := im_mysql_model.FindUserByUID(userID)
|
||||
if err != nil {
|
||||
log.ErrorByKv("search userinfo failed", req.OperationID, "userID", userID, "err=%s", err.Error())
|
||||
continue
|
||||
}
|
||||
userInfo.Uid = user.UID
|
||||
userInfo.Icon = user.Icon
|
||||
userInfo.Name = user.Name
|
||||
userInfo.Gender = user.Gender
|
||||
userInfo.Mobile = user.Mobile
|
||||
userInfo.Birth = user.Birth
|
||||
userInfo.Email = user.Email
|
||||
userInfo.Ex = user.Ex
|
||||
userInfoList = append(userInfoList, &userInfo)
|
||||
}
|
||||
} else {
|
||||
return &pbUser.GetUserInfoResp{ErrorCode: 999, ErrorMsg: "uidList is nil"}, nil
|
||||
}
|
||||
log.InfoByKv("rpc get userInfo return success", req.OperationID, "token", req.Token)
|
||||
return &pbUser.GetUserInfoResp{
|
||||
ErrorCode: 0,
|
||||
ErrorMsg: "",
|
||||
Data: userInfoList,
|
||||
}, nil
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
package internal_service
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUserInfoClient(req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName)
|
||||
client := pbUser.NewUserClient(etcdConn)
|
||||
RpcResp, err := client.GetUserInfo(context.Background(), req)
|
||||
return RpcResp, err
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
/*
|
||||
** description("").
|
||||
** copyright('open-im,www.open-im.io').
|
||||
** author("fg,Gordon@tuoyun.net").
|
||||
** time(2021/9/15 10:28).
|
||||
*/
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.InfoByKv("rpc DeleteUsers arrived server", req.OperationID, "args", req.String())
|
||||
var resp pbUser.DeleteUsersResp
|
||||
var common pbUser.CommonResp
|
||||
c, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.ErrorByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}, FailedUidList: req.DeleteUidList}, nil
|
||||
}
|
||||
for _, uid := range req.DeleteUidList {
|
||||
err = im_mysql_model.UserDelete(uid)
|
||||
if err != nil {
|
||||
common.ErrorCode = 201
|
||||
common.ErrorMsg = "some uid deleted failed"
|
||||
resp.FailedUidList = append(resp.FailedUidList, uid)
|
||||
}
|
||||
}
|
||||
resp.CommonResp = &common
|
||||
return &resp, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUsersUid(_ context.Context, req *pbUser.GetAllUsersUidReq) (*pbUser.GetAllUsersUidResp, error) {
|
||||
log.InfoByKv("rpc GetAllUsersUid arrived server", req.OperationID, "args", req.String())
|
||||
c, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.InfoByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}}, nil
|
||||
}
|
||||
uidList, err := im_mysql_model.SelectAllUID()
|
||||
if err != nil {
|
||||
log.ErrorByKv("db get failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
} else {
|
||||
return &pbUser.GetAllUsersUidResp{CommonResp: &pbUser.CommonResp{ErrorCode: 0, ErrorMsg: ""}, UidList: uidList}, nil
|
||||
}
|
||||
|
||||
}
|
||||
func (s *userServer) AccountCheck(_ context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
log.InfoByKv("rpc AccountCheck arrived server", req.OperationID, "args", req.String())
|
||||
c, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.InfoByKv("parse token failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
}
|
||||
if !utils.IsContain(c.UID, config.Config.Manager.AppManagerUid) {
|
||||
log.ErrorByKv(" Authentication failed", req.OperationID, "args", c)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: 401, ErrorMsg: "not authorized"}}, nil
|
||||
}
|
||||
uidList, err := im_mysql_model.SelectSomeUID(req.UidList)
|
||||
if err != nil {
|
||||
log.ErrorByKv("db get SelectSomeUID failed", req.OperationID, "err", err.Error())
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: constant.ErrMysql.ErrCode, ErrorMsg: err.Error()}}, nil
|
||||
} else {
|
||||
var r []*pbUser.AccountCheckResp_SingleUserStatus
|
||||
for _, v := range req.UidList {
|
||||
temp := new(pbUser.AccountCheckResp_SingleUserStatus)
|
||||
temp.UserID = v
|
||||
if utils.IsContain(v, uidList) {
|
||||
temp.AccountStatus = constant.Registered
|
||||
} else {
|
||||
temp.AccountStatus = constant.UnRegistered
|
||||
}
|
||||
r = append(r, temp)
|
||||
}
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrorCode: 0, ErrorMsg: ""}, Result: r}, nil
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"Open_IM/internal/push/logic"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/pkg/proto/chat"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.CommonResp, error) {
|
||||
log.Info(req.Token, req.OperationID, "rpc modify user is server,args=%s", req.String())
|
||||
claims, err := token_verify.ParseToken(req.Token)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "err=%s,parse token failed", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: constant.ErrParseToken.ErrCode, ErrorMsg: err.Error()}, nil
|
||||
}
|
||||
|
||||
ownerUid := ""
|
||||
//if claims.UID == config.Config.AppManagerUid {
|
||||
if utils.IsContain(claims.UID, config.Config.Manager.AppManagerUid) {
|
||||
ownerUid = req.Uid
|
||||
} else {
|
||||
ownerUid = claims.UID
|
||||
}
|
||||
|
||||
err = im_mysql_model.UpDateUserInfo(ownerUid, req.Name, req.Icon, req.Mobile, req.Birth, req.Email, req.Ex, req.Gender)
|
||||
if err != nil {
|
||||
log.Error(req.Token, req.OperationID, "update user some attribute failed,err=%s", err.Error())
|
||||
return &pbUser.CommonResp{ErrorCode: constant.ErrModifyUserInfo.ErrCode, ErrorMsg: constant.ErrModifyUserInfo.ErrMsg}, nil
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
if RpcResp.ErrorCode != 0 {
|
||||
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
self, err := im_mysql_model.FindUserByUID(ownerUid)
|
||||
if err != nil {
|
||||
log.ErrorByKv("get self info failed", req.OperationID, "err", err.Error(), "req", req.String())
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
var name, faceUrl string
|
||||
if self != nil {
|
||||
name, faceUrl = self.Name, self.Icon
|
||||
}
|
||||
for _, v := range RpcResp.Data {
|
||||
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
|
||||
SendID: ownerUid,
|
||||
RecvID: v.Uid,
|
||||
SenderNickName: name,
|
||||
SenderFaceURL: faceUrl,
|
||||
Content: ownerUid + "'s info has changed",
|
||||
SendTime: utils.GetCurrentTimestampByNano(),
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SetSelfInfoTip,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: req.OperationID,
|
||||
Token: req.Token,
|
||||
})
|
||||
|
||||
}
|
||||
return &pbUser.CommonResp{}, nil
|
||||
}
|
||||
@ -0,0 +1,243 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
chat "Open_IM/internal/rpc/msg"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/token_verify"
|
||||
"Open_IM/pkg/grpc-etcdv3/getcdv3"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdk_ws"
|
||||
pbUser "Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type userServer struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
}
|
||||
|
||||
func NewUserServer(port int) *userServer {
|
||||
log.NewPrivateLog("user")
|
||||
return &userServer{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImUserName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userServer) Run() {
|
||||
log.NewInfo("0", "", "rpc user start...")
|
||||
|
||||
ip := utils.ServerIP
|
||||
registerAddress := ip + ":" + strconv.Itoa(s.rpcPort)
|
||||
//listener network
|
||||
listener, err := net.Listen("tcp", registerAddress)
|
||||
if err != nil {
|
||||
log.NewError("0", "listen network failed ", err.Error(), registerAddress)
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "listen network success, address ", registerAddress, listener)
|
||||
defer listener.Close()
|
||||
//grpc server
|
||||
srv := grpc.NewServer()
|
||||
defer srv.GracefulStop()
|
||||
//Service registers with etcd
|
||||
pbUser.RegisterUserServer(srv, s)
|
||||
err = getcdv3.RegisterEtcd(s.etcdSchema, strings.Join(s.etcdAddr, ","), ip, s.rpcPort, s.rpcRegisterName, 10)
|
||||
if err != nil {
|
||||
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.NewError("0", "Serve failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.NewInfo("0", "rpc user success")
|
||||
}
|
||||
|
||||
func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq) (*pbUser.GetUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetUserInfo args ", req.String())
|
||||
var userInfoList []*sdkws.UserInfo
|
||||
if len(req.UserIDList) > 0 {
|
||||
for _, userID := range req.UserIDList {
|
||||
var userInfo sdkws.UserInfo
|
||||
user, err := imdb.GetUserByUserID(userID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), userID)
|
||||
continue
|
||||
}
|
||||
utils.CopyStructFields(&userInfo, user)
|
||||
userInfo.Birth = uint32(user.Birth.Unix())
|
||||
userInfoList = append(userInfoList, &userInfo)
|
||||
}
|
||||
} else {
|
||||
|
||||
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetUserInfo rpc return ", pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList})
|
||||
return &pbUser.GetUserInfoResp{CommonResp: &pbUser.CommonResp{}, UserInfoList: userInfoList}, nil
|
||||
}
|
||||
|
||||
func (s *userServer) SetReceiveMessageOpt(ctx context.Context, req *pbUser.SetReceiveMessageOptReq) (*pbUser.SetReceiveMessageOptResp, error) {
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt args ", req.String())
|
||||
m := make(map[string]int, len(req.ConversationIDList))
|
||||
for _, v := range req.ConversationIDList {
|
||||
m[v] = int(req.Opt)
|
||||
}
|
||||
err := db.DB.SetMultiConversationMsgOpt(req.FromUserID, m)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SetMultiConversationMsgOpt failed ", err.Error(), req)
|
||||
return &pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
resp := pbUser.SetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
|
||||
|
||||
for _, v := range req.ConversationIDList {
|
||||
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: v, Result: req.Opt})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "SetReceiveMessageOpt rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetReceiveMessageOpt(ctx context.Context, req *pbUser.GetReceiveMessageOptReq) (*pbUser.GetReceiveMessageOptResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOpt args ", req.String())
|
||||
m, err := db.DB.GetMultiConversationMsgOpt(req.FromUserID, req.ConversationIDList)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetMultiConversationMsgOpt failed ", err.Error(), req.FromUserID, req.ConversationIDList)
|
||||
return &pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
resp := pbUser.GetReceiveMessageOptResp{CommonResp: &pbUser.CommonResp{}}
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetReceiveMessageOpt rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllConversationMsgOpt(ctx context.Context, req *pbUser.GetAllConversationMsgOptReq) (*pbUser.GetAllConversationMsgOptResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt args ", req.String())
|
||||
m, err := db.DB.GetAllConversationMsgOpt(req.FromUserID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetAllConversationMsgOpt failed ", err.Error(), req.FromUserID)
|
||||
return &pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
resp := pbUser.GetAllConversationMsgOptResp{CommonResp: &pbUser.CommonResp{}}
|
||||
for k, v := range m {
|
||||
resp.ConversationOptResultList = append(resp.ConversationOptResultList, &pbUser.OptResult{ConversationID: k, Result: int32(v)})
|
||||
}
|
||||
log.NewInfo(req.OperationID, "GetAllConversationMsgOpt rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) {
|
||||
log.NewInfo(req.OperationID, "DeleteUsers args ", req.String())
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.DeleteUsersResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, FailedUserIDList: req.DeleteUserIDList}, nil
|
||||
}
|
||||
var common pbUser.CommonResp
|
||||
resp := pbUser.DeleteUsersResp{CommonResp: &common}
|
||||
for _, userID := range req.DeleteUserIDList {
|
||||
i := imdb.DeleteUser(userID)
|
||||
if i == 0 {
|
||||
log.NewError(req.OperationID, "delete user error", userID)
|
||||
common.ErrCode = 201
|
||||
common.ErrMsg = "some uid deleted failed"
|
||||
resp.FailedUserIDList = append(resp.FailedUserIDList, userID)
|
||||
}
|
||||
}
|
||||
log.NewInfo(req.OperationID, "DeleteUsers rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (s *userServer) GetAllUserID(_ context.Context, req *pbUser.GetAllUserIDReq) (*pbUser.GetAllUserIDResp, error) {
|
||||
log.NewInfo(req.OperationID, "GetAllUserID args ", req.String())
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
uidList, err := imdb.SelectAllUserID()
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SelectAllUserID false ", err.Error())
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
} else {
|
||||
log.NewInfo(req.OperationID, "GetAllUserID rpc return ", pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{}, UserIDList: uidList})
|
||||
return &pbUser.GetAllUserIDResp{CommonResp: &pbUser.CommonResp{}, UserIDList: uidList}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *userServer) AccountCheck(_ context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) {
|
||||
log.NewInfo(req.OperationID, "AccountCheck args ", req.String())
|
||||
if !token_verify.IsMangerUserID(req.OpUserID) {
|
||||
log.NewError(req.OperationID, "IsMangerUserID false ", req.OpUserID)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
uidList, err := imdb.SelectSomeUserID(req.CheckUserIDList)
|
||||
log.NewDebug(req.OperationID, "from db uid list is:", uidList)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SelectSomeUserID failed ", err.Error(), req.CheckUserIDList)
|
||||
return &pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
} else {
|
||||
var r []*pbUser.AccountCheckResp_SingleUserStatus
|
||||
for _, v := range req.CheckUserIDList {
|
||||
temp := new(pbUser.AccountCheckResp_SingleUserStatus)
|
||||
temp.UserID = v
|
||||
if utils.IsContain(v, uidList) {
|
||||
temp.AccountStatus = constant.Registered
|
||||
} else {
|
||||
temp.AccountStatus = constant.UnRegistered
|
||||
}
|
||||
r = append(r, temp)
|
||||
}
|
||||
resp := pbUser.AccountCheckResp{CommonResp: &pbUser.CommonResp{ErrCode: 0, ErrMsg: ""}, ResultList: r}
|
||||
log.NewInfo(req.OperationID, "AccountCheck rpc return ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserInfoReq) (*pbUser.UpdateUserInfoResp, error) {
|
||||
log.NewInfo(req.OperationID, "UpdateUserInfo args ", req.String())
|
||||
if !token_verify.CheckAccess(req.OpUserID, req.UserInfo.UserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.UserInfo.UserID)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil
|
||||
}
|
||||
|
||||
var user db.User
|
||||
utils.CopyStructFields(&user, req.UserInfo)
|
||||
if req.UserInfo.Birth != 0 {
|
||||
user.Birth = utils.UnixSecondToTime(int64(req.UserInfo.Birth))
|
||||
}
|
||||
err := imdb.UpdateUserInfo(user)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), user)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil
|
||||
}
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName)
|
||||
client := pbFriend.NewFriendClient(etcdConn)
|
||||
newReq := &pbFriend.GetFriendListReq{
|
||||
CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID},
|
||||
}
|
||||
|
||||
RpcResp, err := client.GetFriendList(context.Background(), newReq)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
}
|
||||
for _, v := range RpcResp.FriendInfoList {
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID)
|
||||
}
|
||||
chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID)
|
||||
return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func JsonDataList(resp interface{}) []map[string]interface{} {
|
||||
var list []proto.Message
|
||||
if reflect.TypeOf(resp).Kind() == reflect.Slice {
|
||||
s := reflect.ValueOf(resp)
|
||||
for i := 0; i < s.Len(); i++ {
|
||||
ele := s.Index(i)
|
||||
list = append(list, ele.Interface().(proto.Message))
|
||||
}
|
||||
}
|
||||
|
||||
result := make([]map[string]interface{}, 0)
|
||||
for _, v := range list {
|
||||
m := ProtoToMap(v, false)
|
||||
result = append(result, m)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func JsonDataOne(pb proto.Message) map[string]interface{} {
|
||||
return ProtoToMap(pb, false)
|
||||
}
|
||||
|
||||
func ProtoToMap(pb proto.Message, idFix bool) map[string]interface{} {
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
s, _ := marshaler.MarshalToString(pb)
|
||||
out := make(map[string]interface{})
|
||||
json.Unmarshal([]byte(s), &out)
|
||||
if idFix {
|
||||
if _, ok := out["id"]; ok {
|
||||
out["_id"] = out["id"]
|
||||
delete(out, "id")
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package base_info
|
||||
|
||||
//UserID string `protobuf:"bytes,1,opt,name=UserID" json:"UserID,omitempty"`
|
||||
// Nickname string `protobuf:"bytes,2,opt,name=Nickname" json:"Nickname,omitempty"`
|
||||
// FaceUrl string `protobuf:"bytes,3,opt,name=FaceUrl" json:"FaceUrl,omitempty"`
|
||||
// Gender int32 `protobuf:"varint,4,opt,name=Gender" json:"Gender,omitempty"`
|
||||
// PhoneNumber string `protobuf:"bytes,5,opt,name=PhoneNumber" json:"PhoneNumber,omitempty"`
|
||||
// Birth string `protobuf:"bytes,6,opt,name=Birth" json:"Birth,omitempty"`
|
||||
// Email string `protobuf:"bytes,7,opt,name=Email" json:"Email,omitempty"`
|
||||
// Ex string `protobuf:"bytes,8,opt,name=Ex" json:"Ex,omitempty"`
|
||||
|
||||
type UserRegisterReq struct {
|
||||
Secret string `json:"secret" binding:"required,max=32"`
|
||||
Platform int32 `json:"platform" binding:"required,min=1,max=7"`
|
||||
ApiUserInfo
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type UserTokenInfo struct {
|
||||
UserID string `json:"userID"`
|
||||
Token string `json:"token"`
|
||||
ExpiredTime int64 `json:"expiredTime"`
|
||||
}
|
||||
type UserRegisterResp struct {
|
||||
CommResp
|
||||
UserToken UserTokenInfo `json:"data"`
|
||||
}
|
||||
|
||||
type UserTokenReq struct {
|
||||
Secret string `json:"secret" binding:"required,max=32"`
|
||||
Platform int32 `json:"platform" binding:"required,min=1,max=8"`
|
||||
UserID string `json:"userID" binding:"required,min=1,max=64"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
|
||||
type UserTokenResp struct {
|
||||
CommResp
|
||||
UserToken UserTokenInfo `json:"data"`
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package base_info
|
||||
|
||||
type OptResult struct {
|
||||
ConversationID string `json:"conversationID"`
|
||||
Result *int32 `json:"result"`
|
||||
}
|
||||
type GetAllConversationMessageOptReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetAllConversationMessageOptResp struct {
|
||||
CommResp
|
||||
ConversationOptResultList []*OptResult `json:"data"`
|
||||
}
|
||||
type GetReceiveMessageOptReq struct {
|
||||
ConversationIDList []string `json:"conversationIDList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetReceiveMessageOptResp struct {
|
||||
CommResp
|
||||
ConversationOptResultList []*OptResult `json:"data"`
|
||||
}
|
||||
type SetReceiveMessageOptReq struct {
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
Opt *int32 `json:"opt" binding:"required"`
|
||||
ConversationIDList []string `json:"conversationIDList" binding:"required"`
|
||||
}
|
||||
type SetReceiveMessageOptResp struct {
|
||||
CommResp
|
||||
ConversationOptResultList []*OptResult `json:"data"`
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package base_info
|
||||
|
||||
import sts "github.com/tencentyun/qcloud-cos-sts-sdk/go"
|
||||
|
||||
type TencentCloudStorageCredentialReq struct {
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
type TencentCloudStorageCredentialRespData struct {
|
||||
*sts.CredentialResult
|
||||
Region string `json:"region"`
|
||||
Bucket string `json:"bucket"`
|
||||
}
|
||||
|
||||
type TencentCloudStorageCredentialResp struct {
|
||||
CommResp
|
||||
Data TencentCloudStorageCredentialRespData `json:"data"`
|
||||
}
|
||||
@ -0,0 +1,136 @@
|
||||
package base_info
|
||||
|
||||
import 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 UserIDResult struct {
|
||||
UserID string `json:"userID""`
|
||||
Result int32 `json:"result"`
|
||||
}
|
||||
type ImportFriendResp struct {
|
||||
CommResp
|
||||
UserIDResultList []UserIDResult `json:"data"`
|
||||
}
|
||||
|
||||
type AddFriendReq struct {
|
||||
ParamsCommFriend
|
||||
ReqMsg string `json:"reqMsg"`
|
||||
}
|
||||
type AddFriendResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type AddFriendResponseReq struct {
|
||||
ParamsCommFriend
|
||||
Flag int32 `json:"flag" binding:"required,oneof=-1 0 1"`
|
||||
HandleMsg string `json:"handleMsg"`
|
||||
}
|
||||
type AddFriendResponseResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type DeleteFriendReq struct {
|
||||
ParamsCommFriend
|
||||
}
|
||||
type DeleteFriendResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type GetBlackListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetBlackListResp struct {
|
||||
CommResp
|
||||
BlackUserInfoList []*open_im_sdk.PublicUserInfo `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
//type PublicUserInfo struct {
|
||||
// UserID string `json:"userID"`
|
||||
// Nickname string `json:"nickname"`
|
||||
// FaceUrl string `json:"faceUrl"`
|
||||
// Gender int32 `json:"gender"`
|
||||
//}
|
||||
|
||||
type SetFriendRemarkReq struct {
|
||||
ParamsCommFriend
|
||||
Remark string `json:"remark" binding:"required"`
|
||||
}
|
||||
type SetFriendRemarkResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type RemoveBlackListReq struct {
|
||||
ParamsCommFriend
|
||||
}
|
||||
type RemoveBlackListResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type IsFriendReq struct {
|
||||
ParamsCommFriend
|
||||
}
|
||||
type Response struct {
|
||||
Friend bool `json:"isFriend"`
|
||||
}
|
||||
type IsFriendResp struct {
|
||||
CommResp
|
||||
Response Response `json:"data"`
|
||||
}
|
||||
|
||||
type GetFriendsInfoReq struct {
|
||||
ParamsCommFriend
|
||||
}
|
||||
type GetFriendsInfoResp struct {
|
||||
CommResp
|
||||
FriendInfoList []*open_im_sdk.FriendInfo `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type GetFriendListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetFriendListResp struct {
|
||||
CommResp
|
||||
FriendInfoList []*open_im_sdk.FriendInfo `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type GetFriendApplyListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetFriendApplyListResp struct {
|
||||
CommResp
|
||||
FriendRequestList []*open_im_sdk.FriendRequest `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type GetSelfApplyListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetSelfApplyListResp struct {
|
||||
CommResp
|
||||
FriendRequestList []*open_im_sdk.FriendRequest `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
package base_info
|
||||
|
||||
import (
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
)
|
||||
|
||||
type CommResp struct {
|
||||
ErrCode int32 `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
}
|
||||
|
||||
type CommDataResp struct {
|
||||
CommResp
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
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
|
||||
UserIDResultList []*UserIDResult `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
|
||||
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type InviteUserToGroupReq struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
InvitedUserIDList []string `json:"invitedUserIDList" binding:"required"`
|
||||
Reason string `json:"reason"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type InviteUserToGroupResp struct {
|
||||
CommResp
|
||||
UserIDResultList []*UserIDResult `json:"data"`
|
||||
}
|
||||
|
||||
type GetJoinedGroupListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"`
|
||||
}
|
||||
type GetJoinedGroupListResp struct {
|
||||
CommResp
|
||||
GroupInfoList []*open_im_sdk.GroupInfo `json:"-"`
|
||||
Data []map[string]interface{} `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"`
|
||||
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type GetGroupAllMemberReq struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type GetGroupAllMemberResp struct {
|
||||
CommResp
|
||||
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type CreateGroupReq struct {
|
||||
MemberList []*GroupAddMemberInfo `json:"memberList" binding:"required"`
|
||||
OwnerUserID string `json:"ownerUserID" binding:"required"`
|
||||
GroupName string `json:"groupName"`
|
||||
GroupType int32 `json:"groupType"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type CreateGroupResp struct {
|
||||
CommResp
|
||||
GroupInfo open_im_sdk.GroupInfo `json:"-"`
|
||||
Data map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type GetGroupApplicationListReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"` //作为管理员或群主收到的 进群申请
|
||||
}
|
||||
type GetGroupApplicationListResp struct {
|
||||
CommResp
|
||||
GroupRequestList []*open_im_sdk.GroupRequest `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type GetGroupInfoReq struct {
|
||||
GroupIDList []string `json:"groupIDList" binding:"required"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
type GetGroupInfoResp struct {
|
||||
CommResp
|
||||
GroupInfoList []*open_im_sdk.GroupInfo `json:"-"`
|
||||
Data []map[string]interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ApplicationGroupResponseReq struct {
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
FromUserID string `json:"fromUserID" binding:"required"` //application from FromUserID
|
||||
HandledMsg string `json:"handledMsg"`
|
||||
HandleResult int32 `json:"handleResult" binding:"required,oneof=-1 1"`
|
||||
}
|
||||
type ApplicationGroupResponseResp struct {
|
||||
CommResp
|
||||
}
|
||||
|
||||
type JoinGroupReq struct {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
ReqMessage string `json:"reqMessage"`
|
||||
OperationID string `json:"operationID" binding:"required"`
|
||||
}
|
||||
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 {
|
||||
GroupID string `json:"groupID" binding:"required"`
|
||||
GroupName string `json:"groupName"`
|
||||
Notification string `json:"notification"`
|
||||
Introduction string `json:"introduction"`
|
||||
FaceURL string `json:"faceURL"`
|
||||
Ex string `json:"ex"`
|
||||
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"`
|
||||
}
|
||||
type TransferGroupOwnerResp struct {
|
||||
CommResp
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue