summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com>2021-05-23 18:07:04 +0200
committerLibravatar GitHub <noreply@github.com>2021-05-23 18:07:04 +0200
commitee65d19ff343134c55ca968114dcbfe4b7b4431d (patch)
tree778141fb4dc2ff17c78594663b0c0cd2a47f79fc /internal/typeutils
parentsmall fiddling to allow whalebird to work (a bit) (diff)
downloadgotosocial-ee65d19ff343134c55ca968114dcbfe4b7b4431d.tar.xz
status deletes, profile updates (#30)
1. Proper DELETE of federated statuses (not yet deleting all the media and stuff -- i still have to implement this -- but the actual status is toast). 2. Proper UPDATE of profiles. When you change your profile picture on your remote instance, that will now register properly in GoToSocial. 3. Scrolling down the home timeline - it no longer just sort of ends, and will keep loading older statuses as you scroll. 4. Little bugfixes -- still had some nil pointer errors when dereferencing remote accounts.
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/asextractionutil.go35
-rw-r--r--internal/typeutils/astointernal.go22
-rw-r--r--internal/typeutils/astointernal_test.go4
-rw-r--r--internal/typeutils/converter.go8
-rw-r--r--internal/typeutils/internaltofrontend.go6
5 files changed, 47 insertions, 28 deletions
diff --git a/internal/typeutils/asextractionutil.go b/internal/typeutils/asextractionutil.go
index 1c04272e0..b3e6eb2c4 100644
--- a/internal/typeutils/asextractionutil.go
+++ b/internal/typeutils/asextractionutil.go
@@ -29,7 +29,6 @@ import (
"time"
"github.com/go-fed/activity/pub"
- "github.com/go-fed/activity/streams"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
@@ -63,6 +62,9 @@ func extractName(i withName) (string, error) {
func extractInReplyToURI(i withInReplyTo) (*url.URL, error) {
inReplyToProp := i.GetActivityStreamsInReplyTo()
+ if inReplyToProp == nil {
+ return nil, errors.New("in reply to prop was nil")
+ }
for iter := inReplyToProp.Begin(); iter != inReplyToProp.End(); iter = iter.Next() {
if iter.IsIRI() {
if iter.GetIRI() != nil {
@@ -76,6 +78,9 @@ func extractInReplyToURI(i withInReplyTo) (*url.URL, error) {
func extractTos(i withTo) ([]*url.URL, error) {
to := []*url.URL{}
toProp := i.GetActivityStreamsTo()
+ if toProp == nil {
+ return nil, errors.New("toProp was nil")
+ }
for iter := toProp.Begin(); iter != toProp.End(); iter = iter.Next() {
if iter.IsIRI() {
if iter.GetIRI() != nil {
@@ -89,6 +94,9 @@ func extractTos(i withTo) ([]*url.URL, error) {
func extractCCs(i withCC) ([]*url.URL, error) {
cc := []*url.URL{}
ccProp := i.GetActivityStreamsCc()
+ if ccProp == nil {
+ return cc, nil
+ }
for iter := ccProp.Begin(); iter != ccProp.End(); iter = iter.Next() {
if iter.IsIRI() {
if iter.GetIRI() != nil {
@@ -101,6 +109,9 @@ func extractCCs(i withCC) ([]*url.URL, error) {
func extractAttributedTo(i withAttributedTo) (*url.URL, error) {
attributedToProp := i.GetActivityStreamsAttributedTo()
+ if attributedToProp == nil {
+ return nil, errors.New("attributedToProp was nil")
+ }
for iter := attributedToProp.Begin(); iter != attributedToProp.End(); iter = iter.Next() {
if iter.IsIRI() {
if iter.GetIRI() != nil {
@@ -302,27 +313,21 @@ func extractContent(i withContent) (string, error) {
func extractAttachments(i withAttachment) ([]*gtsmodel.MediaAttachment, error) {
attachments := []*gtsmodel.MediaAttachment{}
-
attachmentProp := i.GetActivityStreamsAttachment()
+ if attachmentProp == nil {
+ return attachments, nil
+ }
for iter := attachmentProp.Begin(); iter != attachmentProp.End(); iter = iter.Next() {
-
t := iter.GetType()
if t == nil {
- fmt.Printf("\n\n\nGetType() nil\n\n\n")
continue
}
-
- m, _ := streams.Serialize(t)
- fmt.Printf("\n\n\n%s\n\n\n", m)
-
attachmentable, ok := t.(Attachmentable)
if !ok {
- fmt.Printf("\n\n\nnot attachmentable\n\n\n")
continue
}
attachment, err := extractAttachment(attachmentable)
if err != nil {
- fmt.Printf("\n\n\n%s\n\n\n", err)
continue
}
attachments = append(attachments, attachment)
@@ -373,8 +378,10 @@ func extractAttachment(i Attachmentable) (*gtsmodel.MediaAttachment, error) {
func extractHashtags(i withTag) ([]*gtsmodel.Tag, error) {
tags := []*gtsmodel.Tag{}
-
tagsProp := i.GetActivityStreamsTag()
+ if tagsProp == nil {
+ return tags, nil
+ }
for iter := tagsProp.Begin(); iter != tagsProp.End(); iter = iter.Next() {
t := iter.GetType()
if t == nil {
@@ -421,6 +428,9 @@ func extractHashtag(i Hashtaggable) (*gtsmodel.Tag, error) {
func extractEmojis(i withTag) ([]*gtsmodel.Emoji, error) {
emojis := []*gtsmodel.Emoji{}
tagsProp := i.GetActivityStreamsTag()
+ if tagsProp == nil {
+ return emojis, nil
+ }
for iter := tagsProp.Begin(); iter != tagsProp.End(); iter = iter.Next() {
t := iter.GetType()
if t == nil {
@@ -478,6 +488,9 @@ func extractEmoji(i Emojiable) (*gtsmodel.Emoji, error) {
func extractMentions(i withTag) ([]*gtsmodel.Mention, error) {
mentions := []*gtsmodel.Mention{}
tagsProp := i.GetActivityStreamsTag()
+ if tagsProp == nil {
+ return mentions, nil
+ }
for iter := tagsProp.Begin(); iter != tagsProp.End(); iter = iter.Next() {
t := iter.GetType()
if t == nil {
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go
index 7eb3f5927..dcc2674cd 100644
--- a/internal/typeutils/astointernal.go
+++ b/internal/typeutils/astointernal.go
@@ -28,7 +28,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-func (c *converter) ASRepresentationToAccount(accountable Accountable) (*gtsmodel.Account, error) {
+func (c *converter) ASRepresentationToAccount(accountable Accountable, update bool) (*gtsmodel.Account, error) {
// first check if we actually already know this account
uriProp := accountable.GetJSONLDId()
if uriProp == nil || !uriProp.IsIRI() {
@@ -37,17 +37,19 @@ func (c *converter) ASRepresentationToAccount(accountable Accountable) (*gtsmode
uri := uriProp.GetIRI()
acct := &gtsmodel.Account{}
- err := c.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String()}}, acct)
- if err == nil {
- // we already know this account so we can skip generating it
- return acct, nil
- }
- if _, ok := err.(db.ErrNoEntries); !ok {
- // we don't know the account and there's been a real error
- return nil, fmt.Errorf("error getting account with uri %s from the database: %s", uri.String(), err)
+ if !update {
+ err := c.db.GetWhere([]db.Where{{Key: "uri", Value: uri.String()}}, acct)
+ if err == nil {
+ // we already know this account so we can skip generating it
+ return acct, nil
+ }
+ if _, ok := err.(db.ErrNoEntries); !ok {
+ // we don't know the account and there's been a real error
+ return nil, fmt.Errorf("error getting account with uri %s from the database: %s", uri.String(), err)
+ }
}
- // we don't know the account so we need to generate it from the person -- at least we already have the URI!
+ // we don't know the account, or we're being told to update it, so we need to generate it from the person -- at least we already have the URI!
acct = &gtsmodel.Account{}
acct.URI = uri.String()
diff --git a/internal/typeutils/astointernal_test.go b/internal/typeutils/astointernal_test.go
index f1287e027..9d6ce4e0a 100644
--- a/internal/typeutils/astointernal_test.go
+++ b/internal/typeutils/astointernal_test.go
@@ -349,7 +349,7 @@ func (suite *ASToInternalTestSuite) TestParsePerson() {
testPerson := suite.people["new_person_1"]
- acct, err := suite.typeconverter.ASRepresentationToAccount(testPerson)
+ acct, err := suite.typeconverter.ASRepresentationToAccount(testPerson, false)
assert.NoError(suite.T(), err)
fmt.Printf("%+v", acct)
@@ -367,7 +367,7 @@ func (suite *ASToInternalTestSuite) TestParseGargron() {
rep, ok := t.(typeutils.Accountable)
assert.True(suite.T(), ok)
- acct, err := suite.typeconverter.ASRepresentationToAccount(rep)
+ acct, err := suite.typeconverter.ASRepresentationToAccount(rep, false)
assert.NoError(suite.T(), err)
fmt.Printf("%+v", acct)
diff --git a/internal/typeutils/converter.go b/internal/typeutils/converter.go
index ac2ce4317..63e201ded 100644
--- a/internal/typeutils/converter.go
+++ b/internal/typeutils/converter.go
@@ -95,8 +95,12 @@ type TypeConverter interface {
ACTIVITYSTREAMS MODEL TO INTERNAL (gts) MODEL
*/
- // ASPersonToAccount converts a remote account/person/application representation into a gts model account
- ASRepresentationToAccount(accountable Accountable) (*gtsmodel.Account, error)
+ // ASPersonToAccount converts a remote account/person/application representation into a gts model account.
+ //
+ // If update is false, and the account is already known in the database, then the existing account entry will be returned.
+ // If update is true, then even if the account is already known, all fields in the accountable will be parsed and a new *gtsmodel.Account
+ // will be generated. This is useful when one needs to force refresh of an account, eg., during an Update of a Profile.
+ ASRepresentationToAccount(accountable Accountable, update bool) (*gtsmodel.Account, error)
// ASStatus converts a remote activitystreams 'status' representation into a gts model status.
ASStatusToStatus(statusable Statusable) (*gtsmodel.Status, error)
// ASFollowToFollowRequest converts a remote activitystreams `follow` representation into gts model follow request.
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 4891e31ee..7fbe9eb3f 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -233,9 +233,9 @@ func (c *converter) MentionToMasto(m *gtsmodel.Mention) (model.Mention, error) {
var acct string
if local {
- acct = fmt.Sprintf("@%s", target.Username)
+ acct = target.Username
} else {
- acct = fmt.Sprintf("@%s@%s", target.Username, target.Domain)
+ acct = fmt.Sprintf("%s@%s", target.Username, target.Domain)
}
return model.Mention{
@@ -567,7 +567,7 @@ func (c *converter) InstanceToMasto(i *gtsmodel.Instance) (*model.Instance, erro
if i.ContactAccountID != "" {
ia := &gtsmodel.Account{}
if err := c.db.GetByID(i.ContactAccountID, ia); err == nil {
- ma, err := c.AccountToMastoPublic(ia)
+ ma, err := c.AccountToMastoPublic(ia)
if err == nil {
mi.ContactAccount = ma
}