mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 05:12:25 -05:00 
			
		
		
		
	drafting some stuff out
This commit is contained in:
		
					parent
					
						
							
								3ba528120c
							
						
					
				
			
			
				commit
				
					
						08657c41af
					
				
			
		
					 3 changed files with 100 additions and 4 deletions
				
			
		|  | @ -72,7 +72,6 @@ func (f *federator) PostInboxRequestBodyHook(ctx context.Context, r *http.Reques | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	ctxWithActivity := context.WithValue(ctx, util.APActivity, activity) | 	ctxWithActivity := context.WithValue(ctx, util.APActivity, activity) | ||||||
| 	return ctxWithActivity, nil | 	return ctxWithActivity, nil | ||||||
| } | } | ||||||
|  | @ -145,8 +144,9 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr | ||||||
| 		requestingAccount = a | 		requestingAccount = a | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	contextWithRequestingAccount := context.WithValue(ctx, util.APRequestingAccount, requestingAccount) | 	withRequester := context.WithValue(ctx, util.APRequestingAccount, requestingAccount) | ||||||
| 	return contextWithRequestingAccount, true, nil | 	withRequested := context.WithValue(withRequester, util.APAccount, requestedAccount) | ||||||
|  | 	return withRequested, true, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Blocked should determine whether to permit a set of actors given by | // Blocked should determine whether to permit a set of actors given by | ||||||
|  | @ -163,8 +163,40 @@ func (f *federator) AuthenticatePostInbox(ctx context.Context, w http.ResponseWr | ||||||
| // Finally, if the authentication and authorization succeeds, then | // Finally, if the authentication and authorization succeeds, then | ||||||
| // blocked must be false and error nil. The request will continue | // blocked must be false and error nil. The request will continue | ||||||
| // to be processed. | // to be processed. | ||||||
|  | // | ||||||
|  | // TODO: implement domain block checking here as well | ||||||
| func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, error) { | func (f *federator) Blocked(ctx context.Context, actorIRIs []*url.URL) (bool, error) { | ||||||
| 	// TODO | 	l := f.log.WithFields(logrus.Fields{ | ||||||
|  | 		"func": "Blocked", | ||||||
|  | 	}) | ||||||
|  | 	l.Debugf("entering BLOCKED function with IRI list: %+v", actorIRIs) | ||||||
|  | 
 | ||||||
|  | 	requestedAccountI := ctx.Value(util.APAccount) | ||||||
|  | 	requestedAccount, ok := requestedAccountI.(*gtsmodel.Account) | ||||||
|  | 	if !ok { | ||||||
|  | 		f.log.Errorf("requested account not set on request context") | ||||||
|  | 		return false, errors.New("requested account not set on request context, so couldn't determine blocks") | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	for _, uri := range actorIRIs { | ||||||
|  | 		a := >smodel.Account{} | ||||||
|  | 		if err := f.db.GetWhere("uri", uri.String(), a); err != nil { | ||||||
|  | 			_, ok := err.(db.ErrNoEntries) | ||||||
|  | 			if ok { | ||||||
|  | 				// we don't have an entry for this account so it's not blocked | ||||||
|  | 				// TODO: allow a different default to be set for this behavior | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
|  | 			return false, fmt.Errorf("error getting account with uri %s: %s", uri.String(), err) | ||||||
|  | 		} | ||||||
|  | 		blocked, err := f.db.Blocked(requestedAccount.ID, a.ID) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return false, fmt.Errorf("error checking account blocks: %s", err) | ||||||
|  | 		} | ||||||
|  | 		if blocked { | ||||||
|  | 			return true, nil | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	return false, nil | 	return false, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -20,7 +20,10 @@ package message | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"errors" | ||||||
|  | 	"fmt" | ||||||
| 	"net/http" | 	"net/http" | ||||||
|  | 	"net/url" | ||||||
| 
 | 
 | ||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" | 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" | ||||||
|  | @ -194,6 +197,9 @@ func (p *processor) Start() error { | ||||||
| 				p.log.Infof("received message TO client API: %+v", clientMsg) | 				p.log.Infof("received message TO client API: %+v", clientMsg) | ||||||
| 			case clientMsg := <-p.fromClientAPI: | 			case clientMsg := <-p.fromClientAPI: | ||||||
| 				p.log.Infof("received message FROM client API: %+v", clientMsg) | 				p.log.Infof("received message FROM client API: %+v", clientMsg) | ||||||
|  | 				if err := p.processFromClientAPI(clientMsg); err != nil { | ||||||
|  | 					p.log.Error(err) | ||||||
|  | 				} | ||||||
| 			case federatorMsg := <-p.toFederator: | 			case federatorMsg := <-p.toFederator: | ||||||
| 				p.log.Infof("received message TO federator: %+v", federatorMsg) | 				p.log.Infof("received message TO federator: %+v", federatorMsg) | ||||||
| 			case federatorMsg := <-p.fromFederator: | 			case federatorMsg := <-p.fromFederator: | ||||||
|  | @ -240,3 +246,54 @@ type FromFederator struct { | ||||||
| 	APActivityType gtsmodel.ActivityStreamsActivity | 	APActivityType gtsmodel.ActivityStreamsActivity | ||||||
| 	Activity       interface{} | 	Activity       interface{} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func (p *processor) processFromClientAPI(clientMsg FromClientAPI) error { | ||||||
|  | 	switch clientMsg.APObjectType { | ||||||
|  | 	case gtsmodel.ActivityStreamsNote: | ||||||
|  | 		status, ok := clientMsg.Activity.(*gtsmodel.Status) | ||||||
|  | 		if !ok { | ||||||
|  | 			return errors.New("note was not parseable as *gtsmodel.Status") | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if err := p.notifyStatus(status); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if status.VisibilityAdvanced.Federated { | ||||||
|  | 			return p.federateStatus(status) | ||||||
|  | 		} | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 	return fmt.Errorf("message type unprocessable: %+v", clientMsg) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (p *processor) federateStatus(status *gtsmodel.Status) error { | ||||||
|  | 	// derive the sending account -- it might be attached to the status already | ||||||
|  | 	sendingAcct := >smodel.Account{} | ||||||
|  | 	if status.GTSAccount != nil { | ||||||
|  | 		sendingAcct = status.GTSAccount | ||||||
|  | 	} else { | ||||||
|  | 		// it wasn't attached so get it from the db instead | ||||||
|  | 		if err := p.db.GetByID(status.AccountID, sendingAcct); err != nil { | ||||||
|  | 			return err | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	outboxURI, err := url.Parse(sendingAcct.OutboxURI) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// convert the status to AS format Note | ||||||
|  | 	note, err := p.tc.StatusToAS(status) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return err | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	_, err = p.federator.FederatingActor().Send(context.Background(), outboxURI, note) | ||||||
|  | 	return err | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (p *processor) notifyStatus(status *gtsmodel.Status) error { | ||||||
|  | 	return nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -81,6 +81,13 @@ func (p *processor) StatusCreate(auth *oauth.Auth, form *apimodel.AdvancedStatus | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// put the new status in the appropriate channel for async processing | ||||||
|  | 	p.fromClientAPI <- FromClientAPI{ | ||||||
|  | 		APObjectType:   newStatus.ActivityStreamsType, | ||||||
|  | 		APActivityType: gtsmodel.ActivityStreamsCreate, | ||||||
|  | 		Activity:       newStatus, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// return the frontend representation of the new status to the submitter | 	// return the frontend representation of the new status to the submitter | ||||||
| 	return p.tc.StatusToMasto(newStatus, auth.Account, auth.Account, nil, newStatus.GTSReplyToAccount, nil) | 	return p.tc.StatusToMasto(newStatus, auth.Account, auth.Account, nil, newStatus.GTSReplyToAccount, nil) | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue