kopia lustrzana https://github.com/reiver/greatape
refactor(project): 🎨 improve structure and format of the code
rodzic
d21cfef455
commit
ab7151060e
|
@ -20,11 +20,11 @@ type Actor struct {
|
|||
Url string `json:"url"`
|
||||
Summary string `json:"summary"`
|
||||
Published time.Time `json:"published"`
|
||||
Icon Icon `json:"icon,omitempty"`
|
||||
Image Icon `json:"image,omitempty"`
|
||||
Icon Media `json:"icon,omitempty"`
|
||||
Image Media `json:"image,omitempty"`
|
||||
}
|
||||
|
||||
type Icon struct {
|
||||
type Media struct {
|
||||
Height int64 `json:"height,omitempty"`
|
||||
MediaType string `json:"mediaType,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
|
@ -39,11 +39,11 @@ type PublicKey struct {
|
|||
}
|
||||
|
||||
func UnmarshalActor(data []byte) (Actor, error) {
|
||||
var r Actor
|
||||
err := json.Unmarshal(data, &r)
|
||||
return r, err
|
||||
var actor Actor
|
||||
err := json.Unmarshal(data, &actor)
|
||||
return actor, err
|
||||
}
|
||||
|
||||
func (r *Actor) Marshal() ([]byte, error) {
|
||||
return json.Marshal(r)
|
||||
func (actor *Actor) Marshal() ([]byte, error) {
|
||||
return json.Marshal(actor)
|
||||
}
|
||||
|
|
|
@ -22,11 +22,11 @@ func NewOrderedCollection(id string, items interface{}, length int) *OrderedColl
|
|||
}
|
||||
|
||||
func UnmarshalOrderedCollection(data []byte) (OrderedCollection, error) {
|
||||
var o OrderedCollection
|
||||
err := json.Unmarshal(data, &o)
|
||||
return o, err
|
||||
var orderedCollection OrderedCollection
|
||||
err := json.Unmarshal(data, &orderedCollection)
|
||||
return orderedCollection, err
|
||||
}
|
||||
|
||||
func (o *OrderedCollection) Marshal() ([]byte, error) {
|
||||
return json.Marshal(o)
|
||||
func (orderedCollection *OrderedCollection) Marshal() ([]byte, error) {
|
||||
return json.Marshal(orderedCollection)
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ type Followers struct {
|
|||
}
|
||||
|
||||
func UnmarshalFollowers(data []byte) (Followers, error) {
|
||||
var o Followers
|
||||
err := json.Unmarshal(data, &o)
|
||||
return o, err
|
||||
var followers Followers
|
||||
err := json.Unmarshal(data, &followers)
|
||||
return followers, err
|
||||
}
|
||||
|
||||
func (o *Followers) Marshal() ([]byte, error) {
|
||||
return json.Marshal(o)
|
||||
func (followers *Followers) Marshal() ([]byte, error) {
|
||||
return json.Marshal(followers)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package activitypub
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type Inbox struct {
|
||||
Context string `json:"@context"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
TotalItems int `json:"totalItems"`
|
||||
OrderedItems interface{} `json:"orderedItems,omitempty"`
|
||||
}
|
||||
|
||||
func UnmarshalInbox(data []byte) (Inbox, error) {
|
||||
var inbox Inbox
|
||||
err := json.Unmarshal(data, &inbox)
|
||||
return inbox, err
|
||||
}
|
||||
|
||||
func (inbox *Inbox) Marshal() ([]byte, error) {
|
||||
return json.Marshal(inbox)
|
||||
}
|
|
@ -11,11 +11,11 @@ type Outbox struct {
|
|||
}
|
||||
|
||||
func UnmarshalOutbox(data []byte) (Outbox, error) {
|
||||
var o Outbox
|
||||
err := json.Unmarshal(data, &o)
|
||||
return o, err
|
||||
var outbox Outbox
|
||||
err := json.Unmarshal(data, &outbox)
|
||||
return outbox, err
|
||||
}
|
||||
|
||||
func (o *Outbox) Marshal() ([]byte, error) {
|
||||
return json.Marshal(o)
|
||||
func (outbox *Outbox) Marshal() ([]byte, error) {
|
||||
return json.Marshal(outbox)
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ const (
|
|||
TypeFollow = "Follow"
|
||||
TypeAccept = "Accept"
|
||||
TypeNote = "Note"
|
||||
TypeLike = "Like"
|
||||
TypeOrderedCollection = "OrderedCollection"
|
||||
|
||||
Public = ActivityStreams + "#Public"
|
||||
|
|
|
@ -2,16 +2,6 @@ package activitypub
|
|||
|
||||
import "encoding/json"
|
||||
|
||||
func UnmarshalWebfinger(data []byte) (Webfinger, error) {
|
||||
var r Webfinger
|
||||
err := json.Unmarshal(data, &r)
|
||||
return r, err
|
||||
}
|
||||
|
||||
func (r *Webfinger) Marshal() ([]byte, error) {
|
||||
return json.Marshal(r)
|
||||
}
|
||||
|
||||
type Webfinger struct {
|
||||
Aliases []string `json:"aliases"`
|
||||
Links []Link `json:"links"`
|
||||
|
@ -36,3 +26,13 @@ func (webfinger *Webfinger) Self() string {
|
|||
|
||||
return self
|
||||
}
|
||||
|
||||
func UnmarshalWebfinger(data []byte) (Webfinger, error) {
|
||||
var webfinger Webfinger
|
||||
err := json.Unmarshal(data, &webfinger)
|
||||
return webfinger, err
|
||||
}
|
||||
|
||||
func (webfinger *Webfinger) Marshal() ([]byte, error) {
|
||||
return json.Marshal(webfinger)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package spi
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/reiver/greatape/app/activitypub"
|
||||
. "github.com/reiver/greatape/components/constants"
|
||||
. "github.com/reiver/greatape/components/contracts"
|
||||
)
|
||||
|
@ -15,12 +18,40 @@ func GetInbox(x IDispatcher, username string) (IGetInboxResult, error) {
|
|||
|
||||
actor := x.Format("%s/u/%s", x.PublicUrl(), identity.Username())
|
||||
|
||||
activities := x.FilterActivityPubIncomingActivities(func(activity IActivityPubIncomingActivity) bool {
|
||||
return activity.From() == actor && activity.To() == ACTIVITY_PUB_PUBLIC
|
||||
})
|
||||
|
||||
var orderedItems ActivityPubActivities
|
||||
activities.ForEach(func(incomingActivity IActivityPubIncomingActivity) {
|
||||
published := time.Unix(0, incomingActivity.Timestamp()).Format("2006-01-02T15:04:05Z")
|
||||
|
||||
note := activitypub.NewPublicNote(actor, incomingActivity.Content())
|
||||
noteActivity := note.Wrap(username, x.PublicUrl(), incomingActivity.UniqueIdentifier())
|
||||
|
||||
object, _ := x.NewActivityPubObject()
|
||||
object.SetContext(ACTIVITY_STREAMS)
|
||||
object.SetType(ACTIVITY_PUB_NOTE)
|
||||
object.SetId(note.Id)
|
||||
object.SetContent(note.Content)
|
||||
|
||||
activity, _ := x.NewActivityPubActivity()
|
||||
activity.SetContext(ACTIVITY_STREAMS)
|
||||
activity.SetType(ACTIVITY_PUB_CREATE)
|
||||
activity.SetId(x.Format("%s/posts/%s", actor, incomingActivity.UniqueIdentifier()))
|
||||
activity.SetActor(actor)
|
||||
activity.SetTo(noteActivity.To.([]string))
|
||||
activity.SetPublished(published)
|
||||
activity.SetObject(object)
|
||||
|
||||
orderedItems = append(orderedItems, activity)
|
||||
})
|
||||
|
||||
return x.NewGetInboxResult(
|
||||
ACTIVITY_STREAMS, // context
|
||||
x.Format("%s/inbox", actor), // id
|
||||
ACTIVITY_PUB_ORDERED_COLLECTION, // type
|
||||
0, // totalItems
|
||||
int32(len(orderedItems)), // totalItems
|
||||
orderedItems, // orderedItems
|
||||
"", // first
|
||||
), nil
|
||||
|
|
|
@ -1,10 +1,110 @@
|
|||
package spi
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/reiver/greatape/app/activitypub"
|
||||
. "github.com/reiver/greatape/components/constants"
|
||||
. "github.com/reiver/greatape/components/contracts"
|
||||
)
|
||||
|
||||
func PostToInbox(x IDispatcher, username string) (IPostToInboxResult, error) {
|
||||
return nil, ERROR_NOT_IMPLEMENTED
|
||||
func PostToInbox(x IDispatcher, username string, body string) (IPostToInboxResult, error) {
|
||||
identities := x.FilterIdentities(func(identity IIdentity) bool {
|
||||
return identity.Username() == username
|
||||
})
|
||||
|
||||
x.Assert(identities.HasExactlyOneItem()).Or(ERROR_USER_NOT_FOUND)
|
||||
identity := identities.First()
|
||||
|
||||
object := &activitypub.Object{}
|
||||
if err := json.Unmarshal([]byte(body), object); err != nil {
|
||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_OBJECT
|
||||
}
|
||||
|
||||
keyId := x.Format("%s/u/%s#main-key", x.PublicUrl(), username)
|
||||
|
||||
switch object.Type {
|
||||
case activitypub.TypeFollow:
|
||||
{
|
||||
activity := &activitypub.Activity{}
|
||||
if err := json.Unmarshal([]byte(body), activity); err != nil {
|
||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_ACTIVITY
|
||||
}
|
||||
|
||||
url := activity.Actor
|
||||
var inbox string
|
||||
|
||||
{
|
||||
actor := &activitypub.Actor{}
|
||||
if err := x.GetActivityStreamSigned(url, keyId, identity.PrivateKey(), nil, actor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
inbox = actor.Inbox
|
||||
}
|
||||
|
||||
data, err := json.Marshal(activity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
follower := x.AddActivityPubFollower(
|
||||
activity.Actor,
|
||||
inbox,
|
||||
x.Format("%s/u/%s", x.PublicUrl(), username),
|
||||
string(data),
|
||||
false,
|
||||
)
|
||||
|
||||
data, _ = json.Marshal(&activitypub.Activity{
|
||||
Context: activitypub.ActivityStreams,
|
||||
ID: x.Format("%s/%s", x.PublicUrl(), x.GenerateUUID()),
|
||||
Type: activitypub.TypeAccept,
|
||||
Actor: x.Format("%s/u/%s", x.PublicUrl(), username),
|
||||
Object: activity,
|
||||
})
|
||||
|
||||
if err := x.PostActivityStreamSigned(inbox, keyId, identity.PrivateKey(), data, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
follower.UpdateAccepted(true, x.Identity())
|
||||
}
|
||||
case activitypub.TypeCreate:
|
||||
{
|
||||
activity := &activitypub.Activity{}
|
||||
if err := json.Unmarshal([]byte(body), activity); err != nil {
|
||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_ACTIVITY
|
||||
}
|
||||
|
||||
switch activity.Object.(map[string]interface{})["type"] {
|
||||
case activitypub.TypeNote:
|
||||
note := &activitypub.Note{}
|
||||
if err := mapstructure.Decode(activity.Object, note); err != nil {
|
||||
return nil, ERROR_UNKNOWN_ACTIVITY_PUB_ACTIVITY
|
||||
}
|
||||
|
||||
raw, _ := json.Marshal(note)
|
||||
|
||||
x.AddActivityPubIncomingActivity(
|
||||
identity.Id(),
|
||||
x.GenerateUUID(),
|
||||
x.UnixNano(),
|
||||
note.AttributedTo,
|
||||
note.To[0],
|
||||
note.Content,
|
||||
string(raw),
|
||||
)
|
||||
default:
|
||||
return nil, ERROR_INVALID_PARAMETERS
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
return nil, ERROR_INVALID_PARAMETERS
|
||||
}
|
||||
}
|
||||
|
||||
return x.NewPostToInboxResult(body), nil
|
||||
}
|
||||
|
|
|
@ -238,6 +238,7 @@ func TestGetOutboxApi(test *testing.T) {
|
|||
func TestPostToInboxApi(test *testing.T) {
|
||||
input := &PostToInboxRequest{
|
||||
Username: "username",
|
||||
Body: "body",
|
||||
}
|
||||
|
||||
if output, err := api.PostToInbox(input); err != nil {
|
||||
|
|
|
@ -33,13 +33,17 @@ func (handler *postToInboxHandler) HandlerFunc() HttpHandlerFunc {
|
|||
request.Username = x.Param("username")
|
||||
}
|
||||
|
||||
onRequestProcessed := func(output *PostToInboxResult) (string, []byte) {
|
||||
return "application/activity+json; charset=utf-8", []byte(output.Body)
|
||||
}
|
||||
|
||||
return pipeline.Handle(x,
|
||||
"post_to_inbox",
|
||||
POST_TO_INBOX_REQUEST,
|
||||
POST_TO_INBOX_RESULT,
|
||||
request, result,
|
||||
onRequestUnmarshalled,
|
||||
nil,
|
||||
onRequestProcessed,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -2078,6 +2078,7 @@ type PostToInboxRequest struct {
|
|||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
|
||||
Body string `protobuf:"bytes,2,opt,name=body,proto3" json:"body,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PostToInboxRequest) Reset() {
|
||||
|
@ -2119,10 +2120,19 @@ func (x *PostToInboxRequest) GetUsername() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (x *PostToInboxRequest) GetBody() string {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type PostToInboxResult struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Body string `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"`
|
||||
}
|
||||
|
||||
func (x *PostToInboxResult) Reset() {
|
||||
|
@ -2157,6 +2167,13 @@ func (*PostToInboxResult) Descriptor() ([]byte, []int) {
|
|||
return file_spis_proto_rawDescGZIP(), []int{35}
|
||||
}
|
||||
|
||||
func (x *PostToInboxResult) GetBody() string {
|
||||
if x != nil {
|
||||
return x.Body
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// API: GetInbox
|
||||
// -----------------------------------------------------------
|
||||
type GetInboxRequest struct {
|
||||
|
@ -2492,28 +2509,30 @@ var file_spis_proto_rawDesc = []byte{
|
|||
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, 0x22, 0x30, 0x0a, 0x12, 0x50, 0x6f, 0x73,
|
||||
0x28, 0x09, 0x52, 0x05, 0x66, 0x69, 0x72, 0x73, 0x74, 0x22, 0x44, 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,
|
||||
0x22, 0x2d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 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,
|
||||
0xc8, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x49, 0x6e, 0x62, 0x6f, 0x78, 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, 0x41, 0x0a, 0x0c, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65, 0x64, 0x49, 0x74, 0x65, 0x6d,
|
||||
0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
|
||||
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,
|
||||
0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x62,
|
||||
0x6f, 0x64, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22,
|
||||
0x27, 0x0a, 0x11, 0x50, 0x6f, 0x73, 0x74, 0x54, 0x6f, 0x49, 0x6e, 0x62, 0x6f, 0x78, 0x52, 0x65,
|
||||
0x73, 0x75, 0x6c, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, 0x79, 0x22, 0x2d, 0x0a, 0x0f, 0x47, 0x65, 0x74, 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, 0xc8, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x49,
|
||||
0x6e, 0x62, 0x6f, 0x78, 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, 0x41, 0x0a, 0x0c, 0x6f, 0x72, 0x64,
|
||||
0x65, 0x72, 0x65, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32,
|
||||
0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 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,
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -233,9 +233,11 @@ message GetOutboxResult {
|
|||
//-----------------------------------------------------------
|
||||
message PostToInboxRequest {
|
||||
string username = 0x00000001;
|
||||
string body = 0x00000002;
|
||||
}
|
||||
|
||||
message PostToInboxResult {
|
||||
string body = 0x00000001;
|
||||
}
|
||||
|
||||
// API: GetInbox
|
||||
|
|
|
@ -15,7 +15,7 @@ func PostToInboxService(context IContext, input *PostToInboxRequest) (result *Po
|
|||
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())
|
||||
_result, _err := conductor.PostToInbox(input.Username, input.Body, context.Identity())
|
||||
if _err != nil {
|
||||
err = _err
|
||||
return nil, err
|
||||
|
@ -24,5 +24,6 @@ func PostToInboxService(context IContext, input *PostToInboxRequest) (result *Po
|
|||
_ = _result
|
||||
|
||||
result = context.ResultContainer().(*PostToInboxResult)
|
||||
result.Body = _result.Body()
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
@ -70,7 +70,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)
|
||||
PostToInbox(username string, body string, editor Identity) (IPostToInboxResult, error)
|
||||
GetInbox(username string, editor Identity) (IGetInboxResult, error)
|
||||
}
|
||||
|
||||
|
@ -180,6 +180,7 @@ type (
|
|||
}
|
||||
|
||||
IPostToInboxResult interface {
|
||||
Body() string
|
||||
}
|
||||
|
||||
IGetInboxResult interface {
|
||||
|
|
|
@ -273,7 +273,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)
|
||||
PostToInbox(username string, body string, editor Identity) (IPostToInboxResult, error)
|
||||
GetInbox(username string, editor Identity) (IGetInboxResult, error)
|
||||
|
||||
NewDocument(id int64, content string) (IDocument, error)
|
||||
|
@ -309,7 +309,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
|
||||
NewPostToInboxResult(body string, ignored interface{}) IPostToInboxResult
|
||||
NewGetInboxResult(context string, id string, type_ string, totalItems int32, orderedItems []IActivityPubActivity, first string, ignored interface{}) IGetInboxResult
|
||||
}
|
||||
|
||||
|
|
|
@ -1047,7 +1047,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)
|
||||
PostToInbox(username string, body string) (IPostToInboxResult, error)
|
||||
GetInbox(username string) (IGetInboxResult, error)
|
||||
|
||||
// NewDocument creates a new 'Document' instance using the provided property values.
|
||||
|
@ -1151,7 +1151,7 @@ type IDispatcher interface {
|
|||
// 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
|
||||
NewPostToInboxResult(body string) IPostToInboxResult
|
||||
// NewGetInboxResult creates a new result container for 'Get Inbox' system action.
|
||||
NewGetInboxResult(context string, id string, type_ string, totalItems int32, orderedItems []IActivityPubActivity, first string) IGetInboxResult
|
||||
// Assert asserts the provided condition and panics if the assertion is not valid.
|
||||
|
|
|
@ -1159,8 +1159,8 @@ 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) PostToInbox(username string, body string, editor Identity) (IPostToInboxResult, error) {
|
||||
return conductor.spiManager.PostToInbox(username, body, editor)
|
||||
}
|
||||
|
||||
func (conductor *conductor) GetInbox(username string, editor Identity) (IGetInboxResult, error) {
|
||||
|
@ -1299,8 +1299,8 @@ 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) NewPostToInboxResult(body string, _ interface{}) IPostToInboxResult {
|
||||
return NewPostToInboxResult(body, nil)
|
||||
}
|
||||
|
||||
func (conductor *conductor) NewGetInboxResult(context string, id string, type_ string, totalItems int32, orderedItems []IActivityPubActivity, first string, _ interface{}) IGetInboxResult {
|
||||
|
|
|
@ -299,8 +299,8 @@ func (dispatcher *dispatcher) GetOutbox(username string) (IGetOutboxResult, erro
|
|||
return dispatcher.conductor.SpiManager().GetOutbox(username, dispatcher.identity)
|
||||
}
|
||||
|
||||
func (dispatcher *dispatcher) PostToInbox(username string) (IPostToInboxResult, error) {
|
||||
return dispatcher.conductor.SpiManager().PostToInbox(username, dispatcher.identity)
|
||||
func (dispatcher *dispatcher) PostToInbox(username string, body string) (IPostToInboxResult, error) {
|
||||
return dispatcher.conductor.SpiManager().PostToInbox(username, body, dispatcher.identity)
|
||||
}
|
||||
|
||||
func (dispatcher *dispatcher) GetInbox(username string) (IGetInboxResult, error) {
|
||||
|
|
|
@ -1041,15 +1041,22 @@ func (manager *spiManager) GetOutbox(username string, editor Identity) (result I
|
|||
//region IPostToInboxResult Implementation
|
||||
|
||||
type postToInboxResult struct {
|
||||
body string
|
||||
}
|
||||
|
||||
func NewPostToInboxResult(_ interface{}) IPostToInboxResult {
|
||||
return &postToInboxResult{}
|
||||
func NewPostToInboxResult(body string, _ interface{}) IPostToInboxResult {
|
||||
return &postToInboxResult{
|
||||
body: body,
|
||||
}
|
||||
}
|
||||
|
||||
func (result postToInboxResult) Body() string {
|
||||
return result.body
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
func (manager *spiManager) PostToInbox(username string, editor Identity) (result IPostToInboxResult, err error) {
|
||||
func (manager *spiManager) PostToInbox(username string, body string, editor Identity) (result IPostToInboxResult, err error) {
|
||||
defer func() {
|
||||
if reason := recover(); reason != nil {
|
||||
err = manager.Error(reason)
|
||||
|
@ -1059,7 +1066,7 @@ func (manager *spiManager) PostToInbox(username string, editor Identity) (result
|
|||
editor.Lock(POST_TO_INBOX_REQUEST)
|
||||
defer editor.Unlock(POST_TO_INBOX_REQUEST)
|
||||
|
||||
if result, err = commands.PostToInbox(NewDispatcher(Conductor, editor), username); err != nil {
|
||||
if result, err = commands.PostToInbox(NewDispatcher(Conductor, editor), username, body); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result, nil
|
||||
|
|
|
@ -328,7 +328,7 @@ func TestSpiManager_GetOutbox(test *testing.T) {
|
|||
func TestSpiManager_PostToInbox(test *testing.T) {
|
||||
manager := Conductor.SpiManager()
|
||||
|
||||
result, err := manager.PostToInbox("username", nil)
|
||||
result, err := manager.PostToInbox("username", "body", nil)
|
||||
if err != nil {
|
||||
test.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -68,8 +68,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)
|
||||
func (dispatcher *dispatcher) NewPostToInboxResult(body string) IPostToInboxResult {
|
||||
return NewPostToInboxResult(body, nil)
|
||||
}
|
||||
|
||||
func (dispatcher *dispatcher) NewGetInboxResult(context string, id string, type_ string, totalItems int32, orderedItems []IActivityPubActivity, first string) IGetInboxResult {
|
||||
|
|
3
go.mod
3
go.mod
|
@ -3,9 +3,10 @@ module github.com/reiver/greatape
|
|||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/mitchellh/mapstructure v1.5.0
|
||||
github.com/robfig/cron v1.2.0
|
||||
github.com/sendgrid/sendgrid-go v3.12.0+incompatible
|
||||
github.com/xeronith/diamante v1.8.0
|
||||
github.com/xeronith/diamante v1.8.1
|
||||
google.golang.org/protobuf v1.28.1
|
||||
)
|
||||
|
||||
|
|
6
go.sum
6
go.sum
|
@ -29,6 +29,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
|
|||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
|
||||
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
|
||||
|
@ -45,8 +47,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
|
|||
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
github.com/xeronith/diamante v1.8.0 h1:qMZ9876WB2gEDNlOH6W/J3hRFc9KobPeEXGm48gDXfg=
|
||||
github.com/xeronith/diamante v1.8.0/go.mod h1:9Tm1tILSKRFRLqvGkG6fTNdLpQbsTZohTLD6xRoWkx8=
|
||||
github.com/xeronith/diamante v1.8.1 h1:rAEFVfj+3nOrBCGdfOk2F9FuijG+r/Vws5YLEuup/0Y=
|
||||
github.com/xeronith/diamante v1.8.1/go.mod h1:9Tm1tILSKRFRLqvGkG6fTNdLpQbsTZohTLD6xRoWkx8=
|
||||
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
|
||||
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
|
||||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
|
||||
|
|
Ładowanie…
Reference in New Issue