diff --git a/modules/chat/api_send.go b/modules/chat/api_send.go index cb0aca940..028dfd5c1 100644 --- a/modules/chat/api_send.go +++ b/modules/chat/api_send.go @@ -78,6 +78,7 @@ func (this *apiComp) Send(session comm.IUserSession, req *pb.ChatSendReq) (code code = pb.ErrorCode_DBError return } + session.SendMsg(string(this.module.GetType()), "message", &pb.ChatMessagePush{Chat: msg}) break case pb.ChatChannel_CrossServer: if userexpand, err = this.module.ModuleUser.GetUserExpand(session.GetUserId()); err != nil { diff --git a/modules/forum/api_like.go b/modules/forum/api_like.go new file mode 100644 index 000000000..539bb67b6 --- /dev/null +++ b/modules/forum/api_like.go @@ -0,0 +1,30 @@ +package forum + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) LikeCheck(session comm.IUserSession, req *pb.ForumLikeReq) (code pb.ErrorCode) { + if req.Herocid == "" || req.Cid == "" { + code = pb.ErrorCode_ReqParameterError + } + return +} + +///获取本服聊天消息记录 +func (this *apiComp) Like(session comm.IUserSession, req *pb.ForumLikeReq) (code pb.ErrorCode, data proto.Message) { + var ( + err error + ) + + if _, err = this.module.modelForum.like(req.Herocid, req.Cid, req.Islike); err != nil { + code = pb.ErrorCode_HeroNoExist + } + + session.SendMsg(string(this.module.GetType()), "getlist", &pb.ForumLikeResp{Cid: req.Cid, Islike: req.Islike, Issucc: true}) + return +} diff --git a/modules/forum/modelForum.go b/modules/forum/modelForum.go index 87f51206b..3f8883987 100644 --- a/modules/forum/modelForum.go +++ b/modules/forum/modelForum.go @@ -96,6 +96,34 @@ func (this *modelForumComp) addCommentChache(key string, count int64, msgs ...*p return } +//点赞 +func (this *modelForumComp) like(heroid, id string, islike bool) (comment *pb.DBComment, err error) { + comment = &pb.DBComment{} + key := fmt.Sprintf("%s:%s-%s", this.TableName, heroid, id) + if err = this.Redis.HGetAll(key, comment); err != nil && err != redis.RedisNil { + this.module.Errorln(err) + return + } + if err == redis.RedisNil { + if err = this.DB.FindOne(comm.TableHero, bson.M{"_id": id}).Decode(comment); err != nil { + return + } + } + if islike { + comment.Starlist++ + } else { + comment.Starlist-- + } + if err = this.Redis.HMSet(key, map[string]interface{}{ + "starlist": comment.Starlist, + }); err != nil { + return + } + this.DB.UpdateOne(comm.TableHero, bson.M{"_id": id}, bson.M{"starlist": comment.Starlist}) + return +} + +//查看 func (this *modelForumComp) watchHero(stage string, uid string, herocid string) (hero *pb.DBHero, err error) { tcoon := db.ServerDBConn(stage) var ( diff --git a/pb/forum_msg.pb.go b/pb/forum_msg.pb.go index 0dc4b4c0e..9e95ae1c8 100644 --- a/pb/forum_msg.pb.go +++ b/pb/forum_msg.pb.go @@ -364,6 +364,134 @@ func (x *ForumWatchHeroResp) GetHero() *DBHero { return nil } +//请求点赞 请求 +type ForumLikeReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Herocid string `protobuf:"bytes,1,opt,name=herocid,proto3" json:"herocid"` //英雄配置id + Cid string `protobuf:"bytes,2,opt,name=cid,proto3" json:"cid"` //评论id + Islike bool `protobuf:"varint,3,opt,name=islike,proto3" json:"islike"` //是否点赞 +} + +func (x *ForumLikeReq) Reset() { + *x = ForumLikeReq{} + if protoimpl.UnsafeEnabled { + mi := &file_forum_forum_msg_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ForumLikeReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForumLikeReq) ProtoMessage() {} + +func (x *ForumLikeReq) ProtoReflect() protoreflect.Message { + mi := &file_forum_forum_msg_proto_msgTypes[6] + 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) +} + +// Deprecated: Use ForumLikeReq.ProtoReflect.Descriptor instead. +func (*ForumLikeReq) Descriptor() ([]byte, []int) { + return file_forum_forum_msg_proto_rawDescGZIP(), []int{6} +} + +func (x *ForumLikeReq) GetHerocid() string { + if x != nil { + return x.Herocid + } + return "" +} + +func (x *ForumLikeReq) GetCid() string { + if x != nil { + return x.Cid + } + return "" +} + +func (x *ForumLikeReq) GetIslike() bool { + if x != nil { + return x.Islike + } + return false +} + +//请求点赞 回应 +type ForumLikeResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Cid string `protobuf:"bytes,1,opt,name=cid,proto3" json:"cid"` //评论id + Islike bool `protobuf:"varint,2,opt,name=islike,proto3" json:"islike"` //是否点赞 + Issucc bool `protobuf:"varint,3,opt,name=issucc,proto3" json:"issucc"` //成功失败 +} + +func (x *ForumLikeResp) Reset() { + *x = ForumLikeResp{} + if protoimpl.UnsafeEnabled { + mi := &file_forum_forum_msg_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ForumLikeResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ForumLikeResp) ProtoMessage() {} + +func (x *ForumLikeResp) ProtoReflect() protoreflect.Message { + mi := &file_forum_forum_msg_proto_msgTypes[7] + 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) +} + +// Deprecated: Use ForumLikeResp.ProtoReflect.Descriptor instead. +func (*ForumLikeResp) Descriptor() ([]byte, []int) { + return file_forum_forum_msg_proto_rawDescGZIP(), []int{7} +} + +func (x *ForumLikeResp) GetCid() string { + if x != nil { + return x.Cid + } + return "" +} + +func (x *ForumLikeResp) GetIslike() bool { + if x != nil { + return x.Islike + } + return false +} + +func (x *ForumLikeResp) GetIssucc() bool { + if x != nil { + return x.Issucc + } + return false +} + var File_forum_forum_msg_proto protoreflect.FileDescriptor var file_forum_forum_msg_proto_rawDesc = []byte{ @@ -401,8 +529,18 @@ var file_forum_forum_msg_proto_rawDesc = []byte{ 0x31, 0x0a, 0x12, 0x46, 0x6f, 0x72, 0x75, 0x6d, 0x57, 0x61, 0x74, 0x63, 0x68, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x68, 0x65, 0x72, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x48, 0x65, 0x72, 0x6f, 0x52, 0x04, 0x68, 0x65, - 0x72, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x72, 0x6f, 0x22, 0x52, 0x0a, 0x0c, 0x46, 0x6f, 0x72, 0x75, 0x6d, 0x4c, 0x69, 0x6b, 0x65, 0x52, + 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x68, 0x65, 0x72, 0x6f, 0x63, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x68, 0x65, 0x72, 0x6f, 0x63, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, + 0x63, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x16, + 0x0a, 0x06, 0x69, 0x73, 0x6c, 0x69, 0x6b, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, + 0x69, 0x73, 0x6c, 0x69, 0x6b, 0x65, 0x22, 0x51, 0x0a, 0x0d, 0x46, 0x6f, 0x72, 0x75, 0x6d, 0x4c, + 0x69, 0x6b, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x63, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x6c, + 0x69, 0x6b, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x6c, 0x69, 0x6b, + 0x65, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -417,7 +555,7 @@ func file_forum_forum_msg_proto_rawDescGZIP() []byte { return file_forum_forum_msg_proto_rawDescData } -var file_forum_forum_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_forum_forum_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 8) var file_forum_forum_msg_proto_goTypes = []interface{}{ (*ForumGetListReq)(nil), // 0: ForumGetListReq (*ForumGetListResp)(nil), // 1: ForumGetListResp @@ -425,13 +563,15 @@ var file_forum_forum_msg_proto_goTypes = []interface{}{ (*ForumReleaseCommentResp)(nil), // 3: ForumReleaseCommentResp (*ForumWatchHeroReq)(nil), // 4: ForumWatchHeroReq (*ForumWatchHeroResp)(nil), // 5: ForumWatchHeroResp - (*DBComment)(nil), // 6: DBComment - (*DBHero)(nil), // 7: DBHero + (*ForumLikeReq)(nil), // 6: ForumLikeReq + (*ForumLikeResp)(nil), // 7: ForumLikeResp + (*DBComment)(nil), // 8: DBComment + (*DBHero)(nil), // 9: DBHero } var file_forum_forum_msg_proto_depIdxs = []int32{ - 6, // 0: ForumGetListResp.comment:type_name -> DBComment - 6, // 1: ForumReleaseCommentResp.comment:type_name -> DBComment - 7, // 2: ForumWatchHeroResp.hero:type_name -> DBHero + 8, // 0: ForumGetListResp.comment:type_name -> DBComment + 8, // 1: ForumReleaseCommentResp.comment:type_name -> DBComment + 9, // 2: ForumWatchHeroResp.hero:type_name -> DBHero 3, // [3:3] is the sub-list for method output_type 3, // [3:3] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name @@ -519,6 +659,30 @@ func file_forum_forum_msg_proto_init() { return nil } } + file_forum_forum_msg_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ForumLikeReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_forum_forum_msg_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ForumLikeResp); 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{ @@ -526,7 +690,7 @@ func file_forum_forum_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_forum_forum_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 6, + NumMessages: 8, NumExtensions: 0, NumServices: 0, },