协议获取与好友的关系

This commit is contained in:
wh_zcy 2022-11-21 16:39:38 +08:00
parent 2527e10578
commit b01e92ca66
4 changed files with 207 additions and 6 deletions

View File

@ -26,6 +26,7 @@ const (
FriendSubTypeAssistlist = "assistlist" FriendSubTypeAssistlist = "assistlist"
FriendSubTypeGetreward = "getreward" FriendSubTypeGetreward = "getreward"
FriendSubTypeAssistHeroList = "assistherolist" FriendSubTypeAssistHeroList = "assistherolist"
FriendSubTypeRelation = "getrelation"
) )
type apiComp struct { type apiComp struct {

View File

@ -0,0 +1,58 @@
package friend
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
// 获取好友关系
func (this *apiComp) GetRelationCheck(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode) {
if req.TargetUid == "" {
code = pb.ErrorCode_ReqParameterError
this.moduleFriend.Error("参数错误", log.Fields{"uid": session.GetUserId(), "params": req})
}
return
}
func (this *apiComp) GetRelation(session comm.IUserSession, req *pb.FriendGetRelationReq) (code pb.ErrorCode, data proto.Message) {
if code = this.GetRelationCheck(session, req); code != pb.ErrorCode_Success {
return
}
self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId())
if self == nil {
code = pb.ErrorCode_FriendSelfNoData
return
}
target := this.moduleFriend.modelFriend.GetFriend(req.TargetUid)
if target == nil {
code = pb.ErrorCode_FriendTargetNoData
return
}
var status bool
// 已申请目标玩家
if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok {
status = true
}
//目标玩家已是好友
if _, ok := utils.Findx(self.FriendIds, req.TargetUid); ok {
status = true
}
resp := &pb.FriendGetRelationResp{
TargetUid: req.TargetUid,
Status: status,
}
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeRelation, resp); err != nil {
code = pb.ErrorCode_SystemError
return
}
return
}

View File

@ -45,6 +45,11 @@ func (this *apiComp) List(session comm.IUserSession, req *pb.FriendListReq) (cod
if target == nil { if target == nil {
continue continue
} }
// 申请过的在线好友,设置申请状态
if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok {
base.IsApplied = true
}
if _, ok := utils.Findx(target.ZanIds, self.Uid); ok { if _, ok := utils.Findx(target.ZanIds, self.Uid); ok {
base.IsZaned = true base.IsZaned = true
} }

View File

@ -2008,6 +2008,109 @@ func (x *FriendAssistHeroListResp) GetFriends() []*FriendBase {
return nil return nil
} }
// 查询是否已申请目标玩家为好友或目标玩家是否已是好友
type FriendGetRelationReq struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
TargetUid string `protobuf:"bytes,1,opt,name=targetUid,proto3" json:"targetUid"` //目标玩家ID
}
func (x *FriendGetRelationReq) Reset() {
*x = FriendGetRelationReq{}
if protoimpl.UnsafeEnabled {
mi := &file_friend_friend_msg_proto_msgTypes[40]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *FriendGetRelationReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*FriendGetRelationReq) ProtoMessage() {}
func (x *FriendGetRelationReq) ProtoReflect() protoreflect.Message {
mi := &file_friend_friend_msg_proto_msgTypes[40]
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 FriendGetRelationReq.ProtoReflect.Descriptor instead.
func (*FriendGetRelationReq) Descriptor() ([]byte, []int) {
return file_friend_friend_msg_proto_rawDescGZIP(), []int{40}
}
func (x *FriendGetRelationReq) GetTargetUid() string {
if x != nil {
return x.TargetUid
}
return ""
}
type FriendGetRelationResp struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
TargetUid string `protobuf:"bytes,1,opt,name=targetUid,proto3" json:"targetUid"`
Status bool `protobuf:"varint,2,opt,name=status,proto3" json:"status"` //已是好友或已申请返回true
}
func (x *FriendGetRelationResp) Reset() {
*x = FriendGetRelationResp{}
if protoimpl.UnsafeEnabled {
mi := &file_friend_friend_msg_proto_msgTypes[41]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *FriendGetRelationResp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*FriendGetRelationResp) ProtoMessage() {}
func (x *FriendGetRelationResp) ProtoReflect() protoreflect.Message {
mi := &file_friend_friend_msg_proto_msgTypes[41]
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 FriendGetRelationResp.ProtoReflect.Descriptor instead.
func (*FriendGetRelationResp) Descriptor() ([]byte, []int) {
return file_friend_friend_msg_proto_rawDescGZIP(), []int{41}
}
func (x *FriendGetRelationResp) GetTargetUid() string {
if x != nil {
return x.TargetUid
}
return ""
}
func (x *FriendGetRelationResp) GetStatus() bool {
if x != nil {
return x.Status
}
return false
}
var File_friend_friend_msg_proto protoreflect.FileDescriptor var File_friend_friend_msg_proto protoreflect.FileDescriptor
var file_friend_friend_msg_proto_rawDesc = []byte{ var file_friend_friend_msg_proto_rawDesc = []byte{
@ -2159,8 +2262,16 @@ var file_friend_friend_msg_proto_rawDesc = []byte{
0x48, 0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x07, 0x48, 0x65, 0x72, 0x6f, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x25, 0x0a, 0x07,
0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e,
0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x61, 0x73, 0x65, 0x52, 0x07, 0x66, 0x72, 0x69, 0x65,
0x6e, 0x64, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x6e, 0x64, 0x73, 0x22, 0x34, 0x0a, 0x14, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x47, 0x65, 0x74,
0x74, 0x6f, 0x33, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x1c, 0x0a, 0x09, 0x74,
0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09,
0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x22, 0x4d, 0x0a, 0x15, 0x46, 0x72, 0x69,
0x65, 0x6e, 0x64, 0x47, 0x65, 0x74, 0x52, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65,
0x73, 0x70, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x55, 0x69, 0x64,
0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08,
0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@ -2175,7 +2286,7 @@ func file_friend_friend_msg_proto_rawDescGZIP() []byte {
return file_friend_friend_msg_proto_rawDescData return file_friend_friend_msg_proto_rawDescData
} }
var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 40) var file_friend_friend_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 42)
var file_friend_friend_msg_proto_goTypes = []interface{}{ var file_friend_friend_msg_proto_goTypes = []interface{}{
(*FriendBase)(nil), // 0: FriendBase (*FriendBase)(nil), // 0: FriendBase
(*FriendListReq)(nil), // 1: FriendListReq (*FriendListReq)(nil), // 1: FriendListReq
@ -2217,7 +2328,9 @@ var file_friend_friend_msg_proto_goTypes = []interface{}{
(*FriendAssistHeroUpdatePush)(nil), // 37: FriendAssistHeroUpdatePush (*FriendAssistHeroUpdatePush)(nil), // 37: FriendAssistHeroUpdatePush
(*FriendAssistHeroListReq)(nil), // 38: FriendAssistHeroListReq (*FriendAssistHeroListReq)(nil), // 38: FriendAssistHeroListReq
(*FriendAssistHeroListResp)(nil), // 39: FriendAssistHeroListResp (*FriendAssistHeroListResp)(nil), // 39: FriendAssistHeroListResp
(*AssistRecord)(nil), // 40: AssistRecord (*FriendGetRelationReq)(nil), // 40: FriendGetRelationReq
(*FriendGetRelationResp)(nil), // 41: FriendGetRelationResp
(*AssistRecord)(nil), // 42: AssistRecord
} }
var file_friend_friend_msg_proto_depIdxs = []int32{ var file_friend_friend_msg_proto_depIdxs = []int32{
0, // 0: FriendListResp.list:type_name -> FriendBase 0, // 0: FriendListResp.list:type_name -> FriendBase
@ -2227,7 +2340,7 @@ var file_friend_friend_msg_proto_depIdxs = []int32{
0, // 4: FriendBlackListResp.friends:type_name -> FriendBase 0, // 4: FriendBlackListResp.friends:type_name -> FriendBase
0, // 5: FriendZanlistResp.list:type_name -> FriendBase 0, // 5: FriendZanlistResp.list:type_name -> FriendBase
0, // 6: FriendAssistlistResp.list:type_name -> FriendBase 0, // 6: FriendAssistlistResp.list:type_name -> FriendBase
40, // 7: FriendAssistlistResp.record:type_name -> AssistRecord 42, // 7: FriendAssistlistResp.record:type_name -> AssistRecord
0, // 8: FriendAssistHeroUpdatePush.friend:type_name -> FriendBase 0, // 8: FriendAssistHeroUpdatePush.friend:type_name -> FriendBase
0, // 9: FriendAssistHeroListResp.friends:type_name -> FriendBase 0, // 9: FriendAssistHeroListResp.friends:type_name -> FriendBase
10, // [10:10] is the sub-list for method output_type 10, // [10:10] is the sub-list for method output_type
@ -2724,6 +2837,30 @@ func file_friend_friend_msg_proto_init() {
return nil return nil
} }
} }
file_friend_friend_msg_proto_msgTypes[40].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*FriendGetRelationReq); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_friend_friend_msg_proto_msgTypes[41].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*FriendGetRelationResp); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
} }
type x struct{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -2731,7 +2868,7 @@ func file_friend_friend_msg_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_friend_friend_msg_proto_rawDesc, RawDescriptor: file_friend_friend_msg_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 40, NumMessages: 42,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },