diff --git a/greataped/components/api/handlers/factory.go b/greataped/components/api/handlers/factory.go index b2e010c..68a4416 100644 --- a/greataped/components/api/handlers/factory.go +++ b/greataped/components/api/handlers/factory.go @@ -19,6 +19,7 @@ func (factory *httpHandlerFactory) Handlers() []IHttpHandler { AuthorizeInteractionHandler(), // │ G . /authorize_interaction GetFollowersHandler(), // │ G . /u/:username/followers GetFollowingHandler(), // │ G . /u/:username/following + PostToOutboxHandler(), // │ P . /u/:username/outbox } } diff --git a/greataped/components/api/handlers/post_to_outbox_handler.go b/greataped/components/api/handlers/post_to_outbox_handler.go new file mode 100644 index 0000000..f77f9b7 --- /dev/null +++ b/greataped/components/api/handlers/post_to_outbox_handler.go @@ -0,0 +1,45 @@ +package handlers + +import ( + "net/http" + + . "github.com/xeronith/diamante/contracts/network/http" + pipeline "github.com/xeronith/diamante/network/http" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" +) + +type postToOutboxHandler struct { +} + +func PostToOutboxHandler() IHttpHandler { + return &postToOutboxHandler{} +} + +func (handler *postToOutboxHandler) Method() string { + return http.MethodPost +} + +func (handler *postToOutboxHandler) Path() string { + return "/u/:username/outbox" +} + +func (handler *postToOutboxHandler) HandlerFunc() HttpHandlerFunc { + return func(x IServerDispatcher) error { + request := &PostToOutboxRequest{} + result := &PostToOutboxResult{} + + onRequestUnmarshalled := func(request *PostToOutboxRequest) { + request.Username = x.Param("username") + } + + return pipeline.Handle(x, + "post_to_outbox", + POST_TO_OUTBOX_REQUEST, + POST_TO_OUTBOX_RESULT, + request, result, + onRequestUnmarshalled, + false, + ) + } +} diff --git a/greataped/components/api/operations/factory.go b/greataped/components/api/operations/factory.go index 9a55c8e..74b66e1 100644 --- a/greataped/components/api/operations/factory.go +++ b/greataped/components/api/operations/factory.go @@ -20,6 +20,7 @@ func (factory *operationFactory) Operations() []IOperation { AuthorizeInteractionOperation(), GetFollowersOperation(), GetFollowingOperation(), + PostToOutboxOperation(), } } diff --git a/greataped/components/api/operations/post_to_outbox_operation.go b/greataped/components/api/operations/post_to_outbox_operation.go new file mode 100644 index 0000000..c75355a --- /dev/null +++ b/greataped/components/api/operations/post_to_outbox_operation.go @@ -0,0 +1,51 @@ +package operations + +import ( + . "github.com/xeronith/diamante/contracts/operation" + . "github.com/xeronith/diamante/contracts/service" + . "github.com/xeronith/diamante/contracts/system" + . "github.com/xeronith/diamante/operation" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/api/services" + . "rail.town/infrastructure/components/contracts" +) + +type postToOutboxOperation struct { + Operation + + run func(IContext, *PostToOutboxRequest) (*PostToOutboxResult, error) +} + +func PostToOutboxOperation() IOperation { + return &postToOutboxOperation{ + run: PostToOutboxService, + } +} + +func (operation *postToOutboxOperation) Id() (ID, ID) { + return POST_TO_OUTBOX_REQUEST, POST_TO_OUTBOX_RESULT +} + +func (operation *postToOutboxOperation) InputContainer() Pointer { + return new(PostToOutboxRequest) +} + +func (operation *postToOutboxOperation) OutputContainer() Pointer { + return new(PostToOutboxResult) +} + +func (operation *postToOutboxOperation) Execute(context IContext, payload Pointer) (Pointer, error) { + return operation.run(context, payload.(*PostToOutboxRequest)) +} + +/* +func (operation *postToOutboxOperation) ExecutionTimeLimits() (Duration, Duration, Duration) { + var ( + TIME_LIMIT_WARNING Duration = 20_000_000 + TIME_LIMIT_ALERT Duration = 35_000_000 + TIME_LIMIT_CRITICAL Duration = 50_000_000 + ) + + return TIME_LIMIT_WARNING, TIME_LIMIT_ALERT, TIME_LIMIT_CRITICAL +} +*/ diff --git a/greataped/components/api/protobuf/spis.pb.go b/greataped/components/api/protobuf/spis.pb.go index e8c93fa..3325dca 100644 --- a/greataped/components/api/protobuf/spis.pb.go +++ b/greataped/components/api/protobuf/spis.pb.go @@ -1712,6 +1712,141 @@ func (x *GetFollowingResult) GetFirst() string { return "" } +// API: PostToOutbox +// ----------------------------------------------------------- +type PostToOutboxRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` + Context string `protobuf:"bytes,2,opt,name=context,json=@context,proto3" json:"context,omitempty"` + ActivityType string `protobuf:"bytes,3,opt,name=activityType,json=type,proto3" json:"activityType,omitempty"` + To string `protobuf:"bytes,4,opt,name=to,proto3" json:"to,omitempty"` + AttributedTo string `protobuf:"bytes,5,opt,name=attributedTo,proto3" json:"attributedTo,omitempty"` + InReplyTo string `protobuf:"bytes,6,opt,name=inReplyTo,proto3" json:"inReplyTo,omitempty"` + Content string `protobuf:"bytes,7,opt,name=content,proto3" json:"content,omitempty"` +} + +func (x *PostToOutboxRequest) Reset() { + *x = PostToOutboxRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[28] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PostToOutboxRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PostToOutboxRequest) ProtoMessage() {} + +func (x *PostToOutboxRequest) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[28] + 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 PostToOutboxRequest.ProtoReflect.Descriptor instead. +func (*PostToOutboxRequest) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{28} +} + +func (x *PostToOutboxRequest) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +func (x *PostToOutboxRequest) GetContext() string { + if x != nil { + return x.Context + } + return "" +} + +func (x *PostToOutboxRequest) GetActivityType() string { + if x != nil { + return x.ActivityType + } + return "" +} + +func (x *PostToOutboxRequest) GetTo() string { + if x != nil { + return x.To + } + return "" +} + +func (x *PostToOutboxRequest) GetAttributedTo() string { + if x != nil { + return x.AttributedTo + } + return "" +} + +func (x *PostToOutboxRequest) GetInReplyTo() string { + if x != nil { + return x.InReplyTo + } + return "" +} + +func (x *PostToOutboxRequest) GetContent() string { + if x != nil { + return x.Content + } + return "" +} + +type PostToOutboxResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *PostToOutboxResult) Reset() { + *x = PostToOutboxResult{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[29] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *PostToOutboxResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PostToOutboxResult) ProtoMessage() {} + +func (x *PostToOutboxResult) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[29] + 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 PostToOutboxResult.ProtoReflect.Descriptor instead. +func (*PostToOutboxResult) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{29} +} + var File_spis_proto protoreflect.FileDescriptor var file_spis_proto_rawDesc = []byte{ @@ -1877,7 +2012,22 @@ var file_spis_proto_rawDesc = []byte{ 0x65, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x66, 0x69, 0x72, 0x73, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x66, 0x69, 0x72, 0x73, - 0x74, 0x42, 0x04, 0x5a, 0x02, 0x2e, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x22, 0xd4, 0x01, 0x0a, 0x13, 0x50, 0x6f, 0x73, 0x74, 0x54, 0x6f, 0x4f, 0x75, 0x74, 0x62, + 0x6f, 0x78, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, + 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x40, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, + 0x12, 0x1a, 0x0a, 0x0c, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x54, 0x79, 0x70, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x0e, 0x0a, 0x02, + 0x74, 0x6f, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x74, 0x6f, 0x12, 0x22, 0x0a, 0x0c, + 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x54, 0x6f, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x54, 0x6f, + 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x54, 0x6f, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x54, 0x6f, 0x12, 0x18, + 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x50, 0x6f, 0x73, 0x74, + 0x54, 0x6f, 0x4f, 0x75, 0x74, 0x62, 0x6f, 0x78, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x42, 0x04, + 0x5a, 0x02, 0x2e, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -1892,7 +2042,7 @@ func file_spis_proto_rawDescGZIP() []byte { return file_spis_proto_rawDescData } -var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 28) +var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 30) var file_spis_proto_goTypes = []interface{}{ (*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest (*SystemCallResult)(nil), // 1: protobuf.SystemCallResult @@ -1922,18 +2072,20 @@ var file_spis_proto_goTypes = []interface{}{ (*GetFollowersResult)(nil), // 25: protobuf.GetFollowersResult (*GetFollowingRequest)(nil), // 26: protobuf.GetFollowingRequest (*GetFollowingResult)(nil), // 27: protobuf.GetFollowingResult - (*Document)(nil), // 28: protobuf.Document - (*ActivityPubLink)(nil), // 29: protobuf.ActivityPubLink - (*ActivityPubMedia)(nil), // 30: protobuf.ActivityPubMedia - (*ActivityPubPublicKey)(nil), // 31: protobuf.ActivityPubPublicKey + (*PostToOutboxRequest)(nil), // 28: protobuf.PostToOutboxRequest + (*PostToOutboxResult)(nil), // 29: protobuf.PostToOutboxResult + (*Document)(nil), // 30: protobuf.Document + (*ActivityPubLink)(nil), // 31: protobuf.ActivityPubLink + (*ActivityPubMedia)(nil), // 32: protobuf.ActivityPubMedia + (*ActivityPubPublicKey)(nil), // 33: protobuf.ActivityPubPublicKey } var file_spis_proto_depIdxs = []int32{ - 28, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document - 28, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document - 29, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink - 30, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia - 30, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia - 31, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey + 30, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document + 30, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document + 31, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink + 32, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia + 32, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia + 33, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey 6, // [6:6] is the sub-list for method output_type 6, // [6:6] is the sub-list for method input_type 6, // [6:6] is the sub-list for extension type_name @@ -2284,6 +2436,30 @@ func file_spis_proto_init() { return nil } } + file_spis_proto_msgTypes[28].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PostToOutboxRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_spis_proto_msgTypes[29].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PostToOutboxResult); 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{ @@ -2291,7 +2467,7 @@ func file_spis_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_spis_proto_rawDesc, NumEnums: 0, - NumMessages: 28, + NumMessages: 30, NumExtensions: 0, NumServices: 0, }, diff --git a/greataped/components/api/protobuf/spis.proto b/greataped/components/api/protobuf/spis.proto index 90aae60..bdeb0fe 100644 --- a/greataped/components/api/protobuf/spis.proto +++ b/greataped/components/api/protobuf/spis.proto @@ -190,4 +190,19 @@ message GetFollowingResult { string first = 0x00000006; } +// API: PostToOutbox +//----------------------------------------------------------- +message PostToOutboxRequest { + string username = 0x00000001; + string context = 0x00000002 [json_name = "@context"]; + string activityType = 0x00000003 [json_name = "type"]; + string to = 0x00000004; + string attributedTo = 0x00000005; + string inReplyTo = 0x00000006; + string content = 0x00000007; +} + +message PostToOutboxResult { +} + //----------------------------------------------------------- diff --git a/greataped/components/api/services/post_to_outbox_service.go b/greataped/components/api/services/post_to_outbox_service.go new file mode 100644 index 0000000..a58481e --- /dev/null +++ b/greataped/components/api/services/post_to_outbox_service.go @@ -0,0 +1,28 @@ +package services + +import ( + . "github.com/xeronith/diamante/contracts/service" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" + "rail.town/infrastructure/components/core" +) + +// noinspection GoUnusedParameter +func PostToOutboxService(context IContext, input *PostToOutboxRequest) (result *PostToOutboxResult, err error) { + conductor := core.Conductor + _ = POST_TO_OUTBOX_REQUEST + + conductor.LogRemoteCall(context, INITIALIZE, "post_to_outbox", input, result, err) + defer func() { conductor.LogRemoteCall(context, FINALIZE, "post_to_outbox", input, result, err) }() + + _result, _err := conductor.PostToOutbox(input.Username, input.Context, input.ActivityType, input.To, input.AttributedTo, input.InReplyTo, input.Content, context.Identity()) + if _err != nil { + err = _err + return nil, err + } + + _ = _result + + result = context.ResultContainer().(*PostToOutboxResult) + return result, nil +} diff --git a/greataped/components/contracts/api.go b/greataped/components/contracts/api.go index c712ccd..92c3cdd 100644 --- a/greataped/components/contracts/api.go +++ b/greataped/components/contracts/api.go @@ -20,4 +20,5 @@ type IApi interface { AuthorizeInteraction(*AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error) GetFollowers(*GetFollowersRequest) (*GetFollowersResult, error) GetFollowing(*GetFollowingRequest) (*GetFollowingResult, error) + PostToOutbox(*PostToOutboxRequest) (*PostToOutboxResult, error) } diff --git a/greataped/components/contracts/opcodes.go b/greataped/components/contracts/opcodes.go index a805061..40c59cb 100644 --- a/greataped/components/contracts/opcodes.go +++ b/greataped/components/contracts/opcodes.go @@ -59,6 +59,10 @@ const ( //GetFollowingOperation GET_FOLLOWING_REQUEST = 0xF9841DB9 GET_FOLLOWING_RESULT = 0xD707408F + + //PostToOutboxOperation + POST_TO_OUTBOX_REQUEST = 0x9E489553 + POST_TO_OUTBOX_RESULT = 0xC6C56614 ) var OPCODES = Opcodes{ @@ -89,4 +93,6 @@ var OPCODES = Opcodes{ 0x7F3E2EB5: "GetFollowers", 0xF9841DB9: "GET_FOLLOWING", 0xD707408F: "GetFollowing", + 0x9E489553: "POST_TO_OUTBOX", + 0xC6C56614: "PostToOutbox", } diff --git a/greataped/components/contracts/spi.go b/greataped/components/contracts/spi.go index 8842c84..222b985 100644 --- a/greataped/components/contracts/spi.go +++ b/greataped/components/contracts/spi.go @@ -67,6 +67,7 @@ type ( AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) GetFollowers(username string, editor Identity) (IGetFollowersResult, error) GetFollowing(username string, editor Identity) (IGetFollowingResult, error) + PostToOutbox(username string, context string, activityType string, to string, attributedTo string, inReplyTo string, content string, editor Identity) (IPostToOutboxResult, error) } IEchoResult interface { @@ -157,4 +158,7 @@ type ( OrderedItems() []string First() string } + + IPostToOutboxResult interface { + } ) diff --git a/greataped/components/contracts/system_component.go b/greataped/components/contracts/system_component.go index 1d2b985..ed90a24 100644 --- a/greataped/components/contracts/system_component.go +++ b/greataped/components/contracts/system_component.go @@ -270,6 +270,7 @@ type ( AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) GetFollowers(username string, editor Identity) (IGetFollowersResult, error) GetFollowing(username string, editor Identity) (IGetFollowingResult, error) + PostToOutbox(username string, context string, activityType string, to string, attributedTo string, inReplyTo string, content string, editor Identity) (IPostToOutboxResult, error) NewDocument(id int64, content string) (IDocument, error) NewSystemSchedule(id int64, enabled bool, config string) (ISystemSchedule, error) @@ -301,6 +302,7 @@ type ( NewAuthorizeInteractionResult(uri string, success bool, ignored interface{}) IAuthorizeInteractionResult NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, ignored interface{}) IGetFollowersResult NewGetFollowingResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, ignored interface{}) IGetFollowingResult + NewPostToOutboxResult(ignored interface{}) IPostToOutboxResult } ISystemComponent interface { diff --git a/greataped/components/contracts/system_dispatcher.go b/greataped/components/contracts/system_dispatcher.go index 2f69f3f..95ead19 100644 --- a/greataped/components/contracts/system_dispatcher.go +++ b/greataped/components/contracts/system_dispatcher.go @@ -1044,6 +1044,7 @@ type IDispatcher interface { AuthorizeInteraction(uri string) (IAuthorizeInteractionResult, error) GetFollowers(username string) (IGetFollowersResult, error) GetFollowing(username string) (IGetFollowingResult, error) + PostToOutbox(username string, context string, activityType string, to string, attributedTo string, inReplyTo string, content string) (IPostToOutboxResult, error) // NewDocument creates a new 'Document' instance using the provided property values. NewDocument(id int64, content string) (IDocument, error) @@ -1139,6 +1140,8 @@ type IDispatcher interface { NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string) IGetFollowersResult // NewGetFollowingResult creates a new result container for 'Get Following' system action. NewGetFollowingResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string) IGetFollowingResult + // NewPostToOutboxResult creates a new result container for 'Post To Outbox' system action. + NewPostToOutboxResult() IPostToOutboxResult // Assert asserts the provided condition and panics if the assertion is not valid. Assert(condition bool) IAssertionResult // AssertNoError panics if the provided error is not nil. diff --git a/greataped/components/core/api_methods.go b/greataped/components/core/api_methods.go index 30bad59..c317571 100644 --- a/greataped/components/core/api_methods.go +++ b/greataped/components/core/api_methods.go @@ -145,6 +145,16 @@ func (api *api) GetFollowing(request *GetFollowingRequest) (*GetFollowingResult, } } +func (api *api) PostToOutbox(request *PostToOutboxRequest) (*PostToOutboxResult, error) { + result, err := api.call(POST_TO_OUTBOX_REQUEST, request) + + if err != nil { + return nil, err + } else { + return result.(*PostToOutboxResult), nil + } +} + func init() { API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{} API_RESULT[ECHO_RESULT] = EchoResult{} @@ -160,4 +170,5 @@ func init() { API_RESULT[AUTHORIZE_INTERACTION_RESULT] = AuthorizeInteractionResult{} API_RESULT[GET_FOLLOWERS_RESULT] = GetFollowersResult{} API_RESULT[GET_FOLLOWING_RESULT] = GetFollowingResult{} + API_RESULT[POST_TO_OUTBOX_RESULT] = PostToOutboxResult{} } diff --git a/greataped/components/core/initializer.go b/greataped/components/core/initializer.go index 2a13608..8e22842 100644 --- a/greataped/components/core/initializer.go +++ b/greataped/components/core/initializer.go @@ -1147,6 +1147,10 @@ func (conductor *conductor) GetFollowing(username string, editor Identity) (IGet return conductor.spiManager.GetFollowing(username, editor) } +func (conductor *conductor) PostToOutbox(username string, context string, activityType string, to string, attributedTo string, inReplyTo string, content string, editor Identity) (IPostToOutboxResult, error) { + return conductor.spiManager.PostToOutbox(username, context, activityType, to, attributedTo, inReplyTo, content, editor) +} + func (conductor *conductor) NewDocument(id int64, content string) (IDocument, error) { return NewDocument(id, content) } @@ -1267,6 +1271,10 @@ func (conductor *conductor) NewGetFollowingResult(context string, id string, typ return NewGetFollowingResult(context, id, type_, totalItems, orderedItems, first, nil) } +func (conductor *conductor) NewPostToOutboxResult(_ interface{}) IPostToOutboxResult { + return NewPostToOutboxResult(nil) +} + func (conductor *conductor) LogRemoteCall(context IContext, eventType uint32, source string, input, result interface{}, err error) { errorMessage := "" if err != nil { diff --git a/greataped/components/core/spi.go b/greataped/components/core/spi.go index 2f2db50..7b4e5af 100644 --- a/greataped/components/core/spi.go +++ b/greataped/components/core/spi.go @@ -286,3 +286,7 @@ func (dispatcher *dispatcher) GetFollowers(username string) (IGetFollowersResult func (dispatcher *dispatcher) GetFollowing(username string) (IGetFollowingResult, error) { return dispatcher.conductor.SpiManager().GetFollowing(username, dispatcher.identity) } + +func (dispatcher *dispatcher) PostToOutbox(username string, context string, activityType string, to string, attributedTo string, inReplyTo string, content string) (IPostToOutboxResult, error) { + return dispatcher.conductor.SpiManager().PostToOutbox(username, context, activityType, to, attributedTo, inReplyTo, content, dispatcher.identity) +} diff --git a/greataped/components/core/spi_manager.go b/greataped/components/core/spi_manager.go index fb0755c..a0b2e58 100644 --- a/greataped/components/core/spi_manager.go +++ b/greataped/components/core/spi_manager.go @@ -909,3 +909,31 @@ func (manager *spiManager) GetFollowing(username string, editor Identity) (resul return result, nil } } + +//region IPostToOutboxResult Implementation + +type postToOutboxResult struct { +} + +func NewPostToOutboxResult(_ interface{}) IPostToOutboxResult { + return &postToOutboxResult{} +} + +//endregion + +func (manager *spiManager) PostToOutbox(username string, context string, activityType string, to string, attributedTo string, inReplyTo string, content string, editor Identity) (result IPostToOutboxResult, err error) { + defer func() { + if reason := recover(); reason != nil { + err = manager.Error(reason) + } + }() + + editor.Lock(POST_TO_OUTBOX_REQUEST) + defer editor.Unlock(POST_TO_OUTBOX_REQUEST) + + if result, err = commands.PostToOutbox(NewDispatcher(Conductor, editor), username, context, activityType, to, attributedTo, inReplyTo, content); err != nil { + return nil, err + } else { + return result, nil + } +} diff --git a/greataped/components/core/system_results.go b/greataped/components/core/system_results.go index e49a8fb..412da13 100644 --- a/greataped/components/core/system_results.go +++ b/greataped/components/core/system_results.go @@ -56,4 +56,8 @@ func (dispatcher *dispatcher) NewGetFollowingResult(context string, id string, t return NewGetFollowingResult(context, id, type_, totalItems, orderedItems, first, nil) } +func (dispatcher *dispatcher) NewPostToOutboxResult() IPostToOutboxResult { + return NewPostToOutboxResult(nil) +} + //endregion