mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-08 11:05:59 +08:00
Merge remote-tracking branch 'origin/errcode' into errcode
This commit is contained in:
@@ -62,8 +62,6 @@ func (m Message) newUserSendMsgReq(c *gin.Context, params *apistruct.ManagementS
|
||||
fallthrough
|
||||
case constant.CustomOnlineOnly:
|
||||
fallthrough
|
||||
case constant.AdvancedRevoke:
|
||||
newContent = utils.StructToJsonString(params.Content)
|
||||
case constant.Revoke:
|
||||
newContent = params.Content["revokeMsgClientID"].(string)
|
||||
default:
|
||||
@@ -197,8 +195,6 @@ func (m *Message) SendMessage(c *gin.Context) {
|
||||
data = apistruct.CustomElem{}
|
||||
case constant.Revoke:
|
||||
data = apistruct.RevokeElem{}
|
||||
case constant.AdvancedRevoke:
|
||||
data = apistruct.MessageRevoked{}
|
||||
case constant.OANotification:
|
||||
data = apistruct.OANotificationElem{}
|
||||
params.SessionType = constant.NotificationChatType
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
func NewUser(discov discoveryregistry.SvcDiscoveryRegistry) *User {
|
||||
conn, err := discov.GetConn(context.Background(), config.Config.RpcRegisterName.OpenImUserName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
// panic(err)
|
||||
}
|
||||
log.ZInfo(context.Background(), "user rpc conn", "conn", conn)
|
||||
return &User{conn: conn, discov: discov}
|
||||
@@ -34,7 +34,7 @@ type User struct {
|
||||
func (u *User) client(ctx context.Context) (user.UserClient, error) {
|
||||
conn, err := u.discov.GetConn(ctx, config.Config.RpcRegisterName.OpenImUserName)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
return user.NewUserClient(conn), nil
|
||||
}
|
||||
|
||||
+19
-10
@@ -297,7 +297,11 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo
|
||||
resp.Groups = utils.Slice(utils.Order(groupIDs, groups, func(group *relationTb.GroupModel) string {
|
||||
return group.GroupID
|
||||
}), func(group *relationTb.GroupModel) *sdkws.GroupInfo {
|
||||
return convert.Db2PbGroupInfo(group, ownerMap[group.GroupID].UserID, groupMemberNum[group.GroupID])
|
||||
var userID string
|
||||
if user := ownerMap[group.GroupID]; user != nil {
|
||||
userID = user.UserID
|
||||
}
|
||||
return convert.Db2PbGroupInfo(group, userID, groupMemberNum[group.GroupID])
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
@@ -321,17 +325,22 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var groupMember *relationTb.GroupMemberModel
|
||||
var opUserID string
|
||||
if !tokenverify.IsAppManagerUid(ctx) {
|
||||
opUserID = mcontext.GetOpUserID(ctx)
|
||||
groupMembers, err := s.FindGroupMember(ctx, []string{req.GroupID}, []string{opUserID}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(groupMembers) <= 0 {
|
||||
return nil, errs.ErrNoPermission.Wrap("not in group")
|
||||
}
|
||||
groupMember = groupMembers[0]
|
||||
}
|
||||
if group.NeedVerification == constant.AllNeedVerification {
|
||||
if !tokenverify.IsAppManagerUid(ctx) {
|
||||
opUserID := mcontext.GetOpUserID(ctx)
|
||||
groupMembers, err := s.FindGroupMember(ctx, []string{req.GroupID}, []string{opUserID}, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(groupMembers) <= 0 {
|
||||
return nil, errs.ErrNoPermission.Wrap("not in group")
|
||||
}
|
||||
if !(groupMembers[0].RoleLevel == constant.GroupOwner || groupMembers[0].RoleLevel == constant.GroupAdmin) {
|
||||
if !(groupMember.RoleLevel == constant.GroupOwner || groupMember.RoleLevel == constant.GroupAdmin) {
|
||||
var requests []*relationTb.GroupRequestModel
|
||||
for _, userID := range req.InvitedUserIDs {
|
||||
requests = append(requests, &relationTb.GroupRequestModel{
|
||||
|
||||
+17
-18
@@ -4,40 +4,39 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
)
|
||||
|
||||
func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadReq) (resp *msg.MarkMsgsAsReadResp, err error) {
|
||||
if len(req.Seqs) < 1 {
|
||||
return nil, errs.ErrArgs.Wrap("seqs must not be empty")
|
||||
}
|
||||
conversations, err := m.Conversation.GetConversationsByConversationID(ctx, []string{req.ConversationID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var recvID string
|
||||
if conversations[0].ConversationType == constant.SingleChatType || conversations[0].ConversationType == constant.NotificationChatType {
|
||||
if req.UserID == conversations[0].OwnerUserID {
|
||||
recvID = conversations[0].UserID
|
||||
} else {
|
||||
recvID = conversations[0].OwnerUserID
|
||||
}
|
||||
} else if conversations[0].ConversationType == constant.SuperGroupChatType {
|
||||
recvID = conversations[0].GroupID
|
||||
}
|
||||
err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.ConversationID, req.UserID, req.Seqs)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, req.UserID, recvID, req.Seqs); err != nil {
|
||||
err = m.Conversation.SetHasReadSeq(ctx, req.UserID, req.ConversationID, conversations[0].ConversationType, req.Seqs[len(req.Seqs)-1])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversations[0].ConversationType, req.UserID, m.conversationAndGetRecvID(conversations[0], req.UserID), req.Seqs); err != nil {
|
||||
return
|
||||
}
|
||||
return &msg.MarkMsgsAsReadResp{}, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) sendMarkAsReadNotification(ctx context.Context, conversationID string, sendID, recvID string, seqs []int64) error {
|
||||
// tips := &sdkws.MarkAsReadTips{
|
||||
// MarkAsReadUserID: sendID,
|
||||
// ConversationID: conversationID,
|
||||
// Seqs: seqs,
|
||||
// }
|
||||
// m.notificationSender.NotificationWithSesstionType(ctx)
|
||||
func (m *msgServer) sendMarkAsReadNotification(ctx context.Context, conversationID string, sesstionType int32, sendID, recvID string, seqs []int64) error {
|
||||
tips := &sdkws.MarkAsReadTips{
|
||||
MarkAsReadUserID: sendID,
|
||||
ConversationID: conversationID,
|
||||
Seqs: seqs,
|
||||
}
|
||||
m.notificationSender.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -64,18 +64,8 @@ func (m *msgServer) DeleteMsgs(ctx context.Context, req *msg.DeleteMsgsReq) (*ms
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var recvID string
|
||||
if conversations[0].ConversationType == constant.SingleChatType || conversations[0].ConversationType == constant.NotificationChatType {
|
||||
if conversations[0].OwnerUserID == recvID {
|
||||
recvID = conversations[0].UserID
|
||||
} else if conversations[0].UserID == recvID {
|
||||
recvID = conversations[0].OwnerUserID
|
||||
}
|
||||
} else if conversations[0].ConversationType == constant.SuperGroupChatType {
|
||||
recvID = conversations[0].GroupID
|
||||
}
|
||||
tips := &sdkws.DeleteMsgsTips{UserID: req.UserID, ConversationID: req.ConversationID, Seqs: req.Seqs}
|
||||
m.notificationSender.NotificationWithSesstionType(ctx, req.UserID, recvID, constant.DeleteMsgsNotification, conversations[0].ConversationType, tips)
|
||||
m.notificationSender.NotificationWithSesstionType(ctx, req.UserID, m.conversationAndGetRecvID(conversations[0], req.UserID), constant.DeleteMsgsNotification, conversations[0].ConversationType, tips)
|
||||
} else {
|
||||
if err := m.MsgDatabase.DeleteUserMsgsBySeqs(ctx, req.UserID, req.ConversationID, req.Seqs); err != nil {
|
||||
return nil, err
|
||||
@@ -139,18 +129,8 @@ func (m *msgServer) clearConversation(ctx context.Context, conversationIDs []str
|
||||
return err
|
||||
}
|
||||
for _, conversation := range existConversations {
|
||||
var recvID string
|
||||
if conversation.ConversationType == constant.SingleChatType || conversation.ConversationType == constant.NotificationChatType {
|
||||
if conversation.OwnerUserID == recvID {
|
||||
recvID = conversation.UserID
|
||||
} else if conversation.UserID == recvID {
|
||||
recvID = conversation.OwnerUserID
|
||||
}
|
||||
} else if conversation.ConversationType == constant.SuperGroupChatType {
|
||||
recvID = conversation.GroupID
|
||||
}
|
||||
tips := &sdkws.ClearConversationTips{UserID: userID, ConversationIDs: []string{conversation.ConversationID}}
|
||||
m.notificationSender.NotificationWithSesstionType(ctx, userID, recvID, constant.ClearConversationNotification, conversation.ConversationType, tips)
|
||||
m.notificationSender.NotificationWithSesstionType(ctx, userID, m.conversationAndGetRecvID(conversation, userID), constant.ClearConversationNotification, conversation.ConversationType, tips)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -14,14 +14,14 @@ import (
|
||||
type MessageInterceptorFunc func(ctx context.Context, req *msg.SendMsgReq) (*sdkws.MsgData, error)
|
||||
|
||||
func MessageHasReadEnabled(_ context.Context, req *msg.SendMsgReq) (*sdkws.MsgData, error) {
|
||||
switch req.MsgData.ContentType {
|
||||
case constant.HasReadReceipt:
|
||||
switch {
|
||||
case req.MsgData.ContentType == constant.HasReadReceipt && req.MsgData.SessionType == constant.SingleChatType:
|
||||
if config.Config.SingleMessageHasReadReceiptEnable {
|
||||
return req.MsgData, nil
|
||||
} else {
|
||||
return nil, errs.ErrMessageHasReadDisable.Wrap()
|
||||
}
|
||||
case constant.GroupHasReadReceipt:
|
||||
case req.MsgData.ContentType == constant.HasReadReceipt && req.MsgData.SessionType == constant.SuperGroupChatType:
|
||||
if config.Config.GroupMessageHasReadReceiptEnable {
|
||||
return req.MsgData, nil
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@ package msg
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/cache"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/controller"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/localcache"
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/unrelation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/prome"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/conversation"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/rpcclient"
|
||||
"google.golang.org/grpc"
|
||||
@@ -100,3 +102,24 @@ func (m *msgServer) initPrometheus() {
|
||||
prome.NewWorkSuperGroupChatMsgProcessSuccessCounter()
|
||||
prome.NewWorkSuperGroupChatMsgProcessFailedCounter()
|
||||
}
|
||||
|
||||
func (m *msgServer) getConversationAndGetRecvID(ctx context.Context, userID, conversationID string) (recvID string, err error) {
|
||||
conversations, err := m.Conversation.GetConversationsByConversationID(ctx, []string{conversationID})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return m.conversationAndGetRecvID(conversations[0], userID), nil
|
||||
}
|
||||
|
||||
func (m *msgServer) conversationAndGetRecvID(conversation *conversation.Conversation, userID string) (recvID string) {
|
||||
if conversation.ConversationType == constant.SingleChatType || conversation.ConversationType == constant.NotificationChatType {
|
||||
if userID == conversation.OwnerUserID {
|
||||
recvID = conversation.UserID
|
||||
} else {
|
||||
recvID = conversation.OwnerUserID
|
||||
}
|
||||
} else if conversation.ConversationType == constant.SuperGroupChatType {
|
||||
recvID = conversation.GroupID
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
)
|
||||
|
||||
func isMessageHasReadEnabled(msgData *sdkws.MsgData) bool {
|
||||
switch msgData.ContentType {
|
||||
case constant.HasReadReceipt:
|
||||
switch {
|
||||
case msgData.ContentType == constant.HasReadReceipt && msgData.SessionType == constant.SingleChatType:
|
||||
if config.Config.SingleMessageHasReadReceiptEnable {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case constant.GroupHasReadReceipt:
|
||||
case msgData.ContentType == constant.HasReadReceipt && msgData.SessionType == constant.SuperGroupChatType:
|
||||
if config.Config.GroupMessageHasReadReceiptEnable {
|
||||
return true
|
||||
} else {
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ExcludeContentType = []int{constant.HasReadReceipt, constant.GroupHasReadReceipt}
|
||||
ExcludeContentType = []int{constant.HasReadReceipt}
|
||||
)
|
||||
|
||||
type Validator interface {
|
||||
|
||||
Reference in New Issue
Block a user