mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 14:32:24 -05:00 
			
		
		
		
	Follows and relationships (#27)
* Follows -- create and undo, both remote and local * Statuses -- federate new posts, including media, attachments, CWs and image descriptions.
This commit is contained in:
		
					parent
					
						
							
								dc06e71b76
							
						
					
				
			
			
				commit
				
					
						d839f27c30
					
				
			
		
					 54 changed files with 2260 additions and 299 deletions
				
			
		|  | @ -38,24 +38,60 @@ func (p *processor) processFromFederator(federatorMsg gtsmodel.FromFederator) er | |||
| 
 | ||||
| 	l.Debug("entering function PROCESS FROM FEDERATOR") | ||||
| 
 | ||||
| 	switch federatorMsg.APObjectType { | ||||
| 	case gtsmodel.ActivityStreamsNote: | ||||
| 	switch federatorMsg.APActivityType { | ||||
| 	case gtsmodel.ActivityStreamsCreate: | ||||
| 		// CREATE | ||||
| 		switch federatorMsg.APObjectType { | ||||
| 		case gtsmodel.ActivityStreamsNote: | ||||
| 			// CREATE A STATUS | ||||
| 			incomingStatus, ok := federatorMsg.GTSModel.(*gtsmodel.Status) | ||||
| 			if !ok { | ||||
| 				return errors.New("note was not parseable as *gtsmodel.Status") | ||||
| 			} | ||||
| 
 | ||||
| 		incomingStatus, ok := federatorMsg.GTSModel.(*gtsmodel.Status) | ||||
| 		if !ok { | ||||
| 			return errors.New("note was not parseable as *gtsmodel.Status") | ||||
| 		} | ||||
| 			l.Debug("will now derefence incoming status") | ||||
| 			if err := p.dereferenceStatusFields(incomingStatus); err != nil { | ||||
| 				return fmt.Errorf("error dereferencing status from federator: %s", err) | ||||
| 			} | ||||
| 			if err := p.db.UpdateByID(incomingStatus.ID, incomingStatus); err != nil { | ||||
| 				return fmt.Errorf("error updating dereferenced status in the db: %s", err) | ||||
| 			} | ||||
| 
 | ||||
| 		l.Debug("will now derefence incoming status") | ||||
| 		if err := p.dereferenceStatusFields(incomingStatus); err != nil { | ||||
| 			return fmt.Errorf("error dereferencing status from federator: %s", err) | ||||
| 		} | ||||
| 		if err := p.db.UpdateByID(incomingStatus.ID, incomingStatus); err != nil { | ||||
| 			return fmt.Errorf("error updating dereferenced status in the db: %s", err) | ||||
| 		} | ||||
| 			if err := p.notifyStatus(incomingStatus); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		case gtsmodel.ActivityStreamsProfile: | ||||
| 			// CREATE AN ACCOUNT | ||||
| 			incomingAccount, ok := federatorMsg.GTSModel.(*gtsmodel.Account) | ||||
| 			if !ok { | ||||
| 				return errors.New("profile was not parseable as *gtsmodel.Account") | ||||
| 			} | ||||
| 
 | ||||
| 		if err := p.notifyStatus(incomingStatus); err != nil { | ||||
| 			return err | ||||
| 			l.Debug("will now derefence incoming account") | ||||
| 			if err := p.dereferenceAccountFields(incomingAccount, ""); err != nil { | ||||
| 				return fmt.Errorf("error dereferencing account from federator: %s", err) | ||||
| 			} | ||||
| 			if err := p.db.UpdateByID(incomingAccount.ID, incomingAccount); err != nil { | ||||
| 				return fmt.Errorf("error updating dereferenced account in the db: %s", err) | ||||
| 			} | ||||
| 		} | ||||
| 	case gtsmodel.ActivityStreamsUpdate: | ||||
| 		// UPDATE | ||||
| 		switch federatorMsg.APObjectType { | ||||
| 		case gtsmodel.ActivityStreamsProfile: | ||||
| 			// UPDATE AN ACCOUNT | ||||
| 			incomingAccount, ok := federatorMsg.GTSModel.(*gtsmodel.Account) | ||||
| 			if !ok { | ||||
| 				return errors.New("profile was not parseable as *gtsmodel.Account") | ||||
| 			} | ||||
| 
 | ||||
| 			l.Debug("will now derefence incoming account") | ||||
| 			if err := p.dereferenceAccountFields(incomingAccount, ""); err != nil { | ||||
| 				return fmt.Errorf("error dereferencing account from federator: %s", err) | ||||
| 			} | ||||
| 			if err := p.db.UpdateByID(incomingAccount.ID, incomingAccount); err != nil { | ||||
| 				return fmt.Errorf("error updating dereferenced account in the db: %s", err) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  | @ -121,7 +157,7 @@ func (p *processor) dereferenceStatusFields(status *gtsmodel.Status) error { | |||
| 
 | ||||
| 		// it might have been processed elsewhere so check first if it's already in the database or not | ||||
| 		maybeAttachment := >smodel.MediaAttachment{} | ||||
| 		err := p.db.GetWhere("remote_url", a.RemoteURL, maybeAttachment) | ||||
| 		err := p.db.GetWhere([]db.Where{{Key: "remote_url", Value: a.RemoteURL}}, maybeAttachment) | ||||
| 		if err == nil { | ||||
| 			// we already have it in the db, dereferenced, no need to do it again | ||||
| 			l.Debugf("attachment already exists with id %s", maybeAttachment.ID) | ||||
|  | @ -170,7 +206,7 @@ func (p *processor) dereferenceStatusFields(status *gtsmodel.Status) error { | |||
| 		m.OriginAccountURI = status.GTSAccount.URI | ||||
| 
 | ||||
| 		targetAccount := >smodel.Account{} | ||||
| 		if err := p.db.GetWhere("uri", uri.String(), targetAccount); err != nil { | ||||
| 		if err := p.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String()}}, targetAccount); err != nil { | ||||
| 			// proper error | ||||
| 			if _, ok := err.(db.ErrNoEntries); !ok { | ||||
| 				return fmt.Errorf("db error checking for account with uri %s", uri.String()) | ||||
|  | @ -206,3 +242,27 @@ func (p *processor) dereferenceStatusFields(status *gtsmodel.Status) error { | |||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (p *processor) dereferenceAccountFields(account *gtsmodel.Account, requestingUsername string) error { | ||||
| 	l := p.log.WithFields(logrus.Fields{ | ||||
| 		"func":               "dereferenceAccountFields", | ||||
| 		"requestingUsername": requestingUsername, | ||||
| 	}) | ||||
| 
 | ||||
| 	t, err := p.federator.GetTransportForUser(requestingUsername) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("error getting transport for user: %s", err) | ||||
| 	} | ||||
| 
 | ||||
| 	// fetch the header and avatar | ||||
| 	if err := p.fetchHeaderAndAviForAccount(account, t); err != nil { | ||||
| 		// if this doesn't work, just skip it -- we can do it later | ||||
| 		l.Debugf("error fetching header/avi for account: %s", err) | ||||
| 	} | ||||
| 
 | ||||
| 	if err := p.db.UpdateByID(account.ID, account); err != nil { | ||||
| 		return fmt.Errorf("error updating account in database: %s", err) | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue