From 2be2100fa7133bf5a78547756d570194e392b9a4 Mon Sep 17 00:00:00 2001 From: Xeronith Date: Thu, 8 Dec 2022 22:11:55 +0330 Subject: [PATCH] feat(components): :sparkles: followers retrieval api --- greataped/components/api/handlers/factory.go | 1 + .../api/handlers/get_followers_handler.go | 45 ++++ .../components/api/operations/factory.go | 1 + .../api/operations/get_followers_operation.go | 51 +++++ greataped/components/api/protobuf/spis.pb.go | 204 ++++++++++++++++-- greataped/components/api/protobuf/spis.proto | 15 ++ .../api/services/get_followers_service.go | 34 +++ greataped/components/contracts/api.go | 1 + greataped/components/contracts/opcodes.go | 6 + greataped/components/contracts/spi.go | 10 + .../components/contracts/system_component.go | 2 + .../components/contracts/system_dispatcher.go | 3 + greataped/components/core/api_methods.go | 11 + greataped/components/core/initializer.go | 8 + greataped/components/core/spi.go | 4 + greataped/components/core/spi_manager.go | 65 ++++++ greataped/components/core/system_results.go | 4 + greataped/components/media/.gitignore | 2 + 18 files changed, 453 insertions(+), 14 deletions(-) create mode 100644 greataped/components/api/handlers/get_followers_handler.go create mode 100644 greataped/components/api/operations/get_followers_operation.go create mode 100644 greataped/components/api/services/get_followers_service.go create mode 100644 greataped/components/media/.gitignore diff --git a/greataped/components/api/handlers/factory.go b/greataped/components/api/handlers/factory.go index 4baaa2f..7d00ffb 100644 --- a/greataped/components/api/handlers/factory.go +++ b/greataped/components/api/handlers/factory.go @@ -17,6 +17,7 @@ func (factory *httpHandlerFactory) Handlers() []IHttpHandler { GetActorHandler(), // │ G . /u/:username FollowActorHandler(), // │ G . /u/:username/follow AuthorizeInteractionHandler(), // │ G . /authorize_interaction + GetFollowersHandler(), // │ G . /u/:username/followers } } diff --git a/greataped/components/api/handlers/get_followers_handler.go b/greataped/components/api/handlers/get_followers_handler.go new file mode 100644 index 0000000..bac5386 --- /dev/null +++ b/greataped/components/api/handlers/get_followers_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 getFollowersHandler struct { +} + +func GetFollowersHandler() IHttpHandler { + return &getFollowersHandler{} +} + +func (handler *getFollowersHandler) Method() string { + return http.MethodGet +} + +func (handler *getFollowersHandler) Path() string { + return "/u/:username/followers" +} + +func (handler *getFollowersHandler) HandlerFunc() HttpHandlerFunc { + return func(x IServerDispatcher) error { + request := &GetFollowersRequest{} + result := &GetFollowersResult{} + + onRequestUnmarshalled := func(request *GetFollowersRequest) { + request.Username = x.Param("username") + } + + return pipeline.Handle(x, + "get_followers", + GET_FOLLOWERS_REQUEST, + GET_FOLLOWERS_RESULT, + request, result, + onRequestUnmarshalled, + false, + ) + } +} diff --git a/greataped/components/api/operations/factory.go b/greataped/components/api/operations/factory.go index 32eadc5..d55e821 100644 --- a/greataped/components/api/operations/factory.go +++ b/greataped/components/api/operations/factory.go @@ -18,6 +18,7 @@ func (factory *operationFactory) Operations() []IOperation { GetActorOperation(), FollowActorOperation(), AuthorizeInteractionOperation(), + GetFollowersOperation(), } } diff --git a/greataped/components/api/operations/get_followers_operation.go b/greataped/components/api/operations/get_followers_operation.go new file mode 100644 index 0000000..48bc5ac --- /dev/null +++ b/greataped/components/api/operations/get_followers_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 getFollowersOperation struct { + Operation + + run func(IContext, *GetFollowersRequest) (*GetFollowersResult, error) +} + +func GetFollowersOperation() IOperation { + return &getFollowersOperation{ + run: GetFollowersService, + } +} + +func (operation *getFollowersOperation) Id() (ID, ID) { + return GET_FOLLOWERS_REQUEST, GET_FOLLOWERS_RESULT +} + +func (operation *getFollowersOperation) InputContainer() Pointer { + return new(GetFollowersRequest) +} + +func (operation *getFollowersOperation) OutputContainer() Pointer { + return new(GetFollowersResult) +} + +func (operation *getFollowersOperation) Execute(context IContext, payload Pointer) (Pointer, error) { + return operation.run(context, payload.(*GetFollowersRequest)) +} + +/* +func (operation *getFollowersOperation) 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 b18c61a..1901b92 100644 --- a/greataped/components/api/protobuf/spis.pb.go +++ b/greataped/components/api/protobuf/spis.pb.go @@ -1440,6 +1440,142 @@ func (x *AuthorizeInteractionResult) GetSuccess() bool { return false } +// API: GetFollowers +// ----------------------------------------------------------- +type GetFollowersRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` +} + +func (x *GetFollowersRequest) Reset() { + *x = GetFollowersRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[24] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetFollowersRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFollowersRequest) ProtoMessage() {} + +func (x *GetFollowersRequest) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[24] + 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 GetFollowersRequest.ProtoReflect.Descriptor instead. +func (*GetFollowersRequest) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{24} +} + +func (x *GetFollowersRequest) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +type GetFollowersResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Context string `protobuf:"bytes,1,opt,name=context,json=@context,proto3" json:"context,omitempty"` + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id,omitempty"` + Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"` + TotalItems int32 `protobuf:"varint,4,opt,name=totalItems,proto3" json:"totalItems,omitempty"` + OrderedItems []string `protobuf:"bytes,5,rep,name=orderedItems,proto3" json:"orderedItems,omitempty"` + First string `protobuf:"bytes,6,opt,name=first,proto3" json:"first,omitempty"` +} + +func (x *GetFollowersResult) Reset() { + *x = GetFollowersResult{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[25] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetFollowersResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetFollowersResult) ProtoMessage() {} + +func (x *GetFollowersResult) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[25] + 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 GetFollowersResult.ProtoReflect.Descriptor instead. +func (*GetFollowersResult) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{25} +} + +func (x *GetFollowersResult) GetContext() string { + if x != nil { + return x.Context + } + return "" +} + +func (x *GetFollowersResult) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *GetFollowersResult) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *GetFollowersResult) GetTotalItems() int32 { + if x != nil { + return x.TotalItems + } + return 0 +} + +func (x *GetFollowersResult) GetOrderedItems() []string { + if x != nil { + return x.OrderedItems + } + return nil +} + +func (x *GetFollowersResult) GetFirst() string { + if x != nil { + return x.First + } + return "" +} + var File_spis_proto protoreflect.FileDescriptor var file_spis_proto_rawDesc = []byte{ @@ -1576,8 +1712,22 @@ var file_spis_proto_rawDesc = []byte{ 0x74, 0x65, 0x72, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x42, 0x04, 0x5a, 0x02, 0x2e, - 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x08, 0x52, 0x07, 0x73, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x22, 0x31, 0x0a, 0x13, 0x47, + 0x65, 0x74, 0x46, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x73, 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, 0xad, + 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x46, 0x6f, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x73, 0x52, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x19, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x40, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, + 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x74, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x49, 0x74, 0x65, + 0x6d, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x49, + 0x74, 0x65, 0x6d, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x6f, 0x72, 0x64, 0x65, 0x72, 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, } var ( @@ -1592,7 +1742,7 @@ func file_spis_proto_rawDescGZIP() []byte { return file_spis_proto_rawDescData } -var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 24) +var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 26) var file_spis_proto_goTypes = []interface{}{ (*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest (*SystemCallResult)(nil), // 1: protobuf.SystemCallResult @@ -1618,18 +1768,20 @@ var file_spis_proto_goTypes = []interface{}{ (*FollowActorResult)(nil), // 21: protobuf.FollowActorResult (*AuthorizeInteractionRequest)(nil), // 22: protobuf.AuthorizeInteractionRequest (*AuthorizeInteractionResult)(nil), // 23: protobuf.AuthorizeInteractionResult - (*Document)(nil), // 24: protobuf.Document - (*ActivityPubLink)(nil), // 25: protobuf.ActivityPubLink - (*ActivityPubMedia)(nil), // 26: protobuf.ActivityPubMedia - (*ActivityPubPublicKey)(nil), // 27: protobuf.ActivityPubPublicKey + (*GetFollowersRequest)(nil), // 24: protobuf.GetFollowersRequest + (*GetFollowersResult)(nil), // 25: protobuf.GetFollowersResult + (*Document)(nil), // 26: protobuf.Document + (*ActivityPubLink)(nil), // 27: protobuf.ActivityPubLink + (*ActivityPubMedia)(nil), // 28: protobuf.ActivityPubMedia + (*ActivityPubPublicKey)(nil), // 29: protobuf.ActivityPubPublicKey } var file_spis_proto_depIdxs = []int32{ - 24, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document - 24, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document - 25, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink - 26, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia - 26, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia - 27, // 5: protobuf.GetActorResult.publicKey:type_name -> protobuf.ActivityPubPublicKey + 26, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document + 26, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document + 27, // 2: protobuf.WebfingerResult.links:type_name -> protobuf.ActivityPubLink + 28, // 3: protobuf.GetActorResult.icon:type_name -> protobuf.ActivityPubMedia + 28, // 4: protobuf.GetActorResult.image:type_name -> protobuf.ActivityPubMedia + 29, // 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 @@ -1932,6 +2084,30 @@ func file_spis_proto_init() { return nil } } + file_spis_proto_msgTypes[24].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetFollowersRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_spis_proto_msgTypes[25].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetFollowersResult); 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{ @@ -1939,7 +2115,7 @@ func file_spis_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_spis_proto_rawDesc, NumEnums: 0, - NumMessages: 24, + NumMessages: 26, NumExtensions: 0, NumServices: 0, }, diff --git a/greataped/components/api/protobuf/spis.proto b/greataped/components/api/protobuf/spis.proto index 93c2c88..ff494b5 100644 --- a/greataped/components/api/protobuf/spis.proto +++ b/greataped/components/api/protobuf/spis.proto @@ -160,4 +160,19 @@ message AuthorizeInteractionResult { bool success = 0x00000002; } +// API: GetFollowers +//----------------------------------------------------------- +message GetFollowersRequest { + string username = 0x00000001; +} + +message GetFollowersResult { + string context = 0x00000001 [json_name = "@context"]; + string id = 0x00000002; + string type = 0x00000003; + int32 totalItems = 0x00000004; + repeated string orderedItems = 0x00000005; + string first = 0x00000006; +} + //----------------------------------------------------------- diff --git a/greataped/components/api/services/get_followers_service.go b/greataped/components/api/services/get_followers_service.go new file mode 100644 index 0000000..89797e3 --- /dev/null +++ b/greataped/components/api/services/get_followers_service.go @@ -0,0 +1,34 @@ +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 GetFollowersService(context IContext, input *GetFollowersRequest) (result *GetFollowersResult, err error) { + conductor := core.Conductor + _ = GET_FOLLOWERS_REQUEST + + conductor.LogRemoteCall(context, INITIALIZE, "get_followers", input, result, err) + defer func() { conductor.LogRemoteCall(context, FINALIZE, "get_followers", input, result, err) }() + + _result, _err := conductor.GetFollowers(input.Username, context.Identity()) + if _err != nil { + err = _err + return nil, err + } + + _ = _result + + result = context.ResultContainer().(*GetFollowersResult) + result.Context = _result.Context() + result.Id = _result.Id() + result.Type = _result.Type() + result.TotalItems = _result.TotalItems() + result.OrderedItems = _result.OrderedItems() + result.First = _result.First() + return result, nil +} diff --git a/greataped/components/contracts/api.go b/greataped/components/contracts/api.go index 77240d6..beb5ce3 100644 --- a/greataped/components/contracts/api.go +++ b/greataped/components/contracts/api.go @@ -18,4 +18,5 @@ type IApi interface { GetActor(*GetActorRequest) (*GetActorResult, error) FollowActor(*FollowActorRequest) (*FollowActorResult, error) AuthorizeInteraction(*AuthorizeInteractionRequest) (*AuthorizeInteractionResult, error) + GetFollowers(*GetFollowersRequest) (*GetFollowersResult, error) } diff --git a/greataped/components/contracts/opcodes.go b/greataped/components/contracts/opcodes.go index d8640a8..ab7c4fa 100644 --- a/greataped/components/contracts/opcodes.go +++ b/greataped/components/contracts/opcodes.go @@ -51,6 +51,10 @@ const ( //AuthorizeInteractionOperation AUTHORIZE_INTERACTION_REQUEST = 0x59EA7612 AUTHORIZE_INTERACTION_RESULT = 0xB38E936F + + //GetFollowersOperation + GET_FOLLOWERS_REQUEST = 0x3F20FD65 + GET_FOLLOWERS_RESULT = 0x7F3E2EB5 ) var OPCODES = Opcodes{ @@ -77,4 +81,6 @@ var OPCODES = Opcodes{ 0x30154D74: "FollowActor", 0x59EA7612: "AUTHORIZE_INTERACTION", 0xB38E936F: "AuthorizeInteraction", + 0x3F20FD65: "GET_FOLLOWERS", + 0x7F3E2EB5: "GetFollowers", } diff --git a/greataped/components/contracts/spi.go b/greataped/components/contracts/spi.go index fc34dd6..d744c49 100644 --- a/greataped/components/contracts/spi.go +++ b/greataped/components/contracts/spi.go @@ -65,6 +65,7 @@ type ( GetActor(username string, editor Identity) (IGetActorResult, error) FollowActor(username string, acct string, editor Identity) (IFollowActorResult, error) AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) + GetFollowers(username string, editor Identity) (IGetFollowersResult, error) } IEchoResult interface { @@ -137,4 +138,13 @@ type ( Uri() string Success() bool } + + IGetFollowersResult interface { + Context() string + Id() string + Type() string + TotalItems() int32 + OrderedItems() []string + First() string + } ) diff --git a/greataped/components/contracts/system_component.go b/greataped/components/contracts/system_component.go index fdf0dbd..dca57e7 100644 --- a/greataped/components/contracts/system_component.go +++ b/greataped/components/contracts/system_component.go @@ -268,6 +268,7 @@ type ( GetActor(username string, editor Identity) (IGetActorResult, error) FollowActor(username string, acct string, editor Identity) (IFollowActorResult, error) AuthorizeInteraction(uri string, editor Identity) (IAuthorizeInteractionResult, error) + GetFollowers(username string, editor Identity) (IGetFollowersResult, error) NewDocument(id int64, content string) (IDocument, error) NewSystemSchedule(id int64, enabled bool, config string) (ISystemSchedule, error) @@ -297,6 +298,7 @@ type ( NewGetActorResult(context []string, id string, followers string, following string, inbox string, outbox string, name string, preferredUsername string, type_ string, url string, icon IActivityPubMedia, image IActivityPubMedia, publicKey IActivityPubPublicKey, summary string, published string, ignored interface{}) IGetActorResult NewFollowActorResult(url string, ignored interface{}) IFollowActorResult NewAuthorizeInteractionResult(uri string, success bool, ignored interface{}) IAuthorizeInteractionResult + NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, ignored interface{}) IGetFollowersResult } ISystemComponent interface { diff --git a/greataped/components/contracts/system_dispatcher.go b/greataped/components/contracts/system_dispatcher.go index 85f9765..f682314 100644 --- a/greataped/components/contracts/system_dispatcher.go +++ b/greataped/components/contracts/system_dispatcher.go @@ -1042,6 +1042,7 @@ type IDispatcher interface { GetActor(username string) (IGetActorResult, error) FollowActor(username string, acct string) (IFollowActorResult, error) AuthorizeInteraction(uri string) (IAuthorizeInteractionResult, error) + GetFollowers(username string) (IGetFollowersResult, error) // NewDocument creates a new 'Document' instance using the provided property values. NewDocument(id int64, content string) (IDocument, error) @@ -1133,6 +1134,8 @@ type IDispatcher interface { NewFollowActorResult(url string) IFollowActorResult // NewAuthorizeInteractionResult creates a new result container for 'Authorize Interaction' system action. NewAuthorizeInteractionResult(uri string, success bool) IAuthorizeInteractionResult + // NewGetFollowersResult creates a new result container for 'Get Followers' system action. + NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string) IGetFollowersResult // 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 61104c0..9f8a390 100644 --- a/greataped/components/core/api_methods.go +++ b/greataped/components/core/api_methods.go @@ -125,6 +125,16 @@ func (api *api) AuthorizeInteraction(request *AuthorizeInteractionRequest) (*Aut } } +func (api *api) GetFollowers(request *GetFollowersRequest) (*GetFollowersResult, error) { + result, err := api.call(GET_FOLLOWERS_REQUEST, request) + + if err != nil { + return nil, err + } else { + return result.(*GetFollowersResult), nil + } +} + func init() { API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{} API_RESULT[ECHO_RESULT] = EchoResult{} @@ -138,4 +148,5 @@ func init() { API_RESULT[GET_ACTOR_RESULT] = GetActorResult{} API_RESULT[FOLLOW_ACTOR_RESULT] = FollowActorResult{} API_RESULT[AUTHORIZE_INTERACTION_RESULT] = AuthorizeInteractionResult{} + API_RESULT[GET_FOLLOWERS_RESULT] = GetFollowersResult{} } diff --git a/greataped/components/core/initializer.go b/greataped/components/core/initializer.go index be8f349..a146efa 100644 --- a/greataped/components/core/initializer.go +++ b/greataped/components/core/initializer.go @@ -1139,6 +1139,10 @@ func (conductor *conductor) AuthorizeInteraction(uri string, editor Identity) (I return conductor.spiManager.AuthorizeInteraction(uri, editor) } +func (conductor *conductor) GetFollowers(username string, editor Identity) (IGetFollowersResult, error) { + return conductor.spiManager.GetFollowers(username, editor) +} + func (conductor *conductor) NewDocument(id int64, content string) (IDocument, error) { return NewDocument(id, content) } @@ -1251,6 +1255,10 @@ func (conductor *conductor) NewAuthorizeInteractionResult(uri string, success bo return NewAuthorizeInteractionResult(uri, success, nil) } +func (conductor *conductor) NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, _ interface{}) IGetFollowersResult { + return NewGetFollowersResult(context, id, type_, totalItems, orderedItems, first, 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 29eaa02..ae6d2ef 100644 --- a/greataped/components/core/spi.go +++ b/greataped/components/core/spi.go @@ -278,3 +278,7 @@ func (dispatcher *dispatcher) FollowActor(username string, acct string) (IFollow func (dispatcher *dispatcher) AuthorizeInteraction(uri string) (IAuthorizeInteractionResult, error) { return dispatcher.conductor.SpiManager().AuthorizeInteraction(uri, dispatcher.identity) } + +func (dispatcher *dispatcher) GetFollowers(username string) (IGetFollowersResult, error) { + return dispatcher.conductor.SpiManager().GetFollowers(username, dispatcher.identity) +} diff --git a/greataped/components/core/spi_manager.go b/greataped/components/core/spi_manager.go index 666fae2..178d807 100644 --- a/greataped/components/core/spi_manager.go +++ b/greataped/components/core/spi_manager.go @@ -779,3 +779,68 @@ func (manager *spiManager) AuthorizeInteraction(uri string, editor Identity) (re return result, nil } } + +//region IGetFollowersResult Implementation + +type getFollowersResult struct { + context string + id string + type_ string + totalItems int32 + orderedItems []string + first string +} + +func NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string, _ interface{}) IGetFollowersResult { + return &getFollowersResult{ + context: context, + id: id, + type_: type_, + totalItems: totalItems, + orderedItems: orderedItems, + first: first, + } +} + +func (result getFollowersResult) Context() string { + return result.context +} + +func (result getFollowersResult) Id() string { + return result.id +} + +func (result getFollowersResult) Type() string { + return result.type_ +} + +func (result getFollowersResult) TotalItems() int32 { + return result.totalItems +} + +func (result getFollowersResult) OrderedItems() []string { + return result.orderedItems +} + +func (result getFollowersResult) First() string { + return result.first +} + +//endregion + +func (manager *spiManager) GetFollowers(username string, editor Identity) (result IGetFollowersResult, err error) { + defer func() { + if reason := recover(); reason != nil { + err = manager.Error(reason) + } + }() + + editor.Lock(GET_FOLLOWERS_REQUEST) + defer editor.Unlock(GET_FOLLOWERS_REQUEST) + + if result, err = commands.GetFollowers(NewDispatcher(Conductor, editor), username); 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 b7a09c8..86cfe95 100644 --- a/greataped/components/core/system_results.go +++ b/greataped/components/core/system_results.go @@ -48,4 +48,8 @@ func (dispatcher *dispatcher) NewAuthorizeInteractionResult(uri string, success return NewAuthorizeInteractionResult(uri, success, nil) } +func (dispatcher *dispatcher) NewGetFollowersResult(context string, id string, type_ string, totalItems int32, orderedItems []string, first string) IGetFollowersResult { + return NewGetFollowersResult(context, id, type_, totalItems, orderedItems, first, nil) +} + //endregion diff --git a/greataped/components/media/.gitignore b/greataped/components/media/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/greataped/components/media/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file