feat(components): posting to outbox

master
Xeronith 2022-12-15 18:43:01 +03:30
rodzic d60612d3b5
commit 0a08d86163
17 zmienionych plików z 401 dodań i 13 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ func (factory *httpHandlerFactory) Handlers() []IHttpHandler {
AuthorizeInteractionHandler(), // │ G . /authorize_interaction AuthorizeInteractionHandler(), // │ G . /authorize_interaction
GetFollowersHandler(), // │ G . /u/:username/followers GetFollowersHandler(), // │ G . /u/:username/followers
GetFollowingHandler(), // │ G . /u/:username/following GetFollowingHandler(), // │ G . /u/:username/following
PostToOutboxHandler(), // │ P . /u/:username/outbox
} }
} }

Wyświetl plik

@ -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,
)
}
}

Wyświetl plik

@ -20,6 +20,7 @@ func (factory *operationFactory) Operations() []IOperation {
AuthorizeInteractionOperation(), AuthorizeInteractionOperation(),
GetFollowersOperation(), GetFollowersOperation(),
GetFollowingOperation(), GetFollowingOperation(),
PostToOutboxOperation(),
} }
} }

Wyświetl plik

@ -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
}
*/

Wyświetl plik

@ -1712,6 +1712,141 @@ func (x *GetFollowingResult) GetFirst() string {
return "" 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 protoreflect.FileDescriptor
var file_spis_proto_rawDesc = []byte{ 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, 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, 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, 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 ( var (
@ -1892,7 +2042,7 @@ func file_spis_proto_rawDescGZIP() []byte {
return file_spis_proto_rawDescData 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{}{ var file_spis_proto_goTypes = []interface{}{
(*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest (*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest
(*SystemCallResult)(nil), // 1: protobuf.SystemCallResult (*SystemCallResult)(nil), // 1: protobuf.SystemCallResult
@ -1922,18 +2072,20 @@ var file_spis_proto_goTypes = []interface{}{
(*GetFollowersResult)(nil), // 25: protobuf.GetFollowersResult (*GetFollowersResult)(nil), // 25: protobuf.GetFollowersResult
(*GetFollowingRequest)(nil), // 26: protobuf.GetFollowingRequest (*GetFollowingRequest)(nil), // 26: protobuf.GetFollowingRequest
(*GetFollowingResult)(nil), // 27: protobuf.GetFollowingResult (*GetFollowingResult)(nil), // 27: protobuf.GetFollowingResult
(*Document)(nil), // 28: protobuf.Document (*PostToOutboxRequest)(nil), // 28: protobuf.PostToOutboxRequest
(*ActivityPubLink)(nil), // 29: protobuf.ActivityPubLink (*PostToOutboxResult)(nil), // 29: protobuf.PostToOutboxResult
(*ActivityPubMedia)(nil), // 30: protobuf.ActivityPubMedia (*Document)(nil), // 30: protobuf.Document
(*ActivityPubPublicKey)(nil), // 31: protobuf.ActivityPubPublicKey (*ActivityPubLink)(nil), // 31: protobuf.ActivityPubLink
(*ActivityPubMedia)(nil), // 32: protobuf.ActivityPubMedia
(*ActivityPubPublicKey)(nil), // 33: protobuf.ActivityPubPublicKey
} }
var file_spis_proto_depIdxs = []int32{ var file_spis_proto_depIdxs = []int32{
28, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document 30, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document
28, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document 30, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document
29, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink 31, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink
30, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia 32, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia
30, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia 32, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia
31, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey 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 output_type
6, // [6:6] is the sub-list for method input_type 6, // [6:6] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension type_name 6, // [6:6] is the sub-list for extension type_name
@ -2284,6 +2436,30 @@ func file_spis_proto_init() {
return nil 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{} type x struct{}
out := protoimpl.TypeBuilder{ out := protoimpl.TypeBuilder{
@ -2291,7 +2467,7 @@ func file_spis_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_spis_proto_rawDesc, RawDescriptor: file_spis_proto_rawDesc,
NumEnums: 0, NumEnums: 0,
NumMessages: 28, NumMessages: 30,
NumExtensions: 0, NumExtensions: 0,
NumServices: 0, NumServices: 0,
}, },

Wyświetl plik

@ -190,4 +190,19 @@ message GetFollowingResult {
string first = 0x00000006; 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 {
}
//----------------------------------------------------------- //-----------------------------------------------------------

Wyświetl plik

@ -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
}

Wyświetl plik

@ -20,4 +20,5 @@ type IApi interface {
AuthorizeInteraction(*AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error) AuthorizeInteraction(*AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error)
GetFollowers(*GetFollowersRequest) (*GetFollowersResult, error) GetFollowers(*GetFollowersRequest) (*GetFollowersResult, error)
GetFollowing(*GetFollowingRequest) (*GetFollowingResult, error) GetFollowing(*GetFollowingRequest) (*GetFollowingResult, error)
PostToOutbox(*PostToOutboxRequest) (*PostToOutboxResult, error)
} }

Wyświetl plik

@ -59,6 +59,10 @@ const (
//GetFollowingOperation //GetFollowingOperation
GET_FOLLOWING_REQUEST = 0xF9841DB9 GET_FOLLOWING_REQUEST = 0xF9841DB9
GET_FOLLOWING_RESULT = 0xD707408F GET_FOLLOWING_RESULT = 0xD707408F
//PostToOutboxOperation
POST_TO_OUTBOX_REQUEST = 0x9E489553
POST_TO_OUTBOX_RESULT = 0xC6C56614
) )
var OPCODES = Opcodes{ var OPCODES = Opcodes{
@ -89,4 +93,6 @@ var OPCODES = Opcodes{
0x7F3E2EB5: "GetFollowers", 0x7F3E2EB5: "GetFollowers",
0xF9841DB9: "GET_FOLLOWING", 0xF9841DB9: "GET_FOLLOWING",
0xD707408F: "GetFollowing", 0xD707408F: "GetFollowing",
0x9E489553: "POST_TO_OUTBOX",
0xC6C56614: "PostToOutbox",
} }

Wyświetl plik

@ -67,6 +67,7 @@ type (
AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error)
GetFollowers(username string, editor Identity) (IGetFollowersResult, error) GetFollowers(username string, editor Identity) (IGetFollowersResult, error)
GetFollowing(username string, editor Identity) (IGetFollowingResult, 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 { IEchoResult interface {
@ -157,4 +158,7 @@ type (
OrderedItems() []string OrderedItems() []string
First() string First() string
} }
IPostToOutboxResult interface {
}
) )

Wyświetl plik

@ -270,6 +270,7 @@ type (
AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error)
GetFollowers(username string, editor Identity) (IGetFollowersResult, error) GetFollowers(username string, editor Identity) (IGetFollowersResult, error)
GetFollowing(username string, editor Identity) (IGetFollowingResult, 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) NewDocument(id int64, content string) (IDocument, error)
NewSystemSchedule(id int64, enabled bool, config string) (ISystemSchedule, error) NewSystemSchedule(id int64, enabled bool, config string) (ISystemSchedule, error)
@ -301,6 +302,7 @@ type (
NewAuthorizeInteractionResult(uri string, success bool, ignored interface{}) IAuthorizeInteractionResult NewAuthorizeInteractionResult(uri string, success bool, ignored interface{}) IAuthorizeInteractionResult
NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, ignored interface{}) IGetFollowersResult 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 NewGetFollowingResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, ignored interface{}) IGetFollowingResult
NewPostToOutboxResult(ignored interface{}) IPostToOutboxResult
} }
ISystemComponent interface { ISystemComponent interface {

Wyświetl plik

@ -1044,6 +1044,7 @@ type IDispatcher interface {
AuthorizeInteraction(uri string) (IAuthorizeInteractionResult, error) AuthorizeInteraction(uri string) (IAuthorizeInteractionResult, error)
GetFollowers(username string) (IGetFollowersResult, error) GetFollowers(username string) (IGetFollowersResult, error)
GetFollowing(username string) (IGetFollowingResult, 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 creates a new 'Document' instance using the provided property values.
NewDocument(id int64, content string) (IDocument, error) 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 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 creates a new result container for 'Get Following' system action.
NewGetFollowingResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string) IGetFollowingResult 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 asserts the provided condition and panics if the assertion is not valid.
Assert(condition bool) IAssertionResult Assert(condition bool) IAssertionResult
// AssertNoError panics if the provided error is not nil. // AssertNoError panics if the provided error is not nil.

Wyświetl plik

@ -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() { func init() {
API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{} API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{}
API_RESULT[ECHO_RESULT] = EchoResult{} API_RESULT[ECHO_RESULT] = EchoResult{}
@ -160,4 +170,5 @@ func init() {
API_RESULT[AUTHORIZE_INTERACTION_RESULT] = AuthorizeInteractionResult{} API_RESULT[AUTHORIZE_INTERACTION_RESULT] = AuthorizeInteractionResult{}
API_RESULT[GET_FOLLOWERS_RESULT] = GetFollowersResult{} API_RESULT[GET_FOLLOWERS_RESULT] = GetFollowersResult{}
API_RESULT[GET_FOLLOWING_RESULT] = GetFollowingResult{} API_RESULT[GET_FOLLOWING_RESULT] = GetFollowingResult{}
API_RESULT[POST_TO_OUTBOX_RESULT] = PostToOutboxResult{}
} }

Wyświetl plik

@ -1147,6 +1147,10 @@ func (conductor *conductor) GetFollowing(username string, editor Identity) (IGet
return conductor.spiManager.GetFollowing(username, editor) 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) { func (conductor *conductor) NewDocument(id int64, content string) (IDocument, error) {
return NewDocument(id, content) 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) 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) { func (conductor *conductor) LogRemoteCall(context IContext, eventType uint32, source string, input, result interface{}, err error) {
errorMessage := "" errorMessage := ""
if err != nil { if err != nil {

Wyświetl plik

@ -286,3 +286,7 @@ func (dispatcher *dispatcher) GetFollowers(username string) (IGetFollowersResult
func (dispatcher *dispatcher) GetFollowing(username string) (IGetFollowingResult, error) { func (dispatcher *dispatcher) GetFollowing(username string) (IGetFollowingResult, error) {
return dispatcher.conductor.SpiManager().GetFollowing(username, dispatcher.identity) 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)
}

Wyświetl plik

@ -909,3 +909,31 @@ func (manager *spiManager) GetFollowing(username string, editor Identity) (resul
return result, nil 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
}
}

Wyświetl plik

@ -56,4 +56,8 @@ func (dispatcher *dispatcher) NewGetFollowingResult(context string, id string, t
return NewGetFollowingResult(context, id, type_, totalItems, orderedItems, first, nil) return NewGetFollowingResult(context, id, type_, totalItems, orderedItems, first, nil)
} }
func (dispatcher *dispatcher) NewPostToOutboxResult() IPostToOutboxResult {
return NewPostToOutboxResult(nil)
}
//endregion //endregion