Conflicts: cmd/rpc/auth/main.go cmd/rpc/friend/main.go cmd/rpc/group/main.go cmd/rpc/msg/main.go cmd/rpc/user/main.go internal/rpc/auth/auth.go internal/rpc/conversation/conversaion.go internal/rpc/friend/friend.go internal/rpc/group/callback.go internal/rpc/group/group.go internal/rpc/msg/pull_message.go internal/rpc/msg/query_msg.go internal/rpc/msg/rpc_chat.go internal/rpc/msg/send_msg.go internal/rpc/user/user.go pkg/common/db/cache/redis.go pkg/common/db/controller/msg.go pkg/common/http/http_client.gotest-errcode
commit
1b3eaed0e5
@ -1,26 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
rpcAuth "Open_IM/internal/rpc/auth"
|
||||
"Open_IM/internal/rpc/auth"
|
||||
"Open_IM/internal/startrpc"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/prome"
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
defaultPorts := config.Config.RpcPort.OpenImAuthPort
|
||||
rpcPort := flag.Int("port", defaultPorts[0], "RpcToken default listen port 10800")
|
||||
prometheusPort := flag.Int("prometheus_port", config.Config.Prometheus.AuthPrometheusPort[0], "authPrometheusPort default listen port")
|
||||
flag.Parse()
|
||||
fmt.Println("start auth rpc server, port: ", *rpcPort, ", OpenIM version: ", constant.CurrentVersion, "\n")
|
||||
rpcServer := rpcAuth.NewRpcAuthServer(*rpcPort)
|
||||
go func() {
|
||||
err := prome.StartPromeSrv(*prometheusPort)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
rpcServer.Run()
|
||||
startrpc.Start(config.Config.RpcPort.OpenImAuthPort, config.Config.RpcRegisterName.OpenImAuthName, config.Config.Prometheus.AuthPrometheusPort, auth.Start)
|
||||
}
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||
"Open_IM/pkg/proto/conversation"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type ConversationChecker struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewConversationChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *ConversationChecker {
|
||||
return &ConversationChecker{zk: zk}
|
||||
}
|
||||
|
||||
func (c *ConversationChecker) ModifyConversationField(ctx context.Context, req *pbConversation.ModifyConversationFieldReq) error {
|
||||
cc, err := c.getConn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = conversation.NewConversationClient(cc).ModifyConversationField(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *ConversationChecker) getConn() (*grpc.ClientConn, error) {
|
||||
return c.zk.GetConn(config.Config.RpcRegisterName.OpenImConversationName)
|
||||
}
|
||||
|
||||
func (c *ConversationChecker) GetSingleConversationRecvMsgOpt(ctx context.Context, userID, conversationID string) (int32, error) {
|
||||
|
||||
}
|
||||
@ -1,11 +1,41 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||
"Open_IM/pkg/proto/friend"
|
||||
sdkws "Open_IM/pkg/proto/sdkws"
|
||||
"context"
|
||||
"errors"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func GetFriendsInfo(ctx context.Context, ownerUserID, friendUserID string) (*sdkws.FriendInfo, error) {
|
||||
return nil, errors.New("TODO:GetUserInfo")
|
||||
type FriendChecker struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewFriendChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *FriendChecker {
|
||||
return &FriendChecker{
|
||||
zk: zk,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *FriendChecker) GetFriendsInfo(ctx context.Context, ownerUserID, friendUserID string) (resp *sdkws.FriendInfo, err error) {
|
||||
cc, err := f.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r, err := friend.NewFriendClient(cc).GetPaginationFriends(ctx, &friend.GetPaginationFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{friendUserID}})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp = r.FriendsInfo[0]
|
||||
return
|
||||
}
|
||||
func (f *FriendChecker) getConn() (*grpc.ClientConn, error) {
|
||||
return f.zk.GetConn(config.Config.RpcRegisterName.OpenImFriendName)
|
||||
}
|
||||
|
||||
// possibleFriendUserID是否在userID的好友中
|
||||
func (f *FriendChecker) IsFriend(ctx context.Context, possibleFriendUserID, userID string) (bool, error) {
|
||||
|
||||
}
|
||||
|
||||
@ -1,17 +1,130 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||
"Open_IM/pkg/proto/group"
|
||||
sdkws "Open_IM/pkg/proto/sdkws"
|
||||
"errors"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type GroupChecker struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewGroupChecker() *GroupChecker {
|
||||
return &GroupChecker{}
|
||||
func NewGroupChecker(zk discoveryRegistry.SvcDiscoveryRegistry) *GroupChecker {
|
||||
return &GroupChecker{
|
||||
zk: zk,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupInfo(groupID string) (*sdkws.GroupInfo, error) {
|
||||
return nil, errors.New("TODO:GetUserInfo")
|
||||
func (g *GroupChecker) getConn() (*grpc.ClientConn, error) {
|
||||
return g.zk.GetConn(config.Config.RpcRegisterName.OpenImGroupName)
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupInfos(ctx context.Context, groupIDs []string, complete bool) ([]*sdkws.GroupInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupsInfo(ctx, &group.GetGroupsInfoReq{
|
||||
GroupIDs: groupIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if complete {
|
||||
if ids := utils.Single(groupIDs, utils.Slice(resp.GroupInfos, func(e *sdkws.GroupInfo) string {
|
||||
return e.GroupID
|
||||
})); len(ids) > 0 {
|
||||
return nil, constant.ErrGroupIDNotFound.Wrap(strings.Join(ids, ","))
|
||||
}
|
||||
}
|
||||
return resp.GroupInfos, nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupInfo(ctx context.Context, groupID string) (*sdkws.GroupInfo, error) {
|
||||
groups, err := g.GetGroupInfos(ctx, []string{groupID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return groups[0], nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupInfoMap(ctx context.Context, groupIDs []string, complete bool) (map[string]*sdkws.GroupInfo, error) {
|
||||
groups, err := g.GetGroupInfos(ctx, groupIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(groups, func(e *sdkws.GroupInfo) string {
|
||||
return e.GroupID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupMemberInfos(ctx context.Context, groupID string, userIDs []string, complete bool) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMembersInfo(ctx, &group.GetGroupMembersInfoReq{
|
||||
GroupID: groupID,
|
||||
Members: userIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if complete {
|
||||
if ids := utils.Single(userIDs, utils.Slice(resp.Members, func(e *sdkws.GroupMemberFullInfo) string {
|
||||
return e.UserID
|
||||
})); len(ids) > 0 {
|
||||
return nil, constant.ErrNotInGroupYet.Wrap(strings.Join(ids, ","))
|
||||
}
|
||||
}
|
||||
return resp.Members, nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupMemberInfo(ctx context.Context, groupID string, userID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||
members, err := g.GetGroupMemberInfos(ctx, groupID, []string{userID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return members[0], nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetGroupMemberInfoMap(ctx context.Context, groupID string, userIDs []string, complete bool) (map[string]*sdkws.GroupMemberFullInfo, error) {
|
||||
members, err := g.GetGroupMemberInfos(ctx, groupID, userIDs, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(members, func(e *sdkws.GroupMemberFullInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetOwnerAndAdminInfos(ctx context.Context, groupID string) ([]*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
GroupID: groupID,
|
||||
RoleLevels: []int32{constant.GroupOwner, constant.GroupAdmin},
|
||||
})
|
||||
return resp.Members, err
|
||||
}
|
||||
|
||||
func (g *GroupChecker) GetOwnerInfo(ctx context.Context, groupID string) (*sdkws.GroupMemberFullInfo, error) {
|
||||
cc, err := g.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := group.NewGroupClient(cc).GetGroupMemberRoleLevel(ctx, &group.GetGroupMemberRoleLevelReq{
|
||||
GroupID: groupID,
|
||||
RoleLevels: []int32{constant.GroupOwner},
|
||||
})
|
||||
return resp.Members[0], err
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
"context"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type MsgCheck struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func NewMsgCheck(zk discoveryRegistry.SvcDiscoveryRegistry) *MsgCheck {
|
||||
return &MsgCheck{zk: zk}
|
||||
}
|
||||
|
||||
func (m *MsgCheck) getConn() (*grpc.ClientConn, error) {
|
||||
return m.zk.GetConn(config.Config.RpcRegisterName.OpenImMsgName)
|
||||
}
|
||||
|
||||
func (m *MsgCheck) SendMsg(ctx context.Context, req *msg.SendMsgReq) (*msg.SendMsgResp, error) {
|
||||
cc, err := m.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := msg.NewMsgClient(cc).SendMsg(ctx, req)
|
||||
return resp, err
|
||||
}
|
||||
@ -1,11 +1,108 @@
|
||||
package check
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||
sdkws "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/proto/user"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"google.golang.org/grpc"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetUsersInfo(ctx context.Context, args ...interface{}) ([]*sdkws.UserInfo, error) {
|
||||
return nil, errors.New("TODO:GetUserInfo")
|
||||
//func GetUsersInfo(ctx context.Context, args ...interface{}) ([]*sdkws.UserInfo, error) {
|
||||
// return nil, errors.New("TODO:GetUserInfo")
|
||||
//}
|
||||
|
||||
func NewUserCheck(zk discoveryRegistry.SvcDiscoveryRegistry) *UserCheck {
|
||||
return &UserCheck{
|
||||
zk: zk,
|
||||
}
|
||||
}
|
||||
|
||||
type UserCheck struct {
|
||||
zk discoveryRegistry.SvcDiscoveryRegistry
|
||||
}
|
||||
|
||||
func (u *UserCheck) getConn() (*grpc.ClientConn, error) {
|
||||
return u.zk.GetConn(config.Config.RpcRegisterName.OpenImUserName)
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUsersInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.UserInfo, error) {
|
||||
cc, err := u.getConn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := user.NewUserClient(cc).GetDesignateUsers(ctx, &user.GetDesignateUsersReq{
|
||||
UserIDs: userIDs,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if complete {
|
||||
if ids := utils.Single(userIDs, utils.Slice(resp.UsersInfo, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
})); len(ids) > 0 {
|
||||
return nil, constant.ErrUserIDNotFound.Wrap(strings.Join(ids, ","))
|
||||
}
|
||||
}
|
||||
return resp.UsersInfo, nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUsersInfo(ctx context.Context, userID string) (*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUsersInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.UserInfo, error) {
|
||||
users, err := u.GetUsersInfos(ctx, userIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(users, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetPublicUserInfos(ctx context.Context, userIDs []string, complete bool) ([]*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetUsersInfos(ctx, userIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.Slice(users, func(e *sdkws.UserInfo) *sdkws.PublicUserInfo {
|
||||
return &sdkws.PublicUserInfo{
|
||||
UserID: e.UserID,
|
||||
Nickname: e.Nickname,
|
||||
FaceURL: e.FaceURL,
|
||||
Gender: e.Gender,
|
||||
Ex: e.Ex,
|
||||
}
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetPublicUserInfo(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetPublicUserInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return users[0], nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetPublicUserInfoMap(ctx context.Context, userIDs []string, complete bool) (map[string]*sdkws.PublicUserInfo, error) {
|
||||
users, err := u.GetPublicUserInfos(ctx, userIDs, complete)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (u *UserCheck) GetUserGlobalMsgRecvOpt(ctx context.Context, userID string) (int32, error) {
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,305 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"Open_IM/internal/common/check"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
utils2 "Open_IM/pkg/utils"
|
||||
"context"
|
||||
utils "github.com/OpenIMSDK/open_utils"
|
||||
)
|
||||
|
||||
type Check struct {
|
||||
user *check.UserCheck
|
||||
group *check.GroupChecker
|
||||
msg *check.MsgCheck
|
||||
friend *check.FriendChecker
|
||||
conversation *check.ConversationChecker
|
||||
}
|
||||
|
||||
func NewCheck(zk discoveryRegistry.SvcDiscoveryRegistry) *Check {
|
||||
return &Check{
|
||||
user: check.NewUserCheck(zk),
|
||||
group: check.NewGroupChecker(zk),
|
||||
msg: check.NewMsgCheck(zk),
|
||||
friend: check.NewFriendChecker(zk),
|
||||
conversation: check.NewConversationChecker(zk),
|
||||
}
|
||||
}
|
||||
|
||||
type NotificationMsg struct {
|
||||
SendID string
|
||||
RecvID string
|
||||
Content []byte // sdkws.TipsComm
|
||||
MsgFrom int32
|
||||
ContentType int32
|
||||
SessionType int32
|
||||
SenderNickname string
|
||||
SenderFaceURL string
|
||||
}
|
||||
|
||||
func (c *Check) Notification(ctx context.Context, notificationMsg *NotificationMsg) {
|
||||
var err error
|
||||
defer func() {
|
||||
tracelog.SetCtxDebug(ctx, utils2.GetFuncName(1), err, "notificationMsg", notificationMsg)
|
||||
}()
|
||||
|
||||
var req msg.SendMsgReq
|
||||
var msg sdkws.MsgData
|
||||
var offlineInfo sdkws.OfflinePushInfo
|
||||
var title, desc, ex string
|
||||
var pushSwitch, unReadCount bool
|
||||
var reliabilityLevel int
|
||||
msg.SendID = notificationMsg.SendID
|
||||
msg.RecvID = notificationMsg.RecvID
|
||||
msg.Content = notificationMsg.Content
|
||||
msg.MsgFrom = notificationMsg.MsgFrom
|
||||
msg.ContentType = notificationMsg.ContentType
|
||||
msg.SessionType = notificationMsg.SessionType
|
||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
msg.ClientMsgID = utils.GetMsgID(notificationMsg.SendID)
|
||||
msg.Options = make(map[string]bool, 7)
|
||||
msg.SenderNickname = notificationMsg.SenderNickname
|
||||
msg.SenderFaceURL = notificationMsg.SenderFaceURL
|
||||
switch notificationMsg.SessionType {
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
msg.RecvID = ""
|
||||
msg.GroupID = notificationMsg.RecvID
|
||||
}
|
||||
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
|
||||
reliabilityLevel = config.Config.Notification.GroupCreated.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupCreated.Conversation.UnreadCount
|
||||
case constant.GroupInfoSetNotification:
|
||||
pushSwitch = config.Config.Notification.GroupInfoSet.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupInfoSet.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupInfoSet.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupInfoSet.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupInfoSet.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupInfoSet.Conversation.UnreadCount
|
||||
case constant.JoinGroupApplicationNotification:
|
||||
pushSwitch = config.Config.Notification.JoinGroupApplication.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.JoinGroupApplication.OfflinePush.Title
|
||||
desc = config.Config.Notification.JoinGroupApplication.OfflinePush.Desc
|
||||
ex = config.Config.Notification.JoinGroupApplication.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.JoinGroupApplication.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.JoinGroupApplication.Conversation.UnreadCount
|
||||
case constant.MemberQuitNotification:
|
||||
pushSwitch = config.Config.Notification.MemberQuit.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberQuit.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberQuit.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberQuit.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberQuit.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberQuit.Conversation.UnreadCount
|
||||
case constant.GroupApplicationAcceptedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupApplicationAccepted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupApplicationAccepted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupApplicationAccepted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupApplicationAccepted.Conversation.UnreadCount
|
||||
case constant.GroupApplicationRejectedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupApplicationRejected.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupApplicationRejected.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupApplicationRejected.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupApplicationRejected.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupApplicationRejected.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupApplicationRejected.Conversation.UnreadCount
|
||||
case constant.GroupOwnerTransferredNotification:
|
||||
pushSwitch = config.Config.Notification.GroupOwnerTransferred.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupOwnerTransferred.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupOwnerTransferred.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupOwnerTransferred.Conversation.UnreadCount
|
||||
case constant.MemberKickedNotification:
|
||||
pushSwitch = config.Config.Notification.MemberKicked.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberKicked.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberKicked.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberKicked.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberKicked.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberKicked.Conversation.UnreadCount
|
||||
case constant.MemberInvitedNotification:
|
||||
pushSwitch = config.Config.Notification.MemberInvited.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberInvited.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberInvited.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberInvited.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberInvited.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberInvited.Conversation.UnreadCount
|
||||
case constant.MemberEnterNotification:
|
||||
pushSwitch = config.Config.Notification.MemberEnter.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.MemberEnter.OfflinePush.Title
|
||||
desc = config.Config.Notification.MemberEnter.OfflinePush.Desc
|
||||
ex = config.Config.Notification.MemberEnter.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.MemberEnter.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.MemberEnter.Conversation.UnreadCount
|
||||
case constant.UserInfoUpdatedNotification:
|
||||
pushSwitch = config.Config.Notification.UserInfoUpdated.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.UserInfoUpdated.OfflinePush.Title
|
||||
desc = config.Config.Notification.UserInfoUpdated.OfflinePush.Desc
|
||||
ex = config.Config.Notification.UserInfoUpdated.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.UserInfoUpdated.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.UserInfoUpdated.Conversation.UnreadCount
|
||||
case constant.FriendApplicationNotification:
|
||||
pushSwitch = config.Config.Notification.FriendApplication.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendApplication.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendApplication.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendApplication.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendApplication.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendApplication.Conversation.UnreadCount
|
||||
case constant.FriendApplicationApprovedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendApplicationApproved.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendApplicationApproved.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendApplicationApproved.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendApplicationApproved.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendApplicationApproved.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendApplicationApproved.Conversation.UnreadCount
|
||||
case constant.FriendApplicationRejectedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendApplicationRejected.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendApplicationRejected.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendApplicationRejected.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendApplicationRejected.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendApplicationRejected.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendApplicationRejected.Conversation.UnreadCount
|
||||
case constant.FriendAddedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendAdded.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendAdded.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendAdded.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendAdded.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendAdded.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendAdded.Conversation.UnreadCount
|
||||
case constant.FriendDeletedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendDeleted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendDeleted.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendDeleted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendDeleted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendDeleted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendDeleted.Conversation.UnreadCount
|
||||
case constant.FriendRemarkSetNotification:
|
||||
pushSwitch = config.Config.Notification.FriendRemarkSet.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendRemarkSet.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendRemarkSet.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendRemarkSet.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendRemarkSet.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendRemarkSet.Conversation.UnreadCount
|
||||
case constant.BlackAddedNotification:
|
||||
pushSwitch = config.Config.Notification.BlackAdded.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.BlackAdded.OfflinePush.Title
|
||||
desc = config.Config.Notification.BlackAdded.OfflinePush.Desc
|
||||
ex = config.Config.Notification.BlackAdded.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.BlackAdded.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.BlackAdded.Conversation.UnreadCount
|
||||
case constant.BlackDeletedNotification:
|
||||
pushSwitch = config.Config.Notification.BlackDeleted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.BlackDeleted.OfflinePush.Title
|
||||
desc = config.Config.Notification.BlackDeleted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.BlackDeleted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.BlackDeleted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.BlackDeleted.Conversation.UnreadCount
|
||||
case constant.ConversationOptChangeNotification:
|
||||
pushSwitch = config.Config.Notification.ConversationOptUpdate.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.ConversationOptUpdate.OfflinePush.Title
|
||||
desc = config.Config.Notification.ConversationOptUpdate.OfflinePush.Desc
|
||||
ex = config.Config.Notification.ConversationOptUpdate.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.ConversationOptUpdate.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.ConversationOptUpdate.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupDismissedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupDismissed.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupDismissed.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupDismissed.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupDismissed.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupDismissed.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupDismissed.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupCancelMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberCancelMuted.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberCancelMuted.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberCancelMuted.Conversation.UnreadCount
|
||||
|
||||
case constant.GroupMemberInfoSetNotification:
|
||||
pushSwitch = config.Config.Notification.GroupMemberInfoSet.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Title
|
||||
desc = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Desc
|
||||
ex = config.Config.Notification.GroupMemberInfoSet.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.GroupMemberInfoSet.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.GroupMemberInfoSet.Conversation.UnreadCount
|
||||
|
||||
case constant.ConversationPrivateChatNotification:
|
||||
pushSwitch = config.Config.Notification.ConversationSetPrivate.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.ConversationSetPrivate.OfflinePush.Title
|
||||
desc = config.Config.Notification.ConversationSetPrivate.OfflinePush.Desc
|
||||
ex = config.Config.Notification.ConversationSetPrivate.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.ConversationSetPrivate.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.ConversationSetPrivate.Conversation.UnreadCount
|
||||
case constant.FriendInfoUpdatedNotification:
|
||||
pushSwitch = config.Config.Notification.FriendInfoUpdated.OfflinePush.PushSwitch
|
||||
title = config.Config.Notification.FriendInfoUpdated.OfflinePush.Title
|
||||
desc = config.Config.Notification.FriendInfoUpdated.OfflinePush.Desc
|
||||
ex = config.Config.Notification.FriendInfoUpdated.OfflinePush.Ext
|
||||
reliabilityLevel = config.Config.Notification.FriendInfoUpdated.Conversation.ReliabilityLevel
|
||||
unReadCount = config.Config.Notification.FriendInfoUpdated.Conversation.UnreadCount
|
||||
case constant.DeleteMessageNotification:
|
||||
reliabilityLevel = constant.ReliableNotificationNoMsg
|
||||
case constant.ConversationUnreadNotification, constant.SuperGroupUpdateNotification:
|
||||
reliabilityLevel = constant.UnreliableNotification
|
||||
}
|
||||
switch reliabilityLevel {
|
||||
case constant.UnreliableNotification:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationNoMsg:
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsSenderConversationUpdate, false)
|
||||
case constant.ReliableNotificationMsg:
|
||||
|
||||
}
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsUnreadCount, unReadCount)
|
||||
utils.SetSwitchFromOptions(msg.Options, constant.IsOfflinePush, pushSwitch)
|
||||
offlineInfo.Title = title
|
||||
offlineInfo.Desc = desc
|
||||
offlineInfo.Ex = ex
|
||||
msg.OfflinePushInfo = &offlineInfo
|
||||
req.MsgData = &msg
|
||||
|
||||
_, err = c.msg.SendMsg(ctx, &req)
|
||||
}
|
||||
@ -0,0 +1,548 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
func (c *Check) setOpUserInfo(ctx context.Context, groupID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
opUserID := tracelog.GetOpUserID(ctx)
|
||||
if tokenverify.IsManagerUserID(opUserID) {
|
||||
user, err := c.user.GetUsersInfos(ctx, []string{opUserID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user[0].UserID
|
||||
groupMemberInfo.Nickname = user[0].Nickname
|
||||
groupMemberInfo.AppMangerLevel = user[0].AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user[0].FaceURL
|
||||
return nil
|
||||
}
|
||||
u, err := c.group.GetGroupMemberInfo(ctx, groupID, opUserID)
|
||||
if err == nil {
|
||||
*groupMemberInfo = *u
|
||||
return nil
|
||||
}
|
||||
user, err := c.user.GetUsersInfos(ctx, []string{opUserID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user[0].UserID
|
||||
groupMemberInfo.Nickname = user[0].Nickname
|
||||
groupMemberInfo.AppMangerLevel = user[0].AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user[0].FaceURL
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setGroupInfo(ctx context.Context, groupID string, groupInfo *sdkws.GroupInfo) error {
|
||||
group, err := c.group.GetGroupInfos(ctx, []string{groupID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*groupInfo = *group[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setGroupMemberInfo(ctx context.Context, groupID, userID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
groupMember, err := c.group.GetGroupMemberInfo(ctx, groupID, userID)
|
||||
if err == nil {
|
||||
*groupMemberInfo = *groupMember
|
||||
return nil
|
||||
}
|
||||
user, err := c.user.GetUsersInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user[0].UserID
|
||||
groupMemberInfo.Nickname = user[0].Nickname
|
||||
groupMemberInfo.AppMangerLevel = user[0].AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user[0].FaceURL
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setGroupOwnerInfo(ctx context.Context, groupID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
group, err := c.group.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
groupMember, err := c.group.GetGroupMemberInfo(ctx, groupID, group.OwnerUserID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*groupMemberInfo = *groupMember
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) setPublicUserInfo(ctx context.Context, userID string, publicUserInfo *sdkws.PublicUserInfo) error {
|
||||
user, err := c.user.GetPublicUserInfos(ctx, []string{userID}, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*publicUserInfo = *user[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Check) groupNotification(ctx context.Context, contentType int32, m proto.Message, sendID, groupID, recvUserID string) {
|
||||
var err error
|
||||
var tips sdkws.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
var nickname, toNickname string
|
||||
if sendID != "" {
|
||||
|
||||
from, err := c.user.GetUsersInfos(ctx, []string{sendID}, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
nickname = from[0].Nickname
|
||||
}
|
||||
if recvUserID != "" {
|
||||
to, err := c.user.GetUsersInfos(ctx, []string{recvUserID}, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
toNickname = to[0].Nickname
|
||||
}
|
||||
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.GroupCreatedNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.GroupCreated.DefaultTips.Tips
|
||||
case constant.GroupInfoSetNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.GroupInfoSet.DefaultTips.Tips
|
||||
case constant.JoinGroupApplicationNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.JoinGroupApplication.DefaultTips.Tips
|
||||
case constant.MemberQuitNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.MemberQuit.DefaultTips.Tips
|
||||
case constant.GroupApplicationAcceptedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupApplicationAccepted.DefaultTips.Tips
|
||||
case constant.GroupApplicationRejectedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupApplicationRejected.DefaultTips.Tips
|
||||
case constant.GroupOwnerTransferredNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupOwnerTransferred.DefaultTips.Tips
|
||||
case constant.MemberKickedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberKicked.DefaultTips.Tips
|
||||
case constant.MemberInvitedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
|
||||
case constant.MemberEnterNotification:
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberEnter.DefaultTips.Tips
|
||||
case constant.GroupDismissedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupDismissed.DefaultTips.Tips
|
||||
case constant.GroupMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMuted.DefaultTips.Tips
|
||||
case constant.GroupCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberInfoSetNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberInfoSet.DefaultTips.Tips
|
||||
case constant.GroupMemberSetToAdminNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberSetToAdmin.DefaultTips.Tips
|
||||
case constant.GroupMemberSetToOrdinaryUserNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberSetToOrdinary.DefaultTips.Tips
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
if groupID != "" {
|
||||
n.RecvID = groupID
|
||||
|
||||
group, err := c.group.GetGroupInfo(ctx, groupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch group.GroupType {
|
||||
case constant.NormalGroup:
|
||||
n.SessionType = constant.GroupChatType
|
||||
default:
|
||||
n.SessionType = constant.SuperGroupChatType
|
||||
}
|
||||
} else {
|
||||
n.RecvID = recvUserID
|
||||
n.SessionType = constant.SingleChatType
|
||||
}
|
||||
n.ContentType = contentType
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Notification(ctx, &n)
|
||||
}
|
||||
|
||||
// 创建群后调用
|
||||
func (c *Check) GroupCreatedNotification(ctx context.Context, groupID string, initMemberList []string) {
|
||||
GroupCreatedTips := sdkws.GroupCreatedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, GroupOwnerUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setOpUserInfo(ctx, groupID, GroupCreatedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
err := c.setGroupInfo(ctx, groupID, GroupCreatedTips.Group)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.setGroupOwnerInfo(ctx, groupID, GroupCreatedTips.GroupOwnerUser); err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range initMemberList {
|
||||
var groupMemberInfo sdkws.GroupMemberFullInfo
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, v, &groupMemberInfo); err != nil {
|
||||
continue
|
||||
}
|
||||
GroupCreatedTips.MemberList = append(GroupCreatedTips.MemberList, &groupMemberInfo)
|
||||
if len(GroupCreatedTips.MemberList) == constant.MaxNotificationNum {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
c.groupNotification(ctx, constant.GroupCreatedNotification, &GroupCreatedTips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
// 群信息改变后掉用
|
||||
// groupName := ""
|
||||
//
|
||||
// notification := ""
|
||||
// introduction := ""
|
||||
// faceURL := ""
|
||||
func (c *Check) GroupInfoSetNotification(ctx context.Context, groupID string, groupName, notification, introduction, faceURL string, needVerification *wrapperspb.Int32Value) {
|
||||
GroupInfoChangedTips := sdkws.GroupInfoSetTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, GroupInfoChangedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
GroupInfoChangedTips.Group.GroupName = groupName
|
||||
GroupInfoChangedTips.Group.Notification = notification
|
||||
GroupInfoChangedTips.Group.Introduction = introduction
|
||||
GroupInfoChangedTips.Group.FaceURL = faceURL
|
||||
if needVerification != nil {
|
||||
GroupInfoChangedTips.Group.NeedVerification = needVerification.Value
|
||||
}
|
||||
|
||||
if err := c.setOpUserInfo(ctx, groupID, GroupInfoChangedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupInfoSetNotification, &GroupInfoChangedTips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMutedNotification(ctx context.Context, groupID string) {
|
||||
tips := sdkws.GroupMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupCancelMutedNotification(ctx context.Context, groupID string) {
|
||||
tips := sdkws.GroupCancelMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupCancelMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberMutedNotification(ctx context.Context, groupID, groupMemberUserID string, mutedSeconds uint32) {
|
||||
tips := sdkws.GroupMemberMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
tips.MutedSeconds = mutedSeconds
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMemberMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberInfoSetNotification(ctx context.Context, groupID, groupMemberUserID string) {
|
||||
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.ChangedUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMemberInfoSetNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberRoleLevelChangeNotification(ctx context.Context, operationID, opUserID, groupID, groupMemberUserID string, notificationType int32) {
|
||||
if notificationType != constant.GroupMemberSetToAdminNotification && notificationType != constant.GroupMemberSetToOrdinaryUserNotification {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "invalid notificationType: ", notificationType)
|
||||
return
|
||||
}
|
||||
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.ChangedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, notificationType, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupMemberCancelMutedNotification(ctx context.Context, groupID, groupMemberUserID string) {
|
||||
tips := sdkws.GroupMemberCancelMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, tips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, tips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupMemberCancelMutedNotification, &tips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
// 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 (c *Check) JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGroupReq) {
|
||||
JoinGroupApplicationTips := sdkws.JoinGroupApplicationTips{Group: &sdkws.GroupInfo{}, Applicant: &sdkws.PublicUserInfo{}}
|
||||
err := c.setGroupInfo(ctx, req.GroupID, JoinGroupApplicationTips.Group)
|
||||
if err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
if err = c.setPublicUserInfo(ctx, tracelog.GetOpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
JoinGroupApplicationTips.ReqMsg = req.ReqMessage
|
||||
managerList, err := c.group.GetOwnerAndAdminInfos(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range managerList {
|
||||
c.groupNotification(ctx, constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, tracelog.GetOpUserID(ctx), "", v.UserID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Check) MemberQuitNotification(ctx context.Context, req *pbGroup.QuitGroupReq) {
|
||||
MemberQuitTips := sdkws.MemberQuitTips{Group: &sdkws.GroupInfo{}, QuitUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, MemberQuitTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, MemberQuitTips.QuitUser); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.groupNotification(ctx, constant.MemberQuitNotification, &MemberQuitTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
// message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
// }
|
||||
//
|
||||
// 处理进群请求后调用
|
||||
func (c *Check) GroupApplicationAcceptedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationAcceptedTips := sdkws.GroupApplicationAcceptedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, GroupApplicationAcceptedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, GroupApplicationAcceptedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
c.groupNotification(ctx, constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, tracelog.GetOpUserID(ctx), "", req.FromUserID)
|
||||
adminList, err := c.group.GetOwnerAndAdminInfos(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range adminList {
|
||||
if v.UserID == tracelog.GetOpUserID(ctx) {
|
||||
continue
|
||||
}
|
||||
GroupApplicationAcceptedTips.ReceiverAs = 1
|
||||
c.groupNotification(ctx, constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, tracelog.GetOpUserID(ctx), "", v.UserID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Check) GroupApplicationRejectedNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationRejectedTips := sdkws.GroupApplicationRejectedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, HandleMsg: req.HandledMsg}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, GroupApplicationRejectedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, GroupApplicationRejectedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, tracelog.GetOpUserID(ctx), "", req.FromUserID)
|
||||
adminList, err := c.group.GetOwnerAndAdminInfos(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range adminList {
|
||||
if v.UserID == tracelog.GetOpUserID(ctx) {
|
||||
continue
|
||||
}
|
||||
GroupApplicationRejectedTips.ReceiverAs = 1
|
||||
c.groupNotification(ctx, constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, tracelog.GetOpUserID(ctx), "", v.UserID)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Check) GroupOwnerTransferredNotification(ctx context.Context, req *pbGroup.TransferGroupOwnerReq) {
|
||||
GroupOwnerTransferredTips := sdkws.GroupOwnerTransferredTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, NewGroupOwner: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, GroupOwnerTransferredTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, GroupOwnerTransferredTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, req.GroupID, req.NewOwnerUserID, GroupOwnerTransferredTips.NewGroupOwner); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupOwnerTransferredNotification, &GroupOwnerTransferredTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) GroupDismissedNotification(ctx context.Context, req *pbGroup.DismissGroupReq) {
|
||||
tips := sdkws.GroupDismissedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, tips.Group); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, tips.OpUser); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.GroupDismissedNotification, &tips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
// message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
// }
|
||||
//
|
||||
// 被踢后调用
|
||||
func (c *Check) MemberKickedNotification(ctx context.Context, req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
MemberKickedTips := sdkws.MemberKickedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, MemberKickedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, req.GroupID, MemberKickedTips.OpUser); err != nil {
|
||||
return
|
||||
}
|
||||
for _, v := range kickedUserIDList {
|
||||
var groupMemberInfo sdkws.GroupMemberFullInfo
|
||||
if err := c.setGroupMemberInfo(ctx, req.GroupID, v, &groupMemberInfo); err != nil {
|
||||
continue
|
||||
}
|
||||
MemberKickedTips.KickedUserList = append(MemberKickedTips.KickedUserList, &groupMemberInfo)
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberKickedNotification, &MemberKickedTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
//
|
||||
//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 (c *Check) MemberInvitedNotification(ctx context.Context, groupID, reason string, invitedUserIDList []string) {
|
||||
MemberInvitedTips := sdkws.MemberInvitedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, MemberInvitedTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setOpUserInfo(ctx, groupID, MemberInvitedTips.OpUser); err != nil {
|
||||
|
||||
return
|
||||
}
|
||||
for _, v := range invitedUserIDList {
|
||||
var groupMemberInfo sdkws.GroupMemberFullInfo
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, v, &groupMemberInfo); err != nil {
|
||||
continue
|
||||
}
|
||||
MemberInvitedTips.InvitedUserList = append(MemberInvitedTips.InvitedUserList, &groupMemberInfo)
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberInvitedNotification, &MemberInvitedTips, tracelog.GetOpUserID(ctx), groupID, "")
|
||||
}
|
||||
|
||||
// 群成员主动申请进群,管理员同意后调用,
|
||||
func (c *Check) MemberEnterNotification(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
|
||||
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, req.GroupID, MemberEnterTips.Group); err != nil {
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, req.GroupID, req.FromUserID, MemberEnterTips.EntrantUser); err != nil {
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberEnterNotification, &MemberEnterTips, tracelog.GetOpUserID(ctx), req.GroupID, "")
|
||||
}
|
||||
|
||||
func (c *Check) MemberEnterDirectlyNotification(ctx context.Context, groupID string, entrantUserID string, operationID string) {
|
||||
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := c.setGroupInfo(ctx, groupID, MemberEnterTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID, MemberEnterTips.Group)
|
||||
return
|
||||
}
|
||||
if err := c.setGroupMemberInfo(ctx, groupID, entrantUserID, MemberEnterTips.EntrantUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, entrantUserID, MemberEnterTips.EntrantUser)
|
||||
return
|
||||
}
|
||||
c.groupNotification(ctx, constant.MemberEnterNotification, &MemberEnterTips, entrantUserID, groupID, "")
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
"context"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func (c *Check) DeleteMessageNotification(ctx context.Context, userID string, seqList []uint32, operationID string) {
|
||||
DeleteMessageTips := sdkws.DeleteMessageTips{UserID: userID, SeqList: seqList}
|
||||
c.MessageNotification(ctx, userID, userID, constant.DeleteMessageNotification, &DeleteMessageTips)
|
||||
}
|
||||
|
||||
func (c *Check) MessageNotification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message) {
|
||||
var err error
|
||||
var tips sdkws.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
n.RecvID = recvID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Notification(ctx, &n)
|
||||
}
|
||||
@ -1,23 +1,19 @@
|
||||
package msg
|
||||
package notification
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
//sdk "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
//"github.com/golang/protobuf/jsonpb"
|
||||
//"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func SuperGroupNotification(operationID, sendID, recvID string) {
|
||||
func (c *Check) SuperGroupNotification(ctx context.Context, sendID, recvID string) {
|
||||
n := &NotificationMsg{
|
||||
SendID: sendID,
|
||||
RecvID: recvID,
|
||||
MsgFrom: constant.SysMsgType,
|
||||
ContentType: constant.SuperGroupUpdateNotification,
|
||||
SessionType: constant.SingleChatType,
|
||||
OperationID: operationID,
|
||||
}
|
||||
log.NewInfo(operationID, utils.GetSelfFuncName(), string(n.Content))
|
||||
Notification(n)
|
||||
c.Notification(ctx, n)
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package notification
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
"context"
|
||||
)
|
||||
|
||||
// send to myself
|
||||
func (c *Check) UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) {
|
||||
selfInfoUpdatedTips := sdkws.UserInfoUpdatedTips{UserID: changedUserID}
|
||||
c.friendNotification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips)
|
||||
}
|
||||
@ -1,89 +1,155 @@
|
||||
package msggateway
|
||||
|
||||
import (
|
||||
cbApi "Open_IM/pkg/callback_struct"
|
||||
cbapi "Open_IM/pkg/callbackstruct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/http"
|
||||
http2 "net/http"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
func callbackUserOnline(operationID, userID string, platformID int, token string, isAppBackground bool, connID string) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
||||
func url() string {
|
||||
return config.Config.Callback.CallbackUrl
|
||||
}
|
||||
|
||||
func CallbackUserOnline(ctx context.Context, userID string, platformID int, isAppBackground bool, connID string) error {
|
||||
if !config.Config.Callback.CallbackUserOnline.Enable {
|
||||
return callbackResp
|
||||
return nil
|
||||
}
|
||||
callbackUserOnlineReq := cbApi.CallbackUserOnlineReq{
|
||||
Token: token,
|
||||
UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
|
||||
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
|
||||
req := cbapi.CallbackUserOnlineReq{
|
||||
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
|
||||
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
|
||||
CallbackCommand: constant.CallbackUserOnlineCommand,
|
||||
OperationID: operationID,
|
||||
PlatformID: int32(platformID),
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
PlatformID: platformID,
|
||||
Platform: constant.PlatformIDToName(platformID),
|
||||
},
|
||||
UserID: userID,
|
||||
},
|
||||
Seq: int(time.Now().UnixNano() / 1e6),
|
||||
Seq: time.Now().UnixMilli(),
|
||||
IsAppBackground: isAppBackground,
|
||||
ConnID: connID,
|
||||
}
|
||||
callbackUserOnlineResp := &cbApi.CallbackUserOnlineResp{CommonCallbackResp: &callbackResp}
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOnlineCommand, callbackUserOnlineReq, callbackUserOnlineResp, config.Config.Callback.CallbackUserOnline.CallbackTimeOut); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
}
|
||||
return callbackResp
|
||||
resp := cbapi.CommonCallbackResp{}
|
||||
return http.CallBackPostReturn(url(), &req, &resp, config.Config.Callback.CallbackUserOnline)
|
||||
}
|
||||
|
||||
func callbackUserOffline(operationID, userID string, platformID int, connID string) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
||||
func CallbackUserOffline(ctx context.Context, userID string, platformID int, connID string) error {
|
||||
if !config.Config.Callback.CallbackUserOffline.Enable {
|
||||
return callbackResp
|
||||
return nil
|
||||
}
|
||||
callbackOfflineReq := cbApi.CallbackUserOfflineReq{
|
||||
UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
|
||||
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
|
||||
req := &cbapi.CallbackUserOfflineReq{
|
||||
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
|
||||
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
|
||||
CallbackCommand: constant.CallbackUserOfflineCommand,
|
||||
OperationID: operationID,
|
||||
PlatformID: int32(platformID),
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
PlatformID: platformID,
|
||||
Platform: constant.PlatformIDToName(platformID),
|
||||
},
|
||||
UserID: userID,
|
||||
},
|
||||
Seq: int(time.Now().UnixNano() / 1e6),
|
||||
Seq: time.Now().UnixMilli(),
|
||||
ConnID: connID,
|
||||
}
|
||||
callbackUserOfflineResp := &cbApi.CallbackUserOfflineResp{CommonCallbackResp: &callbackResp}
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOfflineCommand, callbackOfflineReq, callbackUserOfflineResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
}
|
||||
return callbackResp
|
||||
resp := &cbapi.CallbackUserOfflineResp{}
|
||||
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackUserOffline)
|
||||
}
|
||||
|
||||
func callbackUserKickOff(operationID string, userID string, platformID int) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
||||
func CallbackUserKickOff(ctx context.Context, userID string, platformID int) error {
|
||||
if !config.Config.Callback.CallbackUserKickOff.Enable {
|
||||
return callbackResp
|
||||
return nil
|
||||
}
|
||||
callbackUserKickOffReq := cbApi.CallbackUserKickOffReq{
|
||||
UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
|
||||
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
|
||||
req := &cbapi.CallbackUserKickOffReq{
|
||||
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
|
||||
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
|
||||
CallbackCommand: constant.CallbackUserKickOffCommand,
|
||||
OperationID: operationID,
|
||||
PlatformID: int32(platformID),
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
PlatformID: platformID,
|
||||
Platform: constant.PlatformIDToName(platformID),
|
||||
},
|
||||
UserID: userID,
|
||||
},
|
||||
Seq: int(time.Now().UnixNano() / 1e6),
|
||||
}
|
||||
callbackUserKickOffResp := &cbApi.CallbackUserKickOffResp{CommonCallbackResp: &callbackResp}
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserKickOffCommand, callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
Seq: time.Now().UnixMilli(),
|
||||
}
|
||||
return callbackResp
|
||||
resp := &cbapi.CommonCallbackResp{}
|
||||
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackUserOffline)
|
||||
}
|
||||
|
||||
//func callbackUserOnline(operationID, userID string, platformID int, token string, isAppBackground bool, connID string) cbApi.CommonCallbackResp {
|
||||
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
||||
// if !config.Config.Callback.CallbackUserOnline.Enable {
|
||||
// return callbackResp
|
||||
// }
|
||||
// callbackUserOnlineReq := cbApi.CallbackUserOnlineReq{
|
||||
// Token: token,
|
||||
// UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
|
||||
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
|
||||
// CallbackCommand: constant.CallbackUserOnlineCommand,
|
||||
// OperationID: operationID,
|
||||
// PlatformID: int32(platformID),
|
||||
// Platform: constant.PlatformIDToName(platformID),
|
||||
// },
|
||||
// UserID: userID,
|
||||
// },
|
||||
// Seq: int(time.Now().UnixNano() / 1e6),
|
||||
// IsAppBackground: isAppBackground,
|
||||
// ConnID: connID,
|
||||
// }
|
||||
// callbackUserOnlineResp := &cbApi.CallbackUserOnlineResp{CommonCallbackResp: &callbackResp}
|
||||
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOnlineCommand, callbackUserOnlineReq, callbackUserOnlineResp, config.Config.Callback.CallbackUserOnline.CallbackTimeOut); err != nil {
|
||||
// callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
// callbackResp.ErrMsg = err.Error()
|
||||
// }
|
||||
// return callbackResp
|
||||
//}
|
||||
//func callbackUserOffline(operationID, userID string, platformID int, connID string) cbApi.CommonCallbackResp {
|
||||
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
||||
// if !config.Config.Callback.CallbackUserOffline.Enable {
|
||||
// return callbackResp
|
||||
// }
|
||||
// callbackOfflineReq := cbApi.CallbackUserOfflineReq{
|
||||
// UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
|
||||
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
|
||||
// CallbackCommand: constant.CallbackUserOfflineCommand,
|
||||
// OperationID: operationID,
|
||||
// PlatformID: int32(platformID),
|
||||
// Platform: constant.PlatformIDToName(platformID),
|
||||
// },
|
||||
// UserID: userID,
|
||||
// },
|
||||
// Seq: int(time.Now().UnixNano() / 1e6),
|
||||
// ConnID: connID,
|
||||
// }
|
||||
// callbackUserOfflineResp := &cbApi.CallbackUserOfflineResp{CommonCallbackResp: &callbackResp}
|
||||
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOfflineCommand, callbackOfflineReq, callbackUserOfflineResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil {
|
||||
// callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
// callbackResp.ErrMsg = err.Error()
|
||||
// }
|
||||
// return callbackResp
|
||||
//}
|
||||
//func callbackUserKickOff(operationID string, userID string, platformID int) cbApi.CommonCallbackResp {
|
||||
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
||||
// if !config.Config.Callback.CallbackUserKickOff.Enable {
|
||||
// return callbackResp
|
||||
// }
|
||||
// callbackUserKickOffReq := cbApi.CallbackUserKickOffReq{
|
||||
// UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
|
||||
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
|
||||
// CallbackCommand: constant.CallbackUserKickOffCommand,
|
||||
// OperationID: operationID,
|
||||
// PlatformID: int32(platformID),
|
||||
// Platform: constant.PlatformIDToName(platformID),
|
||||
// },
|
||||
// UserID: userID,
|
||||
// },
|
||||
// Seq: int(time.Now().UnixNano() / 1e6),
|
||||
// }
|
||||
// callbackUserKickOffResp := &cbApi.CallbackUserKickOffResp{CommonCallbackResp: &callbackResp}
|
||||
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserKickOffCommand, callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil {
|
||||
// callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
// callbackResp.ErrMsg = err.Error()
|
||||
// }
|
||||
// return callbackResp
|
||||
//}
|
||||
|
||||
@ -0,0 +1,148 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/envoyproxy/protoc-gen-validate/validate"
|
||||
"github.com/go-playground/validator/v10"
|
||||
"open_im_sdk/pkg/log"
|
||||
"open_im_sdk/pkg/utils"
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// MessageText is for UTF-8 encoded text messages like JSON.
|
||||
MessageText = iota + 1
|
||||
// MessageBinary is for binary messages like protobufs.
|
||||
MessageBinary
|
||||
// CloseMessage denotes a close control message. The optional message
|
||||
// payload contains a numeric code and text. Use the FormatCloseMessage
|
||||
// function to format a close message payload.
|
||||
CloseMessage = 8
|
||||
|
||||
// PingMessage denotes a ping control message. The optional message payload
|
||||
// is UTF-8 encoded text.
|
||||
PingMessage = 9
|
||||
|
||||
// PongMessage denotes a pong control message. The optional message payload
|
||||
// is UTF-8 encoded text.
|
||||
PongMessage = 10
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
w *sync.Mutex
|
||||
conn LongConn
|
||||
PlatformID int32
|
||||
PushedMaxSeq uint32
|
||||
IsCompress bool
|
||||
userID string
|
||||
IsBackground bool
|
||||
token string
|
||||
connID string
|
||||
onlineAt int64 // 上线时间戳(毫秒)
|
||||
handler MessageHandler
|
||||
unregisterChan chan *Client
|
||||
compressor Compressor
|
||||
encoder Encoder
|
||||
userContext UserConnContext
|
||||
validate *validator.Validate
|
||||
}
|
||||
|
||||
func newClient( conn LongConn,isCompress bool, userID string, isBackground bool, token string,
|
||||
connID string, onlineAt int64, handler MessageHandler,unregisterChan chan *Client) *Client {
|
||||
return &Client{
|
||||
conn: conn,
|
||||
IsCompress: isCompress,
|
||||
userID: userID, IsBackground:
|
||||
isBackground, token: token,
|
||||
connID: connID,
|
||||
onlineAt: onlineAt,
|
||||
handler: handler,
|
||||
unregisterChan: unregisterChan,
|
||||
}
|
||||
}
|
||||
func(c *Client) readMessage(){
|
||||
defer func() {
|
||||
if r:=recover(); r != nil {
|
||||
fmt.Println("socket have panic err:", r, string(debug.Stack()))
|
||||
}
|
||||
//c.close()
|
||||
}()
|
||||
var returnErr error
|
||||
for {
|
||||
messageType, message, returnErr := c.conn.ReadMessage()
|
||||
if returnErr!=nil{
|
||||
break
|
||||
}
|
||||
switch messageType {
|
||||
case PingMessage:
|
||||
case PongMessage:
|
||||
case CloseMessage:
|
||||
return
|
||||
case MessageText:
|
||||
case MessageBinary:
|
||||
if len(message) == 0 {
|
||||
continue
|
||||
}
|
||||
returnErr = c.handleMessage(message)
|
||||
if returnErr!=nil{
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
func (c *Client) handleMessage(message []byte)error {
|
||||
if c.IsCompress {
|
||||
var decompressErr error
|
||||
message,decompressErr = c.compressor.DeCompress(message)
|
||||
if decompressErr != nil {
|
||||
return utils.Wrap(decompressErr,"")
|
||||
}
|
||||
}
|
||||
var binaryReq Req
|
||||
err := c.encoder.Decode(message, &binaryReq)
|
||||
if err != nil {
|
||||
return utils.Wrap(err,"")
|
||||
}
|
||||
if err := c.validate.Struct(binaryReq); err != nil {
|
||||
return utils.Wrap(err,"")
|
||||
}
|
||||
if binaryReq.SendID != c.userID {
|
||||
return errors.New("exception conn userID not same to req userID")
|
||||
}
|
||||
ctx:=context.Background()
|
||||
ctx =context.WithValue(ctx,"operationID",binaryReq.OperationID)
|
||||
ctx = context.WithValue(ctx,"userID",binaryReq.SendID)
|
||||
var messageErr error
|
||||
var resp []byte
|
||||
switch binaryReq.ReqIdentifier {
|
||||
case constant.WSGetNewestSeq:
|
||||
resp,messageErr=c.handler.GetSeq(ctx,binaryReq)
|
||||
case constant.WSSendMsg:
|
||||
resp,messageErr=c.handler.SendMessage(ctx,binaryReq)
|
||||
case constant.WSSendSignalMsg:
|
||||
resp,messageErr=c.handler.SendSignalMessage(ctx,binaryReq)
|
||||
case constant.WSPullMsgBySeqList:
|
||||
resp,messageErr=c.handler.PullMessageBySeqList(ctx,binaryReq)
|
||||
case constant.WsLogoutMsg:
|
||||
resp,messageErr=c.handler.UserLogout(ctx,binaryReq)
|
||||
case constant.WsSetBackgroundStatus:
|
||||
resp,messageErr=c.handler.SetUserDeviceBackground(ctx,binaryReq)
|
||||
default:
|
||||
return errors.New(fmt.Sprintf("ReqIdentifier failed,sendID:%d,msgIncr:%s,reqIdentifier:%s",binaryReq.SendID,binaryReq.MsgIncr,binaryReq.ReqIdentifier))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
func (c *Client) close() {
|
||||
|
||||
}
|
||||
func () {
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io/ioutil"
|
||||
"open_im_sdk/pkg/utils"
|
||||
)
|
||||
|
||||
type Compressor interface {
|
||||
Compress(rawData []byte) ([]byte, error)
|
||||
DeCompress(compressedData []byte) ([]byte, error)
|
||||
}
|
||||
type GzipCompressor struct {
|
||||
compressProtocol string
|
||||
}
|
||||
|
||||
func NewGzipCompressor() *GzipCompressor {
|
||||
return &GzipCompressor{compressProtocol: "gzip"}
|
||||
}
|
||||
func (g *GzipCompressor) Compress(rawData []byte) ([]byte, error) {
|
||||
gzipBuffer := bytes.Buffer{}
|
||||
gz := gzip.NewWriter(&gzipBuffer)
|
||||
if _, err := gz.Write(rawData); err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
if err := gz.Close(); err != nil {
|
||||
return nil, utils.Wrap(err, "")
|
||||
}
|
||||
return gzipBuffer.Bytes(), nil
|
||||
}
|
||||
func (g *GzipCompressor) DeCompress(compressedData []byte) ([]byte, error) {
|
||||
buff := bytes.NewBuffer(compressedData)
|
||||
reader, err := gzip.NewReader(buff)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "NewReader failed")
|
||||
}
|
||||
compressedData, err = ioutil.ReadAll(reader)
|
||||
if err != nil {
|
||||
return nil, utils.Wrap(err, "ReadAll failed")
|
||||
}
|
||||
_ = reader.Close()
|
||||
return compressedData, nil
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
package new
|
||||
|
||||
import "net/http"
|
||||
|
||||
type UserConnContext struct {
|
||||
RespWriter http.ResponseWriter
|
||||
Req *http.Request
|
||||
Path string
|
||||
Method string
|
||||
RemoteAddr string
|
||||
}
|
||||
|
||||
func newContext(respWriter http.ResponseWriter, req *http.Request) *UserConnContext {
|
||||
return &UserConnContext{
|
||||
RespWriter: respWriter,
|
||||
Req: req,
|
||||
Path: req.URL.Path,
|
||||
Method: req.Method,
|
||||
RemoteAddr: req.RemoteAddr,
|
||||
}
|
||||
}
|
||||
func (c *UserConnContext) Query(key string) string {
|
||||
return c.Req.URL.Query().Get(key)
|
||||
}
|
||||
func (c *UserConnContext) GetHeader(key string) string {
|
||||
return c.Req.Header.Get(key)
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"open_im_sdk/pkg/utils"
|
||||
)
|
||||
|
||||
type Encoder interface {
|
||||
Encode(data interface{}) ([]byte, error)
|
||||
Decode(encodeData []byte, decodeData interface{}) error
|
||||
}
|
||||
|
||||
type GobEncoder struct {
|
||||
}
|
||||
|
||||
func NewGobEncoder() *GobEncoder {
|
||||
return &GobEncoder{}
|
||||
}
|
||||
func (g *GobEncoder) Encode(data interface{}) ([]byte, error) {
|
||||
buff := bytes.Buffer{}
|
||||
enc := gob.NewEncoder(&buff)
|
||||
err := enc.Encode(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buff.Bytes(), nil
|
||||
}
|
||||
func (g *GobEncoder) Decode(encodeData []byte, decodeData interface{}) error {
|
||||
buff := bytes.NewBuffer(encodeData)
|
||||
dec := gob.NewDecoder(buff)
|
||||
err := dec.Decode(decodeData)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LongConn interface {
|
||||
//Close this connection
|
||||
Close() error
|
||||
//Write message to connection,messageType means data type,can be set binary(2) and text(1).
|
||||
WriteMessage(messageType int, message []byte) error
|
||||
//Read message from connection.
|
||||
ReadMessage() (int, []byte, error)
|
||||
//SetReadTimeout sets the read deadline on the underlying network connection,
|
||||
//after a read has timed out, will return an error.
|
||||
SetReadTimeout(timeout int) error
|
||||
//SetWriteTimeout sets the write deadline when send message,when read has timed out,will return error.
|
||||
SetWriteTimeout(timeout int) error
|
||||
//Try to dial a connection,url must set auth args,header can control compress data
|
||||
Dial(urlStr string, requestHeader http.Header) (*http.Response, error)
|
||||
//Whether the connection of the current long connection is nil
|
||||
IsNil() bool
|
||||
//Set the connection of the current long connection to nil
|
||||
SetConnNil()
|
||||
//Check the connection of the current and when it was sent are the same
|
||||
CheckSendConnDiffNow() bool
|
||||
}
|
||||
type GWebSocket struct {
|
||||
protocolType int
|
||||
conn *websocket.Conn
|
||||
}
|
||||
|
||||
func NewDefault(protocolType int) *GWebSocket {
|
||||
return &GWebSocket{protocolType: protocolType}
|
||||
}
|
||||
func (d *GWebSocket) Close() error {
|
||||
return d.conn.Close()
|
||||
}
|
||||
|
||||
func (d *GWebSocket) WriteMessage(messageType int, message []byte) error {
|
||||
d.setSendConn(d.conn)
|
||||
return d.conn.WriteMessage(messageType, message)
|
||||
}
|
||||
|
||||
func (d *GWebSocket) setSendConn(sendConn *websocket.Conn) {
|
||||
d.sendConn = sendConn
|
||||
}
|
||||
|
||||
func (d *GWebSocket) ReadMessage() (int, []byte, error) {
|
||||
return d.conn.ReadMessage()
|
||||
}
|
||||
func (d *GWebSocket) SetReadTimeout(timeout int) error {
|
||||
return d.conn.SetReadDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
|
||||
}
|
||||
|
||||
func (d *GWebSocket) SetWriteTimeout(timeout int) error {
|
||||
return d.conn.SetWriteDeadline(time.Now().Add(time.Duration(timeout) * time.Second))
|
||||
}
|
||||
|
||||
func (d *GWebSocket) Dial(urlStr string, requestHeader http.Header) (*http.Response, error) {
|
||||
conn, httpResp, err := websocket.DefaultDialer.Dial(urlStr, requestHeader)
|
||||
if err == nil {
|
||||
d.conn = conn
|
||||
}
|
||||
return httpResp, err
|
||||
|
||||
}
|
||||
|
||||
func (d *GWebSocket) IsNil() bool {
|
||||
if d.conn != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (d *GWebSocket) SetConnNil() {
|
||||
d.conn = nil
|
||||
}
|
||||
func (d *GWebSocket) CheckSendConnDiffNow() bool {
|
||||
return d.conn == d.sendConn
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package new
|
||||
|
||||
import "context"
|
||||
|
||||
type Req struct {
|
||||
ReqIdentifier int32 `json:"reqIdentifier" validate:"required"`
|
||||
Token string `json:"token" `
|
||||
SendID string `json:"sendID" validate:"required"`
|
||||
OperationID string `json:"operationID" validate:"required"`
|
||||
MsgIncr string `json:"msgIncr" validate:"required"`
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
type MessageHandler interface {
|
||||
GetSeq(context context.Context, data Req) ([]byte, error)
|
||||
SendMessage(context context.Context, data Req) ([]byte, error)
|
||||
SendSignalMessage(context context.Context, data Req) ([]byte, error)
|
||||
PullMessageBySeqList(context context.Context, data Req) ([]byte, error)
|
||||
UserLogout(context context.Context, data Req) ([]byte, error)
|
||||
SetUserDeviceBackground(context context.Context, data Req) ([]byte, error)
|
||||
}
|
||||
|
||||
var _ MessageHandler = (*GrpcHandler)(nil)
|
||||
|
||||
type GrpcHandler struct {
|
||||
}
|
||||
|
||||
func (g GrpcHandler) GetSeq(context context.Context, data Req) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g GrpcHandler) SendMessage(context context.Context, data Req) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g GrpcHandler) SendSignalMessage(context context.Context, data Req) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g GrpcHandler) PullMessageBySeqList(context context.Context, data Req) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g GrpcHandler) UserLogout(context context.Context, data Req) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (g GrpcHandler) SetUserDeviceBackground(context context.Context, data Req) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
package new
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"open_im_sdk/pkg/utils"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LongConnServer interface {
|
||||
Run() error
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
rpcPort int
|
||||
wsMaxConnNum int
|
||||
longConnServer *LongConnServer
|
||||
rpcServer *RpcServer
|
||||
}
|
||||
type WsServer struct {
|
||||
port int
|
||||
wsMaxConnNum int
|
||||
wsUpGrader *websocket.Upgrader
|
||||
registerChan chan *Client
|
||||
unregisterChan chan *Client
|
||||
clients *UserMap
|
||||
clientPool sync.Pool
|
||||
onlineUserNum int64
|
||||
onlineUserConnNum int64
|
||||
compressor Compressor
|
||||
handler MessageHandler
|
||||
}
|
||||
|
||||
func newWsServer(opts ...Option) (*WsServer, error) {
|
||||
var config configs
|
||||
for _, o := range opts {
|
||||
o(&config)
|
||||
}
|
||||
if config.port < 1024 {
|
||||
return nil, errors.New("port not allow to listen")
|
||||
|
||||
}
|
||||
return &WsServer{
|
||||
port: config.port,
|
||||
wsMaxConnNum: config.maxConnNum,
|
||||
wsUpGrader: &websocket.Upgrader{
|
||||
HandshakeTimeout: config.handshakeTimeout,
|
||||
ReadBufferSize: config.messageMaxMsgLength,
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
},
|
||||
clientPool: sync.Pool{
|
||||
New: func() interface{} {
|
||||
return new(Client)
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
func (ws *WsServer) Run() error {
|
||||
http.HandleFunc("/", ws.wsHandler) //Get request from client to handle by wsHandler
|
||||
return http.ListenAndServe(":"+utils.IntToString(ws.port), nil) //Start listening
|
||||
|
||||
}
|
||||
func (ws *WsServer) wsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
context := newContext(w, r)
|
||||
if isPass, compression := ws.headerCheck(w, r, operationID); isPass {
|
||||
conn, err := ws.wsUpGrader.Upgrade(w, r, nil) //Conn is obtained through the upgraded escalator
|
||||
if err != nil {
|
||||
log.Error(operationID, "upgrade http conn err", err.Error(), query)
|
||||
return
|
||||
} else {
|
||||
newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0, compression, query["sendID"][0], false, query["token"][0], conn.RemoteAddr().String() + "_" + strconv.Itoa(int(utils.GetCurrentTimestampByMill()))}
|
||||
userCount++
|
||||
ws.addUserConn(query["sendID"][0], utils.StringToInt(query["platformID"][0]), newConn, query["token"][0], newConn.connID, operationID)
|
||||
go ws.readMsg(newConn)
|
||||
}
|
||||
} else {
|
||||
log.Error(operationID, "headerCheck failed ")
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package new
|
||||
|
||||
import "time"
|
||||
|
||||
type Option func(opt *configs)
|
||||
type configs struct {
|
||||
//长连接监听端口
|
||||
port int
|
||||
//长连接允许最大链接数
|
||||
maxConnNum int
|
||||
//连接握手超时时间
|
||||
handshakeTimeout time.Duration
|
||||
//允许消息最大长度
|
||||
messageMaxMsgLength int
|
||||
}
|
||||
|
||||
func WithPort(port int) Option {
|
||||
return func(opt *configs) {
|
||||
opt.port = port
|
||||
}
|
||||
}
|
||||
func WithMaxConnNum(num int) Option {
|
||||
return func(opt *configs) {
|
||||
opt.maxConnNum = num
|
||||
}
|
||||
}
|
||||
func WithHandshakeTimeout(t time.Duration) Option {
|
||||
return func(opt *configs) {
|
||||
opt.handshakeTimeout = t
|
||||
}
|
||||
}
|
||||
func WithMessageMaxMsgLength(length int) Option {
|
||||
return func(opt *configs) {
|
||||
opt.messageMaxMsgLength = length
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package new
|
||||
|
||||
import "sync"
|
||||
|
||||
type UserMap struct {
|
||||
m sync.Map
|
||||
}
|
||||
|
||||
func newUserMap() *UserMap {
|
||||
return &UserMap{}
|
||||
}
|
||||
func (u *UserMap) GetAll(key string) []*Client {
|
||||
allClients, ok := u.m.Load(key)
|
||||
if ok {
|
||||
return allClients.([]*Client)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (u *UserMap) Get(key string, platformID int32) (*Client, bool) {
|
||||
allClients, existed := u.m.Load(key)
|
||||
if existed {
|
||||
for _, client := range allClients.([]*Client) {
|
||||
if client.PlatformID == platformID {
|
||||
return client, existed
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
return nil, existed
|
||||
}
|
||||
func (u *UserMap) Set(key string, v *Client) {
|
||||
allClients, existed := u.m.Load(key)
|
||||
if existed {
|
||||
oldClients := allClients.([]*Client)
|
||||
oldClients = append(oldClients, v)
|
||||
u.m.Store(key, oldClients)
|
||||
} else {
|
||||
clients := make([]*Client, 3)
|
||||
clients = append(clients, v)
|
||||
u.m.Store(key, clients)
|
||||
}
|
||||
}
|
||||
func (u *UserMap) delete(key string, platformID int32) {
|
||||
allClients, existed := u.m.Load(key)
|
||||
if existed {
|
||||
oldClients := allClients.([]*Client)
|
||||
|
||||
a := make([]*Client, len(oldClients))
|
||||
for _, client := range oldClients {
|
||||
if client.PlatformID != platformID {
|
||||
a = append(a, client)
|
||||
}
|
||||
}
|
||||
if len(a) == 0 {
|
||||
u.m.Delete(key)
|
||||
} else {
|
||||
u.m.Store(key, a)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
func (u *UserMap) DeleteAll(key string) {
|
||||
u.m.Delete(key)
|
||||
}
|
||||
@ -1,59 +1,26 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
cbApi "Open_IM/pkg/callback_struct"
|
||||
cbapi "Open_IM/pkg/callbackstruct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
pbFriend "Open_IM/pkg/proto/friend"
|
||||
pbfriend "Open_IM/pkg/proto/friend"
|
||||
"context"
|
||||
|
||||
//"Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
http2 "net/http"
|
||||
)
|
||||
|
||||
func callbackBeforeAddFriendV1(ctx context.Context, req *pbFriend.AddFriendReq) error {
|
||||
resp := callbackBeforeAddFriend(ctx, req)
|
||||
if resp.ErrCode != 0 {
|
||||
return (&constant.ErrInfo{
|
||||
ErrCode: resp.ErrCode,
|
||||
ErrMsg: resp.ErrMsg,
|
||||
}).Wrap()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackBeforeAddFriend(ctx context.Context, req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp {
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: tracelog.GetOperationID(ctx)}
|
||||
func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error {
|
||||
if !config.Config.Callback.CallbackBeforeAddFriend.Enable {
|
||||
return callbackResp
|
||||
return nil
|
||||
}
|
||||
|
||||
commonCallbackReq := &cbApi.CallbackBeforeAddFriendReq{
|
||||
cbReq := &cbapi.CallbackBeforeAddFriendReq{
|
||||
CallbackCommand: constant.CallbackBeforeAddFriendCommand,
|
||||
FromUserID: req.FromUserID,
|
||||
ToUserID: req.ToUserID,
|
||||
ReqMsg: req.ReqMsg,
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeAddFriendResp{
|
||||
CommonCallbackResp: &callbackResp,
|
||||
}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), commonCallbackReq, *resp)
|
||||
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil {
|
||||
callbackResp.ErrCode = http2.StatusInternalServerError
|
||||
callbackResp.ErrMsg = err.Error()
|
||||
if !*config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue {
|
||||
callbackResp.ActionCode = constant.ActionForbidden
|
||||
return callbackResp
|
||||
} else {
|
||||
callbackResp.ActionCode = constant.ActionAllow
|
||||
return callbackResp
|
||||
}
|
||||
}
|
||||
return callbackResp
|
||||
resp := &cbapi.CallbackBeforeAddFriendResp{}
|
||||
return http.CallBackPostReturn(config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriend)
|
||||
}
|
||||
|
||||
@ -1,167 +1,139 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/apistruct"
|
||||
"Open_IM/pkg/callbackstruct"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db/table/relation"
|
||||
"Open_IM/pkg/common/http"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
"time"
|
||||
)
|
||||
|
||||
func callbackBeforeCreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", req)
|
||||
}()
|
||||
func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) (err error) {
|
||||
if !config.Config.Callback.CallbackBeforeCreateGroup.Enable {
|
||||
return nil
|
||||
}
|
||||
commonCallbackReq := &cbApi.CallbackBeforeCreateGroupReq{
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", req)
|
||||
}()
|
||||
cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{
|
||||
CallbackCommand: constant.CallbackBeforeCreateGroupCommand,
|
||||
OperationID: req.OperationID,
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
GroupInfo: *req.GroupInfo,
|
||||
InitMemberList: req.InitMemberList,
|
||||
}
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID}
|
||||
resp := &cbApi.CallbackBeforeCreateGroupResp{
|
||||
CommonCallbackResp: &callbackResp,
|
||||
}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(req.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp)
|
||||
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeCreateGroupCommand, commonCallbackReq,
|
||||
resp, config.Config.Callback.CallbackBeforeCreateGroup)
|
||||
if err == nil {
|
||||
if resp.GroupID != nil {
|
||||
req.GroupInfo.GroupID = *resp.GroupID
|
||||
}
|
||||
if resp.GroupName != nil {
|
||||
req.GroupInfo.GroupName = *resp.GroupName
|
||||
}
|
||||
if resp.Notification != nil {
|
||||
req.GroupInfo.Notification = *resp.Notification
|
||||
}
|
||||
if resp.Introduction != nil {
|
||||
req.GroupInfo.Introduction = *resp.Introduction
|
||||
}
|
||||
if resp.FaceURL != nil {
|
||||
req.GroupInfo.FaceURL = *resp.FaceURL
|
||||
}
|
||||
if resp.OwnerUserID != nil {
|
||||
req.GroupInfo.OwnerUserID = *resp.OwnerUserID
|
||||
}
|
||||
if resp.Ex != nil {
|
||||
req.GroupInfo.Ex = *resp.Ex
|
||||
}
|
||||
if resp.Status != nil {
|
||||
req.GroupInfo.Status = *resp.Status
|
||||
}
|
||||
if resp.CreatorUserID != nil {
|
||||
req.GroupInfo.CreatorUserID = *resp.CreatorUserID
|
||||
}
|
||||
if resp.GroupType != nil {
|
||||
req.GroupInfo.GroupType = *resp.GroupType
|
||||
}
|
||||
if resp.NeedVerification != nil {
|
||||
req.GroupInfo.NeedVerification = *resp.NeedVerification
|
||||
}
|
||||
if resp.LookMemberInfo != nil {
|
||||
req.GroupInfo.LookMemberInfo = *resp.LookMemberInfo
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
|
||||
UserID: req.OwnerUserID,
|
||||
RoleLevel: constant.GroupOwner,
|
||||
})
|
||||
for _, userID := range req.AdminUserIDs {
|
||||
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
|
||||
UserID: userID,
|
||||
RoleLevel: constant.GroupAdmin,
|
||||
})
|
||||
}
|
||||
for _, userID := range req.AdminUserIDs {
|
||||
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
|
||||
UserID: userID,
|
||||
RoleLevel: constant.GroupOrdinaryUsers,
|
||||
})
|
||||
}
|
||||
resp := &callbackstruct.CallbackBeforeCreateGroupResp{}
|
||||
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeCreateGroup)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
utils.NotNilReplace(&req.GroupInfo.GroupID, resp.GroupID)
|
||||
utils.NotNilReplace(&req.GroupInfo.GroupName, resp.GroupName)
|
||||
utils.NotNilReplace(&req.GroupInfo.Notification, resp.Notification)
|
||||
utils.NotNilReplace(&req.GroupInfo.Introduction, resp.Introduction)
|
||||
utils.NotNilReplace(&req.GroupInfo.FaceURL, resp.FaceURL)
|
||||
utils.NotNilReplace(&req.GroupInfo.OwnerUserID, resp.OwnerUserID)
|
||||
utils.NotNilReplace(&req.GroupInfo.Ex, resp.Ex)
|
||||
utils.NotNilReplace(&req.GroupInfo.Status, resp.Status)
|
||||
utils.NotNilReplace(&req.GroupInfo.CreatorUserID, resp.CreatorUserID)
|
||||
utils.NotNilReplace(&req.GroupInfo.GroupType, resp.GroupType)
|
||||
utils.NotNilReplace(&req.GroupInfo.NeedVerification, resp.NeedVerification)
|
||||
utils.NotNilReplace(&req.GroupInfo.LookMemberInfo, resp.LookMemberInfo)
|
||||
return nil
|
||||
}
|
||||
|
||||
func CallbackBeforeMemberJoinGroup(ctx context.Context, operationID string, groupMember *relation.GroupMemberModel, groupEx string) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "groupMember", *groupMember, "groupEx", groupEx)
|
||||
}()
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
||||
func CallbackBeforeMemberJoinGroup(ctx context.Context, groupMember *relation.GroupMemberModel, groupEx string) (err error) {
|
||||
if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable {
|
||||
return nil
|
||||
}
|
||||
log.NewDebug(operationID, "args: ", *groupMember)
|
||||
callbackReq := cbApi.CallbackBeforeMemberJoinGroupReq{
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "groupMember", *groupMember, "groupEx", groupEx)
|
||||
}()
|
||||
callbackReq := &callbackstruct.CallbackBeforeMemberJoinGroupReq{
|
||||
CallbackCommand: constant.CallbackBeforeMemberJoinGroupCommand,
|
||||
OperationID: operationID,
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
GroupID: groupMember.GroupID,
|
||||
UserID: groupMember.UserID,
|
||||
Ex: groupMember.Ex,
|
||||
GroupEx: groupEx,
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeMemberJoinGroupResp{
|
||||
CommonCallbackResp: &callbackResp,
|
||||
}
|
||||
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeMemberJoinGroupCommand, callbackReq,
|
||||
resp, config.Config.Callback.CallbackBeforeMemberJoinGroup)
|
||||
if err == nil {
|
||||
if resp.MuteEndTime != nil {
|
||||
groupMember.MuteEndTime = utils.UnixSecondToTime(*resp.MuteEndTime)
|
||||
}
|
||||
if resp.FaceURL != nil {
|
||||
groupMember.FaceURL = *resp.FaceURL
|
||||
}
|
||||
if resp.Ex != nil {
|
||||
groupMember.Ex = *resp.Ex
|
||||
}
|
||||
if resp.NickName != nil {
|
||||
groupMember.Nickname = *resp.NickName
|
||||
}
|
||||
if resp.RoleLevel != nil {
|
||||
groupMember.RoleLevel = *resp.RoleLevel
|
||||
}
|
||||
}
|
||||
return err
|
||||
resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{}
|
||||
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.MuteEndTime != nil {
|
||||
groupMember.MuteEndTime = time.UnixMilli(*resp.MuteEndTime)
|
||||
}
|
||||
utils.NotNilReplace(&groupMember.FaceURL, resp.FaceURL)
|
||||
utils.NotNilReplace(&groupMember.Ex, resp.Ex)
|
||||
utils.NotNilReplace(&groupMember.Nickname, resp.Nickname)
|
||||
utils.NotNilReplace(&groupMember.RoleLevel, resp.RoleLevel)
|
||||
return nil
|
||||
}
|
||||
|
||||
func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfo) (err error) {
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", *req)
|
||||
}()
|
||||
callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID}
|
||||
func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMemberInfo) (err error) {
|
||||
if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.Enable {
|
||||
return nil
|
||||
}
|
||||
callbackReq := cbApi.CallbackBeforeSetGroupMemberInfoReq{
|
||||
defer func() {
|
||||
tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "req", *req)
|
||||
}()
|
||||
callbackReq := callbackstruct.CallbackBeforeSetGroupMemberInfoReq{
|
||||
CallbackCommand: constant.CallbackBeforeSetGroupMemberInfoCommand,
|
||||
OperationID: req.OperationID,
|
||||
OperationID: tracelog.GetOperationID(ctx),
|
||||
GroupID: req.GroupID,
|
||||
UserID: req.UserID,
|
||||
}
|
||||
if req.Nickname != nil {
|
||||
callbackReq.Nickname = req.Nickname.Value
|
||||
callbackReq.Nickname = &req.Nickname.Value
|
||||
}
|
||||
if req.FaceURL != nil {
|
||||
callbackReq.FaceURL = req.FaceURL.Value
|
||||
callbackReq.FaceURL = &req.FaceURL.Value
|
||||
}
|
||||
if req.RoleLevel != nil {
|
||||
callbackReq.RoleLevel = req.RoleLevel.Value
|
||||
callbackReq.RoleLevel = &req.RoleLevel.Value
|
||||
}
|
||||
if req.Ex != nil {
|
||||
callbackReq.Ex = req.Ex.Value
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeSetGroupMemberInfoResp{
|
||||
CommonCallbackResp: &callbackResp,
|
||||
}
|
||||
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetGroupMemberInfoCommand, callbackReq,
|
||||
resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackTimeOut, &config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackFailedContinue)
|
||||
if err == nil {
|
||||
if resp.FaceURL != nil {
|
||||
req.FaceURL = &wrapperspb.StringValue{Value: *resp.FaceURL}
|
||||
}
|
||||
if resp.Nickname != nil {
|
||||
req.Nickname = &wrapperspb.StringValue{Value: *resp.Nickname}
|
||||
}
|
||||
if resp.RoleLevel != nil {
|
||||
req.RoleLevel = &wrapperspb.Int32Value{Value: *resp.RoleLevel}
|
||||
}
|
||||
if resp.Ex != nil {
|
||||
req.Ex = &wrapperspb.StringValue{Value: *resp.Ex}
|
||||
}
|
||||
}
|
||||
return err
|
||||
callbackReq.Ex = &req.Ex.Value
|
||||
}
|
||||
resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{}
|
||||
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.FaceURL != nil {
|
||||
req.FaceURL = wrapperspb.String(*resp.FaceURL)
|
||||
}
|
||||
if resp.Nickname != nil {
|
||||
req.Nickname = wrapperspb.String(*resp.Nickname)
|
||||
}
|
||||
if resp.RoleLevel != nil {
|
||||
req.RoleLevel = wrapperspb.Int32(*resp.RoleLevel)
|
||||
}
|
||||
if resp.Ex != nil {
|
||||
req.Ex = wrapperspb.String(*resp.Ex)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -1,94 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
sdkws "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"errors"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetPublicUserInfoOne(ctx context.Context, userID string) (*sdkws.PublicUserInfo, error) {
|
||||
return nil, errors.New("todo")
|
||||
}
|
||||
|
||||
func GetUsersInfo(ctx context.Context, userIDs []string) ([]*sdkws.UserInfo, error) {
|
||||
return nil, errors.New("todo")
|
||||
}
|
||||
|
||||
func GetUserInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.UserInfo, error) {
|
||||
users, err := GetUsersInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(users, func(e *sdkws.UserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func GetPublicUserInfo(ctx context.Context, userIDs []string) ([]*sdkws.PublicUserInfo, error) {
|
||||
return nil, errors.New("todo")
|
||||
}
|
||||
|
||||
func GetPublicUserInfoMap(ctx context.Context, userIDs []string) (map[string]*sdkws.PublicUserInfo, error) {
|
||||
users, err := GetPublicUserInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return utils.SliceToMap(users, func(e *sdkws.PublicUserInfo) string {
|
||||
return e.UserID
|
||||
}), nil
|
||||
}
|
||||
|
||||
func GetUsername(ctx context.Context, userIDs []string) (map[string]string, error) {
|
||||
if len(userIDs) == 0 {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
users, err := GetPublicUserInfo(ctx, userIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ids := utils.Single(userIDs, utils.Slice(users, func(e *sdkws.PublicUserInfo) string {
|
||||
return e.UserID
|
||||
})); len(ids) > 0 {
|
||||
return nil, constant.ErrUserIDNotFound.Wrap(strings.Join(ids, ","))
|
||||
}
|
||||
return utils.SliceToMapAny(users, func(e *sdkws.PublicUserInfo) (string, string) {
|
||||
return e.UserID, e.Nickname
|
||||
}), nil
|
||||
}
|
||||
|
||||
func GroupNotification(ctx context.Context, groupID string) {
|
||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||
conversation := pbConversation.Conversation{
|
||||
OwnerUserID: tracelog.GetOpUserID(ctx),
|
||||
ConversationID: utils.GetConversationIDBySessionType(groupID, constant.GroupChatType),
|
||||
ConversationType: constant.GroupChatType,
|
||||
GroupID: groupID,
|
||||
}
|
||||
conversationReq.Conversation = &conversation
|
||||
conversationReq.OperationID = tracelog.GetOperationID(ctx)
|
||||
conversationReq.FieldType = constant.FieldGroupAtType
|
||||
conversation.GroupAtType = constant.GroupNotification
|
||||
conversationReq.UserIDList = cacheResp.UserIDList
|
||||
|
||||
_, err = pbConversation.NewConversationClient(s.etcdConn.GetConn("", config.Config.RpcRegisterName.OpenImConversationName)).ModifyConversationField(ctx, &conversationReq)
|
||||
tracelog.SetCtxInfo(ctx, "ModifyConversationField", err, "req", &conversationReq, "resp", conversationReply)
|
||||
}
|
||||
|
||||
func genGroupID(ctx context.Context, groupID string) string {
|
||||
if groupID != "" {
|
||||
return groupID
|
||||
}
|
||||
groupID = utils.Md5(tracelog.GetOperationID(ctx) + strconv.FormatInt(time.Now().UnixNano(), 10))
|
||||
bi := big.NewInt(0)
|
||||
bi.SetString(groupID[0:8], 16)
|
||||
groupID = bi.String()
|
||||
return groupID
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/tracelog"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func IsNotFound(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
return tracelog.Unwrap(err) == gorm.ErrRecordNotFound
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
pbChat "Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) ClearMsg(_ context.Context, req *pbChat.ClearMsgReq) (*pbChat.ClearMsgResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc req: ", req.String())
|
||||
if req.OpUserID != req.UserID && !tokenverify.IsManagerUserID(req.UserID) {
|
||||
errMsg := "No permission" + req.OpUserID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "CleanUpOneUserAllMsgFromRedis args", req.UserID)
|
||||
err := db.DB.CleanUpOneUserAllMsgFromRedis(req.UserID, req.OperationID)
|
||||
if err != nil {
|
||||
errMsg := "CleanUpOneUserAllMsgFromRedis failed " + err.Error() + req.OperationID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
log.Debug(req.OperationID, "CleanUpUserMsgFromMongo args", req.UserID)
|
||||
err = db.DB.CleanUpUserMsgFromMongo(req.UserID, req.OperationID)
|
||||
if err != nil {
|
||||
errMsg := "CleanUpUserMsgFromMongo failed " + err.Error() + req.OperationID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
|
||||
resp := pbChat.ClearMsgResp{ErrCode: 0}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) SetMsgMinSeq(_ context.Context, req *pbChat.SetMsgMinSeqReq) (*pbChat.SetMsgMinSeqResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc req: ", req.String())
|
||||
if req.OpUserID != req.UserID && !tokenverify.IsManagerUserID(req.UserID) {
|
||||
errMsg := "No permission" + req.OpUserID + req.UserID
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
if req.GroupID == "" {
|
||||
err := db.DB.SetUserMinSeq(req.UserID, req.MinSeq)
|
||||
if err != nil {
|
||||
errMsg := "SetUserMinSeq failed " + err.Error() + req.OperationID + req.UserID + utils.Uint32ToString(req.MinSeq)
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
return &pbChat.SetMsgMinSeqResp{}, nil
|
||||
}
|
||||
err := db.DB.SetGroupUserMinSeq(req.GroupID, req.UserID, uint64(req.MinSeq))
|
||||
if err != nil {
|
||||
errMsg := "SetGroupUserMinSeq failed " + err.Error() + req.OperationID + req.GroupID + req.UserID + utils.Uint32ToString(req.MinSeq)
|
||||
log.Error(req.OperationID, errMsg)
|
||||
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
|
||||
}
|
||||
return &pbChat.SetMsgMinSeqResp{}, nil
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
common "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) DelMsgList(_ context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
resp := &common.DelMsgListResp{}
|
||||
select {
|
||||
case rpc.delMsgCh <- deleteMsg{
|
||||
UserID: req.UserID,
|
||||
OpUserID: req.OpUserID,
|
||||
SeqList: req.SeqList,
|
||||
OperationID: req.OperationID,
|
||||
}:
|
||||
case <-time.After(1 * time.Second):
|
||||
resp.ErrCode = constant.ErrSendLimit.ErrCode
|
||||
resp.ErrMsg = constant.ErrSendLimit.ErrMsg
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
func (rpc *rpcChat) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) {
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
||||
if !tokenverify.CheckAccess(ctx, req.OpUserID, req.UserID) {
|
||||
log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.UserID)
|
||||
return &msg.DelSuperGroupMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: constant.ErrNoPermission.ErrMsg}, nil
|
||||
}
|
||||
resp := &msg.DelSuperGroupMsgResp{}
|
||||
groupMaxSeq, err := db.DB.GetGroupMaxSeq(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "GetGroupMaxSeq false ", req.OpUserID, req.UserID, req.GroupID)
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
err = db.DB.SetGroupUserMinSeq(req.GroupID, req.UserID, groupMaxSeq)
|
||||
if err != nil {
|
||||
log.NewError(req.OperationID, "SetGroupUserMinSeq false ", req.OpUserID, req.UserID, req.GroupID)
|
||||
resp.ErrCode = constant.ErrDB.ErrCode
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/tokenverify"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
common "Open_IM/pkg/proto/sdkws"
|
||||
"context"
|
||||
)
|
||||
|
||||
func (m *msgServer) DelMsgList(ctx context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) {
|
||||
resp := &common.DelMsgListResp{}
|
||||
if err := m.MsgInterface.DelMsgFromCache(ctx, req.UserID, req.SeqList); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
DeleteMessageNotification(ctx, req.UserID, req.SeqList)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) {
|
||||
resp := &msg.DelSuperGroupMsgResp{}
|
||||
if err := tokenverify.CheckAdmin(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
maxSeq, err := m.MsgInterface.GetGroupMaxSeq(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := m.MsgInterface.SetGroupUserMinSeq(ctx, req.GroupID, maxSeq); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) ClearMsg(ctx context.Context, req *msg.ClearMsgReq) (*msg.ClearMsgResp, error) {
|
||||
resp := &msg.ClearMsgResp{}
|
||||
if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := m.MsgInterface.DelUserAllSeq(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@ -1,621 +0,0 @@
|
||||
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/tokenverify"
|
||||
utils2 "Open_IM/pkg/common/utils"
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
//message GroupCreatedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo Creator = 2;
|
||||
// repeated GroupMemberFullInfo MemberList = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
//} creator->group
|
||||
|
||||
func setOpUserInfo(opUserID, groupID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
if tokenverify.IsManagerUserID(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 {
|
||||
if err = utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, u); err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
}
|
||||
user, err := imdb.GetUserByUserID(opUserID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user.UserID
|
||||
groupMemberInfo.Nickname = user.Nickname
|
||||
groupMemberInfo.AppMangerLevel = user.AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user.FaceURL
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupInfo(groupID string, groupInfo *sdkws.GroupInfo) error {
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "GetGroupInfoByGroupID failed")
|
||||
}
|
||||
err = utils2.GroupDBCopyOpenIM(groupInfo, group)
|
||||
if err != nil {
|
||||
log.NewWarn("", "GroupDBCopyOpenIM failed ", groupID, err.Error())
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupMemberInfo(groupID, userID string, groupMemberInfo *sdkws.GroupMemberFullInfo) error {
|
||||
groupMember, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID)
|
||||
if err == nil {
|
||||
return utils.Wrap(utils2.GroupMemberDBCopyOpenIM(groupMemberInfo, groupMember), "")
|
||||
}
|
||||
|
||||
user, err := imdb.GetUserByUserID(userID)
|
||||
if err != nil {
|
||||
return utils.Wrap(err, "")
|
||||
}
|
||||
groupMemberInfo.GroupID = groupID
|
||||
groupMemberInfo.UserID = user.UserID
|
||||
groupMemberInfo.Nickname = user.Nickname
|
||||
groupMemberInfo.AppMangerLevel = user.AppMangerLevel
|
||||
groupMemberInfo.FaceURL = user.FaceURL
|
||||
return nil
|
||||
}
|
||||
|
||||
func setGroupOwnerInfo(groupID string, groupMemberInfo *sdkws.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 *sdkws.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, sendID, groupID, recvUserID)
|
||||
|
||||
var err error
|
||||
var tips sdkws.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
var nickname string
|
||||
|
||||
from, err := imdb.GetUserByUserID(sendID)
|
||||
if err != nil {
|
||||
log.Error(operationID, "GetUserByUserID failed ", err.Error(), sendID)
|
||||
}
|
||||
if from != nil {
|
||||
nickname = from.Nickname
|
||||
}
|
||||
|
||||
to, err := imdb.GetUserByUserID(recvUserID)
|
||||
if err != nil {
|
||||
log.NewWarn(operationID, "GetUserByUserID failed ", err.Error(), recvUserID)
|
||||
}
|
||||
toNickname := ""
|
||||
if to != nil {
|
||||
toNickname = to.Nickname
|
||||
}
|
||||
|
||||
cn := config.Config.Notification
|
||||
switch contentType {
|
||||
case constant.GroupCreatedNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.GroupCreated.DefaultTips.Tips
|
||||
case constant.GroupInfoSetNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.GroupInfoSet.DefaultTips.Tips
|
||||
case constant.JoinGroupApplicationNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.JoinGroupApplication.DefaultTips.Tips
|
||||
case constant.MemberQuitNotification:
|
||||
tips.DefaultTips = nickname + " " + cn.MemberQuit.DefaultTips.Tips
|
||||
case constant.GroupApplicationAcceptedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupApplicationAccepted.DefaultTips.Tips
|
||||
case constant.GroupApplicationRejectedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupApplicationRejected.DefaultTips.Tips
|
||||
case constant.GroupOwnerTransferredNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.GroupOwnerTransferred.DefaultTips.Tips
|
||||
case constant.MemberKickedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberKicked.DefaultTips.Tips
|
||||
case constant.MemberInvitedNotification: //
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberInvited.DefaultTips.Tips
|
||||
case constant.MemberEnterNotification:
|
||||
tips.DefaultTips = toNickname + " " + cn.MemberEnter.DefaultTips.Tips
|
||||
case constant.GroupDismissedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupDismissed.DefaultTips.Tips
|
||||
case constant.GroupMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMuted.DefaultTips.Tips
|
||||
case constant.GroupCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberCancelMutedNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberCancelMuted.DefaultTips.Tips
|
||||
case constant.GroupMemberInfoSetNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberInfoSet.DefaultTips.Tips
|
||||
case constant.GroupMemberSetToAdminNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberSetToAdmin.DefaultTips.Tips
|
||||
case constant.GroupMemberSetToOrdinaryUserNotification:
|
||||
tips.DefaultTips = toNickname + "" + cn.GroupMemberSetToOrdinary.DefaultTips.Tips
|
||||
default:
|
||||
log.Error(operationID, "contentType failed ", contentType)
|
||||
return
|
||||
}
|
||||
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
if groupID != "" {
|
||||
n.RecvID = groupID
|
||||
group, err := imdb.GetGroupInfoByGroupID(groupID)
|
||||
if err != nil {
|
||||
log.NewError(operationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID)
|
||||
}
|
||||
switch group.GroupType {
|
||||
case constant.NormalGroup:
|
||||
n.SessionType = constant.GroupChatType
|
||||
default:
|
||||
n.SessionType = constant.SuperGroupChatType
|
||||
}
|
||||
} 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 := sdkws.GroupCreatedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, GroupOwnerUser: &sdkws.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 sdkws.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)
|
||||
if len(GroupCreatedTips.MemberList) == constant.MaxNotificationNum {
|
||||
break
|
||||
}
|
||||
}
|
||||
groupNotification(constant.GroupCreatedNotification, &GroupCreatedTips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
// 群信息改变后掉用
|
||||
// groupName := ""
|
||||
//
|
||||
// notification := ""
|
||||
// introduction := ""
|
||||
// faceURL := ""
|
||||
func GroupInfoSetNotification(operationID, opUserID, groupID string, groupName, notification, introduction, faceURL string, needVerification *wrapperspb.Int32Value) {
|
||||
GroupInfoChangedTips := sdkws.GroupInfoSetTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, GroupInfoChangedTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
GroupInfoChangedTips.Group.GroupName = groupName
|
||||
GroupInfoChangedTips.Group.Notification = notification
|
||||
GroupInfoChangedTips.Group.Introduction = introduction
|
||||
GroupInfoChangedTips.Group.FaceURL = faceURL
|
||||
if needVerification != nil {
|
||||
GroupInfoChangedTips.Group.NeedVerification = needVerification.Value
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func GroupMutedNotification(operationID, opUserID, groupID string) {
|
||||
tips := sdkws.GroupMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupCancelMutedNotification(operationID, opUserID, groupID string) {
|
||||
tips := sdkws.GroupCancelMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupCancelMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberMutedNotification(operationID, opUserID, groupID, groupMemberUserID string, mutedSeconds uint32) {
|
||||
tips := sdkws.GroupMemberMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
tips.MutedSeconds = mutedSeconds
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberMutedNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberInfoSetNotification(operationID, opUserID, groupID, groupMemberUserID string) {
|
||||
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.ChangedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberInfoSetNotification, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberRoleLevelChangeNotification(operationID, opUserID, groupID, groupMemberUserID string, notificationType int32) {
|
||||
if notificationType != constant.GroupMemberSetToAdminNotification && notificationType != constant.GroupMemberSetToOrdinaryUserNotification {
|
||||
log.NewError(operationID, utils.GetSelfFuncName(), "invalid notificationType: ", notificationType)
|
||||
return
|
||||
}
|
||||
tips := sdkws.GroupMemberInfoSetTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, ChangedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.ChangedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(notificationType, &tips, opUserID, groupID, "", operationID)
|
||||
}
|
||||
|
||||
func GroupMemberCancelMutedNotification(operationID, opUserID, groupID, groupMemberUserID string) {
|
||||
tips := sdkws.GroupMemberCancelMutedTips{Group: &sdkws.GroupInfo{},
|
||||
OpUser: &sdkws.GroupMemberFullInfo{}, MutedUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, tips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(opUserID, groupID, tips.OpUser); err != nil {
|
||||
log.Error(operationID, "setOpUserInfo failed ", err.Error(), opUserID, groupID)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, groupMemberUserID, tips.MutedUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, groupMemberUserID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupMemberCancelMutedNotification, &tips, 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(ctx context.Context, req *pbGroup.JoinGroupReq) {
|
||||
JoinGroupApplicationTips := sdkws.JoinGroupApplicationTips{Group: &sdkws.GroupInfo{}, Applicant: &sdkws.PublicUserInfo{}}
|
||||
err := setGroupInfo(req.GroupID, JoinGroupApplicationTips.Group)
|
||||
if err != nil {
|
||||
log.Error(utils.OperationID(ctx), "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err = setPublicUserInfo(utils.OpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil {
|
||||
log.Error(utils.OperationID(ctx), "setPublicUserInfo failed ", err.Error(), utils.OpUserID(ctx))
|
||||
return
|
||||
}
|
||||
JoinGroupApplicationTips.ReqMsg = req.ReqMessage
|
||||
|
||||
managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.NewError(utils.OperationID(ctx), "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
for _, v := range managerList {
|
||||
groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, utils.OpUserID(ctx), "", v.UserID, utils.OperationID(ctx))
|
||||
log.NewInfo(utils.OperationID(ctx), "Notification ", v)
|
||||
}
|
||||
}
|
||||
|
||||
func MemberQuitNotification(req *pbGroup.QuitGroupReq) {
|
||||
MemberQuitTips := sdkws.MemberQuitTips{Group: &sdkws.GroupInfo{}, QuitUser: &sdkws.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)
|
||||
}
|
||||
|
||||
// message ApplicationProcessedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// int32 Result = 3;
|
||||
// string Reason = 4;
|
||||
// }
|
||||
//
|
||||
// 处理进群请求后调用
|
||||
func GroupApplicationAcceptedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationAcceptedTips := sdkws.GroupApplicationAcceptedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.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)
|
||||
adminList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetOwnerManagerByGroupID failed", req.GroupID)
|
||||
return
|
||||
}
|
||||
for _, v := range adminList {
|
||||
if v.UserID == req.OpUserID {
|
||||
continue
|
||||
}
|
||||
GroupApplicationAcceptedTips.ReceiverAs = 1
|
||||
groupNotification(constant.GroupApplicationAcceptedNotification, &GroupApplicationAcceptedTips, req.OpUserID, "", v.UserID, req.OperationID)
|
||||
}
|
||||
}
|
||||
|
||||
func GroupApplicationRejectedNotification(req *pbGroup.GroupApplicationResponseReq) {
|
||||
GroupApplicationRejectedTips := sdkws.GroupApplicationRejectedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.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)
|
||||
adminList, err := imdb.GetOwnerManagerByGroupID(req.GroupID)
|
||||
if err != nil {
|
||||
log.Error(req.OperationID, "GetOwnerManagerByGroupID failed", req.GroupID)
|
||||
return
|
||||
}
|
||||
for _, v := range adminList {
|
||||
if v.UserID == req.OpUserID {
|
||||
continue
|
||||
}
|
||||
GroupApplicationRejectedTips.ReceiverAs = 1
|
||||
groupNotification(constant.GroupApplicationRejectedNotification, &GroupApplicationRejectedTips, req.OpUserID, "", v.UserID, req.OperationID)
|
||||
}
|
||||
}
|
||||
|
||||
func GroupOwnerTransferredNotification(req *pbGroup.TransferGroupOwnerReq) {
|
||||
GroupOwnerTransferredTips := sdkws.GroupOwnerTransferredTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}, NewGroupOwner: &sdkws.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.GroupID, "", req.OperationID)
|
||||
}
|
||||
|
||||
func GroupDismissedNotification(req *pbGroup.DismissGroupReq) {
|
||||
tips := sdkws.GroupDismissedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(req.GroupID, tips.Group); err != nil {
|
||||
log.NewError(req.OperationID, "setGroupInfo failed ", err.Error(), req.GroupID)
|
||||
return
|
||||
}
|
||||
if err := setOpUserInfo(req.OpUserID, req.GroupID, tips.OpUser); err != nil {
|
||||
log.Error(req.OperationID, "setOpUserInfo failed", req.OpUserID, req.GroupID)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.GroupDismissedNotification, &tips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
}
|
||||
|
||||
// message MemberKickedTips{
|
||||
// GroupInfo Group = 1;
|
||||
// GroupMemberFullInfo OpUser = 2;
|
||||
// GroupMemberFullInfo KickedUser = 3;
|
||||
// uint64 OperationTime = 4;
|
||||
// }
|
||||
//
|
||||
// 被踢后调用
|
||||
func MemberKickedNotification(req *pbGroup.KickGroupMemberReq, kickedUserIDList []string) {
|
||||
MemberKickedTips := sdkws.MemberKickedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.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 sdkws.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 := sdkws.MemberInvitedTips{Group: &sdkws.GroupInfo{}, OpUser: &sdkws.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 sdkws.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(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) {
|
||||
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.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 := setGroupMemberInfo(req.GroupID, req.FromUserID, MemberEnterTips.EntrantUser); err != nil {
|
||||
log.Error(req.OperationID, "setGroupMemberInfo failed ", err.Error(), req.OpUserID, req.GroupID, MemberEnterTips.EntrantUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.MemberEnterNotification, &MemberEnterTips, req.OpUserID, req.GroupID, "", req.OperationID)
|
||||
}
|
||||
|
||||
func MemberEnterDirectlyNotification(groupID string, entrantUserID string, operationID string) {
|
||||
MemberEnterTips := sdkws.MemberEnterTips{Group: &sdkws.GroupInfo{}, EntrantUser: &sdkws.GroupMemberFullInfo{}}
|
||||
if err := setGroupInfo(groupID, MemberEnterTips.Group); err != nil {
|
||||
log.Error(operationID, "setGroupInfo failed ", err.Error(), groupID, MemberEnterTips.Group)
|
||||
return
|
||||
}
|
||||
if err := setGroupMemberInfo(groupID, entrantUserID, MemberEnterTips.EntrantUser); err != nil {
|
||||
log.Error(operationID, "setGroupMemberInfo failed ", err.Error(), groupID, entrantUserID, MemberEnterTips.EntrantUser)
|
||||
return
|
||||
}
|
||||
groupNotification(constant.MemberEnterNotification, &MemberEnterTips, entrantUserID, groupID, "", operationID)
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
sdkws "Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
func DeleteMessageNotification(opUserID, userID string, seqList []uint32, operationID string) {
|
||||
DeleteMessageTips := sdkws.DeleteMessageTips{OpUserID: opUserID, UserID: userID, SeqList: seqList}
|
||||
MessageNotification(operationID, userID, userID, constant.DeleteMessageNotification, &DeleteMessageTips)
|
||||
}
|
||||
|
||||
func MessageNotification(operationID, sendID, recvID string, contentType int32, m proto.Message) {
|
||||
log.Debug(operationID, utils.GetSelfFuncName(), "args: ", m.String(), contentType)
|
||||
var err error
|
||||
var tips sdkws.TipsComm
|
||||
tips.Detail, err = proto.Marshal(m)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), m.String())
|
||||
return
|
||||
}
|
||||
|
||||
marshaler := jsonpb.Marshaler{
|
||||
OrigName: true,
|
||||
EnumsAsInts: false,
|
||||
EmitDefaults: false,
|
||||
}
|
||||
|
||||
tips.JsonDetail, _ = marshaler.MarshalToString(m)
|
||||
var n NotificationMsg
|
||||
n.SendID = sendID
|
||||
n.RecvID = recvID
|
||||
n.ContentType = contentType
|
||||
n.SessionType = constant.SingleChatType
|
||||
n.MsgFrom = constant.SysMsgType
|
||||
n.OperationID = operationID
|
||||
n.Content, err = proto.Marshal(&tips)
|
||||
if err != nil {
|
||||
log.Error(operationID, "Marshal failed ", err.Error(), tips.String())
|
||||
return
|
||||
}
|
||||
Notification(&n)
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package msg
|
||||
|
||||
import "context"
|
||||
|
||||
func DeleteMessageNotification(ctx context.Context, userID string, seqs []uint32) {
|
||||
panic("todo")
|
||||
}
|
||||
@ -1,126 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
go_redis "github.com/go-redis/redis/v8"
|
||||
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
sdkws "Open_IM/pkg/proto/sdkws"
|
||||
|
||||
prome "Open_IM/pkg/common/prometheus"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) GetMaxAndMinSeq(_ context.Context, in *sdkws.GetMaxAndMinSeqReq) (*sdkws.GetMaxAndMinSeqResp, error) {
|
||||
log.NewInfo(in.OperationID, "rpc getMaxAndMinSeq is arriving", in.String())
|
||||
resp := new(sdkws.GetMaxAndMinSeqResp)
|
||||
m := make(map[string]*sdkws.MaxAndMinSeq)
|
||||
var maxSeq, minSeq uint64
|
||||
var err1, err2 error
|
||||
maxSeq, err1 = commonDB.DB.GetUserMaxSeq(in.UserID)
|
||||
minSeq, err2 = commonDB.DB.GetUserMinSeq(in.UserID)
|
||||
if (err1 != nil && err1 != go_redis.Nil) || (err2 != nil && err2 != go_redis.Nil) {
|
||||
log.NewError(in.OperationID, "getMaxSeq from redis error", in.String())
|
||||
if err1 != nil {
|
||||
log.NewError(in.OperationID, utils.GetSelfFuncName(), err1.Error())
|
||||
}
|
||||
if err2 != nil {
|
||||
log.NewError(in.OperationID, utils.GetSelfFuncName(), err2.Error())
|
||||
}
|
||||
resp.ErrCode = 200
|
||||
resp.ErrMsg = "redis get err"
|
||||
return resp, nil
|
||||
}
|
||||
resp.MaxSeq = uint32(maxSeq)
|
||||
resp.MinSeq = uint32(minSeq)
|
||||
for _, groupID := range in.GroupIDList {
|
||||
x := new(sdkws.MaxAndMinSeq)
|
||||
maxSeq, _ := commonDB.DB.GetGroupMaxSeq(groupID)
|
||||
minSeq, _ := commonDB.DB.GetGroupUserMinSeq(groupID, in.UserID)
|
||||
x.MaxSeq = uint32(maxSeq)
|
||||
x.MinSeq = uint32(minSeq)
|
||||
m[groupID] = x
|
||||
}
|
||||
resp.GroupMaxAndMinSeq = m
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *sdkws.PullMessageBySeqListReq) (*sdkws.PullMessageBySeqListResp, error) {
|
||||
log.NewInfo(in.OperationID, "rpc PullMessageBySeqList is arriving", in.String())
|
||||
resp := new(sdkws.PullMessageBySeqListResp)
|
||||
m := make(map[string]*sdkws.MsgDataList)
|
||||
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(in.UserID, in.SeqList, in.OperationID)
|
||||
if err != nil {
|
||||
if err != go_redis.Nil {
|
||||
prome.PromeAdd(prome.MsgPullFromRedisFailedCounter, len(failedSeqList))
|
||||
log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
||||
} else {
|
||||
log.Debug(in.OperationID, "get message from redis is nil", failedSeqList)
|
||||
}
|
||||
msgList, err1 := commonDB.DB.GetMsgBySeqs(in.UserID, failedSeqList, in.OperationID)
|
||||
if err1 != nil {
|
||||
prome.PromeAdd(prome.MsgPullFromMongoFailedCounter, len(failedSeqList))
|
||||
log.Error(in.OperationID, "PullMessageBySeqList data error", in.String(), err1.Error())
|
||||
resp.ErrCode = 201
|
||||
resp.ErrMsg = err1.Error()
|
||||
return resp, nil
|
||||
} else {
|
||||
prome.PromeAdd(prome.MsgPullFromMongoSuccessCounter, len(msgList))
|
||||
redisMsgList = append(redisMsgList, msgList...)
|
||||
resp.List = redisMsgList
|
||||
}
|
||||
} else {
|
||||
prome.PromeAdd(prome.MsgPullFromRedisSuccessCounter, len(redisMsgList))
|
||||
resp.List = redisMsgList
|
||||
}
|
||||
|
||||
for k, v := range in.GroupSeqList {
|
||||
x := new(sdkws.MsgDataList)
|
||||
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(k, v.SeqList, in.OperationID)
|
||||
if err != nil {
|
||||
if err != go_redis.Nil {
|
||||
prome.PromeAdd(prome.MsgPullFromRedisFailedCounter, len(failedSeqList))
|
||||
log.Error(in.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
||||
} else {
|
||||
log.Debug(in.OperationID, "get message from redis is nil", failedSeqList)
|
||||
}
|
||||
msgList, err1 := commonDB.DB.GetSuperGroupMsgBySeqs(k, failedSeqList, in.OperationID)
|
||||
if err1 != nil {
|
||||
prome.PromeAdd(prome.MsgPullFromMongoFailedCounter, len(failedSeqList))
|
||||
log.Error(in.OperationID, "PullMessageBySeqList data error", in.String(), err1.Error())
|
||||
resp.ErrCode = 201
|
||||
resp.ErrMsg = err1.Error()
|
||||
return resp, nil
|
||||
} else {
|
||||
prome.PromeAdd(prome.MsgPullFromMongoSuccessCounter, len(msgList))
|
||||
redisMsgList = append(redisMsgList, msgList...)
|
||||
x.MsgDataList = redisMsgList
|
||||
m[k] = x
|
||||
}
|
||||
} else {
|
||||
prome.PromeAdd(prome.MsgPullFromRedisSuccessCounter, len(redisMsgList))
|
||||
x.MsgDataList = redisMsgList
|
||||
m[k] = x
|
||||
}
|
||||
}
|
||||
resp.GroupMsgDataList = m
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type MsgFormats []*sdkws.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,51 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
commonDB "Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/log"
|
||||
prome "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
go_redis "github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
func (rpc *rpcChat) GetSuperGroupMsg(context context.Context, req *msg.GetSuperGroupMsgReq) (*msg.GetSuperGroupMsgResp, error) {
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), req.String())
|
||||
resp := new(msg.GetSuperGroupMsgResp)
|
||||
redisMsgList, failedSeqList, err := commonDB.DB.GetMessageListBySeq(req.GroupID, []uint32{req.Seq}, req.OperationID)
|
||||
if err != nil {
|
||||
if err != go_redis.Nil {
|
||||
prome.PromeAdd(prome.MsgPullFromRedisFailedCounter, len(failedSeqList))
|
||||
log.Error(req.OperationID, "get message from redis exception", err.Error(), failedSeqList)
|
||||
} else {
|
||||
log.Debug(req.OperationID, "get message from redis is nil", failedSeqList)
|
||||
}
|
||||
msgList, err1 := commonDB.DB.GetSuperGroupMsgBySeqs(req.GroupID, failedSeqList, req.OperationID)
|
||||
if err1 != nil {
|
||||
prome.PromeAdd(prome.MsgPullFromMongoFailedCounter, len(failedSeqList))
|
||||
log.Error(req.OperationID, "GetSuperGroupMsg data error", req.String(), err.Error())
|
||||
resp.ErrCode = 201
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
} else {
|
||||
prome.PromeAdd(prome.MsgPullFromMongoSuccessCounter, len(msgList))
|
||||
redisMsgList = append(redisMsgList, msgList...)
|
||||
for _, m := range msgList {
|
||||
resp.MsgData = m
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
prome.PromeAdd(prome.MsgPullFromRedisSuccessCounter, len(redisMsgList))
|
||||
for _, m := range redisMsgList {
|
||||
resp.MsgData = m
|
||||
}
|
||||
}
|
||||
log.Debug(req.OperationID, utils.GetSelfFuncName(), resp.String())
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) GetWriteDiffMsg(context context.Context, req *msg.GetWriteDiffMsgReq) (*msg.GetWriteDiffMsgResp, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
@ -1,159 +0,0 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/db"
|
||||
"Open_IM/pkg/common/kafka"
|
||||
"Open_IM/pkg/common/log"
|
||||
prome "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/OpenIMSDK/getcdv3"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type MessageWriter interface {
|
||||
SendMessage(m proto.Message, key string, operationID string) (int32, int64, error)
|
||||
}
|
||||
type rpcChat struct {
|
||||
rpcPort int
|
||||
rpcRegisterName string
|
||||
etcdSchema string
|
||||
etcdAddr []string
|
||||
messageWriter MessageWriter
|
||||
//offlineProducer *kafka.Producer
|
||||
delMsgCh chan deleteMsg
|
||||
dMessageLocker MessageLocker
|
||||
}
|
||||
|
||||
type deleteMsg struct {
|
||||
UserID string
|
||||
OpUserID string
|
||||
SeqList []uint32
|
||||
OperationID string
|
||||
}
|
||||
|
||||
func NewRpcChatServer(port int) *rpcChat {
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
rc := rpcChat{
|
||||
rpcPort: port,
|
||||
rpcRegisterName: config.Config.RpcRegisterName.OpenImMsgName,
|
||||
etcdSchema: config.Config.Etcd.EtcdSchema,
|
||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||
dMessageLocker: NewLockerMessage(),
|
||||
}
|
||||
rc.messageWriter = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschat.Addr, config.Config.Kafka.Ws2mschat.Topic)
|
||||
//rc.offlineProducer = kafka.NewKafkaProducer(config.Config.Kafka.Ws2mschatOffline.Addr, config.Config.Kafka.Ws2mschatOffline.Topic)
|
||||
rc.delMsgCh = make(chan deleteMsg, 1000)
|
||||
return &rc
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) initPrometheus() {
|
||||
//sendMsgSuccessCounter = promauto.NewCounter(prometheus.CounterOpts{
|
||||
// Name: "send_msg_success",
|
||||
// Help: "The number of send msg success",
|
||||
//})
|
||||
//sendMsgFailedCounter = promauto.NewCounter(prometheus.CounterOpts{
|
||||
// Name: "send_msg_failed",
|
||||
// Help: "The number of send msg failed",
|
||||
//})
|
||||
prome.NewMsgPullFromRedisSuccessCounter()
|
||||
prome.NewMsgPullFromRedisFailedCounter()
|
||||
prome.NewMsgPullFromMongoSuccessCounter()
|
||||
prome.NewMsgPullFromMongoFailedCounter()
|
||||
|
||||
prome.NewSingleChatMsgRecvSuccessCounter()
|
||||
prome.NewGroupChatMsgRecvSuccessCounter()
|
||||
prome.NewWorkSuperGroupChatMsgRecvSuccessCounter()
|
||||
|
||||
prome.NewSingleChatMsgProcessSuccessCounter()
|
||||
prome.NewSingleChatMsgProcessFailedCounter()
|
||||
prome.NewGroupChatMsgProcessSuccessCounter()
|
||||
prome.NewGroupChatMsgProcessFailedCounter()
|
||||
prome.NewWorkSuperGroupChatMsgProcessSuccessCounter()
|
||||
prome.NewWorkSuperGroupChatMsgProcessFailedCounter()
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) Run() {
|
||||
log.Info("", "rpcChat init...")
|
||||
listenIP := ""
|
||||
if config.Config.ListenIP == "" {
|
||||
listenIP = "0.0.0.0"
|
||||
} else {
|
||||
listenIP = config.Config.ListenIP
|
||||
}
|
||||
address := listenIP + ":" + strconv.Itoa(rpc.rpcPort)
|
||||
listener, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
panic("listening err:" + err.Error() + rpc.rpcRegisterName)
|
||||
}
|
||||
log.Info("", "listen network success, address ", address)
|
||||
recvSize := 1024 * 1024 * 30
|
||||
sendSize := 1024 * 1024 * 30
|
||||
var grpcOpts = []grpc.ServerOption{
|
||||
grpc.MaxRecvMsgSize(recvSize),
|
||||
grpc.MaxSendMsgSize(sendSize),
|
||||
}
|
||||
if config.Config.Prometheus.Enable {
|
||||
prome.NewGrpcRequestCounter()
|
||||
prome.NewGrpcRequestFailedCounter()
|
||||
prome.NewGrpcRequestSuccessCounter()
|
||||
grpcOpts = append(grpcOpts, []grpc.ServerOption{
|
||||
// grpc.UnaryInterceptor(prome.UnaryServerInterceptorProme),
|
||||
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
|
||||
grpc.UnaryInterceptor(grpcPrometheus.UnaryServerInterceptor),
|
||||
}...)
|
||||
}
|
||||
srv := grpc.NewServer(grpcOpts...)
|
||||
defer srv.GracefulStop()
|
||||
|
||||
rpcRegisterIP := config.Config.RpcRegisterIP
|
||||
msg.RegisterMsgServer(srv, rpc)
|
||||
if config.Config.RpcRegisterIP == "" {
|
||||
rpcRegisterIP, err = utils.GetLocalIP()
|
||||
if err != nil {
|
||||
log.Error("", "GetLocalIP failed ", err.Error())
|
||||
}
|
||||
}
|
||||
err = getcdv3.RegisterEtcd(rpc.etcdSchema, strings.Join(rpc.etcdAddr, ","), rpcRegisterIP, rpc.rpcPort, rpc.rpcRegisterName, 10, "")
|
||||
if err != nil {
|
||||
log.Error("", "register rpcChat to etcd failed ", err.Error())
|
||||
panic(utils.Wrap(err, "register chat module rpc to etcd err"))
|
||||
}
|
||||
go rpc.runCh()
|
||||
rpc.initPrometheus()
|
||||
err = srv.Serve(listener)
|
||||
if err != nil {
|
||||
log.Error("", "rpc rpcChat failed ", err.Error())
|
||||
return
|
||||
}
|
||||
log.Info("", "rpc rpcChat init success")
|
||||
}
|
||||
|
||||
func (rpc *rpcChat) runCh() {
|
||||
log.NewInfo("", "start del msg chan ")
|
||||
for {
|
||||
select {
|
||||
case msg := <-rpc.delMsgCh:
|
||||
log.NewInfo(msg.OperationID, utils.GetSelfFuncName(), "delmsgch recv new: ", msg)
|
||||
db.DB.DelMsgFromCache(msg.UserID, msg.SeqList, msg.OperationID)
|
||||
unexistSeqList, err := db.DB.DelMsgBySeqs(msg.UserID, msg.SeqList, msg.OperationID)
|
||||
if err != nil {
|
||||
log.NewError(msg.OperationID, utils.GetSelfFuncName(), "DelMsgBySeqs args: ", msg.UserID, msg.SeqList, msg.OperationID, err.Error())
|
||||
continue
|
||||
}
|
||||
if len(unexistSeqList) > 0 {
|
||||
DeleteMessageNotification(msg.OpUserID, msg.UserID, unexistSeqList, msg.OperationID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,304 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/constant"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
pbConversation "Open_IM/pkg/proto/conversation"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"context"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func (m *msgServer) sendMsgSuperGroupChat(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
|
||||
promePkg.PromeInc(promePkg.WorkSuperGroupChatMsgRecvSuccessCounter)
|
||||
// callback
|
||||
if err = CallbackBeforeSendGroupMsg(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, err = m.messageVerification(ctx, req); err != nil {
|
||||
promePkg.PromeInc(promePkg.WorkSuperGroupChatMsgProcessFailedCounter)
|
||||
return nil, err
|
||||
}
|
||||
msgToMQSingle := msg.MsgDataToMQ{MsgData: req.MsgData}
|
||||
err = m.MsgInterface.MsgToMQ(ctx, msgToMQSingle.MsgData.GroupID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// callback
|
||||
if err = CallbackAfterSendGroupMsg(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
promePkg.PromeInc(promePkg.WorkSuperGroupChatMsgProcessSuccessCounter)
|
||||
resp.SendTime = msgToMQSingle.MsgData.SendTime
|
||||
resp.ServerMsgID = msgToMQSingle.MsgData.ServerMsgID
|
||||
resp.ClientMsgID = msgToMQSingle.MsgData.ClientMsgID
|
||||
return resp, nil
|
||||
}
|
||||
func (m *msgServer) sendMsgNotification(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
|
||||
msgToMQSingle := msg.MsgDataToMQ{MsgData: req.MsgData}
|
||||
err = m.MsgInterface.MsgToMQ(ctx, msgToMQSingle.MsgData.RecvID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if msgToMQSingle.MsgData.SendID != msgToMQSingle.MsgData.RecvID { //Filter messages sent to yourself
|
||||
err = m.MsgInterface.MsgToMQ(ctx, msgToMQSingle.MsgData.SendID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
resp.SendTime = msgToMQSingle.MsgData.SendTime
|
||||
resp.ServerMsgID = msgToMQSingle.MsgData.ServerMsgID
|
||||
resp.ClientMsgID = msgToMQSingle.MsgData.ClientMsgID
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) sendMsgSingleChat(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
|
||||
promePkg.PromeInc(promePkg.SingleChatMsgRecvSuccessCounter)
|
||||
if err = CallbackBeforeSendSingleMsg(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = m.messageVerification(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
isSend, err := modifyMessageByUserMessageReceiveOpt(req.MsgData.RecvID, req.MsgData.SendID, constant.SingleChatType, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
msgToMQSingle := msg.MsgDataToMQ{MsgData: req.MsgData}
|
||||
if isSend {
|
||||
err = m.MsgInterface.MsgToMQ(ctx, req.MsgData.RecvID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, constant.ErrInternalServer.Wrap("insert to mq")
|
||||
}
|
||||
}
|
||||
if msgToMQSingle.MsgData.SendID != msgToMQSingle.MsgData.RecvID { //Filter messages sent to yourself
|
||||
err = m.MsgInterface.MsgToMQ(ctx, req.MsgData.SendID, &msgToMQSingle)
|
||||
if err != nil {
|
||||
return nil, constant.ErrInternalServer.Wrap("insert to mq")
|
||||
}
|
||||
}
|
||||
err = CallbackAfterSendSingleMsg(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
promePkg.PromeInc(promePkg.SingleChatMsgProcessSuccessCounter)
|
||||
resp.SendTime = msgToMQSingle.MsgData.SendTime
|
||||
resp.ServerMsgID = msgToMQSingle.MsgData.ServerMsgID
|
||||
resp.ClientMsgID = msgToMQSingle.MsgData.ClientMsgID
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) sendMsgGroupChat(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, err error) {
|
||||
// callback
|
||||
promePkg.PromeInc(promePkg.GroupChatMsgRecvSuccessCounter)
|
||||
err = CallbackBeforeSendGroupMsg(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var memberUserIDList []string
|
||||
if memberUserIDList, err = m.messageVerification(ctx, req); err != nil {
|
||||
promePkg.PromeInc(promePkg.GroupChatMsgProcessFailedCounter)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var addUidList []string
|
||||
switch req.MsgData.ContentType {
|
||||
case constant.MemberKickedNotification:
|
||||
var tips sdkws.TipsComm
|
||||
var memberKickedTips sdkws.MemberKickedTips
|
||||
err := proto.Unmarshal(req.MsgData.Content, &tips)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = proto.Unmarshal(tips.Detail, &memberKickedTips)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range memberKickedTips.KickedUserList {
|
||||
addUidList = append(addUidList, v.UserID)
|
||||
}
|
||||
case constant.MemberQuitNotification:
|
||||
addUidList = append(addUidList, req.MsgData.SendID)
|
||||
|
||||
default:
|
||||
}
|
||||
if len(addUidList) > 0 {
|
||||
memberUserIDList = append(memberUserIDList, addUidList...)
|
||||
}
|
||||
|
||||
//split parallel send
|
||||
var wg sync.WaitGroup
|
||||
var split = 20
|
||||
msgToMQSingle := msg.MsgDataToMQ{MsgData: req.MsgData}
|
||||
mErr := make([]error, 0)
|
||||
var mutex sync.RWMutex
|
||||
remain := len(memberUserIDList) % split
|
||||
for i := 0; i < len(memberUserIDList)/split; i++ {
|
||||
wg.Add(1)
|
||||
tmp := valueCopy(req)
|
||||
go func() {
|
||||
err := m.sendMsgToGroupOptimization(ctx, memberUserIDList[i*split:(i+1)*split], tmp, &wg)
|
||||
if err != nil {
|
||||
mutex.Lock()
|
||||
mErr = append(mErr, err)
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
}()
|
||||
}
|
||||
if remain > 0 {
|
||||
wg.Add(1)
|
||||
tmp := valueCopy(req)
|
||||
go m.sendMsgToGroupOptimization(ctx, memberUserIDList[split*(len(memberUserIDList)/split):], tmp, &wg)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
// callback
|
||||
err = CallbackAfterSendGroupMsg(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, v := range mErr {
|
||||
if v != nil {
|
||||
return nil, v
|
||||
}
|
||||
}
|
||||
|
||||
if req.MsgData.ContentType == constant.AtText {
|
||||
go func() {
|
||||
var conversationReq pbConversation.ModifyConversationFieldReq
|
||||
var tag bool
|
||||
var atUserID []string
|
||||
conversation := pbConversation.Conversation{
|
||||
OwnerUserID: req.MsgData.SendID,
|
||||
ConversationID: utils.GetConversationIDBySessionType(req.MsgData.GroupID, constant.GroupChatType),
|
||||
ConversationType: constant.GroupChatType,
|
||||
GroupID: req.MsgData.GroupID,
|
||||
}
|
||||
conversationReq.Conversation = &conversation
|
||||
conversationReq.FieldType = constant.FieldGroupAtType
|
||||
tagAll := utils.IsContain(constant.AtAllString, req.MsgData.AtUserIDList)
|
||||
if tagAll {
|
||||
atUserID = utils.DifferenceString([]string{constant.AtAllString}, req.MsgData.AtUserIDList)
|
||||
if len(atUserID) == 0 { //just @everyone
|
||||
conversationReq.UserIDList = memberUserIDList
|
||||
conversation.GroupAtType = constant.AtAll
|
||||
} else { //@Everyone and @other people
|
||||
conversationReq.UserIDList = atUserID
|
||||
conversation.GroupAtType = constant.AtAllAtMe
|
||||
tag = true
|
||||
}
|
||||
} else {
|
||||
conversationReq.UserIDList = req.MsgData.AtUserIDList
|
||||
conversation.GroupAtType = constant.AtMe
|
||||
}
|
||||
|
||||
err := m.Conversation.ModifyConversationField(ctx, &conversationReq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if tag {
|
||||
conversationReq.UserIDList = utils.DifferenceString(atUserID, memberUserIDList)
|
||||
conversation.GroupAtType = constant.AtAll
|
||||
err := m.Conversation.ModifyConversationField(ctx, &conversationReq)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
//
|
||||
|
||||
promePkg.PromeInc(promePkg.GroupChatMsgProcessSuccessCounter)
|
||||
resp.SendTime = msgToMQSingle.MsgData.SendTime
|
||||
resp.ServerMsgID = msgToMQSingle.MsgData.ServerMsgID
|
||||
resp.ClientMsgID = msgToMQSingle.MsgData.ClientMsgID
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) SendMsg(ctx context.Context, req *msg.SendMsgReq) (resp *msg.SendMsgResp, error error) {
|
||||
resp = &msg.SendMsgResp{}
|
||||
flag := isMessageHasReadEnabled(req.MsgData)
|
||||
if !flag {
|
||||
return nil, constant.ErrMessageHasReadDisable.Wrap()
|
||||
}
|
||||
m.encapsulateMsgData(req.MsgData)
|
||||
if err := CallbackMsgModify(ctx, req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch req.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
return m.sendMsgSingleChat(ctx, req)
|
||||
case constant.GroupChatType:
|
||||
return m.sendMsgGroupChat(ctx, req)
|
||||
case constant.NotificationChatType:
|
||||
return m.sendMsgNotification(ctx, req)
|
||||
case constant.SuperGroupChatType:
|
||||
return m.sendMsgSuperGroupChat(ctx, req)
|
||||
default:
|
||||
return nil, constant.ErrArgs.Wrap("unknown sessionType")
|
||||
}
|
||||
}
|
||||
|
||||
func (m *msgServer) GetMaxAndMinSeq(ctx context.Context, req *sdkws.GetMaxAndMinSeqReq) (*sdkws.GetMaxAndMinSeqResp, error) {
|
||||
resp := new(sdkws.GetMaxAndMinSeqResp)
|
||||
m2 := make(map[string]*sdkws.MaxAndMinSeq)
|
||||
maxSeq, err := m.MsgInterface.GetUserMaxSeq(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
minSeq, err := m.MsgInterface.GetUserMinSeq(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.MaxSeq = maxSeq
|
||||
resp.MinSeq = minSeq
|
||||
if len(req.GroupIDList) > 0 {
|
||||
resp.GroupMaxAndMinSeq = make(map[string]*sdkws.MaxAndMinSeq)
|
||||
for _, groupID := range req.GroupIDList {
|
||||
maxSeq, err := m.MsgInterface.GetGroupMaxSeq(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
minSeq, err := m.MsgInterface.GetGroupMinSeq(ctx, groupID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m2[groupID] = &sdkws.MaxAndMinSeq{
|
||||
MaxSeq: maxSeq,
|
||||
MinSeq: minSeq,
|
||||
}
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) PullMessageBySeqList(ctx context.Context, req *sdkws.PullMessageBySeqListReq) (*sdkws.PullMessageBySeqListResp, error) {
|
||||
resp := &sdkws.PullMessageBySeqListResp{GroupMsgDataList: make(map[string]*sdkws.MsgDataList)}
|
||||
msgs, err := m.MsgInterface.GetMessageListBySeq(ctx, req.UserID, req.SeqList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.List = msgs
|
||||
for userID, list := range req.GroupSeqList {
|
||||
msgs, err := m.MsgInterface.GetMessageListBySeq(ctx, userID, list.SeqList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.GroupMsgDataList[userID] = &sdkws.MsgDataList{
|
||||
MsgDataList: msgs,
|
||||
}
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/internal/common/check"
|
||||
"Open_IM/pkg/common/db/controller"
|
||||
"Open_IM/pkg/common/db/localcache"
|
||||
"Open_IM/pkg/common/db/relation"
|
||||
tablerelation "Open_IM/pkg/common/db/table/relation"
|
||||
discoveryRegistry "Open_IM/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"Open_IM/pkg/proto/msg"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type msgServer struct {
|
||||
RegisterCenter discoveryRegistry.SvcDiscoveryRegistry
|
||||
MsgInterface controller.MsgInterface
|
||||
Group *check.GroupChecker
|
||||
User *check.UserCheck
|
||||
Conversation *check.ConversationChecker
|
||||
friend *check.FriendChecker
|
||||
*localcache.GroupLocalCache
|
||||
black *check.BlackChecker
|
||||
}
|
||||
|
||||
type deleteMsg struct {
|
||||
UserID string
|
||||
OpUserID string
|
||||
SeqList []uint32
|
||||
OperationID string
|
||||
}
|
||||
|
||||
func Start(client *openKeeper.ZkClient, server *grpc.Server) error {
|
||||
mysql, err := relation.NewGormDB()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := mysql.AutoMigrate(&tablerelation.UserModel{}); err != nil {
|
||||
return err
|
||||
}
|
||||
s := &msgServer{
|
||||
Conversation: check.NewConversationChecker(client),
|
||||
User: check.NewUserCheck(client),
|
||||
Group: check.NewGroupChecker(client),
|
||||
//MsgInterface: controller.MsgInterface(),
|
||||
RegisterCenter: client,
|
||||
GroupLocalCache: localcache.NewGroupMemberIDsLocalCache(client),
|
||||
black: check.NewBlackChecker(client),
|
||||
friend: check.NewFriendChecker(client),
|
||||
}
|
||||
s.initPrometheus()
|
||||
msg.RegisterMsgServer(server, s)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *msgServer) initPrometheus() {
|
||||
promePkg.NewMsgPullFromRedisSuccessCounter()
|
||||
promePkg.NewMsgPullFromRedisFailedCounter()
|
||||
promePkg.NewMsgPullFromMongoSuccessCounter()
|
||||
promePkg.NewMsgPullFromMongoFailedCounter()
|
||||
promePkg.NewSingleChatMsgRecvSuccessCounter()
|
||||
promePkg.NewGroupChatMsgRecvSuccessCounter()
|
||||
promePkg.NewWorkSuperGroupChatMsgRecvSuccessCounter()
|
||||
promePkg.NewSingleChatMsgProcessSuccessCounter()
|
||||
promePkg.NewSingleChatMsgProcessFailedCounter()
|
||||
promePkg.NewGroupChatMsgProcessSuccessCounter()
|
||||
promePkg.NewGroupChatMsgProcessFailedCounter()
|
||||
promePkg.NewWorkSuperGroupChatMsgProcessSuccessCounter()
|
||||
promePkg.NewWorkSuperGroupChatMsgProcessFailedCounter()
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/proto/sdkws"
|
||||
"Open_IM/pkg/utils"
|
||||
"github.com/go-redis/redis/v8"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func isMessageHasReadEnabled(msgData *sdkws.MsgData) bool {
|
||||
switch msgData.ContentType {
|
||||
case constant.HasReadReceipt:
|
||||
if config.Config.SingleMessageHasReadReceiptEnable {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case constant.GroupHasReadReceipt:
|
||||
if config.Config.GroupMessageHasReadReceiptEnable {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsNotFound(err error) bool {
|
||||
switch utils.Unwrap(err) {
|
||||
case redis.Nil, gorm.ErrRecordNotFound:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package startrpc
|
||||
|
||||
import (
|
||||
"Open_IM/internal/common/network"
|
||||
"Open_IM/pkg/common/config"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/middleware"
|
||||
promePkg "Open_IM/pkg/common/prometheus"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/openKeeper"
|
||||
grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
)
|
||||
|
||||
func start(rpcPorts []int, rpcRegisterName string, prometheusPorts []int, rpcFn func(client *openKeeper.ZkClient, server *grpc.Server) error, options []grpc.ServerOption) error {
|
||||
flagRpcPort := flag.Int("port", rpcPorts[0], "get RpcGroupPort from cmd,default 16000 as port")
|
||||
flagPrometheusPort := flag.Int("prometheus_port", prometheusPorts[0], "groupPrometheusPort default listen port")
|
||||
flag.Parse()
|
||||
fmt.Println("start group rpc server, port: ", *flagRpcPort, ", OpenIM version: ", constant.CurrentVersion)
|
||||
log.NewPrivateLog(constant.LogFileName)
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", config.Config.ListenIP, *flagRpcPort))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer listener.Close()
|
||||
zkClient, err := openKeeper.NewClient(config.Config.Zookeeper.ZkAddr, config.Config.Zookeeper.Schema, 10, "", "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer zkClient.Close()
|
||||
registerIP, err := network.GetRpcRegisterIP(config.Config.RpcRegisterIP)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
options = append(options, grpc.UnaryInterceptor(middleware.RpcServerInterceptor)) // ctx 中间件
|
||||
if config.Config.Prometheus.Enable {
|
||||
promePkg.NewGrpcRequestCounter()
|
||||
promePkg.NewGrpcRequestFailedCounter()
|
||||
promePkg.NewGrpcRequestSuccessCounter()
|
||||
options = append(options, []grpc.ServerOption{
|
||||
// grpc.UnaryInterceptor(promePkg.UnaryServerInterceptorProme),
|
||||
grpc.StreamInterceptor(grpcPrometheus.StreamServerInterceptor),
|
||||
grpc.UnaryInterceptor(grpcPrometheus.UnaryServerInterceptor),
|
||||
}...)
|
||||
}
|
||||
srv := grpc.NewServer(options...)
|
||||
defer srv.GracefulStop()
|
||||
err = zkClient.Register(rpcRegisterName, registerIP, *flagRpcPort)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if config.Config.Prometheus.Enable {
|
||||
err := promePkg.StartPromeSrv(*flagPrometheusPort)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return rpcFn(zkClient, srv)
|
||||
}
|
||||
|
||||
func Start(rpcPorts []int, rpcRegisterName string, prometheusPorts []int, rpcFn func(client *openKeeper.ZkClient, server *grpc.Server) error, options ...grpc.ServerOption) {
|
||||
err := start(rpcPorts, rpcRegisterName, prometheusPorts, rpcFn, options)
|
||||
fmt.Println("end", err)
|
||||
}
|
||||
@ -0,0 +1,148 @@
|
||||
package relation
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
func NewGormDB() (*gorm.DB, error) {
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
|
||||
db, err := gorm.Open(mysql.Open(dsn), nil)
|
||||
if err != nil {
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
db, err = gorm.Open(mysql.Open(dsn), nil)
|
||||
if err != nil {
|
||||
panic(err.Error() + " open failed " + dsn)
|
||||
}
|
||||
}
|
||||
sqlDB, err := db.DB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer sqlDB.Close()
|
||||
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
|
||||
err = db.Exec(sql).Error
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("init db %w", err)
|
||||
}
|
||||
dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||
newLogger := logger.New(
|
||||
Writer{},
|
||||
logger.Config{
|
||||
SlowThreshold: time.Duration(config.Config.Mysql.SlowThreshold) * time.Millisecond, // Slow SQL threshold
|
||||
LogLevel: logger.LogLevel(config.Config.Mysql.LogLevel), // Log level
|
||||
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
|
||||
Colorful: true, // Disable color
|
||||
},
|
||||
)
|
||||
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
Logger: newLogger,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sqlDB, err = db.DB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sqlDB.SetConnMaxLifetime(time.Second * time.Duration(config.Config.Mysql.DBMaxLifeTime))
|
||||
sqlDB.SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns)
|
||||
sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
|
||||
return db, nil
|
||||
}
|
||||
|
||||
type Mysql struct {
|
||||
gormConn *gorm.DB
|
||||
}
|
||||
|
||||
func (m *Mysql) GormConn() *gorm.DB {
|
||||
return m.gormConn
|
||||
}
|
||||
|
||||
//func (m *Mysql) SetGormConn(gormConn *gorm.DB) {
|
||||
// m.gormConn = gormConn
|
||||
//}
|
||||
//
|
||||
//func (m *Mysql) InitConn() *Mysql {
|
||||
// dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
// config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
|
||||
// var db *gorm.DB
|
||||
// db, err := gorm.Open(mysql.Open(dsn), nil)
|
||||
// if err != nil {
|
||||
// time.Sleep(time.Duration(30) * time.Second)
|
||||
// db, err = gorm.Open(mysql.Open(dsn), nil)
|
||||
// if err != nil {
|
||||
// panic(err.Error() + " open failed " + dsn)
|
||||
// }
|
||||
// }
|
||||
// sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s default charset utf8 COLLATE utf8_general_ci;", config.Config.Mysql.DBDatabaseName)
|
||||
// err = db.Exec(sql).Error
|
||||
// if err != nil {
|
||||
// panic(err.Error() + " Exec failed:" + sql)
|
||||
// }
|
||||
// dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||
// config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName)
|
||||
// newLogger := logger.New(
|
||||
// Writer{},
|
||||
// logger.Config{
|
||||
// SlowThreshold: time.Duration(config.Config.Mysql.SlowThreshold) * time.Millisecond, // Slow SQL threshold
|
||||
// LogLevel: logger.LogLevel(config.Config.Mysql.LogLevel), // Log level
|
||||
// IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
|
||||
// Colorful: true, // Disable color
|
||||
// },
|
||||
// )
|
||||
// db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||
// Logger: newLogger,
|
||||
// })
|
||||
// if err != nil {
|
||||
// panic(err.Error() + " Open failed " + dsn)
|
||||
// }
|
||||
// sqlDB, err := db.DB()
|
||||
// if err != nil {
|
||||
// panic(err.Error() + " DB.DB() failed ")
|
||||
// }
|
||||
// sqlDB.SetConnMaxLifetime(time.Second * time.Duration(config.Config.Mysql.DBMaxLifeTime))
|
||||
// sqlDB.SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns)
|
||||
// sqlDB.SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns)
|
||||
// if db == nil {
|
||||
// panic("db is nil")
|
||||
// }
|
||||
// m.SetGormConn(db)
|
||||
// return m
|
||||
//}
|
||||
|
||||
//models := []interface{}{&Friend{}, &FriendRequest{}, &Group{}, &GroupMember{}, &GroupRequest{},
|
||||
// &User{}, &Black{}, &ChatLog{}, &Conversation{}, &AppVersion{}}
|
||||
|
||||
//func (m *Mysql) AutoMigrateModel(model interface{}) error {
|
||||
// err := m.gormConn.AutoMigrate(model)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// m.gormConn.Set("gorm:table_options", "CHARSET=utf8")
|
||||
// m.gormConn.Set("gorm:table_options", "collation=utf8_unicode_ci")
|
||||
// _ = m.gormConn.Migrator().CreateTable(model)
|
||||
// return nil
|
||||
//}
|
||||
|
||||
type Writer struct{}
|
||||
|
||||
func (w Writer) Printf(format string, args ...interface{}) {
|
||||
fmt.Printf(format, args...)
|
||||
}
|
||||
|
||||
func getDBConn(db *gorm.DB, tx []any) *gorm.DB {
|
||||
if len(tx) > 0 {
|
||||
if txDB, ok := tx[0].(*gorm.DB); ok {
|
||||
return txDB
|
||||
}
|
||||
}
|
||||
return db
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue