diff --git a/core/api/node/service.pb.go b/core/api/node/service.pb.go index 02efb0ef1e..5afacc4db0 100644 --- a/core/api/node/service.pb.go +++ b/core/api/node/service.pb.go @@ -93,7 +93,6 @@ type ServiceClient interface { ContactList(ctx context.Context, in *Void, opts ...grpc.CallOption) (Service_ContactListClient, error) ConversationCreate(ctx context.Context, in *berty_entity2.Conversation, opts ...grpc.CallOption) (*berty_entity2.Conversation, error) ConversationList(ctx context.Context, in *Void, opts ...grpc.CallOption) (Service_ConversationListClient, error) - ConversationAcceptInvite(ctx context.Context, in *berty_entity2.Conversation, opts ...grpc.CallOption) (*berty_entity2.Conversation, error) ConversationInvite(ctx context.Context, in *berty_entity2.ConversationMember, opts ...grpc.CallOption) (*berty_entity2.Conversation, error) } @@ -278,15 +277,6 @@ func (x *serviceConversationListClient) Recv() (*berty_entity2.Conversation, err return m, nil } -func (c *serviceClient) ConversationAcceptInvite(ctx context.Context, in *berty_entity2.Conversation, opts ...grpc.CallOption) (*berty_entity2.Conversation, error) { - out := new(berty_entity2.Conversation) - err := grpc.Invoke(ctx, "/berty.node.Service/ConversationAcceptInvite", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *serviceClient) ConversationInvite(ctx context.Context, in *berty_entity2.ConversationMember, opts ...grpc.CallOption) (*berty_entity2.Conversation, error) { out := new(berty_entity2.Conversation) err := grpc.Invoke(ctx, "/berty.node.Service/ConversationInvite", in, out, c.cc, opts...) @@ -308,7 +298,6 @@ type ServiceServer interface { ContactList(*Void, Service_ContactListServer) error ConversationCreate(context.Context, *berty_entity2.Conversation) (*berty_entity2.Conversation, error) ConversationList(*Void, Service_ConversationListServer) error - ConversationAcceptInvite(context.Context, *berty_entity2.Conversation) (*berty_entity2.Conversation, error) ConversationInvite(context.Context, *berty_entity2.ConversationMember) (*berty_entity2.Conversation, error) } @@ -490,24 +479,6 @@ func (x *serviceConversationListServer) Send(m *berty_entity2.Conversation) erro return x.ServerStream.SendMsg(m) } -func _Service_ConversationAcceptInvite_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(berty_entity2.Conversation) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ServiceServer).ConversationAcceptInvite(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/berty.node.Service/ConversationAcceptInvite", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ServiceServer).ConversationAcceptInvite(ctx, req.(*berty_entity2.Conversation)) - } - return interceptor(ctx, in, info, handler) -} - func _Service_ConversationInvite_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(berty_entity2.ConversationMember) if err := dec(in); err != nil { @@ -550,10 +521,6 @@ var _Service_serviceDesc = grpc.ServiceDesc{ MethodName: "ConversationCreate", Handler: _Service_ConversationCreate_Handler, }, - { - MethodName: "ConversationAcceptInvite", - Handler: _Service_ConversationAcceptInvite_Handler, - }, { MethodName: "ConversationInvite", Handler: _Service_ConversationInvite_Handler, @@ -948,31 +915,30 @@ var ( func init() { proto.RegisterFile("api/node/service.proto", fileDescriptorService) } var fileDescriptorService = []byte{ - // 408 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0xaa, 0xd3, 0x40, - 0x14, 0x76, 0x44, 0xef, 0xe5, 0x9e, 0x7a, 0xe5, 0x32, 0xb7, 0x4a, 0xcd, 0x22, 0x96, 0xea, 0xa2, - 0xab, 0x49, 0x4d, 0x41, 0xdc, 0xb8, 0xb0, 0x55, 0xb0, 0xd0, 0x6e, 0x52, 0x74, 0xe1, 0x46, 0x92, - 0xf4, 0x50, 0x07, 0xc9, 0xcc, 0x38, 0x99, 0x06, 0xfa, 0x26, 0x3e, 0x92, 0x4b, 0x1f, 0x41, 0xea, - 0x23, 0xf8, 0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xfd, 0xe3, 0xa0, 0xf4, 0x71, 0x5d, 0xd7, 0xb0, 0x04, - 0xa7, 0x39, 0x33, 0x7d, 0x0d, 0xdd, 0xb2, 0x7c, 0x15, 0xc7, 0xa8, 0xf6, 0x7e, 0xcd, 0xf4, 0x36, - 0x97, 0x97, 0x70, 0xb9, 0x9f, 0x99, 0xc8, 0x0c, 0xff, 0x5b, 0xfe, 0x4e, 0xad, 0x42, 0xf3, 0xaf, - 0xf2, 0x17, 0xd0, 0x29, 0xcb, 0x96, 0x15, 0x36, 0xeb, 0x46, 0x84, 0xce, 0x81, 0x4e, 0x6b, 0xaf, - 0xd1, 0x54, 0x63, 0x3e, 0xdd, 0xf9, 0x83, 0xbe, 0x67, 0x38, 0x27, 0x7a, 0x74, 0x02, 0x57, 0xf5, - 0xfb, 0x96, 0xc3, 0x9c, 0x70, 0x18, 0x11, 0x1a, 0x40, 0xaf, 0x8e, 0xd8, 0x87, 0x32, 0x13, 0x19, - 0xbf, 0xc1, 0xb9, 0x82, 0xe3, 0x94, 0xa5, 0x5b, 0xbf, 0x5d, 0xb1, 0xc0, 0x24, 0x42, 0x7d, 0xca, - 0x73, 0xf2, 0xfc, 0xdb, 0xce, 0x25, 0xdf, 0x77, 0x2e, 0xf9, 0xb1, 0x73, 0xc9, 0xd7, 0x9f, 0xee, - 0xad, 0x0f, 0x4f, 0xd7, 0xdc, 0x7c, 0xda, 0x44, 0x2c, 0x96, 0x89, 0x57, 0xe8, 0xca, 0x6b, 0x2c, - 0x35, 0x7a, 0xd5, 0x2f, 0x20, 0x3a, 0x2b, 0xbe, 0xd4, 0xf1, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x54, 0xbf, 0x16, 0x4a, 0x15, 0x04, 0x00, 0x00, + // 398 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xcb, 0x6e, 0xda, 0x40, + 0x14, 0xed, 0x54, 0x2d, 0x88, 0xa1, 0x54, 0x68, 0xa0, 0x15, 0xf5, 0xc2, 0x45, 0xb4, 0x0b, 0x56, + 0x63, 0x6a, 0xa4, 0xaa, 0x9b, 0x2e, 0x02, 0x89, 0x14, 0x24, 0xd8, 0x80, 0x92, 0x45, 0x36, 0x91, + 0x6d, 0xae, 0xc8, 0x28, 0xf2, 0xcc, 0x64, 0x3c, 0x58, 0xe2, 0x4f, 0xb2, 0xcb, 0xef, 0x64, 0x99, + 0x4f, 0x88, 0xc8, 0x8f, 0x44, 0x7e, 0xf1, 0x50, 0x6c, 0x94, 0x64, 0x63, 0x5d, 0x9f, 0x7b, 0xce, + 0xb9, 0x73, 0x46, 0x73, 0xf1, 0x77, 0x47, 0x32, 0x8b, 0x8b, 0x39, 0x58, 0x01, 0xa8, 0x90, 0x79, + 0x40, 0xa5, 0x12, 0x5a, 0x10, 0xec, 0x82, 0xd2, 0x2b, 0x1a, 0x75, 0x8c, 0x46, 0xc4, 0x91, 0xb6, + 0xb4, 0x20, 0x04, 0xae, 0x13, 0x82, 0xd1, 0x04, 0xae, 0x99, 0x5e, 0x59, 0x9e, 0xe0, 0xda, 0xf1, + 0x32, 0xf4, 0xc7, 0x16, 0x0d, 0x41, 0x05, 0x8e, 0x66, 0x82, 0x27, 0xad, 0xce, 0x35, 0x6e, 0x0c, + 0x13, 0xee, 0x14, 0x6e, 0x96, 0x10, 0xe8, 0x11, 0x97, 0x4b, 0x4d, 0x2c, 0x5c, 0x4e, 0x2d, 0x5a, + 0xa8, 0x8d, 0xba, 0x55, 0xfb, 0x1b, 0x4d, 0x46, 0x27, 0x4e, 0x34, 0xd3, 0x64, 0x2c, 0xf2, 0x0b, + 0xd7, 0x18, 0xd7, 0x4a, 0x5c, 0xfa, 0x10, 0x04, 0xce, 0x02, 0x5a, 0x1f, 0xdb, 0xa8, 0x5b, 0x99, + 0x7e, 0x89, 0xc1, 0x49, 0x82, 0x75, 0x4a, 0xf8, 0xd3, 0xb9, 0x60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, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4e, 0xc5, 0x97, 0xb5, 0xc1, 0x03, 0x00, 0x00, } diff --git a/core/api/node/service.proto b/core/api/node/service.proto index 6a11ffa6aa..323bff57f6 100644 --- a/core/api/node/service.proto +++ b/core/api/node/service.proto @@ -33,7 +33,6 @@ service Service { rpc ConversationCreate(berty.entity.Conversation) returns (berty.entity.Conversation); rpc ConversationList(Void) returns (stream berty.entity.Conversation); - rpc ConversationAcceptInvite(berty.entity.Conversation) returns (berty.entity.Conversation); rpc ConversationInvite(berty.entity.ConversationMember) returns (berty.entity.Conversation); //rpc ConversationLeave(berty.entity.Conversation) returns (berty.entity.Conversation); //rpc ConversationJoinRequest(berty.entity.Conversation) returns (berty.entity.Conversation); diff --git a/core/api/p2p/event.pb.go b/core/api/p2p/event.pb.go index cdfa20ef09..f9fcc54590 100644 --- a/core/api/p2p/event.pb.go +++ b/core/api/p2p/event.pb.go @@ -18,6 +18,7 @@ ContactRequestAcceptedAttrs ContactShareMeAttrs ContactShareAttrs + ConversationInviteAttrs Void */ package p2p diff --git a/core/api/p2p/kind.gen.go b/core/api/p2p/kind.gen.go index 08626041c4..d33276e02a 100644 --- a/core/api/p2p/kind.gen.go +++ b/core/api/p2p/kind.gen.go @@ -141,6 +141,25 @@ func (e *Event) SetContactShareAttrs(attrs *ContactShareAttrs) error { return nil } +// GetConversationInviteAttrs is a typesafe version of GetAttrs +func (e *Event) GetConversationInviteAttrs() (*ConversationInviteAttrs, error) { + if e.Attributes == nil || len(e.Attributes) == 0 { + return &ConversationInviteAttrs{}, nil + } + var attrs ConversationInviteAttrs + return &attrs, proto.Unmarshal(e.Attributes, &attrs) +} + +// SetConversationInviteAttrs is a typesafe version of the generic SetAttrs method +func (e *Event) SetConversationInviteAttrs(attrs *ConversationInviteAttrs) error { + raw, err := proto.Marshal(attrs) + if err != nil { + return err + } + e.Attributes = raw + return nil +} + // GetAttrs parses the embedded attributes func (e *Event) GetAttrs() (proto.Message, error) { switch e.Kind { @@ -158,6 +177,8 @@ func (e *Event) GetAttrs() (proto.Message, error) { return e.GetContactShareMeAttrs() case Kind_ContactShare: return e.GetContactShareAttrs() + case Kind_ConversationInvite: + return e.GetConversationInviteAttrs() } return nil, fmt.Errorf("not supported event kind: %q", e.Kind) } diff --git a/core/api/p2p/kind.pb.go b/core/api/p2p/kind.pb.go index 19f487d15e..ee2f72a051 100644 --- a/core/api/p2p/kind.pb.go +++ b/core/api/p2p/kind.pb.go @@ -7,6 +7,7 @@ import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" import berty_entity1 "github.com/berty/berty/core/entity" +import berty_entity2 "github.com/berty/berty/core/entity" import _ "github.com/gogo/protobuf/gogoproto" import io "io" @@ -30,6 +31,7 @@ const ( Kind_ContactRequestAccepted Kind = 202 Kind_ContactShareMe Kind = 203 Kind_ContactShare Kind = 204 + Kind_ConversationInvite Kind = 301 ) var Kind_name = map[int32]string{ @@ -41,6 +43,7 @@ var Kind_name = map[int32]string{ 202: "ContactRequestAccepted", 203: "ContactShareMe", 204: "ContactShare", + 301: "ConversationInvite", } var Kind_value = map[string]int32{ "Unknown": 0, @@ -51,6 +54,7 @@ var Kind_value = map[string]int32{ "ContactRequestAccepted": 202, "ContactShareMe": 203, "ContactShare": 204, + "ConversationInvite": 301, } func (x Kind) String() string { @@ -170,6 +174,22 @@ func (m *ContactShareAttrs) GetContact() *berty_entity1.Contact { return nil } +type ConversationInviteAttrs struct { + Conversation *berty_entity2.Conversation `protobuf:"bytes,1,opt,name=conversation" json:"conversation,omitempty"` +} + +func (m *ConversationInviteAttrs) Reset() { *m = ConversationInviteAttrs{} } +func (m *ConversationInviteAttrs) String() string { return proto.CompactTextString(m) } +func (*ConversationInviteAttrs) ProtoMessage() {} +func (*ConversationInviteAttrs) Descriptor() ([]byte, []int) { return fileDescriptorKind, []int{7} } + +func (m *ConversationInviteAttrs) GetConversation() *berty_entity2.Conversation { + if m != nil { + return m.Conversation + } + return nil +} + func init() { proto.RegisterType((*SentAttrs)(nil), "berty.p2p.SentAttrs") proto.RegisterType((*AckAttrs)(nil), "berty.p2p.AckAttrs") @@ -178,6 +198,7 @@ func init() { proto.RegisterType((*ContactRequestAcceptedAttrs)(nil), "berty.p2p.ContactRequestAcceptedAttrs") proto.RegisterType((*ContactShareMeAttrs)(nil), "berty.p2p.ContactShareMeAttrs") proto.RegisterType((*ContactShareAttrs)(nil), "berty.p2p.ContactShareAttrs") + proto.RegisterType((*ConversationInviteAttrs)(nil), "berty.p2p.ConversationInviteAttrs") proto.RegisterEnum("berty.p2p.Kind", Kind_name, Kind_value) } func (m *SentAttrs) Marshal() (dAtA []byte, err error) { @@ -378,6 +399,34 @@ func (m *ContactShareAttrs) MarshalTo(dAtA []byte) (int, error) { return i, nil } +func (m *ConversationInviteAttrs) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalTo(dAtA) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ConversationInviteAttrs) MarshalTo(dAtA []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Conversation != nil { + dAtA[i] = 0xa + i++ + i = encodeVarintKind(dAtA, i, uint64(m.Conversation.Size())) + n4, err := m.Conversation.MarshalTo(dAtA[i:]) + if err != nil { + return 0, err + } + i += n4 + } + return i, nil +} + func encodeVarintKind(dAtA []byte, offset int, v uint64) int { for v >= 1<<7 { dAtA[offset] = uint8(v&0x7f | 0x80) @@ -461,6 +510,16 @@ func (m *ContactShareAttrs) Size() (n int) { return n } +func (m *ConversationInviteAttrs) Size() (n int) { + var l int + _ = l + if m.Conversation != nil { + l = m.Conversation.Size() + n += 1 + l + sovKind(uint64(l)) + } + return n +} + func sovKind(x uint64) (n int) { for { n++ @@ -1039,6 +1098,89 @@ func (m *ContactShareAttrs) Unmarshal(dAtA []byte) error { } return nil } +func (m *ConversationInviteAttrs) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowKind + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ConversationInviteAttrs: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ConversationInviteAttrs: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Conversation", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowKind + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthKind + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Conversation == nil { + m.Conversation = &berty_entity2.Conversation{} + } + if err := m.Conversation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipKind(dAtA[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthKind + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipKind(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 @@ -1147,30 +1289,33 @@ var ( func init() { proto.RegisterFile("api/p2p/kind.proto", fileDescriptorKind) } var fileDescriptorKind = []byte{ - // 395 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x52, 0xcd, 0xca, 0xd3,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96, 0xe8, 0xfe, 0xcf, 0x00, 0x00, - 0x00, 0xff, 0xff, 0xf0, 0x5c, 0x30, 0x86, 0x91, 0x02, 0x00, 0x00, + // 447 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0xed, 0x26, 0x55, 0x53, 0x4f, 0x02, 0xda, 0x6e, 0x4b, 0x9b, 0xa6, 0x22, 0x44, 0xae, 0x40, + 0x11, 0x07, 0x5b, 0x0a, 0xe2, 0x06, 0x48, 0x69, 0xcb, 0xa1, 0x42, 0x91, 0x50, 0x2a, 0x0e, 0x70, + 0x41, 0xce, 0x66, 0x70, 0x57, 0x91, 0x77, 0xcd, 0xee, 0xb6, 0xa8, 0xff, 0x84, 0x3b, 0x67, 0xfe, + 0x07, 0x5f, 0x07, 0x7e, 0x01, 0x42, 0xe6, 0x8f, 0x20, 0x7b, 0xb7, 0xc5, 0xa5, 0x08, 0xc4, 0xc5, + 0x5a, 0x3f, 0xbf, 0x99, 0x79, 0x6f, 0x9e, 0x17, 0x58, 0x92, 0x8b, 0x38, 0x1f, 0xe5, 0xf1, 0x42, + 0xc8, 0x79, 0x94, 0x6b, 0x65, 0x15, 0x0b, 0x66, 0xa8, 0xed, 0x59, 0x94, 0x8f, 0xf2, 0xde, 0x06, + 0x4a, 0x2b, 0xec, 0x59, 0xcc, 0x95, 0xb4, 0x09, 0xb7, 0x8e, 0xd0, 0xdb, 0xfe, 0x85, 0x9e, 0xa2, + 0x36, 0x89, 0x15, 0x4a, 0xfa, 0x4f, 0x1b, 0xa9, 0x4a, 0x55, 0x75, 0x8c, 0xcb, 0x93, 0x43, 0xc3, + 0x3b, 0x10, 0x1c, 0xa1, 0xb4, 0x63, 0x6b, 0xb5, 0x61, 0xdb, 0xd0, 0x14, 0x73, 0xd3, 0x25, 0x83, + 0xe6, 0x30, 0xd8, 0x6b, 0x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, 0xe6, 0x0b, 0xfa, 0xaa, 0x84, 0xca, + 0x58, 0x68, 0xca, 0xd6, 0xe1, 0xfa, 0xe5, 0x85, 0xd1, 0x8f, 0x84, 0xed, 0xc0, 0xe6, 0x9f, 0xb7, + 0x48, 0x3f, 0x91, 0x5a, 0x85, 0xdf, 0x21, 0xfd, 0x4c, 0xd8, 0x1a, 0x74, 0xea, 0x20, 0xfd, 0x42, + 0xd8, 0x16, 0xb0, 0xab, 0x3e, 0xe9, 0xfb, 0xc6, 0xde, 0xfd, 0x0f, 0x45, 0x9f, 0x7c, 0x2d, 0xfa, + 0xe4, 0x7b, 0xd1, 0x27, 0x6f, 0x7f, 0xf4, 0x97, 0x5e, 0xec, 0xa6, 0xc2, 0x1e, 0x9f, 0xcc, 0x22, + 0xae, 0xb2, 0xb8, 0xf2, 0xea, 0x9f, 0x5c, 0x69, 0x8c, 0xfd, 0x75, 0x98, 0xad, 0x54, 0x3f, 0xee, + 0xbd, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x12, 0xf3, 0xca, 0x60, 0x20, 0x03, 0x00, 0x00, } diff --git a/core/api/p2p/kind.proto b/core/api/p2p/kind.proto index 56d783b656..fb22d6f5df 100644 --- a/core/api/p2p/kind.proto +++ b/core/api/p2p/kind.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package berty.p2p; import "entity/contact.proto"; +import "entity/conversation.proto"; import "gogoproto/gogo.proto"; option go_package = "github.com/berty/berty/core/api/p2p"; @@ -36,17 +37,13 @@ enum Kind { // Conversation events // - /* - ConversationCreate = 301; - ConversationDelete = 302; - ConversationLeave = 303; - ConversationInvite = 304; - ConversationSetTitle = 305; - ConversationAcceptInvite = 306; - ConversationRefuseInvite = 307; - ConversationNewMessage = 308; - ... - */ + ConversationInvite = 301; + + // + // Message events + // + + // FIXME: todo } // @@ -65,3 +62,9 @@ message ContactRequestAttrs { berty.entity.Contact me = 1; string intro_message message ContactRequestAcceptedAttrs { } message ContactShareMeAttrs { berty.entity.Contact me = 1; } message ContactShareAttrs { berty.entity.Contact contact = 1; } + +// +// Conversation events +// + +message ConversationInviteAttrs { berty.entity.Conversation conversation = 1; } \ No newline at end of file diff --git a/core/client/jsonclient/berty.node.service.gen.go b/core/client/jsonclient/berty.node.service.gen.go index fcfef7fcf6..f13f98826d 100644 --- a/core/client/jsonclient/berty.node.service.gen.go +++ b/core/client/jsonclient/berty.node.service.gen.go @@ -23,7 +23,6 @@ func init() { registerServerStream("berty.node.ContactList", NodeContactList) registerUnary("berty.node.ConversationCreate", NodeConversationCreate) registerServerStream("berty.node.ConversationList", NodeConversationList) - registerUnary("berty.node.ConversationAcceptInvite", NodeConversationAcceptInvite) registerUnary("berty.node.ConversationInvite", NodeConversationInvite) } @@ -225,20 +224,6 @@ func NodeConversationList(client *client.Client, ctx context.Context, jsonInput return streamProxy, nil } -func NodeConversationAcceptInvite(client *client.Client, ctx context.Context, jsonInput []byte) (interface{}, error) { - zap.L().Debug("client call", - zap.String("service", "Service"), - zap.String("method", "ConversationAcceptInvite"), - zap.String("input", string(jsonInput)), - ) - - var typedInput entity.Conversation - if err := json.Unmarshal(jsonInput, &typedInput); err != nil { - return nil, err - } - return client.Node().ConversationAcceptInvite(ctx, &typedInput) -} - func NodeConversationInvite(client *client.Client, ctx context.Context, jsonInput []byte) (interface{}, error) { zap.L().Debug("client call", zap.String("service", "Service"), diff --git a/core/entity/contact.go b/core/entity/contact.go index 9f110551b2..067691aa4f 100644 --- a/core/entity/contact.go +++ b/core/entity/contact.go @@ -9,6 +9,7 @@ func (c *Contact) Validate() error { func (c *Contact) Filtered() *Contact { return &Contact{ + ID: c.ID, DisplayName: c.DisplayName, DisplayStatus: c.DisplayStatus, // FIXME: share sigchain diff --git a/core/entity/conversation.go b/core/entity/conversation.go new file mode 100644 index 0000000000..39cab2d5fe --- /dev/null +++ b/core/entity/conversation.go @@ -0,0 +1,29 @@ +package entity + +func (c *Conversation) Validate() error { + if c == nil { + return ErrInvalidEntity + } + return nil +} + +func (c *Conversation) Filtered() *Conversation { + filteredMembers := []*ConversationMember{} + for _, member := range c.Members { + filteredMembers = append(filteredMembers, member.Filtered()) + } + return &Conversation{ + ID: c.ID, + Title: c.Title, + Topic: c.Topic, + Members: filteredMembers, + } +} + +func (m *ConversationMember) Filtered() *ConversationMember { + return &ConversationMember{ + ID: m.ID, + Status: m.Status, + Contact: m.Contact.Filtered(), + } +} diff --git a/core/entity/conversation.pb.go b/core/entity/conversation.pb.go index 577108b97a..9ad2e7e18b 100644 --- a/core/entity/conversation.pb.go +++ b/core/entity/conversation.pb.go @@ -27,23 +27,20 @@ const ( ConversationMember_Unknown ConversationMember_Status = 0 ConversationMember_Owner ConversationMember_Status = 1 ConversationMember_Active ConversationMember_Status = 2 - ConversationMember_Invited ConversationMember_Status = 3 - ConversationMember_Blocked ConversationMember_Status = 4 + ConversationMember_Blocked ConversationMember_Status = 3 ) var ConversationMember_Status_name = map[int32]string{ 0: "Unknown", 1: "Owner", 2: "Active", - 3: "Invited", - 4: "Blocked", + 3: "Blocked", } var ConversationMember_Status_value = map[string]int32{ "Unknown": 0, "Owner": 1, "Active": 2, - "Invited": 3, - "Blocked": 4, + "Blocked": 3, } func (x ConversationMember_Status) String() string { @@ -1095,37 +1092,36 @@ var ( func init() { proto.RegisterFile("entity/conversation.proto", fileDescriptorConversation) } var fileDescriptorConversation = []byte{ - // 502 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x53, 0xc1, 0x6e, 0xd3, 0x40, - 0x10, 0xad, 0x9d, 0x34, 0x21, 0x93, 0x12, 0xa2, 0x55, 0x2a, 0x99, 0x08, 0xc5, 0x91, 0x2f, 0xe4, - 0x50, 0xd9, 0x52, 0xe0, 0x54, 0x0e, 0x55, 0xd2, 0x08, 0xc9, 0x07, 0x84, 0x64, 0xe0, 0xc2, 0x25, - 0x72, 0xbc, 0x5b, 0xb3, 0x4a, 0xec, 0x8d,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x65, 0xb2, 0x6f, 0x10, 0x80, 0xd6, 0x2c, 0x42, 0x7e, 0x60, 0x7d, 0xb3, - 0xc0, 0xf8, 0xe9, 0x81, 0x23, 0xa3, 0xfd, 0x46, 0x11, 0xcc, 0x37, 0x22, 0x5a, 0x33, 0xda, 0x6f, - 0xce, 0x5f, 0xde, 0xe5, 0x23, 0xe3, 0x5b, 0x3e, 0x32, 0x7e, 0xe4, 0x23, 0xe3, 0xcb, 0xcf, 0xd1, - 0xc9, 0x47, 0x27, 0xe6, 0xf8, 0x69, 0xbf, 0x72, 0x23, 0x91, 0x78, 0x6a, 0x5d, 0xfd, 0x8d, 0x84, - 0x64, 0x5e, 0xb9, 0xf9, 0xaa, 0xa5, 0xfc, 0x7f, 0xf1, 0x27, 0x00, 0x00, 0xff, 0xff, 0xef, 0x1a, - 0xd1, 0x4e, 0x5b, 0x04, 0x00, 0x00, + // 494 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x53, 0xb1, 0x8e, 0xd3, 0x40, + 0x10, 0x8d, 0x9d, 0x5c, 0x42, 0x26, 0x47, 0x88, 0x56, 0x39, 0xc9, 0x44, 0x28, 0x8e, 0xdc, 0x90, + 0xe2, 0x64, 0x4b, 0x81, 0x86, 0xa3, 0x38, 0x25, 0x97, 0x26, 0x05, 0x42, 0x32, 0xd0, 0xd0, 0x44, + 0x8e, 0x77, 0xcf, 0xac, 0x12, 0x7b, 0xa3, 0xf5, 0xe4, 0x4e, 0xf9, 0x0b, 0x4a, 0x7e, 0x80, 0x7f, + 0xb9, 0x92, 0x2f, 0x30, 0xc8, 0x7c, 0x00, 0x12, 0x5f, 0x80, 0xbc, 0x5e, 0x0b, 0x4b, 0x57, 0x9c, + 0xa8, 0x69, 0x2c, 0xcf, 0xcc, 0x7b, 0x6f, 0x66, 0xde, 0xee, 0xc2, 0x53, 0x96, 0x20, 0xc7, 0xa3, + 0x17, 0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, 0x36, 0x6e, + 0x28, 0x62, 0x4f, 0x6d, 0xa8, 0xbf, 0xa1, 0x90, 0xcc, 0x2b, 0x97, 0xdd, 0xb4, 0x95, 0xe5, 0x2f, + 0xfe, 0x04, 0x00, 0x00, 0xff, 0xff, 0x82, 0x41, 0x6d, 0x6b, 0x4e, 0x04, 0x00, 0x00, } diff --git a/core/entity/conversation.proto b/core/entity/conversation.proto index cf313e15ef..ec56c1fb27 100644 --- a/core/entity/conversation.proto +++ b/core/entity/conversation.proto @@ -46,9 +46,9 @@ message ConversationMember { Unknown = 0; Owner = 1; Active = 2; - Invited = 3; - Blocked = 4; - // Alumni = 5; + Blocked = 3; + // Alumni = 4; // if we want to keep track of removed ones + // Invited = 5; // if we want to add an invite step } // diff --git a/core/node/event_handlers.go b/core/node/event_handlers.go index 3ab4e395e5..3eef7ffcd2 100644 --- a/core/node/event_handlers.go +++ b/core/node/event_handlers.go @@ -12,6 +12,10 @@ import ( type EventHandler func(context.Context, *p2p.Event) error +// +// Contact handlers +// + func (n *Node) handleContactRequest(ctx context.Context, input *p2p.Event) error { attrs, err := input.GetContactRequestAttrs() if err != nil { @@ -77,3 +81,36 @@ func (n *Node) handleContactShareMe(ctx context.Context, input *p2p.Event) error // FIXME: save more attributes return n.sql.Save(contact).Error } + +// +// Conversation handlers +// + +func (n *Node) handleConversationInvite(ctx context.Context, input *p2p.Event) error { + attrs, err := input.GetConversationInviteAttrs() + if err != nil { + return err + } + + members := []*entity.ConversationMember{} + for _, member := range attrs.Conversation.Members { + members = append(members, &entity.ConversationMember{ + ID: member.ID, + ContactID: member.Contact.ID, + Status: member.Status, + }) + } + conversation := &entity.Conversation{ + Members: members, + ID: attrs.Conversation.ID, + Title: attrs.Conversation.Title, + Topic: attrs.Conversation.Topic, + } + + // save conversation + if err := n.sql.Set("gorm:association_autoupdate", true).Save(conversation).Error; err != nil { + return errors.Wrap(err, "failed to save conversation") + } + + return nil +} diff --git a/core/node/nodeapi.go b/core/node/nodeapi.go index f8dab11c76..96a3c41635 100644 --- a/core/node/nodeapi.go +++ b/core/node/nodeapi.go @@ -160,11 +160,62 @@ func (n *Node) ContactList(_ *node.Void, stream node.Service_ContactListServer) // Conversation // -func (n *Node) ConversationCreate(context.Context, *entity.Conversation) (*entity.Conversation, error) { - return nil, ErrNotImplemented +func (n *Node) ConversationCreate(_ context.Context, input *entity.Conversation) (*entity.Conversation, error) { + members := []*entity.ConversationMember{ + { + ID: n.NewID(), + ContactID: n.UserID(), + Status: entity.ConversationMember_Owner, + }, + } + for _, member := range input.Members { + members = append(members, &entity.ConversationMember{ + ID: n.NewID(), + ContactID: member.ContactID, + Status: entity.ConversationMember_Active, + }) + } + + // save new conversation + createConversation := &entity.Conversation{ + ID: n.NewID(), + Members: members, + Title: input.Title, + Topic: input.Topic, + } + if err := n.sql.Set("gorm:association_autoupdate", true).Save(&createConversation).Error; err != nil { + return nil, errors.Wrap(err, "failed to save conversation") + } + + // load new conversation again, to preload associations + conversation, err := sql.ConversationByID(n.sql, createConversation.ID) + if err != nil { + return nil, errors.Wrap(err, "failed to load freshly created conversation") + } + + // send invite to peers + filtered := conversation.Filtered() + for _, member := range conversation.Members { + if member.Contact.ID == n.UserID() { + // skipping myself + continue + } + event := n.NewContactEvent(member.Contact, p2p.Kind_ConversationInvite) + if err := event.SetAttrs(&p2p.ConversationInviteAttrs{ + Conversation: filtered, + }); err != nil { + return nil, err + } + if err := n.EnqueueOutgoingEvent(event); err != nil { + return nil, err + } + } + + return conversation, err } -func (n *Node) ConversationAcceptInvite(context.Context, *entity.Conversation) (*entity.Conversation, error) { +func (n *Node) ConversationAcceptInvite(_ context.Context, conversation *entity.Conversation) (*entity.Conversation, error) { + return nil, ErrNotImplemented } diff --git a/core/node/p2papi.go b/core/node/p2papi.go index 2bc304b381..4e9d085b21 100644 --- a/core/node/p2papi.go +++ b/core/node/p2papi.go @@ -58,6 +58,7 @@ func (n *Node) handle(ctx context.Context, input *p2p.Event) error { p2p.Kind_ContactRequest: n.handleContactRequest, p2p.Kind_ContactRequestAccepted: n.handleContactRequestAccepted, p2p.Kind_ContactShareMe: n.handleContactShareMe, + p2p.Kind_ConversationInvite: n.handleConversationInvite, }[input.Kind] var handlingError error if !found { diff --git a/core/sql/helpers.go b/core/sql/helpers.go index cb9d29cd50..dc2cbe6683 100644 --- a/core/sql/helpers.go +++ b/core/sql/helpers.go @@ -13,7 +13,6 @@ func ContactByID(db *gorm.DB, id string) (*entity.Contact, error) { return &contact, db.First(&contact, "ID = ?", id).Error } -// FindContact tries different approaches to get a full contact based on a partial one func FindContact(db *gorm.DB, input *entity.Contact) (*entity.Contact, error) { if input.ID != "" { return ContactByID(db, input.ID) @@ -21,3 +20,8 @@ func FindContact(db *gorm.DB, input *entity.Contact) (*entity.Contact, error) { // FIXME: support looking-up by sigchain return nil, errors.New("not enough information to search contact") } + +func ConversationByID(db *gorm.DB, id string) (*entity.Conversation, error) { + var conversation entity.Conversation + return &conversation, db.First(&conversation, "ID = ?", id).Error +} diff --git a/core/test/e2e_test.go b/core/test/e2e_test.go index 8896ac13a1..5e5b5fba1f 100644 --- a/core/test/e2e_test.go +++ b/core/test/e2e_test.go @@ -20,6 +20,7 @@ func TestWithSimpleNetwork(t *testing.T) { alice, bob, eve *AppMock err error internalCtx = context.Background() + cache = map[string]interface{}{} sleepBetweenSteps, _ = time.ParseDuration("50ms") ) defer func() { @@ -192,13 +193,98 @@ func TestWithSimpleNetwork(t *testing.T) { So(err, ShouldBeNil) So(len(conversations), ShouldEqual, 0) }) - Convey("Eve has no conversation", FailureHalts, nil) - Convey("Bob calls node.ConversationCreate", FailureHalts, nil) - Convey("Bob calls node.ConversationInvite", FailureHalts, nil) - Convey("Alice calls node.ConversationAcceptInvite", FailureHalts, nil) - Convey("Bob has the conversation with Alice", FailureHalts, nil) - Convey("Alice has the conversation with Bob", FailureHalts, nil) - Convey("Eve has no conversation (again)", FailureHalts, nil) + Convey("Eve has no conversation", FailureHalts, func() { + stream, err := eve.client.Node().ConversationList(internalCtx, &node.Void{}) + So(err, ShouldBeNil) + conversations := []*entity.Conversation{} + for { + conversation, err := stream.Recv() + if err == io.EOF { + break + } + So(err, ShouldBeNil) + conversations = append(conversations, conversation) + } + So(err, ShouldBeNil) + So(len(conversations), ShouldEqual, 0) + }) + Convey("Bob creates a conversation with Alice", FailureHalts, func() { + res, err := bob.client.Node().ConversationCreate(internalCtx, &entity.Conversation{ + Title: "Alice & Bob", + Topic: "hey!", + Members: []*entity.ConversationMember{ + {ContactID: alice.node.UserID()}, + }, + }) + So(err, ShouldBeNil) + So(res, ShouldNotBeNil) + cache["conversation_id"] = res.ID + time.Sleep(sleepBetweenSteps) + }) + Convey("Bob has the conversation with Alice", FailureHalts, func() { + stream, err := bob.client.Node().ConversationList(internalCtx, &node.Void{}) + So(err, ShouldBeNil) + conversations := []*entity.Conversation{} + for { + conversation, err := stream.Recv() + if err == io.EOF { + break + } + So(err, ShouldBeNil) + conversations = append(conversations, conversation) + } + So(err, ShouldBeNil) + So(len(conversations), ShouldEqual, 1) + + So(conversations[0].Title, ShouldEqual, "Alice & Bob") + So(len(conversations[0].Members), ShouldEqual, 2) + So(conversations[0].Members[0].ContactID, ShouldEqual, bob.node.UserID()) + So(conversations[0].Members[1].ContactID, ShouldEqual, alice.node.UserID()) + So(conversations[0].Members[0].Status, ShouldEqual, entity.ConversationMember_Owner) + So(conversations[0].Members[1].Status, ShouldEqual, entity.ConversationMember_Active) + }) + Convey("Alice has the conversation with Bob", FailureHalts, func() { + stream, err := alice.client.Node().ConversationList(internalCtx, &node.Void{}) + So(err, ShouldBeNil) + conversations := []*entity.Conversation{} + for { + conversation, err := stream.Recv() + if err == io.EOF { + break + } + So(err, ShouldBeNil) + conversations = append(conversations, conversation) + } + So(err, ShouldBeNil) + So(len(conversations), ShouldEqual, 1) + + So(conversations[0].Title, ShouldEqual, "Alice & Bob") + So(len(conversations[0].Members), ShouldEqual, 2) + So(conversations[0].Members[0].ContactID, ShouldNotEqual, conversations[0].Members[1].ContactID) + for _, member := range conversations[0].Members { + switch member.ContactID { + case alice.node.UserID(): + So(member.Status, ShouldEqual, entity.ConversationMember_Active) + case bob.node.UserID(): + So(member.Status, ShouldEqual, entity.ConversationMember_Owner) + } + } + }) + Convey("Eve has no conversation (again)", FailureHalts, func() { + stream, err := eve.client.Node().ConversationList(internalCtx, &node.Void{}) + So(err, ShouldBeNil) + conversations := []*entity.Conversation{} + for { + conversation, err := stream.Recv() + if err == io.EOF { + break + } + So(err, ShouldBeNil) + conversations = append(conversations, conversation) + } + So(err, ShouldBeNil) + So(len(conversations), ShouldEqual, 0) + }) }) }) } @@ -501,7 +587,7 @@ func TestWithEnqueuer(t *testing.T) { So(event.Direction, ShouldEqual, p2p.Event_Outgoing) attrs, err := event.GetContactShareMeAttrs() So(err, ShouldBeNil) - So(attrs.Me.ID, ShouldBeEmpty) + So(attrs.Me.ID, ShouldEqual, alice.node.UserID()) So(attrs.Me.Status, ShouldEqual, entity.Contact_Unknown) So(attrs.Me.DisplayStatus, ShouldBeEmpty) @@ -562,7 +648,7 @@ func TestWithEnqueuer(t *testing.T) { So(event.SenderAPIVersion, ShouldEqual, p2p.Version) attrs, err := event.GetContactShareMeAttrs() So(err, ShouldBeNil) - So(attrs.Me.ID, ShouldBeEmpty) + So(attrs.Me.ID, ShouldEqual, alice.node.UserID()) So(attrs.Me.DisplayName, ShouldEqual, "Alice") So(attrs.Me.Status, ShouldEqual, entity.Contact_Unknown) So(attrs.Me.DisplayStatus, ShouldBeEmpty) diff --git a/core/test/test_test.go b/core/test/test_test.go index 7c467ccd2d..2c9877cd76 100644 --- a/core/test/test_test.go +++ b/core/test/test_test.go @@ -3,8 +3,10 @@ package test import ( "encoding/json" "fmt" + "log" "math/rand" "os" + "runtime" "time" "go.uber.org/zap" @@ -31,6 +33,31 @@ func jsonPrintIndent(i interface{}) { fmt.Println(string(out)) } +// +// duration / bench helpers +// + +var durations map[string][]time.Time + +func printDuration(key string) { + if durations == nil { + durations = make(map[string][]time.Time) + } + _, fn, line, _ := runtime.Caller(1) + now := time.Now() + if _, found := durations[key]; found { + log.Printf("\n[duration] %s: %s:%d diff=%s total=%s\n", key, fn, line, now.Sub(durations[key][1]), now.Sub(durations[key][0])) + durations[key][1] = now + } else { + log.Printf("\n[duration] %s: %s:%d init\n", key, fn, line) + durations[key] = []time.Time{now, now} + } +} + +// +// appmock helpers +// + func nodeChansLens(apps ...*AppMock) []int { time.Sleep(1 * time.Millisecond) // FIXME: wait for an event instead of waiting for a fixed time out := []int{} @@ -41,6 +68,10 @@ func nodeChansLens(apps ...*AppMock) []int { return out } +// +// logging +// + func setupTestLogging() { // initialize zap config := zap.NewDevelopmentConfig()