feat(components): post to inbox

master
Xeronith 2022-12-22 20:16:08 +03:30
rodzic 713d294344
commit e1f296269b
17 zmienionych plików z 339 dodań i 16 usunięć

Wyświetl plik

@ -21,6 +21,7 @@ func (factory *httpHandlerFactory) Handlers() []IHttpHandler {
GetFollowingHandler(), // │ G . /u/:username/following
PostToOutboxHandler(), // │ P . /u/:username/outbox
GetOutboxHandler(), // │ G . /u/:username/outbox
PostToInboxHandler(), // │ P . /u/:username/inbox
}
}

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 postToInboxHandler struct {
}
func PostToInboxHandler() IHttpHandler {
return &postToInboxHandler{}
}
func (handler *postToInboxHandler) Method() string {
return http.MethodPost
}
func (handler *postToInboxHandler) Path() string {
return "/u/:username/inbox"
}
func (handler *postToInboxHandler) HandlerFunc() HttpHandlerFunc {
return func(x IServerDispatcher) error {
request := &PostToInboxRequest{}
result := &PostToInboxResult{}
onRequestUnmarshalled := func(request *PostToInboxRequest) {
request.Username = x.Param("username")
}
return pipeline.Handle(x,
"post_to_inbox",
POST_TO_INBOX_REQUEST,
POST_TO_INBOX_RESULT,
request, result,
onRequestUnmarshalled,
false,
)
}
}

Wyświetl plik

@ -22,6 +22,7 @@ func (factory *operationFactory) Operations() []IOperation {
GetFollowingOperation(),
PostToOutboxOperation(),
GetOutboxOperation(),
PostToInboxOperation(),
}
}

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 postToInboxOperation struct {
Operation
run func(IContext, *PostToInboxRequest) (*PostToInboxResult, error)
}
func PostToInboxOperation() IOperation {
return &postToInboxOperation{
run: PostToInboxService,
}
}
func (operation *postToInboxOperation) Id() (ID, ID) {
return POST_TO_INBOX_REQUEST, POST_TO_INBOX_RESULT
}
func (operation *postToInboxOperation) InputContainer() Pointer {
return new(PostToInboxRequest)
}
func (operation *postToInboxOperation) OutputContainer() Pointer {
return new(PostToInboxResult)
}
func (operation *postToInboxOperation) Execute(context IContext, payload Pointer) (Pointer, error) {
return operation.run(context, payload.(*PostToInboxRequest))
}
/*
func (operation *postToInboxOperation) 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

@ -1983,6 +1983,93 @@ func (x *GetOutboxResult) GetFirst() string {
return ""
}
// API: PostToInbox
// -----------------------------------------------------------
type PostToInboxRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
}
func (x *PostToInboxRequest) Reset() {
*x = PostToInboxRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_spis_proto_msgTypes[32]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PostToInboxRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PostToInboxRequest) ProtoMessage() {}
func (x *PostToInboxRequest) ProtoReflect() protoreflect.Message {
mi := &file_spis_proto_msgTypes[32]
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 PostToInboxRequest.ProtoReflect.Descriptor instead.
func (*PostToInboxRequest) Descriptor() ([]byte, []int) {
return file_spis_proto_rawDescGZIP(), []int{32}
}
func (x *PostToInboxRequest) GetUsername() string {
if x != nil {
return x.Username
}
return ""
}
type PostToInboxResult struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *PostToInboxResult) Reset() {
*x = PostToInboxResult{}
if protoimpl.UnsafeEnabled {
mi := &file_spis_proto_msgTypes[33]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PostToInboxResult) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PostToInboxResult) ProtoMessage() {}
func (x *PostToInboxResult) ProtoReflect() protoreflect.Message {
mi := &file_spis_proto_msgTypes[33]
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 PostToInboxResult.ProtoReflect.Descriptor instead.
func (*PostToInboxResult) Descriptor() ([]byte, []int) {
return file_spis_proto_rawDescGZIP(), []int{33}
}
var File_spis_proto protoreflect.FileDescriptor
var file_spis_proto_rawDesc = []byte{
@ -2178,8 +2265,12 @@ var file_spis_proto_rawDesc = []byte{
0x75, 0x66, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x50, 0x75, 0x62, 0x41, 0x63,
0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 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,
0x01, 0x28, 0x09, 0x52, 0x05, 0x66, 0x69, 0x72, 0x73, 0x74, 0x22, 0x30, 0x0a, 0x12, 0x50, 0x6f,
0x73, 0x74, 0x54, 0x6f, 0x49, 0x6e, 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, 0x22, 0x13, 0x0a, 0x11,
0x50, 0x6f, 0x73, 0x74, 0x54, 0x6f, 0x49, 0x6e, 0x62, 0x6f, 0x78, 0x52, 0x65, 0x73, 0x75, 0x6c,
0x74, 0x42, 0x04, 0x5a, 0x02, 0x2e, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -2194,7 +2285,7 @@ func file_spis_proto_rawDescGZIP() []byte {
return file_spis_proto_rawDescData
}
var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 32)
var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 34)
var file_spis_proto_goTypes = []interface{}{
(*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest
(*SystemCallResult)(nil), // 1: protobuf.SystemCallResult
@ -2228,20 +2319,22 @@ var file_spis_proto_goTypes = []interface{}{
(*PostToOutboxResult)(nil), // 29: protobuf.PostToOutboxResult
(*GetOutboxRequest)(nil), // 30: protobuf.GetOutboxRequest
(*GetOutboxResult)(nil), // 31: protobuf.GetOutboxResult
(*Document)(nil), // 32: protobuf.Document
(*ActivityPubLink)(nil), // 33: protobuf.ActivityPubLink
(*ActivityPubMedia)(nil), // 34: protobuf.ActivityPubMedia
(*ActivityPubPublicKey)(nil), // 35: protobuf.ActivityPubPublicKey
(*ActivityPubActivity)(nil), // 36: protobuf.ActivityPubActivity
(*PostToInboxRequest)(nil), // 32: protobuf.PostToInboxRequest
(*PostToInboxResult)(nil), // 33: protobuf.PostToInboxResult
(*Document)(nil), // 34: protobuf.Document
(*ActivityPubLink)(nil), // 35: protobuf.ActivityPubLink
(*ActivityPubMedia)(nil), // 36: protobuf.ActivityPubMedia
(*ActivityPubPublicKey)(nil), // 37: protobuf.ActivityPubPublicKey
(*ActivityPubActivity)(nil), // 38: protobuf.ActivityPubActivity
}
var file_spis_proto_depIdxs = []int32{
32, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document
32, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document
33, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink
34, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia
34, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia
35, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey
36, // 6: protobuf.GetOutboxResult.orderedItems:type_name -> protobuf.ActivityPubActivity
34, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document
34, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document
35, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink
36, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia
36, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia
37, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey
38, // 6: protobuf.GetOutboxResult.orderedItems:type_name -> protobuf.ActivityPubActivity
7, // [7:7] is the sub-list for method output_type
7, // [7:7] is the sub-list for method input_type
7, // [7:7] is the sub-list for extension type_name
@ -2640,6 +2733,30 @@ func file_spis_proto_init() {
return nil
}
}
file_spis_proto_msgTypes[32].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PostToInboxRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_spis_proto_msgTypes[33].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PostToInboxResult); 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{
@ -2647,7 +2764,7 @@ func file_spis_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_spis_proto_rawDesc,
NumEnums: 0,
NumMessages: 32,
NumMessages: 34,
NumExtensions: 0,
NumServices: 0,
},

Wyświetl plik

@ -220,4 +220,13 @@ message GetOutboxResult {
string first = 0x00000006;
}
// API: PostToInbox
//-----------------------------------------------------------
message PostToInboxRequest {
string username = 0x00000001;
}
message PostToInboxResult {
}
//-----------------------------------------------------------

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 PostToInboxService(context IContext, input *PostToInboxRequest) (result *PostToInboxResult, err error) {
conductor := core.Conductor
_ = POST_TO_INBOX_REQUEST
conductor.LogRemoteCall(context, INITIALIZE, "post_to_inbox", input, result, err)
defer func() { conductor.LogRemoteCall(context, FINALIZE, "post_to_inbox", input, result, err) }()
_result, _err := conductor.PostToInbox(input.Username, context.Identity())
if _err != nil {
err = _err
return nil, err
}
_ = _result
result = context.ResultContainer().(*PostToInboxResult)
return result, nil
}

Wyświetl plik

@ -22,4 +22,5 @@ type IApi interface {
GetFollowing(*GetFollowingRequest) (*GetFollowingResult, error)
PostToOutbox(*PostToOutboxRequest) (*PostToOutboxResult, error)
GetOutbox(*GetOutboxRequest) (*GetOutboxResult, error)
PostToInbox(*PostToInboxRequest) (*PostToInboxResult, error)
}

Wyświetl plik

@ -67,6 +67,10 @@ const (
//GetOutboxOperation
GET_OUTBOX_REQUEST = 0x527B6997
GET_OUTBOX_RESULT = 0xF94E37A0
//PostToInboxOperation
POST_TO_INBOX_REQUEST = 0x7400C331
POST_TO_INBOX_RESULT = 0x5BD43D90
)
var OPCODES = Opcodes{
@ -101,4 +105,6 @@ var OPCODES = Opcodes{
0xC6C56614: "PostToOutbox",
0x527B6997: "GET_OUTBOX",
0xF94E37A0: "GetOutbox",
0x7400C331: "POST_TO_INBOX",
0x5BD43D90: "PostToInbox",
}

Wyświetl plik

@ -69,6 +69,7 @@ type (
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)
GetOutbox(username string, editor Identity) (IGetOutboxResult, error)
PostToInbox(username string, editor Identity) (IPostToInboxResult, error)
}
IEchoResult interface {
@ -171,4 +172,7 @@ type (
OrderedItems() []IActivityPubActivity
First() string
}
IPostToInboxResult interface {
}
)

Wyświetl plik

@ -272,6 +272,7 @@ type (
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)
GetOutbox(username string, editor Identity) (IGetOutboxResult, error)
PostToInbox(username string, editor Identity) (IPostToInboxResult, error)
NewDocument(id int64, content string) (IDocument, error)
NewSystemSchedule(id int64, enabled bool, config string) (ISystemSchedule, error)
@ -305,6 +306,7 @@ type (
NewGetFollowingResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, ignored interface{}) IGetFollowingResult
NewPostToOutboxResult(ignored interface{}) IPostToOutboxResult
NewGetOutboxResult(context string, id string, type_ string, totalItems int32, orderedItems []IActivityPubActivity, first string, ignored interface{}) IGetOutboxResult
NewPostToInboxResult(ignored interface{}) IPostToInboxResult
}
ISystemComponent interface {

Wyświetl plik

@ -1046,6 +1046,7 @@ type IDispatcher interface {
GetFollowing(username string) (IGetFollowingResult, error)
PostToOutbox(username string, context string, activityType string, to string, attributedTo string, inReplyTo string, content string) (IPostToOutboxResult, error)
GetOutbox(username string) (IGetOutboxResult, error)
PostToInbox(username string) (IPostToInboxResult, error)
// NewDocument creates a new 'Document' instance using the provided property values.
NewDocument(id int64, content string) (IDocument, error)
@ -1145,6 +1146,8 @@ type IDispatcher interface {
NewPostToOutboxResult() IPostToOutboxResult
// NewGetOutboxResult creates a new result container for 'Get Outbox' system action.
NewGetOutboxResult(context string, id string, type_ string, totalItems int32, orderedItems []IActivityPubActivity, first string) IGetOutboxResult
// NewPostToInboxResult creates a new result container for 'Post To Inbox' system action.
NewPostToInboxResult() IPostToInboxResult
// 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.

Wyświetl plik

@ -165,6 +165,16 @@ func (api *api) GetOutbox(request *GetOutboxRequest) (*GetOutboxResult, error) {
}
}
func (api *api) PostToInbox(request *PostToInboxRequest) (*PostToInboxResult, error) {
result, err := api.call(POST_TO_INBOX_REQUEST, request)
if err != nil {
return nil, err
} else {
return result.(*PostToInboxResult), nil
}
}
func init() {
API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{}
API_RESULT[ECHO_RESULT] = EchoResult{}
@ -182,4 +192,5 @@ func init() {
API_RESULT[GET_FOLLOWING_RESULT] = GetFollowingResult{}
API_RESULT[POST_TO_OUTBOX_RESULT] = PostToOutboxResult{}
API_RESULT[GET_OUTBOX_RESULT] = GetOutboxResult{}
API_RESULT[POST_TO_INBOX_RESULT] = PostToInboxResult{}
}

Wyświetl plik

@ -1155,6 +1155,10 @@ func (conductor *conductor) GetOutbox(username string, editor Identity) (IGetOut
return conductor.spiManager.GetOutbox(username, editor)
}
func (conductor *conductor) PostToInbox(username string, editor Identity) (IPostToInboxResult, error) {
return conductor.spiManager.PostToInbox(username, editor)
}
func (conductor *conductor) NewDocument(id int64, content string) (IDocument, error) {
return NewDocument(id, content)
}
@ -1283,6 +1287,10 @@ func (conductor *conductor) NewGetOutboxResult(context string, id string, type_
return NewGetOutboxResult(context, id, type_, totalItems, orderedItems, first, nil)
}
func (conductor *conductor) NewPostToInboxResult(_ interface{}) IPostToInboxResult {
return NewPostToInboxResult(nil)
}
func (conductor *conductor) LogRemoteCall(context IContext, eventType uint32, source string, input, result interface{}, err error) {
errorMessage := ""
if err != nil {

Wyświetl plik

@ -294,3 +294,7 @@ func (dispatcher *dispatcher) PostToOutbox(username string, context string, acti
func (dispatcher *dispatcher) GetOutbox(username string) (IGetOutboxResult, error) {
return dispatcher.conductor.SpiManager().GetOutbox(username, dispatcher.identity)
}
func (dispatcher *dispatcher) PostToInbox(username string) (IPostToInboxResult, error) {
return dispatcher.conductor.SpiManager().PostToInbox(username, dispatcher.identity)
}

Wyświetl plik

@ -1002,3 +1002,31 @@ func (manager *spiManager) GetOutbox(username string, editor Identity) (result I
return result, nil
}
}
//region IPostToInboxResult Implementation
type postToInboxResult struct {
}
func NewPostToInboxResult(_ interface{}) IPostToInboxResult {
return &postToInboxResult{}
}
//endregion
func (manager *spiManager) PostToInbox(username string, editor Identity) (result IPostToInboxResult, err error) {
defer func() {
if reason := recover(); reason != nil {
err = manager.Error(reason)
}
}()
editor.Lock(POST_TO_INBOX_REQUEST)
defer editor.Unlock(POST_TO_INBOX_REQUEST)
if result, err = commands.PostToInbox(NewDispatcher(Conductor, editor), username); err != nil {
return nil, err
} else {
return result, nil
}
}

Wyświetl plik

@ -64,4 +64,8 @@ func (dispatcher *dispatcher) NewGetOutboxResult(context string, id string, type
return NewGetOutboxResult(context, id, type_, totalItems, orderedItems, first, nil)
}
func (dispatcher *dispatcher) NewPostToInboxResult() IPostToInboxResult {
return NewPostToInboxResult(nil)
}
//endregion