From 3f5dd5bad88f0a4bc3024d98350509fc94b98569 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 16 Nov 2022 11:54:24 +0800 Subject: [PATCH 01/19] read after burn time --- internal/rpc/conversation/conversaion.go | 2 + pkg/base_info/conversation_api_struct.go | 1 + pkg/common/constant/constant.go | 1 + pkg/common/db/model_struct.go | 1 + pkg/proto/conversation/conversation.pb.go | 686 ++++++++-------------- pkg/proto/conversation/conversation.proto | 1 + 6 files changed, 264 insertions(+), 428 deletions(-) diff --git a/internal/rpc/conversation/conversaion.go b/internal/rpc/conversation/conversaion.go index be51e770f..c6ffb8580 100644 --- a/internal/rpc/conversation/conversaion.go +++ b/internal/rpc/conversation/conversaion.go @@ -78,6 +78,8 @@ func (rpc *rpcConversation) ModifyConversationField(c context.Context, req *pbCo case constant.FieldUnread: isSyncConversation = false err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"update_unread_count_time": conversation.UpdateUnreadCountTime}) + case constant.FieldBurnDuration: + err = imdb.UpdateColumnsConversations(haveUserID, req.Conversation.ConversationID, map[string]interface{}{"burn_duration": conversation.BurnDuration}) } if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "UpdateColumnsConversations error", err.Error()) diff --git a/pkg/base_info/conversation_api_struct.go b/pkg/base_info/conversation_api_struct.go index be913a3c0..08353e2ed 100644 --- a/pkg/base_info/conversation_api_struct.go +++ b/pkg/base_info/conversation_api_struct.go @@ -43,6 +43,7 @@ type Conversation struct { DraftTextTime int64 `json:"draftTextTime"` IsPinned bool `json:"isPinned" binding:"omitempty"` IsPrivateChat bool `json:"isPrivateChat"` + BurnDuration int32 `json:"burnDuration"` GroupAtType int32 `json:"groupAtType"` IsNotInGroup bool `json:"isNotInGroup"` UpdateUnreadCountTime int64 `json:"updateUnreadCountTime"` diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 48b0cfca6..a817ab02c 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -275,6 +275,7 @@ const ( FieldIsNotInGroup = 6 FieldEx = 7 FieldUnread = 8 + FieldBurnDuration = 9 ) const ( diff --git a/pkg/common/db/model_struct.go b/pkg/common/db/model_struct.go index 6b767b6dc..882ae6b46 100644 --- a/pkg/common/db/model_struct.go +++ b/pkg/common/db/model_struct.go @@ -263,6 +263,7 @@ type Conversation struct { DraftTextTime int64 `gorm:"column:draft_text_time" json:"draftTextTime"` IsPinned bool `gorm:"column:is_pinned" json:"isPinned"` IsPrivateChat bool `gorm:"column:is_private_chat" json:"isPrivateChat"` + BurnDuration int32 `gorm:"column:burn_duration;default:30" json:"burnDuration"` GroupAtType int32 `gorm:"column:group_at_type" json:"groupAtType"` IsNotInGroup bool `gorm:"column:is_not_in_group" json:"isNotInGroup"` UpdateUnreadCountTime int64 `gorm:"column:update_unread_count_time" json:"updateUnreadCountTime"` diff --git a/pkg/proto/conversation/conversation.pb.go b/pkg/proto/conversation/conversation.pb.go index ae7a03c16..ddb265d42 100644 --- a/pkg/proto/conversation/conversation.pb.go +++ b/pkg/proto/conversation/conversation.pb.go @@ -1,587 +1,376 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// versions: -// protoc-gen-go v1.27.1 -// protoc v3.15.5 // source: conversation/conversation.proto -package conversation +package conversation // import "Open_IM/pkg/proto/conversation" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" import ( - context "context" + context "golang.org/x/net/context" grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) -const ( - // Verify that this generated code is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) - // Verify that runtime/protoimpl is sufficiently up-to-date. - _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) -) +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf -type CommonResp struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - ErrCode int32 `protobuf:"varint,1,opt,name=errCode,proto3" json:"errCode,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=errMsg,proto3" json:"errMsg,omitempty"` +type CommonResp struct { + ErrCode int32 `protobuf:"varint,1,opt,name=errCode" json:"errCode,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=errMsg" json:"errMsg,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (x *CommonResp) Reset() { - *x = CommonResp{} - if protoimpl.UnsafeEnabled { - mi := &file_conversation_conversation_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *CommonResp) Reset() { *m = CommonResp{} } +func (m *CommonResp) String() string { return proto.CompactTextString(m) } +func (*CommonResp) ProtoMessage() {} +func (*CommonResp) Descriptor() ([]byte, []int) { + return fileDescriptor_conversation_7438d6c35155b4e4, []int{0} } - -func (x *CommonResp) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *CommonResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CommonResp.Unmarshal(m, b) } - -func (*CommonResp) ProtoMessage() {} - -func (x *CommonResp) ProtoReflect() protoreflect.Message { - mi := &file_conversation_conversation_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *CommonResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CommonResp.Marshal(b, m, deterministic) } - -// Deprecated: Use CommonResp.ProtoReflect.Descriptor instead. -func (*CommonResp) Descriptor() ([]byte, []int) { - return file_conversation_conversation_proto_rawDescGZIP(), []int{0} +func (dst *CommonResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_CommonResp.Merge(dst, src) +} +func (m *CommonResp) XXX_Size() int { + return xxx_messageInfo_CommonResp.Size(m) } +func (m *CommonResp) XXX_DiscardUnknown() { + xxx_messageInfo_CommonResp.DiscardUnknown(m) +} + +var xxx_messageInfo_CommonResp proto.InternalMessageInfo -func (x *CommonResp) GetErrCode() int32 { - if x != nil { - return x.ErrCode +func (m *CommonResp) GetErrCode() int32 { + if m != nil { + return m.ErrCode } return 0 } -func (x *CommonResp) GetErrMsg() string { - if x != nil { - return x.ErrMsg +func (m *CommonResp) GetErrMsg() string { + if m != nil { + return m.ErrMsg } return "" } type Conversation struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - OwnerUserID string `protobuf:"bytes,1,opt,name=ownerUserID,proto3" json:"ownerUserID,omitempty"` - ConversationID string `protobuf:"bytes,2,opt,name=conversationID,proto3" json:"conversationID,omitempty"` - RecvMsgOpt int32 `protobuf:"varint,3,opt,name=recvMsgOpt,proto3" json:"recvMsgOpt,omitempty"` - ConversationType int32 `protobuf:"varint,4,opt,name=conversationType,proto3" json:"conversationType,omitempty"` - UserID string `protobuf:"bytes,5,opt,name=userID,proto3" json:"userID,omitempty"` - GroupID string `protobuf:"bytes,6,opt,name=groupID,proto3" json:"groupID,omitempty"` - UnreadCount int32 `protobuf:"varint,7,opt,name=unreadCount,proto3" json:"unreadCount,omitempty"` - DraftTextTime int64 `protobuf:"varint,8,opt,name=draftTextTime,proto3" json:"draftTextTime,omitempty"` - IsPinned bool `protobuf:"varint,9,opt,name=isPinned,proto3" json:"isPinned,omitempty"` - AttachedInfo string `protobuf:"bytes,10,opt,name=attachedInfo,proto3" json:"attachedInfo,omitempty"` - IsPrivateChat bool `protobuf:"varint,11,opt,name=isPrivateChat,proto3" json:"isPrivateChat,omitempty"` - GroupAtType int32 `protobuf:"varint,12,opt,name=groupAtType,proto3" json:"groupAtType,omitempty"` - IsNotInGroup bool `protobuf:"varint,13,opt,name=isNotInGroup,proto3" json:"isNotInGroup,omitempty"` - Ex string `protobuf:"bytes,14,opt,name=ex,proto3" json:"ex,omitempty"` - UpdateUnreadCountTime int64 `protobuf:"varint,15,opt,name=updateUnreadCountTime,proto3" json:"updateUnreadCountTime,omitempty"` -} - -func (x *Conversation) Reset() { - *x = Conversation{} - if protoimpl.UnsafeEnabled { - mi := &file_conversation_conversation_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + OwnerUserID string `protobuf:"bytes,1,opt,name=ownerUserID" json:"ownerUserID,omitempty"` + ConversationID string `protobuf:"bytes,2,opt,name=conversationID" json:"conversationID,omitempty"` + RecvMsgOpt int32 `protobuf:"varint,3,opt,name=recvMsgOpt" json:"recvMsgOpt,omitempty"` + ConversationType int32 `protobuf:"varint,4,opt,name=conversationType" json:"conversationType,omitempty"` + UserID string `protobuf:"bytes,5,opt,name=userID" json:"userID,omitempty"` + GroupID string `protobuf:"bytes,6,opt,name=groupID" json:"groupID,omitempty"` + UnreadCount int32 `protobuf:"varint,7,opt,name=unreadCount" json:"unreadCount,omitempty"` + DraftTextTime int64 `protobuf:"varint,8,opt,name=draftTextTime" json:"draftTextTime,omitempty"` + IsPinned bool `protobuf:"varint,9,opt,name=isPinned" json:"isPinned,omitempty"` + AttachedInfo string `protobuf:"bytes,10,opt,name=attachedInfo" json:"attachedInfo,omitempty"` + IsPrivateChat bool `protobuf:"varint,11,opt,name=isPrivateChat" json:"isPrivateChat,omitempty"` + GroupAtType int32 `protobuf:"varint,12,opt,name=groupAtType" json:"groupAtType,omitempty"` + IsNotInGroup bool `protobuf:"varint,13,opt,name=isNotInGroup" json:"isNotInGroup,omitempty"` + Ex string `protobuf:"bytes,14,opt,name=ex" json:"ex,omitempty"` + UpdateUnreadCountTime int64 `protobuf:"varint,15,opt,name=updateUnreadCountTime" json:"updateUnreadCountTime,omitempty"` + BurnDuration int32 `protobuf:"varint,16,opt,name=burnDuration" json:"burnDuration,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Conversation) Reset() { *m = Conversation{} } +func (m *Conversation) String() string { return proto.CompactTextString(m) } +func (*Conversation) ProtoMessage() {} +func (*Conversation) Descriptor() ([]byte, []int) { + return fileDescriptor_conversation_7438d6c35155b4e4, []int{1} } - -func (x *Conversation) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *Conversation) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Conversation.Unmarshal(m, b) } - -func (*Conversation) ProtoMessage() {} - -func (x *Conversation) ProtoReflect() protoreflect.Message { - mi := &file_conversation_conversation_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *Conversation) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Conversation.Marshal(b, m, deterministic) } - -// Deprecated: Use Conversation.ProtoReflect.Descriptor instead. -func (*Conversation) Descriptor() ([]byte, []int) { - return file_conversation_conversation_proto_rawDescGZIP(), []int{1} +func (dst *Conversation) XXX_Merge(src proto.Message) { + xxx_messageInfo_Conversation.Merge(dst, src) +} +func (m *Conversation) XXX_Size() int { + return xxx_messageInfo_Conversation.Size(m) +} +func (m *Conversation) XXX_DiscardUnknown() { + xxx_messageInfo_Conversation.DiscardUnknown(m) } -func (x *Conversation) GetOwnerUserID() string { - if x != nil { - return x.OwnerUserID +var xxx_messageInfo_Conversation proto.InternalMessageInfo + +func (m *Conversation) GetOwnerUserID() string { + if m != nil { + return m.OwnerUserID } return "" } -func (x *Conversation) GetConversationID() string { - if x != nil { - return x.ConversationID +func (m *Conversation) GetConversationID() string { + if m != nil { + return m.ConversationID } return "" } -func (x *Conversation) GetRecvMsgOpt() int32 { - if x != nil { - return x.RecvMsgOpt +func (m *Conversation) GetRecvMsgOpt() int32 { + if m != nil { + return m.RecvMsgOpt } return 0 } -func (x *Conversation) GetConversationType() int32 { - if x != nil { - return x.ConversationType +func (m *Conversation) GetConversationType() int32 { + if m != nil { + return m.ConversationType } return 0 } -func (x *Conversation) GetUserID() string { - if x != nil { - return x.UserID +func (m *Conversation) GetUserID() string { + if m != nil { + return m.UserID } return "" } -func (x *Conversation) GetGroupID() string { - if x != nil { - return x.GroupID +func (m *Conversation) GetGroupID() string { + if m != nil { + return m.GroupID } return "" } -func (x *Conversation) GetUnreadCount() int32 { - if x != nil { - return x.UnreadCount +func (m *Conversation) GetUnreadCount() int32 { + if m != nil { + return m.UnreadCount } return 0 } -func (x *Conversation) GetDraftTextTime() int64 { - if x != nil { - return x.DraftTextTime +func (m *Conversation) GetDraftTextTime() int64 { + if m != nil { + return m.DraftTextTime } return 0 } -func (x *Conversation) GetIsPinned() bool { - if x != nil { - return x.IsPinned +func (m *Conversation) GetIsPinned() bool { + if m != nil { + return m.IsPinned } return false } -func (x *Conversation) GetAttachedInfo() string { - if x != nil { - return x.AttachedInfo +func (m *Conversation) GetAttachedInfo() string { + if m != nil { + return m.AttachedInfo } return "" } -func (x *Conversation) GetIsPrivateChat() bool { - if x != nil { - return x.IsPrivateChat +func (m *Conversation) GetIsPrivateChat() bool { + if m != nil { + return m.IsPrivateChat } return false } -func (x *Conversation) GetGroupAtType() int32 { - if x != nil { - return x.GroupAtType +func (m *Conversation) GetGroupAtType() int32 { + if m != nil { + return m.GroupAtType } return 0 } -func (x *Conversation) GetIsNotInGroup() bool { - if x != nil { - return x.IsNotInGroup +func (m *Conversation) GetIsNotInGroup() bool { + if m != nil { + return m.IsNotInGroup } return false } -func (x *Conversation) GetEx() string { - if x != nil { - return x.Ex +func (m *Conversation) GetEx() string { + if m != nil { + return m.Ex } return "" } -func (x *Conversation) GetUpdateUnreadCountTime() int64 { - if x != nil { - return x.UpdateUnreadCountTime +func (m *Conversation) GetUpdateUnreadCountTime() int64 { + if m != nil { + return m.UpdateUnreadCountTime } return 0 } -type ModifyConversationFieldReq struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - Conversation *Conversation `protobuf:"bytes,1,opt,name=conversation,proto3" json:"conversation,omitempty"` - FieldType int32 `protobuf:"varint,2,opt,name=fieldType,proto3" json:"fieldType,omitempty"` - UserIDList []string `protobuf:"bytes,3,rep,name=userIDList,proto3" json:"userIDList,omitempty"` - OperationID string `protobuf:"bytes,4,opt,name=operationID,proto3" json:"operationID,omitempty"` -} - -func (x *ModifyConversationFieldReq) Reset() { - *x = ModifyConversationFieldReq{} - if protoimpl.UnsafeEnabled { - mi := &file_conversation_conversation_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) +func (m *Conversation) GetBurnDuration() int32 { + if m != nil { + return m.BurnDuration } + return 0 } -func (x *ModifyConversationFieldReq) String() string { - return protoimpl.X.MessageStringOf(x) +type ModifyConversationFieldReq struct { + Conversation *Conversation `protobuf:"bytes,1,opt,name=conversation" json:"conversation,omitempty"` + FieldType int32 `protobuf:"varint,2,opt,name=fieldType" json:"fieldType,omitempty"` + UserIDList []string `protobuf:"bytes,3,rep,name=userIDList" json:"userIDList,omitempty"` + OperationID string `protobuf:"bytes,4,opt,name=operationID" json:"operationID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *ModifyConversationFieldReq) Reset() { *m = ModifyConversationFieldReq{} } +func (m *ModifyConversationFieldReq) String() string { return proto.CompactTextString(m) } +func (*ModifyConversationFieldReq) ProtoMessage() {} +func (*ModifyConversationFieldReq) Descriptor() ([]byte, []int) { + return fileDescriptor_conversation_7438d6c35155b4e4, []int{2} } - -func (*ModifyConversationFieldReq) ProtoMessage() {} - -func (x *ModifyConversationFieldReq) ProtoReflect() protoreflect.Message { - mi := &file_conversation_conversation_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *ModifyConversationFieldReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ModifyConversationFieldReq.Unmarshal(m, b) } - -// Deprecated: Use ModifyConversationFieldReq.ProtoReflect.Descriptor instead. -func (*ModifyConversationFieldReq) Descriptor() ([]byte, []int) { - return file_conversation_conversation_proto_rawDescGZIP(), []int{2} +func (m *ModifyConversationFieldReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ModifyConversationFieldReq.Marshal(b, m, deterministic) +} +func (dst *ModifyConversationFieldReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModifyConversationFieldReq.Merge(dst, src) +} +func (m *ModifyConversationFieldReq) XXX_Size() int { + return xxx_messageInfo_ModifyConversationFieldReq.Size(m) +} +func (m *ModifyConversationFieldReq) XXX_DiscardUnknown() { + xxx_messageInfo_ModifyConversationFieldReq.DiscardUnknown(m) } -func (x *ModifyConversationFieldReq) GetConversation() *Conversation { - if x != nil { - return x.Conversation +var xxx_messageInfo_ModifyConversationFieldReq proto.InternalMessageInfo + +func (m *ModifyConversationFieldReq) GetConversation() *Conversation { + if m != nil { + return m.Conversation } return nil } -func (x *ModifyConversationFieldReq) GetFieldType() int32 { - if x != nil { - return x.FieldType +func (m *ModifyConversationFieldReq) GetFieldType() int32 { + if m != nil { + return m.FieldType } return 0 } -func (x *ModifyConversationFieldReq) GetUserIDList() []string { - if x != nil { - return x.UserIDList +func (m *ModifyConversationFieldReq) GetUserIDList() []string { + if m != nil { + return m.UserIDList } return nil } -func (x *ModifyConversationFieldReq) GetOperationID() string { - if x != nil { - return x.OperationID +func (m *ModifyConversationFieldReq) GetOperationID() string { + if m != nil { + return m.OperationID } return "" } type ModifyConversationFieldResp struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp,proto3" json:"commonResp,omitempty"` + CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (x *ModifyConversationFieldResp) Reset() { - *x = ModifyConversationFieldResp{} - if protoimpl.UnsafeEnabled { - mi := &file_conversation_conversation_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } +func (m *ModifyConversationFieldResp) Reset() { *m = ModifyConversationFieldResp{} } +func (m *ModifyConversationFieldResp) String() string { return proto.CompactTextString(m) } +func (*ModifyConversationFieldResp) ProtoMessage() {} +func (*ModifyConversationFieldResp) Descriptor() ([]byte, []int) { + return fileDescriptor_conversation_7438d6c35155b4e4, []int{3} } - -func (x *ModifyConversationFieldResp) String() string { - return protoimpl.X.MessageStringOf(x) +func (m *ModifyConversationFieldResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_ModifyConversationFieldResp.Unmarshal(m, b) } - -func (*ModifyConversationFieldResp) ProtoMessage() {} - -func (x *ModifyConversationFieldResp) ProtoReflect() protoreflect.Message { - mi := &file_conversation_conversation_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - if ms.LoadMessageInfo() == nil { - ms.StoreMessageInfo(mi) - } - return ms - } - return mi.MessageOf(x) +func (m *ModifyConversationFieldResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_ModifyConversationFieldResp.Marshal(b, m, deterministic) } - -// Deprecated: Use ModifyConversationFieldResp.ProtoReflect.Descriptor instead. -func (*ModifyConversationFieldResp) Descriptor() ([]byte, []int) { - return file_conversation_conversation_proto_rawDescGZIP(), []int{3} +func (dst *ModifyConversationFieldResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_ModifyConversationFieldResp.Merge(dst, src) +} +func (m *ModifyConversationFieldResp) XXX_Size() int { + return xxx_messageInfo_ModifyConversationFieldResp.Size(m) +} +func (m *ModifyConversationFieldResp) XXX_DiscardUnknown() { + xxx_messageInfo_ModifyConversationFieldResp.DiscardUnknown(m) } -func (x *ModifyConversationFieldResp) GetCommonResp() *CommonResp { - if x != nil { - return x.CommonResp +var xxx_messageInfo_ModifyConversationFieldResp proto.InternalMessageInfo + +func (m *ModifyConversationFieldResp) GetCommonResp() *CommonResp { + if m != nil { + return m.CommonResp } return nil } -var File_conversation_conversation_proto protoreflect.FileDescriptor - -var file_conversation_conversation_proto_rawDesc = []byte{ - 0x0a, 0x1f, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x63, - 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x0c, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, - 0x3e, 0x0a, 0x0a, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, - 0x07, 0x65, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, - 0x65, 0x72, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, - 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x72, 0x72, 0x4d, 0x73, 0x67, 0x22, - 0x90, 0x04, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x12, 0x20, 0x0a, 0x0b, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x55, 0x73, 0x65, 0x72, - 0x49, 0x44, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x63, 0x6f, 0x6e, 0x76, - 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x65, - 0x63, 0x76, 0x4d, 0x73, 0x67, 0x4f, 0x70, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, - 0x72, 0x65, 0x63, 0x76, 0x4d, 0x73, 0x67, 0x4f, 0x70, 0x74, 0x12, 0x2a, 0x0a, 0x10, 0x63, 0x6f, - 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x12, 0x18, - 0x0a, 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x44, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x49, 0x44, 0x12, 0x20, 0x0a, 0x0b, 0x75, 0x6e, 0x72, 0x65, - 0x61, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x75, - 0x6e, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x64, 0x72, - 0x61, 0x66, 0x74, 0x54, 0x65, 0x78, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x03, 0x52, 0x0d, 0x64, 0x72, 0x61, 0x66, 0x74, 0x54, 0x65, 0x78, 0x74, 0x54, 0x69, 0x6d, 0x65, - 0x12, 0x1a, 0x0a, 0x08, 0x69, 0x73, 0x50, 0x69, 0x6e, 0x6e, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x08, 0x69, 0x73, 0x50, 0x69, 0x6e, 0x6e, 0x65, 0x64, 0x12, 0x22, 0x0a, 0x0c, - 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x65, 0x64, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x0a, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0c, 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x65, 0x64, 0x49, 0x6e, 0x66, 0x6f, - 0x12, 0x24, 0x0a, 0x0d, 0x69, 0x73, 0x50, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, - 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0d, 0x69, 0x73, 0x50, 0x72, 0x69, 0x76, 0x61, - 0x74, 0x65, 0x43, 0x68, 0x61, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x41, - 0x74, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x67, 0x72, 0x6f, - 0x75, 0x70, 0x41, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x69, 0x73, 0x4e, 0x6f, - 0x74, 0x49, 0x6e, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, - 0x69, 0x73, 0x4e, 0x6f, 0x74, 0x49, 0x6e, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x0e, 0x0a, 0x02, - 0x65, 0x78, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x65, 0x78, 0x12, 0x34, 0x0a, 0x15, - 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x55, 0x6e, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75, 0x6e, - 0x74, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x03, 0x52, 0x15, 0x75, 0x70, 0x64, - 0x61, 0x74, 0x65, 0x55, 0x6e, 0x72, 0x65, 0x61, 0x64, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x54, 0x69, - 0x6d, 0x65, 0x22, 0xbc, 0x01, 0x0a, 0x1a, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x6e, - 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x52, 0x65, - 0x71, 0x12, 0x3e, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, - 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x54, 0x79, 0x70, 0x65, 0x12, - 0x1e, 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, - 0x03, 0x28, 0x09, 0x52, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x49, 0x44, 0x4c, 0x69, 0x73, 0x74, 0x12, - 0x20, 0x0a, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, - 0x44, 0x22, 0x57, 0x0a, 0x1b, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x6e, 0x76, 0x65, - 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x52, 0x65, 0x73, 0x70, - 0x12, 0x38, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x52, 0x0a, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x32, 0x7e, 0x0a, 0x0c, 0x63, 0x6f, - 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x6e, 0x0a, 0x17, 0x4d, 0x6f, - 0x64, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x46, 0x69, 0x65, 0x6c, 0x64, 0x12, 0x28, 0x2e, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x6e, 0x76, 0x65, - 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x52, 0x65, 0x71, 0x1a, - 0x29, 0x2e, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x4d, - 0x6f, 0x64, 0x69, 0x66, 0x79, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x52, 0x65, 0x73, 0x70, 0x42, 0x2d, 0x5a, 0x2b, 0x4f, 0x70, - 0x65, 0x6e, 0x5f, 0x49, 0x4d, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, - 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x63, 0x6f, 0x6e, - 0x76, 0x65, 0x72, 0x73, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, -} - -var ( - file_conversation_conversation_proto_rawDescOnce sync.Once - file_conversation_conversation_proto_rawDescData = file_conversation_conversation_proto_rawDesc -) - -func file_conversation_conversation_proto_rawDescGZIP() []byte { - file_conversation_conversation_proto_rawDescOnce.Do(func() { - file_conversation_conversation_proto_rawDescData = protoimpl.X.CompressGZIP(file_conversation_conversation_proto_rawDescData) - }) - return file_conversation_conversation_proto_rawDescData -} - -var file_conversation_conversation_proto_msgTypes = make([]protoimpl.MessageInfo, 4) -var file_conversation_conversation_proto_goTypes = []interface{}{ - (*CommonResp)(nil), // 0: conversation.CommonResp - (*Conversation)(nil), // 1: conversation.Conversation - (*ModifyConversationFieldReq)(nil), // 2: conversation.ModifyConversationFieldReq - (*ModifyConversationFieldResp)(nil), // 3: conversation.ModifyConversationFieldResp -} -var file_conversation_conversation_proto_depIdxs = []int32{ - 1, // 0: conversation.ModifyConversationFieldReq.conversation:type_name -> conversation.Conversation - 0, // 1: conversation.ModifyConversationFieldResp.commonResp:type_name -> conversation.CommonResp - 2, // 2: conversation.conversation.ModifyConversationField:input_type -> conversation.ModifyConversationFieldReq - 3, // 3: conversation.conversation.ModifyConversationField:output_type -> conversation.ModifyConversationFieldResp - 3, // [3:4] is the sub-list for method output_type - 2, // [2:3] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name -} - -func init() { file_conversation_conversation_proto_init() } -func file_conversation_conversation_proto_init() { - if File_conversation_conversation_proto != nil { - return - } - if !protoimpl.UnsafeEnabled { - file_conversation_conversation_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CommonResp); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conversation_conversation_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*Conversation); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conversation_conversation_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ModifyConversationFieldReq); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_conversation_conversation_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ModifyConversationFieldResp); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } - type x struct{} - out := protoimpl.TypeBuilder{ - File: protoimpl.DescBuilder{ - GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_conversation_conversation_proto_rawDesc, - NumEnums: 0, - NumMessages: 4, - NumExtensions: 0, - NumServices: 1, - }, - GoTypes: file_conversation_conversation_proto_goTypes, - DependencyIndexes: file_conversation_conversation_proto_depIdxs, - MessageInfos: file_conversation_conversation_proto_msgTypes, - }.Build() - File_conversation_conversation_proto = out.File - file_conversation_conversation_proto_rawDesc = nil - file_conversation_conversation_proto_goTypes = nil - file_conversation_conversation_proto_depIdxs = nil +func init() { + proto.RegisterType((*CommonResp)(nil), "conversation.CommonResp") + proto.RegisterType((*Conversation)(nil), "conversation.Conversation") + proto.RegisterType((*ModifyConversationFieldReq)(nil), "conversation.ModifyConversationFieldReq") + proto.RegisterType((*ModifyConversationFieldResp)(nil), "conversation.ModifyConversationFieldResp") } // Reference imports to suppress errors if they are not otherwise used. var _ context.Context -var _ grpc.ClientConnInterface +var _ grpc.ClientConn // This is a compile-time assertion to ensure that this generated file // is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion6 +const _ = grpc.SupportPackageIsVersion4 + +// Client API for Conversation service -// ConversationClient is the client API for Conversation service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type ConversationClient interface { ModifyConversationField(ctx context.Context, in *ModifyConversationFieldReq, opts ...grpc.CallOption) (*ModifyConversationFieldResp, error) } type conversationClient struct { - cc grpc.ClientConnInterface + cc *grpc.ClientConn } -func NewConversationClient(cc grpc.ClientConnInterface) ConversationClient { +func NewConversationClient(cc *grpc.ClientConn) ConversationClient { return &conversationClient{cc} } func (c *conversationClient) ModifyConversationField(ctx context.Context, in *ModifyConversationFieldReq, opts ...grpc.CallOption) (*ModifyConversationFieldResp, error) { out := new(ModifyConversationFieldResp) - err := c.cc.Invoke(ctx, "/conversation.conversation/ModifyConversationField", in, out, opts...) + err := grpc.Invoke(ctx, "/conversation.conversation/ModifyConversationField", in, out, c.cc, opts...) if err != nil { return nil, err } return out, nil } -// ConversationServer is the server API for Conversation service. +// Server API for Conversation service + type ConversationServer interface { ModifyConversationField(context.Context, *ModifyConversationFieldReq) (*ModifyConversationFieldResp, error) } -// UnimplementedConversationServer can be embedded to have forward compatible implementations. -type UnimplementedConversationServer struct { -} - -func (*UnimplementedConversationServer) ModifyConversationField(context.Context, *ModifyConversationFieldReq) (*ModifyConversationFieldResp, error) { - return nil, status.Errorf(codes.Unimplemented, "method ModifyConversationField not implemented") -} - func RegisterConversationServer(s *grpc.Server, srv ConversationServer) { s.RegisterService(&_Conversation_serviceDesc, srv) } @@ -616,3 +405,44 @@ var _Conversation_serviceDesc = grpc.ServiceDesc{ Streams: []grpc.StreamDesc{}, Metadata: "conversation/conversation.proto", } + +func init() { + proto.RegisterFile("conversation/conversation.proto", fileDescriptor_conversation_7438d6c35155b4e4) +} + +var fileDescriptor_conversation_7438d6c35155b4e4 = []byte{ + // 520 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x94, 0xd1, 0x6b, 0x13, 0x41, + 0x10, 0xc6, 0xb9, 0xb4, 0x4d, 0x93, 0x49, 0x1a, 0xcb, 0x82, 0xba, 0x44, 0xd1, 0x10, 0x44, 0x4e, + 0xc5, 0x06, 0xaa, 0x0f, 0x82, 0x50, 0xd0, 0x04, 0xe5, 0xc0, 0xd8, 0x72, 0xa4, 0x08, 0xbe, 0xc8, + 0x35, 0x37, 0x49, 0x0f, 0xcd, 0xee, 0xba, 0xbb, 0x17, 0xd3, 0x17, 0xff, 0x2a, 0x1f, 0xfd, 0xe3, + 0x64, 0x27, 0x49, 0xb3, 0x5b, 0x0d, 0xf8, 0x38, 0xbf, 0x9d, 0xfb, 0xe6, 0x9b, 0xcd, 0x97, 0x85, + 0x87, 0x63, 0x29, 0xe6, 0xa8, 0x4d, 0x66, 0x0b, 0x29, 0x7a, 0x7e, 0x71, 0xa4, 0xb4, 0xb4, 0x92, + 0x35, 0x7d, 0xd6, 0x3d, 0x01, 0xe8, 0xcb, 0xd9, 0x4c, 0x8a, 0x14, 0x8d, 0x62, 0x1c, 0xf6, 0x51, + 0xeb, 0xbe, 0xcc, 0x91, 0x47, 0x9d, 0x28, 0xde, 0x4b, 0xd7, 0x25, 0xbb, 0x03, 0x55, 0xd4, 0x7a, + 0x68, 0xa6, 0xbc, 0xd2, 0x89, 0xe2, 0x7a, 0xba, 0xaa, 0xba, 0xbf, 0x76, 0xa1, 0xd9, 0xf7, 0x04, + 0x59, 0x07, 0x1a, 0xf2, 0x87, 0x40, 0x7d, 0x6e, 0x50, 0x27, 0x03, 0x92, 0xa9, 0xa7, 0x3e, 0x62, + 0x8f, 0xa1, 0xe5, 0x5b, 0x48, 0x06, 0x2b, 0xc9, 0x1b, 0x94, 0x3d, 0x00, 0xd0, 0x38, 0x9e, 0x0f, + 0xcd, 0xf4, 0x54, 0x59, 0xbe, 0x43, 0x7e, 0x3c, 0xc2, 0x9e, 0xc2, 0xa1, 0xff, 0xc5, 0xe8, 0x4a, + 0x21, 0xdf, 0xa5, 0xae, 0xbf, 0xb8, 0xb3, 0x5f, 0x2e, 0x0d, 0xed, 0x2d, 0xed, 0x2f, 0x2b, 0xb7, + 0xf0, 0x54, 0xcb, 0x52, 0x25, 0x03, 0x5e, 0xa5, 0x83, 0x75, 0xe9, 0xf6, 0x28, 0x85, 0xc6, 0x2c, + 0xef, 0xcb, 0x52, 0x58, 0xbe, 0x4f, 0xc2, 0x3e, 0x62, 0x8f, 0xe0, 0x20, 0xd7, 0xd9, 0xc4, 0x8e, + 0x70, 0x61, 0x47, 0xc5, 0x0c, 0x79, 0xad, 0x13, 0xc5, 0x3b, 0x69, 0x08, 0x59, 0x1b, 0x6a, 0x85, + 0x39, 0x2b, 0x84, 0xc0, 0x9c, 0xd7, 0x3b, 0x51, 0x5c, 0x4b, 0xaf, 0x6b, 0xd6, 0x85, 0x66, 0x66, + 0x6d, 0x36, 0xbe, 0xc4, 0x3c, 0x11, 0x13, 0xc9, 0x81, 0x2c, 0x04, 0xcc, 0x4d, 0x29, 0xcc, 0x99, + 0x2e, 0xe6, 0x99, 0xc5, 0xfe, 0x65, 0x66, 0x79, 0x83, 0x44, 0x42, 0xe8, 0xdc, 0x92, 0xf1, 0x37, + 0x96, 0xae, 0xa1, 0xb9, 0x74, 0xeb, 0x21, 0x37, 0xab, 0x30, 0x1f, 0xa5, 0x4d, 0xc4, 0x7b, 0x47, + 0xf9, 0x01, 0xc9, 0x04, 0x8c, 0xb5, 0xa0, 0x82, 0x0b, 0xde, 0x22, 0x17, 0x15, 0x5c, 0xb0, 0x97, + 0x70, 0xbb, 0x54, 0x79, 0x66, 0xf1, 0x7c, 0xb3, 0x36, 0x6d, 0x7a, 0x8b, 0x36, 0xfd, 0xf7, 0xa1, + 0x9b, 0x74, 0x51, 0x6a, 0x31, 0x28, 0x35, 0xdd, 0x3f, 0x3f, 0x24, 0x33, 0x01, 0xeb, 0xfe, 0x8e, + 0xa0, 0x3d, 0x94, 0x79, 0x31, 0xb9, 0xf2, 0xc3, 0xf3, 0xae, 0xc0, 0x6f, 0x79, 0x8a, 0xdf, 0xd9, + 0x09, 0x04, 0x29, 0xa5, 0x14, 0x35, 0x8e, 0xdb, 0x47, 0x41, 0x9c, 0xfd, 0x2f, 0xd3, 0xa0, 0x9f, + 0xdd, 0x87, 0xfa, 0xc4, 0x69, 0xd1, 0x65, 0x54, 0x68, 0xfe, 0x06, 0xb8, 0x60, 0x2d, 0x7f, 0xfe, + 0x0f, 0x85, 0x71, 0xc1, 0xda, 0x89, 0xeb, 0xa9, 0x47, 0x28, 0xc2, 0x0a, 0xf5, 0x3a, 0x9d, 0xbb, + 0xab, 0x08, 0x6f, 0x50, 0xf7, 0x13, 0xdc, 0xdb, 0xea, 0xde, 0x28, 0xf6, 0x0a, 0x60, 0x7c, 0xfd, + 0xa7, 0x5a, 0x99, 0xe7, 0x37, 0xcd, 0xaf, 0xcf, 0x53, 0xaf, 0xf7, 0xf8, 0x67, 0xb8, 0x38, 0x13, + 0x70, 0x77, 0xcb, 0x20, 0x16, 0x87, 0x82, 0xdb, 0x6f, 0xb3, 0xfd, 0xe4, 0x3f, 0x3b, 0x8d, 0x7a, + 0xfb, 0xfc, 0xf3, 0xb3, 0x53, 0x85, 0xe2, 0x4b, 0x32, 0xec, 0xa9, 0xaf, 0xd3, 0x1e, 0xbd, 0x18, + 0xc1, 0x23, 0xf2, 0xda, 0x2f, 0x2e, 0xaa, 0xd4, 0xf0, 0xe2, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xb3, 0xd2, 0x40, 0x56, 0x75, 0x04, 0x00, 0x00, +} diff --git a/pkg/proto/conversation/conversation.proto b/pkg/proto/conversation/conversation.proto index e8447f1b0..ec10bfd2f 100644 --- a/pkg/proto/conversation/conversation.proto +++ b/pkg/proto/conversation/conversation.proto @@ -22,6 +22,7 @@ message Conversation{ bool isNotInGroup = 13; string ex = 14; int64 updateUnreadCountTime = 15; + int32 burnDuration = 16; } message ModifyConversationFieldReq{ From 9aaee04a692891644a0c8c8d342b674c8dffab6d Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 16 Nov 2022 12:40:44 +0800 Subject: [PATCH 02/19] read after burn time --- pkg/common/db/mysql_model/im_mysql_model/conversation_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go index 52fe1dcb9..dd1a143ee 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go @@ -23,7 +23,7 @@ func SetConversation(conversation db.Conversation) (bool, error) { } } func SetOneConversation(conversation db.Conversation) error { - return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error } From 05d83ebe8b6fa3215a8554f9f2a81e36b16ba1a1 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 16 Nov 2022 18:55:42 +0800 Subject: [PATCH 03/19] gzip msg --- internal/msg_gateway/gate/ws_server.go | 37 +++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index eb101f2ff..53f2807cd 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -11,8 +11,10 @@ import ( pbRelay "Open_IM/pkg/proto/relay" "Open_IM/pkg/utils" "bytes" + "compress/gzip" "context" "encoding/gob" + "io/ioutil" "strings" go_redis "github.com/go-redis/redis/v8" @@ -31,6 +33,7 @@ type UserConn struct { w *sync.Mutex platformID int32 PushedMaxSeq uint32 + IsCompress bool } type WServer struct { wsAddr string @@ -75,7 +78,11 @@ func (ws *WServer) wsHandler(w http.ResponseWriter, r *http.Request) { log.Error(operationID, "upgrade http conn err", err.Error(), query) return } else { - newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0} + var isCompress = false + if r.Header.Get("compression") == "gzip" { + isCompress = true + } + newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0, isCompress} userCount++ ws.addUserConn(query["sendID"][0], utils.StringToInt(query["platformID"][0]), newConn, query["token"][0], operationID) go ws.readMsg(newConn) @@ -97,6 +104,23 @@ func (ws *WServer) readMsg(conn *UserConn) { ws.delUserConn(conn) return } + if conn.IsCompress { + buff := bytes.NewBuffer(msg) + reader, err := gzip.NewReader(buff) + if err != nil { + log.NewWarn("", "un gzip read failed") + continue + } + msg, err = ioutil.ReadAll(reader) + if err != nil { + log.NewWarn("", "ReadAll failed") + continue + } + err = reader.Close() + if err != nil { + log.NewWarn("", "reader close failed") + } + } ws.msgParse(conn, msg) } } @@ -110,6 +134,17 @@ func (ws *WServer) SetWriteTimeout(conn *UserConn, timeout int) { func (ws *WServer) writeMsg(conn *UserConn, a int, msg []byte) error { conn.w.Lock() defer conn.w.Unlock() + if conn.IsCompress { + buff := bytes.NewBuffer(msg) + gz := gzip.NewWriter(buff) + if _, err := gz.Write(buff.Bytes()); err != nil { + return utils.Wrap(err, "") + } + if err := gz.Close(); err != nil { + return utils.Wrap(err, "") + } + msg = buff.Bytes() + } conn.SetWriteDeadline(time.Now().Add(time.Duration(60) * time.Second)) return conn.WriteMessage(a, msg) } From 4a3f168720208e2180fee91828c460ffd13ad52d Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 16 Nov 2022 19:26:49 +0800 Subject: [PATCH 04/19] gzip msg --- internal/msg_gateway/gate/ws_server.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 53f2807cd..076d88d6b 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -135,15 +135,15 @@ func (ws *WServer) writeMsg(conn *UserConn, a int, msg []byte) error { conn.w.Lock() defer conn.w.Unlock() if conn.IsCompress { - buff := bytes.NewBuffer(msg) - gz := gzip.NewWriter(buff) - if _, err := gz.Write(buff.Bytes()); err != nil { + var buffer bytes.Buffer + gz := gzip.NewWriter(&buffer) + if _, err := gz.Write(msg); err != nil { return utils.Wrap(err, "") } if err := gz.Close(); err != nil { return utils.Wrap(err, "") } - msg = buff.Bytes() + msg = buffer.Bytes() } conn.SetWriteDeadline(time.Now().Add(time.Duration(60) * time.Second)) return conn.WriteMessage(a, msg) From fdb0ba4349ae897df49aace42f219295f44c1117 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 17 Nov 2022 11:17:26 +0800 Subject: [PATCH 05/19] msg size --- internal/msg_gateway/gate/logic.go | 7 ++- internal/msg_gateway/gate/ws_server.go | 4 +- pkg/utils/file.go | 76 ++++++++++++++------------ 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/internal/msg_gateway/gate/logic.go b/internal/msg_gateway/gate/logic.go index 90ef3ce63..7fa144bd0 100644 --- a/internal/msg_gateway/gate/logic.go +++ b/internal/msg_gateway/gate/logic.go @@ -40,7 +40,12 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) { return } log.NewInfo(m.OperationID, "Basic Info Authentication Success", m.SendID, m.MsgIncr, m.ReqIdentifier) - + if m.SendID != conn.userID { + if err = conn.Close(); err != nil { + log.NewError(m.OperationID, "close ws conn failed", conn.userID, "send id", m.SendID, err.Error()) + return + } + } switch m.ReqIdentifier { case constant.WSGetNewestSeq: log.NewInfo(m.OperationID, "getSeqReq ", m.SendID, m.MsgIncr, m.ReqIdentifier) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 076d88d6b..0aa66bb88 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -34,6 +34,7 @@ type UserConn struct { platformID int32 PushedMaxSeq uint32 IsCompress bool + userID string } type WServer struct { wsAddr string @@ -82,7 +83,7 @@ func (ws *WServer) wsHandler(w http.ResponseWriter, r *http.Request) { if r.Header.Get("compression") == "gzip" { isCompress = true } - newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0, isCompress} + newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0, isCompress, query["sendID"][0]} userCount++ ws.addUserConn(query["sendID"][0], utils.StringToInt(query["platformID"][0]), newConn, query["token"][0], operationID) go ws.readMsg(newConn) @@ -121,6 +122,7 @@ func (ws *WServer) readMsg(conn *UserConn) { log.NewWarn("", "reader close failed") } } + log.NewDebug("", "size", utils.ByteSize(uint64(len(msg)))) ws.msgParse(conn, msg) } } diff --git a/pkg/utils/file.go b/pkg/utils/file.go index 9108ede8f..b385c55d7 100644 --- a/pkg/utils/file.go +++ b/pkg/utils/file.go @@ -2,14 +2,25 @@ package utils import ( "Open_IM/pkg/common/constant" - "errors" "fmt" "math/rand" "os" "path" + "strconv" + "strings" "time" ) +const ( + BYTE = 1 << (10 * iota) + KILOBYTE + MEGABYTE + GIGABYTE + TERABYTE + PETABYTE + EXABYTE +) + // Determine whether the given path is a folder func IsDir(path string) bool { s, err := os.Stat(path) @@ -39,39 +50,34 @@ func GetNewFileNameAndContentType(fileName string, fileType int) (string, string return newName, contentType } -func GetUploadAppNewName(appType int, version, fileName, yamlName string) (string, string, error) { - var newFileName, newYamlName = "_" + version + "_app", "_" + version + "_yaml" - switch appType { - case constant.IOSPlatformID: - newFileName = constant.IOSPlatformStr + newFileName - newYamlName = constant.IOSPlatformStr + newYamlName - case constant.AndroidPlatformID: - newFileName = constant.AndroidPlatformStr + newFileName - newYamlName = constant.AndroidPlatformStr + newYamlName - case constant.WindowsPlatformID: - newFileName = constant.WindowsPlatformStr + newFileName - newYamlName = constant.WindowsPlatformStr + newYamlName - case constant.OSXPlatformID: - newFileName = constant.OSXPlatformStr + newFileName - newYamlName = constant.OSXPlatformStr + newYamlName - case constant.WebPlatformID: - newFileName = constant.WebPlatformStr + newFileName - newYamlName = constant.WebPlatformStr + newYamlName - case constant.MiniWebPlatformID: - newFileName = constant.MiniWebPlatformStr + newFileName - newYamlName = constant.MiniWebPlatformStr + newYamlName - case constant.LinuxPlatformID: - newFileName = constant.LinuxPlatformStr + newFileName - newYamlName = constant.LinuxPlatformStr + newYamlName - default: - return "", "", errors.New("invalid app type") - } - suffixFile := path.Ext(fileName) - suffixYaml := path.Ext(yamlName) - newFileName = fmt.Sprintf("%s%s", newFileName, suffixFile) - newYamlName = fmt.Sprintf("%s%s", newYamlName, suffixYaml) - if yamlName == "" { - newYamlName = "" +func ByteSize(bytes uint64) string { + unit := "" + value := float64(bytes) + switch { + case bytes >= EXABYTE: + unit = "E" + value = value / EXABYTE + case bytes >= PETABYTE: + unit = "P" + value = value / PETABYTE + case bytes >= TERABYTE: + unit = "T" + value = value / TERABYTE + case bytes >= GIGABYTE: + unit = "G" + value = value / GIGABYTE + case bytes >= MEGABYTE: + unit = "M" + value = value / MEGABYTE + case bytes >= KILOBYTE: + unit = "K" + value = value / KILOBYTE + case bytes >= BYTE: + unit = "B" + case bytes == 0: + return "0" } - return newFileName, newYamlName, nil + result := strconv.FormatFloat(value, 'f', 1, 64) + result = strings.TrimSuffix(result, ".0") + return result + unit } From 4b0a95fc1bdebbf1eb8f0456e388e8f1f0d43bf1 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 17 Nov 2022 16:18:13 +0800 Subject: [PATCH 06/19] fix bug --- internal/msg_gateway/gate/ws_server.go | 1 + .../db/mysql_model/im_mysql_model/conversation_model.go | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 0aa66bb88..27c067eef 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -81,6 +81,7 @@ func (ws *WServer) wsHandler(w http.ResponseWriter, r *http.Request) { } else { var isCompress = false if r.Header.Get("compression") == "gzip" { + log.NewDebug(operationID, query["sendID"][0], "enable compression") isCompress = true } newConn := &UserConn{conn, new(sync.Mutex), utils.StringToInt32(query["platformID"][0]), 0, isCompress, query["sendID"][0]} diff --git a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go index dd1a143ee..ac1be495f 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go @@ -11,7 +11,7 @@ func SetConversation(conversation db.Conversation) (bool, error) { newConversation := conversation if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error + return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error // if exist, then update record } else { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") @@ -31,7 +31,7 @@ func PeerUserSetConversation(conversation db.Conversation) error { newConversation := conversation if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error // if exist, then update record } log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") @@ -46,7 +46,7 @@ func SetRecvMsgOpt(conversation db.Conversation) (bool, error) { newConversation := conversation if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error + return isUpdate, db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(&conversation).Error // if exist, then update record } else { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") From 68ad1e9645650e4eead75d0177e441c2111ad196 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 18 Nov 2022 10:45:48 +0800 Subject: [PATCH 07/19] log print size --- internal/msg_gateway/gate/ws_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/msg_gateway/gate/ws_server.go b/internal/msg_gateway/gate/ws_server.go index 27c067eef..5994bb793 100644 --- a/internal/msg_gateway/gate/ws_server.go +++ b/internal/msg_gateway/gate/ws_server.go @@ -106,6 +106,7 @@ func (ws *WServer) readMsg(conn *UserConn) { ws.delUserConn(conn) return } + log.NewDebug("", "size", utils.ByteSize(uint64(len(msg)))) if conn.IsCompress { buff := bytes.NewBuffer(msg) reader, err := gzip.NewReader(buff) @@ -123,7 +124,6 @@ func (ws *WServer) readMsg(conn *UserConn) { log.NewWarn("", "reader close failed") } } - log.NewDebug("", "size", utils.ByteSize(uint64(len(msg)))) ws.msgParse(conn, msg) } } From c0d7f0f5fd78746045a2adbfe59c9a4824ff1a2f Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 18 Nov 2022 16:59:31 +0800 Subject: [PATCH 08/19] cron test --- cmd/open_im_cron_task/main.go | 3 +- internal/cron_task/clear_msg_test.go | 56 +++++++++++++++++++++++++++- internal/cron_task/cron_task.go | 14 +++---- 3 files changed, 64 insertions(+), 9 deletions(-) diff --git a/cmd/open_im_cron_task/main.go b/cmd/open_im_cron_task/main.go index 1e7396d61..30ed7aea7 100644 --- a/cmd/open_im_cron_task/main.go +++ b/cmd/open_im_cron_task/main.go @@ -3,9 +3,10 @@ package main import ( "Open_IM/internal/cron_task" "fmt" + "time" ) func main() { - fmt.Println("start cronTask") + fmt.Println(time.Now(), "start cronTask") cronTask.StartCronTask() } diff --git a/internal/cron_task/clear_msg_test.go b/internal/cron_task/clear_msg_test.go index b1621c26d..046af9162 100644 --- a/internal/cron_task/clear_msg_test.go +++ b/internal/cron_task/clear_msg_test.go @@ -2,14 +2,68 @@ package cronTask import ( "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" + pbMsg "Open_IM/pkg/proto/msg" + server_api_params "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" "testing" + "time" ) +func getMsgListFake(num int) []*pbMsg.MsgDataToMQ { + var msgList []*pbMsg.MsgDataToMQ + for i := 1; i < num; i++ { + msgList = append(msgList, &pbMsg.MsgDataToMQ{ + Token: "tk", + OperationID: "operationID", + MsgData: &server_api_params.MsgData{ + SendID: "sendID1", + RecvID: "recvID1", + GroupID: "", + ClientMsgID: "xxx", + ServerMsgID: "xxx", + SenderPlatformID: 1, + SenderNickname: "testNickName", + SenderFaceURL: "testFaceURL", + SessionType: 1, + MsgFrom: 100, + ContentType: 101, + Content: []byte("testFaceURL"), + Seq: uint32(i), + SendTime: time.Now().Unix(), + CreateTime: time.Now().Unix(), + Status: 1, + }, + }) + } +} + func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) { operationID := getCronTaskOperationID() - testUserIDList := []string{"test_del_id1", "test_del_id2", "test_del_id3", "test_del_id4", "test_del_id5"} + testUID1 := "test_del_id1" + //testUID2 := "test_del_id2" + //testUID3 := "test_del_id3" + //testUID4 := "test_del_id4" + //testUID5 := "test_del_id5" + //testUID6 := "test_del_id6" + testUserIDList := []string{testUID1} + + db.DB.SetUserMaxSeq(testUID1, 500) + db.DB.BatchInsertChat2DB(testUID1, getMsgListFake(500), testUID1+"-"+operationID, 500) + + //db.DB.SetUserMaxSeq(testUID1, 6000) + //db.DB.BatchInsertChat2DB() + // + //db.DB.SetUserMaxSeq(testUID1, 4999) + //db.DB.BatchInsertChat2DB() + // + //db.DB.SetUserMaxSeq(testUID1, 30000) + //db.DB.BatchInsertChat2DB() + // + //db.DB.SetUserMaxSeq(testUID1, 9999) + //db.DB.BatchInsertChat2DB() + for _, userID := range testUserIDList { operationID = userID + "-" + operationID if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil { diff --git a/internal/cron_task/cron_task.go b/internal/cron_task/cron_task.go index b493b1f37..87c2fbb46 100644 --- a/internal/cron_task/cron_task.go +++ b/internal/cron_task/cron_task.go @@ -31,14 +31,14 @@ func StartCronTask() { if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil { log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), userID) } - //if err := checkMaxSeqWithMongo(operationID, userID, constant.WriteDiffusion); err != nil { - // log.NewError(operationID, utils.GetSelfFuncName(), userID, err) - //} + if err := checkMaxSeqWithMongo(operationID, userID, constant.WriteDiffusion); err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), userID, err) + } } } else { log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) } - return + //return // working group msg clear workingGroupIDList, err := im_mysql_model.GetGroupIDListByGroupType(constant.WorkingGroup) if err == nil { @@ -53,9 +53,9 @@ func StartCronTask() { if err := ResetUserGroupMinSeq(operationID, groupID, userIDList); err != nil { log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID, userIDList) } - //if err := checkMaxSeqWithMongo(operationID, groupID, constant.ReadDiffusion); err != nil { - // log.NewError(operationID, utils.GetSelfFuncName(), groupID, err) - //} + if err := checkMaxSeqWithMongo(operationID, groupID, constant.ReadDiffusion); err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), groupID, err) + } } } else { log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) From 11405adcf61f046178f892814e777722202761ee Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 18 Nov 2022 17:35:45 +0800 Subject: [PATCH 09/19] cron test --- internal/cron_task/clear_msg_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/cron_task/clear_msg_test.go b/internal/cron_task/clear_msg_test.go index 046af9162..f9ac97ce8 100644 --- a/internal/cron_task/clear_msg_test.go +++ b/internal/cron_task/clear_msg_test.go @@ -37,6 +37,7 @@ func getMsgListFake(num int) []*pbMsg.MsgDataToMQ { }, }) } + return msgList } func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) { From f3a16e1ecdd308dfdee45bb4f64208776c964754 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 18 Nov 2022 18:09:43 +0800 Subject: [PATCH 10/19] cron --- internal/cron_task/clear_msg_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/internal/cron_task/clear_msg_test.go b/internal/cron_task/clear_msg_test.go index f9ac97ce8..3bcb0f00b 100644 --- a/internal/cron_task/clear_msg_test.go +++ b/internal/cron_task/clear_msg_test.go @@ -7,6 +7,7 @@ import ( pbMsg "Open_IM/pkg/proto/msg" server_api_params "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" + "os/exec" "testing" "time" ) @@ -41,6 +42,17 @@ func getMsgListFake(num int) []*pbMsg.MsgDataToMQ { } func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) { + cmd := exec.Command("/bin/bash", "CONFIG_NAME=../../") + _, err := cmd.StdoutPipe() + if err != nil { + return + } + + //执行命令 + if err := cmd.Start(); err != nil { + return + } + operationID := getCronTaskOperationID() testUID1 := "test_del_id1" //testUID2 := "test_del_id2" @@ -64,7 +76,16 @@ func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) { // //db.DB.SetUserMaxSeq(testUID1, 9999) //db.DB.BatchInsertChat2DB() + cmd = exec.Command("/bin/bash", "unset $CONFIG_NAME") + _, err = cmd.StdoutPipe() + if err != nil { + return + } + //执行命令 + if err := cmd.Start(); err != nil { + return + } for _, userID := range testUserIDList { operationID = userID + "-" + operationID if err := DeleteMongoMsgAndResetRedisSeq(operationID, userID); err != nil { From 7f9812a4882c70e91be19cf246c49a3bfad80323 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 18 Nov 2022 18:16:44 +0800 Subject: [PATCH 11/19] cron --- internal/cron_task/clear_msg_test.go | 33 ++++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/internal/cron_task/clear_msg_test.go b/internal/cron_task/clear_msg_test.go index 3bcb0f00b..2788bb82b 100644 --- a/internal/cron_task/clear_msg_test.go +++ b/internal/cron_task/clear_msg_test.go @@ -12,6 +12,19 @@ import ( "time" ) +func init() { + cmd := exec.Command("/bin/bash", "CONFIG_NAME=../../") + _, err := cmd.StdoutPipe() + if err != nil { + return + } + + //执行命令 + if err := cmd.Start(); err != nil { + return + } +} + func getMsgListFake(num int) []*pbMsg.MsgDataToMQ { var msgList []*pbMsg.MsgDataToMQ for i := 1; i < num; i++ { @@ -42,16 +55,6 @@ func getMsgListFake(num int) []*pbMsg.MsgDataToMQ { } func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) { - cmd := exec.Command("/bin/bash", "CONFIG_NAME=../../") - _, err := cmd.StdoutPipe() - if err != nil { - return - } - - //执行命令 - if err := cmd.Start(); err != nil { - return - } operationID := getCronTaskOperationID() testUID1 := "test_del_id1" @@ -62,9 +65,11 @@ func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) { //testUID6 := "test_del_id6" testUserIDList := []string{testUID1} - db.DB.SetUserMaxSeq(testUID1, 500) - db.DB.BatchInsertChat2DB(testUID1, getMsgListFake(500), testUID1+"-"+operationID, 500) - + err := db.DB.SetUserMaxSeq(testUID1, 500) + err = db.DB.BatchInsertChat2DB(testUID1, getMsgListFake(500), testUID1+"-"+operationID, 500) + if err != nil { + t.Error(err.Error(), testUID1) + } //db.DB.SetUserMaxSeq(testUID1, 6000) //db.DB.BatchInsertChat2DB() // @@ -76,7 +81,7 @@ func TestDeleteMongoMsgAndResetRedisSeq(t *testing.T) { // //db.DB.SetUserMaxSeq(testUID1, 9999) //db.DB.BatchInsertChat2DB() - cmd = exec.Command("/bin/bash", "unset $CONFIG_NAME") + cmd := exec.Command("/bin/bash", "unset $CONFIG_NAME") _, err = cmd.StdoutPipe() if err != nil { return From 9fddf6819bae0ab8d500f5baf723c1f0c9410db9 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Sun, 20 Nov 2022 17:45:49 +0800 Subject: [PATCH 12/19] user notification --- internal/api/auth/auth.go | 1 - internal/api/manage/management_chat.go | 4 ++++ internal/rpc/user/user.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/api/auth/auth.go b/internal/api/auth/auth.go index b50e9e2ae..ec2503675 100644 --- a/internal/api/auth/auth.go +++ b/internal/api/auth/auth.go @@ -199,7 +199,6 @@ func ForceLogout(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": errMsg}) return } - req := &rpc.ForceLogoutReq{} utils.CopyStructFields(req, ¶ms) diff --git a/internal/api/manage/management_chat.go b/internal/api/manage/management_chat.go index a2254a70a..78e441d82 100644 --- a/internal/api/manage/management_chat.go +++ b/internal/api/manage/management_chat.go @@ -52,6 +52,10 @@ func newUserSendMsgReq(params *api.ManagementSendMsgReq) *pbChat.SendMsgReq { fallthrough case constant.File: fallthrough + case constant.CustomNotTriggerConversation: + fallthrough + case constant.CustomOnlineOnly: + fallthrough case constant.AdvancedRevoke: newContent = utils.StructToJsonString(params.Content) case constant.Revoke: diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 27db600ec..3b11359ac 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -450,7 +450,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq) return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } - chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID) + chat.UserInfoUpdatedNotification(req.OperationID, req.OpUserID, req.UserInfo.UserID) log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID) if req.UserInfo.FaceURL != "" { s.SyncJoinedGroupMemberFaceURL(req.UserInfo.UserID, req.UserInfo.FaceURL, req.OperationID, req.OpUserID) From 135973de09d677fc574d74eb700a2910b9b475a6 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 21 Nov 2022 10:20:56 +0800 Subject: [PATCH 13/19] fix bug --- internal/rpc/msg/send_msg.go | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index 035043de1..e84c443cd 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -171,14 +171,12 @@ func (rpc *rpcChat) messageVerification(data *pbChat.SendMsgReq) (bool, int32, s log.NewError(data.OperationID, errMsg) return false, 201, errMsg, nil } - if !token_verify.IsManagerUserID(data.MsgData.SendID) { - if data.MsgData.ContentType <= constant.NotificationEnd && data.MsgData.ContentType >= constant.NotificationBegin { - return true, 0, "", userIDList - } - if !utils.IsContain(data.MsgData.SendID, userIDList) { - //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) - return false, 202, "you are not in group", nil - } + if token_verify.IsManagerUserID(data.MsgData.SendID) { + return true, 0, "", userIDList + } + if !utils.IsContain(data.MsgData.SendID, userIDList) { + //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) + return false, 202, "you are not in group", nil } isMute, err := userIsMuteInGroup(data.MsgData.GroupID, data.MsgData.SendID) if err != nil { @@ -232,14 +230,12 @@ func (rpc *rpcChat) messageVerification(data *pbChat.SendMsgReq) (bool, int32, s log.NewError(data.OperationID, errMsg) return false, 201, errMsg, nil } - if !token_verify.IsManagerUserID(data.MsgData.SendID) { - if data.MsgData.ContentType <= constant.NotificationEnd && data.MsgData.ContentType >= constant.NotificationBegin { - return true, 0, "", userIDList - } - if !utils.IsContain(data.MsgData.SendID, userIDList) { - //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) - return false, 202, "you are not in group", nil - } + if token_verify.IsManagerUserID(data.MsgData.SendID) { + return true, 0, "", userIDList + } + if !utils.IsContain(data.MsgData.SendID, userIDList) { + //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) + return false, 202, "you are not in group", nil } isMute, err := userIsMuteInGroup(data.MsgData.GroupID, data.MsgData.SendID) if err != nil { From 672de78c81599b2e001464419597e02c04b3566e Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 21 Nov 2022 15:41:38 +0800 Subject: [PATCH 14/19] user --- internal/rpc/user/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 3b11359ac..27db600ec 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -450,7 +450,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq) return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } - chat.UserInfoUpdatedNotification(req.OperationID, req.OpUserID, req.UserInfo.UserID) + chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID) log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID) if req.UserInfo.FaceURL != "" { s.SyncJoinedGroupMemberFaceURL(req.UserInfo.UserID, req.UserInfo.FaceURL, req.OperationID, req.OpUserID) From a1a79ea619bff200ca62e86c016db9acfe9d1d70 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 21 Nov 2022 15:47:30 +0800 Subject: [PATCH 15/19] user --- internal/rpc/user/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 27db600ec..3b11359ac 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -450,7 +450,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq) return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } - chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID) + chat.UserInfoUpdatedNotification(req.OperationID, req.OpUserID, req.UserInfo.UserID) log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID) if req.UserInfo.FaceURL != "" { s.SyncJoinedGroupMemberFaceURL(req.UserInfo.UserID, req.UserInfo.FaceURL, req.OperationID, req.OpUserID) From 157f85897554ad21beab4e7b1eb40470b86bf21e Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 21 Nov 2022 15:57:56 +0800 Subject: [PATCH 16/19] user --- internal/rpc/msg/friend_notification.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/msg/friend_notification.go b/internal/rpc/msg/friend_notification.go index 91d926bf9..08f3880a5 100644 --- a/internal/rpc/msg/friend_notification.go +++ b/internal/rpc/msg/friend_notification.go @@ -159,7 +159,7 @@ func BlackDeletedNotification(req *pbFriend.RemoveBlacklistReq) { } func UserInfoUpdatedNotification(operationID, userID string, needNotifiedUserID string) { - selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: userID} + selfInfoUpdatedTips := open_im_sdk.UserInfoUpdatedTips{UserID: needNotifiedUserID} commID := pbFriend.CommID{FromUserID: userID, ToUserID: needNotifiedUserID, OpUserID: userID, OperationID: operationID} friendNotification(&commID, constant.UserInfoUpdatedNotification, &selfInfoUpdatedTips) } From 819ebf0ede1eb350d126b59c385aa3adc9c95f52 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 22 Nov 2022 11:07:20 +0800 Subject: [PATCH 17/19] add callback and fix cache --- config/config.yaml | 4 + internal/cron_task/clear_msg_test.go | 13 - internal/rpc/group/callback.go | 52 +++- internal/rpc/group/group.go | 417 +++++++++++++-------------- pkg/call_back_struct/group.go | 19 ++ pkg/common/config/config.go | 1 + pkg/common/constant/constant.go | 27 +- 7 files changed, 293 insertions(+), 240 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index a25b39fd8..f7758615b 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -341,6 +341,10 @@ callback: enable: false callbackTimeOut: 2 callbackFailedContinue: true # 回调超时是否继续 + callbackBeforeMemberJoinGroup: + enable: false + callbackTimeOut: 2 + callbackFailedContinue: true # 回调超时是否继续 notification: groupCreated: diff --git a/internal/cron_task/clear_msg_test.go b/internal/cron_task/clear_msg_test.go index 2788bb82b..0a2ba7071 100644 --- a/internal/cron_task/clear_msg_test.go +++ b/internal/cron_task/clear_msg_test.go @@ -12,19 +12,6 @@ import ( "time" ) -func init() { - cmd := exec.Command("/bin/bash", "CONFIG_NAME=../../") - _, err := cmd.StdoutPipe() - if err != nil { - return - } - - //执行命令 - if err := cmd.Start(); err != nil { - return - } -} - func getMsgListFake(num int) []*pbMsg.MsgDataToMQ { var msgList []*pbMsg.MsgDataToMQ for i := 1; i < num; i++ { diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index b74c89918..28212c829 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -4,6 +4,7 @@ import ( cbApi "Open_IM/pkg/call_back_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db" "Open_IM/pkg/common/http" "Open_IM/pkg/common/log" pbGroup "Open_IM/pkg/proto/group" @@ -19,6 +20,8 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback log.NewDebug(req.OperationID, utils.GetSelfFuncName(), req.String()) commonCallbackReq := &cbApi.CallbackBeforeCreateGroupReq{ CallbackCommand: constant.CallbackBeforeCreateGroupCommand, + GroupInfo: *req.GroupInfo, + InitMemberList: req.InitMemberList, } resp := &cbApi.CallbackBeforeCreateGroupResp{ CommonCallbackResp: &callbackResp, @@ -41,7 +44,7 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback req.GroupInfo.GroupID = *resp.GroupID } if resp.GroupName != nil { - req.GroupInfo.GroupName = *resp.GroupID + req.GroupInfo.GroupName = *resp.GroupName } if resp.Notification != nil { req.GroupInfo.Notification = *resp.Notification @@ -68,7 +71,7 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback req.GroupInfo.GroupType = *resp.GroupType } if resp.NeedVerification != nil { - req.GroupInfo.NeedVerification = *resp.GroupType + req.GroupInfo.NeedVerification = *resp.NeedVerification } if resp.LookMemberInfo != nil { req.GroupInfo.LookMemberInfo = *resp.LookMemberInfo @@ -76,3 +79,48 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback } return callbackResp } + +func CallbackBeforeMemberJoinGroup(operationID string, groupMember *db.GroupMember, groupEx string) cbApi.CommonCallbackResp { + callbackResp := cbApi.CommonCallbackResp{OperationID: operationID} + if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable { + return callbackResp + } + log.NewDebug(operationID, "args: ", *groupMember) + callbackReq := cbApi.CallbackBeforeMemberJoinGroupReq{ + CallbackCommand: constant.CallbackBeforeMemberJoinGroupCommand, + GroupID: groupMember.GroupID, + UserID: groupMember.UserID, + Ex: groupMember.Ex, + GroupEx: groupEx, + } + resp := &cbApi.CallbackBeforeMemberJoinGroupResp{ + CommonCallbackResp: &callbackResp, + } + if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeMemberJoinGroupCommand, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackTimeOut); err != nil { + callbackResp.ErrCode = http2.StatusInternalServerError + callbackResp.ErrMsg = err.Error() + if !config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackFailedContinue { + callbackResp.ActionCode = constant.ActionForbidden + return callbackResp + } else { + callbackResp.ActionCode = constant.ActionAllow + return callbackResp + } + } + 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 callbackResp +} diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index c5597ab1f..d0d88cc41 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -20,6 +20,7 @@ import ( "Open_IM/pkg/utils" "context" "errors" + "fmt" "math/big" "net" "strconv" @@ -157,6 +158,16 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR groupMember := db.GroupMember{} us := &db.User{} if req.OwnerUserID != "" { + var userIDList []string + for _, v := range req.InitMemberList { + userIDList = append(userIDList, v.UserID) + } + userIDList = append(userIDList, req.OwnerUserID) + if err := s.DelGroupAndUserCache(req.OperationID, "", userIDList); err != nil { + log.NewError(req.OperationID, "DelGroupAndUserCache failed, ", err.Error(), userIDList) + return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}, nil + } + us, err = imdb.GetUserByUserID(req.OwnerUserID) if err != nil { log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OwnerUserID) @@ -165,6 +176,21 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR //to group member groupMember = db.GroupMember{GroupID: groupId, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID, JoinSource: constant.JoinByInvitation, InviterUserID: req.OpUserID} utils.CopyStructFields(&groupMember, us) + callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex) + if callbackResp.ErrCode != 0 { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp) + } + if callbackResp.ActionCode != constant.ActionAllow { + if callbackResp.ErrCode == 0 { + callbackResp.ErrCode = 201 + } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp) + return &pbGroup.CreateGroupResp{ + ErrCode: int32(callbackResp.ErrCode), + ErrMsg: callbackResp.ErrMsg, + }, nil + } + err = imdb.InsertIntoGroupMember(groupMember) if err != nil { log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) @@ -188,6 +214,17 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR groupMember.JoinSource = constant.JoinByInvitation groupMember.InviterUserID = req.OpUserID utils.CopyStructFields(&groupMember, us) + callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex) + if callbackResp.ErrCode != 0 { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp) + } + if callbackResp.ActionCode != constant.ActionAllow { + if callbackResp.ErrCode == 0 { + callbackResp.ErrCode = 201 + } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp) + continue + } err = imdb.InsertIntoGroupMember(groupMember) if err != nil { log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) @@ -231,11 +268,6 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR if len(okUserIDList) != 0 { log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String()) if req.GroupInfo.GroupType != constant.SuperGroup { - for _, userID := range okUserIDList { - if err := rocksCache.DelJoinedGroupIDListFromCache(userID); err != nil { - log.NewWarn(req.OperationID, utils.GetSelfFuncName(), userID, err.Error()) - } - } chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList) } else { for _, userID := range okUserIDList { @@ -362,7 +394,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite log.NewInfo(req.OperationID, "InviteUserToGroup rpc return ", resp) return &resp, nil } - // + if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, req.InvitedUserIDList); err != nil { + log.NewError(req.OperationID, "DelGroupAndUserCache failed", err.Error()) + return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}, nil + } //from User: invite: applicant //to user: invite: invited var okUserIDList []string @@ -392,6 +427,15 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite toInsertInfo.OperatorUserID = req.OpUserID toInsertInfo.InviterUserID = req.OpUserID toInsertInfo.JoinSource = constant.JoinByInvitation + callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &toInsertInfo, groupInfo.Ex) + if callbackResp.ErrCode != 0 { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp) + } + if callbackResp.ActionCode != constant.ActionAllow { + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp) + continue + } + err = imdb.InsertIntoGroupMember(toInsertInfo) if err != nil { log.NewError(req.OperationID, "InsertIntoGroupMember failed ", req.GroupID, toUserInfo.UserID, toUserInfo.Nickname, toUserInfo.FaceURL) @@ -473,40 +517,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}, nil } } - - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil" - log.NewError(req.OperationID, errMsg) - return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil - } - cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ - GroupID: req.GroupID, - OperationID: req.OperationID, - }) - if err != nil { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) - return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil - } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) - return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil - } - if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) - } - if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } if groupInfo.GroupType != constant.SuperGroup { - for _, userID := range okUserIDList { - err = rocksCache.DelJoinedGroupIDListFromCache(userID) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID) - } - } - chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList) } else { for _, v := range req.InvitedUserIDList { @@ -634,7 +645,10 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou log.NewError(req.OperationID, "failed, kick list 0") return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}, nil } - + if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, req.KickedUserIDList); err != nil { + log.NewError(req.OperationID, "DelGroupAndUserCache failed", err.Error()) + return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}, nil + } //remove for _, v := range req.KickedUserIDList { kickedInfo, err := rocksCache.GetGroupMemberInfoFromCache(req.GroupID, v) @@ -701,42 +715,12 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou } } - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil" - log.NewError(req.OperationID, errMsg) - return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil - } - cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ - GroupID: req.GroupID, - OperationID: req.OperationID, - }) - if err != nil { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) - return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil - } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) - return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil - } - if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) - } - if groupInfo.GroupType != constant.SuperGroup { for _, userID := range okUserIDList { - err = rocksCache.DelJoinedGroupIDListFromCache(userID) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), userID) - } if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, userID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) } } - if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } chat.MemberKickedNotification(req, okUserIDList) } else { for _, userID := range okUserIDList { @@ -761,7 +745,6 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String()) var resp pbGroup.GetGroupMembersInfoResp resp.MemberList = []*open_im_sdk.GroupMemberFullInfo{} - for _, userID := range req.MemberList { groupMember, err := rocksCache.GetGroupMemberInfoFromCache(req.GroupID, userID) if err != nil { @@ -773,24 +756,6 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG memberNode.JoinTime = int32(groupMember.JoinTime.Unix()) resp.MemberList = append(resp.MemberList, &memberNode) } - - //groupMembers, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID) - //if err != nil { - // log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) - // resp.ErrCode = constant.ErrDB.ErrCode - // resp.ErrMsg = constant.ErrDB.ErrMsg - // return &resp, nil - //} - //for _, member := range groupMembers { - // if utils.IsContain(member.UserID, req.MemberList) { - // var memberNode open_im_sdk.GroupMemberFullInfo - // utils.CopyStructFields(&memberNode, member) - // memberNode.JoinTime = int32(member.JoinTime.Unix()) - // resp.MemberList = append(resp.MemberList, &memberNode) - // } - //} - - resp.ErrCode = 0 log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", resp.String()) return &resp, nil } @@ -875,7 +840,11 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), req.GroupID, req.FromUserID) return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - + groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID) + if err != nil { + log.NewError(req.OperationID, "GetGroupInfoFromCache failed ", err.Error(), req.GroupID, req.FromUserID) + return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } if req.HandleResult == constant.GroupResponseAgree { user, err := imdb.GetUserByUserID(req.FromUserID) if err != nil { @@ -891,6 +860,22 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G member.Nickname = user.Nickname member.JoinSource = request.JoinSource member.InviterUserID = request.InviterUserID + callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &member, groupInfo.Ex) + if callbackResp.ErrCode != 0 { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp) + } + if callbackResp.ActionCode != constant.ActionAllow { + if callbackResp.ErrCode == 0 { + callbackResp.ErrCode = 201 + } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp) + return &pbGroup.GroupApplicationResponseResp{ + CommonResp: &pbGroup.CommonResp{ + ErrCode: int32(callbackResp.ErrCode), + ErrMsg: callbackResp.ErrMsg, + }, + }, nil + } err = imdb.InsertIntoGroupMember(member) if err != nil { log.NewError(req.OperationID, "GroupApplicationResponse failed ", err.Error(), member) @@ -980,7 +965,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID) + groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID) if err != nil { log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", req.GroupID, err) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil @@ -1000,40 +985,34 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) //to group member groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: req.OpUserID} utils.CopyStructFields(&groupMember, us) - err = imdb.InsertIntoGroupMember(groupMember) - if err != nil { - log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) - return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + callbackResp := CallbackBeforeMemberJoinGroup(req.OperationID, &groupMember, groupInfo.Ex) + if callbackResp.ErrCode != 0 { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg resp: ", callbackResp) } - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil" - log.NewError(req.OperationID, errMsg) - return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil - } - cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ - GroupID: req.GroupID, - OperationID: req.OperationID, - }) - if err != nil { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) - return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + if callbackResp.ActionCode != constant.ActionAllow { + if callbackResp.ErrCode == 0 { + callbackResp.ErrCode = 201 + } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "callbackBeforeSendSingleMsg result", "end rpc and return", callbackResp) + return &pbGroup.JoinGroupResp{ + CommonResp: &pbGroup.CommonResp{ + ErrCode: int32(callbackResp.ErrCode), + ErrMsg: callbackResp.ErrMsg, + }, + }, nil } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) - return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + + if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, []string{req.OpUserID}); err != nil { + log.NewError(req.OperationID, "DelGroupAndUserCache failed, ", err.Error(), req.OpUserID) + return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } - err = rocksCache.DelJoinedGroupIDListFromCache(req.OpUserID) + + err = imdb.InsertIntoGroupMember(groupMember) if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) - } - if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) - } - if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) + return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID) log.NewInfo(req.OperationID, "JoinGroup rpc return ") return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1042,7 +1021,6 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil } } - var groupRequest db.GroupRequest groupRequest.UserID = req.OpUserID groupRequest.ReqMsg = req.ReqMessage @@ -1053,13 +1031,11 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) log.NewError(req.OperationID, "InsertIntoGroupRequest failed ", err.Error(), groupRequest) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - //_, err = imdb.GetGroupMemberListByGroupIDAndRoleLevel(req.GroupID, constant.GroupOwner) //if err != nil { // log.NewError(req.OperationID, "GetGroupMemberListByGroupIDAndRoleLevel failed ", err.Error(), req.GroupID, constant.GroupOwner) // return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil //} - chat.JoinGroupApplicationNotification(req) log.NewInfo(req.OperationID, "JoinGroup rpc return ") return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1079,6 +1055,11 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, []string{req.OpUserID}); err != nil { + log.NewError(req.OperationID, "DelGroupAndUserCache failed, ", err.Error(), req.OpUserID) + return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } + err = imdb.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, req.OpUserID) if err != nil { log.NewError(req.OperationID, "DeleteGroupMemberByGroupIdAndUserId failed ", err.Error(), req.GroupID, req.OpUserID) @@ -1121,35 +1102,7 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) } } - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil" - log.NewError(req.OperationID, errMsg) - return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil - } - cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ - GroupID: req.GroupID, - OperationID: req.OperationID, - }) - if err != nil { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) - return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil - } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) - return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil - } - if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) - } if groupInfo.GroupType != constant.SuperGroup { - if err := rocksCache.DelJoinedGroupIDListFromCache(req.OpUserID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.OpUserID) - } - if err := rocksCache.DelGroupMemberNumFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.OpUserID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) } @@ -1259,16 +1212,15 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf groupInfo.NotificationUserID = req.OpUserID groupInfo.NotificationUpdateTime = time.Now() } + if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID) + return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } err = imdb.SetGroupInfo(groupInfo) if err != nil { log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo) return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID) - return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil - } - log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}) if changedType != 0 { chat.GroupInfoSetNotification(req.OperationID, req.OpUserID, req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification) @@ -1339,6 +1291,18 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe log.NewError(req.OperationID, "same owner ", req.OldOwnerUserID, req.NewOwnerUserID) return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil } + err = rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.NewOwnerUserID) + if err != nil { + log.NewError(req.OperationID, "DelGroupMemberInfoFromCache failed ", req.GroupID, req.NewOwnerUserID) + return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + + } + err = rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.OldOwnerUserID) + if err != nil { + log.NewError(req.OperationID, "DelGroupMemberInfoFromCache failed ", req.GroupID, req.OldOwnerUserID) + return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } + groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.OldOwnerUserID, RoleLevel: constant.GroupOrdinaryUsers} err = imdb.UpdateGroupMemberInfo(groupMemberInfo) if err != nil { @@ -1351,14 +1315,7 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo) return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - err = rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.NewOwnerUserID) - if err != nil { - log.NewError(req.OperationID, "DelGroupMemberInfoFromCache failed ", req.GroupID, req.NewOwnerUserID) - } - err = rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.OldOwnerUserID) - if err != nil { - log.NewError(req.OperationID, "DelGroupMemberInfoFromCache failed ", req.GroupID, req.OldOwnerUserID) - } + chat.GroupOwnerTransferredNotification(req) return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1503,6 +1460,15 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } + if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } + if err := s.DelGroupAndUserCache(req.OperationID, req.GroupID, nil); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } + err := imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusDismissed) if err != nil { log.NewError(req.OperationID, "OperateGroupStatus failed ", req.GroupID, constant.GroupStatusDismissed) @@ -1554,34 +1520,8 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou if err != nil { log.NewError(req.OperationID, "DeleteGroupMemberByGroupID failed ", req.GroupID) return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil - } } - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil" - log.NewError(req.OperationID, errMsg) - return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: errMsg}}, nil - } - cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ - GroupID: req.GroupID, - OperationID: req.OperationID, - }) - if err != nil { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) - return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil - } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) - return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil - } - if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } - if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil } @@ -1605,7 +1545,7 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil } - mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.UserID) + mutedInfo, err := rocksCache.GetGroupMemberInfoFromCache(req.GroupID, req.UserID) if err != nil { errMsg := req.OperationID + " GetGroupMemberInfoByGroupIDAndUserID failed " + req.GroupID + req.UserID + err.Error() return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil @@ -1619,17 +1559,17 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil } + if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, req.UserID) + return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID} - groupMemberInfo.MuteEndTime = time.Unix(int64(time.Now().Second())+int64(req.MutedSeconds), time.Now().UnixNano()) err = imdb.UpdateGroupMemberInfo(groupMemberInfo) if err != nil { log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo) return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } chat.GroupMemberMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, req.MutedSeconds) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1663,6 +1603,10 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.UserID return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil } + if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } groupMemberInfo := db.GroupMember{GroupID: req.GroupID, UserID: req.UserID} groupMemberInfo.MuteEndTime = time.Unix(0, 0) @@ -1671,9 +1615,7 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo) return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } + chat.GroupMemberCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1707,15 +1649,17 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) // errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.OpUserID + err.Error() // return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil //} + if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } err = imdb.OperateGroupStatus(req.GroupID, constant.GroupStatusMuted) if err != nil { log.Error(req.OperationID, "OperateGroupStatus failed ", err.Error(), req.GroupID, constant.GroupStatusMuted) return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } + chat.GroupMutedNotification(req.OperationID, req.OpUserID, req.GroupID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1723,7 +1667,6 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (*pbGroup.CancelMuteGroupResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc args ", req.String()) - opFlag, err := s.getGroupUserLevel(req.GroupID, req.OpUserID) if err != nil { errMsg := req.OperationID + " getGroupUserLevel failed " + req.GroupID + req.OpUserID + err.Error() @@ -1735,7 +1678,6 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu log.Error(req.OperationID, errMsg) return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil } - //mutedInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(req.GroupID, req.) //if err != nil { // errMsg := req.OperationID + " GetGroupMemberInfoByGroupIDAndUserID failed " + req.GroupID + req.OpUserID + err.Error() @@ -1750,14 +1692,16 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu // return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil //} log.Debug(req.OperationID, "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk}) + if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } err = imdb.UpdateGroupInfoDefaultZero(req.GroupID, map[string]interface{}{"status": constant.GroupOk}) if err != nil { log.Error(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), req.GroupID) return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } + chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1785,15 +1729,17 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S } else { groupMemberInfo.Nickname = req.Nickname } + + if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } err := imdb.UpdateGroupMemberInfo(groupMemberInfo) if err != nil { errMsg := req.OperationID + " UpdateGroupMemberInfo failed " + err.Error() log.Error(req.OperationID, errMsg) return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) - } chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1802,6 +1748,12 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (resp *pbGroup.SetGroupMemberInfoResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp = &pbGroup.SetGroupMemberInfoResp{CommonResp: &pbGroup.CommonResp{}} + if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + resp.CommonResp.ErrCode = constant.ErrDB.ErrCode + resp.CommonResp.ErrMsg = err.Error() + return resp, nil + } groupMember := db.GroupMember{ GroupID: req.GroupID, UserID: req.UserID, @@ -1826,9 +1778,6 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + ":" + err.Error() return resp, nil } - if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID, req.UserID) - } if req.RoleLevel != nil { switch req.RoleLevel.Value { case constant.GroupOrdinaryUsers: @@ -1867,3 +1816,47 @@ func (s *groupServer) GetGroupAbstractInfo(c context.Context, req *pbGroup.GetGr log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String()) return resp, nil } + +func (s *groupServer) DelGroupAndUserCache(operationID, groupID string, userIDList []string) error { + if groupID != "" { + etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, operationID) + if etcdConn == nil { + errMsg := operationID + "getcdv3.GetDefaultConn == nil" + log.NewError(operationID, errMsg) + return errors.New("etcdConn is nil") + } + cacheClient := pbCache.NewCacheClient(etcdConn) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: groupID, + OperationID: operationID, + }) + if err != nil { + log.NewError(operationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) + return utils.Wrap(err, "") + } + if cacheResp.CommonResp.ErrCode != 0 { + log.NewError(operationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) + return errors.New(fmt.Sprintf("errMsg is %s, errCode is %d", cacheResp.CommonResp.ErrMsg, cacheResp.CommonResp.ErrCode)) + } + err = rocksCache.DelGroupMemberListHashFromCache(groupID) + if err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), groupID, err.Error()) + return utils.Wrap(err, "") + } + err = rocksCache.DelGroupMemberNumFromCache(groupID) + if err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID) + return utils.Wrap(err, "") + } + } + if userIDList != nil { + for _, userID := range userIDList { + err := rocksCache.DelJoinedGroupIDListFromCache(userID) + if err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) + return utils.Wrap(err, "") + } + } + } + return nil +} diff --git a/pkg/call_back_struct/group.go b/pkg/call_back_struct/group.go index 92d5c77dd..93651b34f 100644 --- a/pkg/call_back_struct/group.go +++ b/pkg/call_back_struct/group.go @@ -1,12 +1,14 @@ package call_back_struct import ( + "Open_IM/pkg/proto/group" commonPb "Open_IM/pkg/proto/sdk_ws" ) type CallbackBeforeCreateGroupReq struct { CallbackCommand string `json:"callbackCommand"` commonPb.GroupInfo + InitMemberList []*group.GroupAddMemberInfo `json:"initMemberList"` } type CallbackBeforeCreateGroupResp struct { @@ -25,3 +27,20 @@ type CallbackBeforeCreateGroupResp struct { LookMemberInfo *int32 `json:"lookMemberInfo"` ApplyMemberFriend *int32 `json:"applyMemberFriend"` } + +type CallbackBeforeMemberJoinGroupReq struct { + CallbackCommand string `json:"callbackCommand"` + GroupID string `json:"groupID"` + UserID string `json:"userID"` + Ex string `json:"ex"` + GroupEx string `json:"groupEx"` +} + +type CallbackBeforeMemberJoinGroupResp struct { + *CommonCallbackResp + NickName *string `json:"nickName"` + FaceURL *string `json:"faceURL"` + RoleLevel *int32 `json:"roleLevel"` + MuteEndTime *int64 `json:"muteEndTime"` + Ex *string `json:"ex"` +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 4fce63c19..f2906c2c0 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -291,6 +291,7 @@ type config struct { CallbackBeforeSuperGroupOnlinePush callBackConfig `yaml:"callbackSuperGroupOnlinePush"` CallbackBeforeAddFriend callBackConfig `yaml:"callbackBeforeAddFriend"` CallbackBeforeCreateGroup callBackConfig `yaml:"callbackBeforeCreateGroup"` + CallbackBeforeMemberJoinGroup callBackConfig `yaml:"callbackBeforeMemberJoinGroup"` } `yaml:"callback"` Notification struct { ///////////////////////group///////////////////////////// diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index a817ab02c..3179ff46b 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -196,19 +196,20 @@ const ( VerificationCodeForResetSuffix = "_forReset" //callbackCommand - CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand" - CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand" - CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand" - CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand" - CallbackMsgModifyCommand = "callbackMsgModifyCommand" - CallbackUserOnlineCommand = "callbackUserOnlineCommand" - CallbackUserOfflineCommand = "callbackUserOfflineCommand" - CallbackUserKickOffCommand = "callbackUserKickOffCommand" - CallbackOfflinePushCommand = "callbackOfflinePushCommand" - CallbackOnlinePushCommand = "callbackOnlinePushCommand" - CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand" - CallbackBeforeAddFriendCommand = "callbackBeforeAddFriendCommand" - CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroup" + CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand" + CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand" + CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand" + CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand" + CallbackMsgModifyCommand = "callbackMsgModifyCommand" + CallbackUserOnlineCommand = "callbackUserOnlineCommand" + CallbackUserOfflineCommand = "callbackUserOfflineCommand" + CallbackUserKickOffCommand = "callbackUserKickOffCommand" + CallbackOfflinePushCommand = "callbackOfflinePushCommand" + CallbackOnlinePushCommand = "callbackOnlinePushCommand" + CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand" + CallbackBeforeAddFriendCommand = "callbackBeforeAddFriendCommand" + CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroupCommand" + CallbackBeforeMemberJoinGroupCommand = "callbackBeforeMemberJoinGroupCommand" //callback actionCode ActionAllow = 0 From 07cdd8bbab2aeac2e18b7e3c4cd52f53a1df2e50 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 22 Nov 2022 14:18:57 +0800 Subject: [PATCH 18/19] add callback and fix cache --- internal/rpc/group/group.go | 7 +++++-- internal/rpc/msg/group_notification.go | 2 -- internal/rpc/msg/send_msg.go | 20 ++++++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index d0d88cc41..7a445a353 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -1111,10 +1111,13 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) if err := rocksCache.DelJoinedSuperGroupIDListFromCache(req.OpUserID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.OpUserID) } + if err := rocksCache.DelGroupMemberListHashFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) + } chat.SuperGroupNotification(req.OperationID, req.OpUserID, req.OpUserID) } - log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}) - return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil + log.NewInfo(req.OperationID, "rpc QuitGroup return ", pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{}}) + return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{}}, nil } func hasAccess(req *pbGroup.SetGroupInfoReq) bool { diff --git a/internal/rpc/msg/group_notification.go b/internal/rpc/msg/group_notification.go index 697e51824..bbadbd3b5 100644 --- a/internal/rpc/msg/group_notification.go +++ b/internal/rpc/msg/group_notification.go @@ -416,8 +416,6 @@ func MemberQuitNotification(req *pbGroup.QuitGroupReq) { } groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, req.GroupID, "", req.OperationID) - // groupNotification(constant.MemberQuitNotification, &MemberQuitTips, req.OpUserID, "", req.OpUserID, req.OperationID) - } //message ApplicationProcessedTips{ diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index e84c443cd..c072b1b71 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -174,9 +174,13 @@ func (rpc *rpcChat) messageVerification(data *pbChat.SendMsgReq) (bool, int32, s if token_verify.IsManagerUserID(data.MsgData.SendID) { return true, 0, "", userIDList } - if !utils.IsContain(data.MsgData.SendID, userIDList) { - //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) - return false, 202, "you are not in group", nil + if data.MsgData.ContentType <= constant.NotificationEnd && data.MsgData.ContentType >= constant.NotificationBegin { + return true, 0, "", userIDList + } else { + if !utils.IsContain(data.MsgData.SendID, userIDList) { + //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) + return false, 202, "you are not in group", nil + } } isMute, err := userIsMuteInGroup(data.MsgData.GroupID, data.MsgData.SendID) if err != nil { @@ -233,9 +237,13 @@ func (rpc *rpcChat) messageVerification(data *pbChat.SendMsgReq) (bool, int32, s if token_verify.IsManagerUserID(data.MsgData.SendID) { return true, 0, "", userIDList } - if !utils.IsContain(data.MsgData.SendID, userIDList) { - //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) - return false, 202, "you are not in group", nil + if data.MsgData.ContentType <= constant.NotificationEnd && data.MsgData.ContentType >= constant.NotificationBegin { + return true, 0, "", userIDList + } else { + if !utils.IsContain(data.MsgData.SendID, userIDList) { + //return returnMsg(&replay, pb, 202, "you are not in group", "", 0) + return false, 202, "you are not in group", nil + } } isMute, err := userIsMuteInGroup(data.MsgData.GroupID, data.MsgData.SendID) if err != nil { From e9f6521c6ad0cbe2f1b2b6f6789ef8ebf9fa9217 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 22 Nov 2022 14:44:52 +0800 Subject: [PATCH 19/19] add callback and fix cache --- internal/rpc/group/group.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 7a445a353..4945bed83 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -1733,7 +1733,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S groupMemberInfo.Nickname = req.Nickname } - if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } @@ -1751,7 +1751,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (resp *pbGroup.SetGroupMemberInfoResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp = &pbGroup.SetGroupMemberInfoResp{CommonResp: &pbGroup.CommonResp{}} - if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode resp.CommonResp.ErrMsg = err.Error()