2023-03-12 15:00:57 +00:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-05-08 12:25:55 +00:00
|
|
|
|
|
|
|
package typeutils
|
|
|
|
|
|
|
|
import (
|
2021-08-25 13:34:33 +00:00
|
|
|
"context"
|
2021-05-08 12:25:55 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2023-01-25 10:12:27 +00:00
|
|
|
"net/url"
|
2021-12-20 17:42:19 +00:00
|
|
|
|
2022-09-23 19:27:35 +00:00
|
|
|
"github.com/miekg/dns"
|
2021-08-10 11:32:39 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
2023-01-25 10:12:27 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
2021-05-08 12:25:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/db"
|
2023-06-17 15:49:11 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
2021-05-08 12:25:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
2022-07-19 08:47:55 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
2023-01-25 10:12:27 +00:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/uris"
|
2021-05-08 12:25:55 +00:00
|
|
|
)
|
|
|
|
|
2023-02-03 20:03:05 +00:00
|
|
|
func (c *converter) ASRepresentationToAccount(ctx context.Context, accountable ap.Accountable, accountDomain string) (*gtsmodel.Account, error) {
|
2021-05-08 12:25:55 +00:00
|
|
|
// first check if we actually already know this account
|
|
|
|
uriProp := accountable.GetJSONLDId()
|
|
|
|
if uriProp == nil || !uriProp.IsIRI() {
|
|
|
|
return nil, errors.New("no id property found on person, or id was not an iri")
|
|
|
|
}
|
|
|
|
uri := uriProp.GetIRI()
|
|
|
|
|
2021-05-23 16:07:04 +00:00
|
|
|
// 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!
|
2021-08-20 10:26:56 +00:00
|
|
|
acct := >smodel.Account{}
|
2021-05-08 12:25:55 +00:00
|
|
|
acct.URI = uri.String()
|
|
|
|
|
|
|
|
// Username aka preferredUsername
|
|
|
|
// We need this one so bail if it's not set.
|
2021-08-10 11:32:39 +00:00
|
|
|
username, err := ap.ExtractPreferredUsername(accountable)
|
2021-05-08 12:25:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't extract username: %s", err)
|
|
|
|
}
|
|
|
|
acct.Username = username
|
|
|
|
|
|
|
|
// Domain
|
2022-06-11 09:01:34 +00:00
|
|
|
if accountDomain != "" {
|
|
|
|
acct.Domain = accountDomain
|
|
|
|
} else {
|
|
|
|
acct.Domain = uri.Host
|
|
|
|
}
|
2021-05-08 12:25:55 +00:00
|
|
|
|
|
|
|
// avatar aka icon
|
|
|
|
// if this one isn't extractable in a format we recognise we'll just skip it
|
2023-06-17 15:49:11 +00:00
|
|
|
if avatarURL, err := ap.ExtractIconURI(accountable); err == nil {
|
2021-05-08 12:25:55 +00:00
|
|
|
acct.AvatarRemoteURL = avatarURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// header aka image
|
|
|
|
// if this one isn't extractable in a format we recognise we'll just skip it
|
2023-06-17 15:49:11 +00:00
|
|
|
if headerURL, err := ap.ExtractImageURI(accountable); err == nil {
|
2021-05-08 12:25:55 +00:00
|
|
|
acct.HeaderRemoteURL = headerURL.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// display name aka name
|
|
|
|
// we default to the username, but take the more nuanced name property if it exists
|
2023-02-02 15:41:02 +00:00
|
|
|
if displayName := ap.ExtractName(accountable); displayName != "" {
|
2021-05-08 12:25:55 +00:00
|
|
|
acct.DisplayName = displayName
|
2023-02-02 15:41:02 +00:00
|
|
|
} else {
|
|
|
|
acct.DisplayName = username
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
2022-09-26 09:56:01 +00:00
|
|
|
// account emojis (used in bio, display name, fields)
|
|
|
|
if emojis, err := ap.ExtractEmojis(accountable); err != nil {
|
2023-02-17 11:02:29 +00:00
|
|
|
log.Infof(nil, "error extracting account emojis: %s", err)
|
2022-09-26 09:56:01 +00:00
|
|
|
} else {
|
|
|
|
acct.Emojis = emojis
|
|
|
|
}
|
|
|
|
|
2023-05-09 10:16:10 +00:00
|
|
|
// fields aka attachment array
|
|
|
|
acct.Fields = ap.ExtractFields(accountable)
|
2021-05-08 12:25:55 +00:00
|
|
|
|
|
|
|
// note aka summary
|
2023-02-02 15:41:02 +00:00
|
|
|
acct.Note = ap.ExtractSummary(accountable)
|
2021-05-08 12:25:55 +00:00
|
|
|
|
|
|
|
// check for bot and actor type
|
2021-05-21 13:48:26 +00:00
|
|
|
switch accountable.GetTypeName() {
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActorPerson, ap.ActorGroup, ap.ActorOrganization:
|
2021-05-08 12:25:55 +00:00
|
|
|
// people, groups, and organizations aren't bots
|
2022-08-15 10:35:05 +00:00
|
|
|
bot := false
|
|
|
|
acct.Bot = &bot
|
2021-05-08 12:25:55 +00:00
|
|
|
// apps and services are
|
2021-08-31 13:59:12 +00:00
|
|
|
case ap.ActorApplication, ap.ActorService:
|
2022-08-15 10:35:05 +00:00
|
|
|
bot := true
|
|
|
|
acct.Bot = &bot
|
2021-05-08 12:25:55 +00:00
|
|
|
default:
|
|
|
|
// we don't know what this is!
|
2021-08-31 13:59:12 +00:00
|
|
|
return nil, fmt.Errorf("type name %s not recognised or not convertible to ap.ActivityStreamsActor", accountable.GetTypeName())
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
2021-05-21 13:48:26 +00:00
|
|
|
acct.ActorType = accountable.GetTypeName()
|
2021-05-08 12:25:55 +00:00
|
|
|
|
2022-08-15 10:35:05 +00:00
|
|
|
// assume not memorial (todo)
|
|
|
|
memorial := false
|
|
|
|
acct.Memorial = &memorial
|
|
|
|
|
|
|
|
// assume not sensitive (todo)
|
|
|
|
sensitive := false
|
|
|
|
acct.Sensitive = &sensitive
|
|
|
|
|
|
|
|
// assume not hide collections (todo)
|
|
|
|
hideCollections := false
|
|
|
|
acct.HideCollections = &hideCollections
|
|
|
|
|
2021-08-23 10:46:05 +00:00
|
|
|
// locked aka manuallyApprovesFollowers
|
2022-08-15 10:35:05 +00:00
|
|
|
locked := true
|
|
|
|
acct.Locked = &locked // assume locked by default
|
2021-08-23 10:46:05 +00:00
|
|
|
maf := accountable.GetActivityStreamsManuallyApprovesFollowers()
|
|
|
|
if maf != nil && maf.IsXMLSchemaBoolean() {
|
2022-08-15 10:35:05 +00:00
|
|
|
locked = maf.Get()
|
|
|
|
acct.Locked = &locked
|
2021-08-23 10:46:05 +00:00
|
|
|
}
|
2021-05-08 12:25:55 +00:00
|
|
|
|
|
|
|
// discoverable
|
|
|
|
// default to false -- take custom value if it's set though
|
2022-08-15 10:35:05 +00:00
|
|
|
discoverable := false
|
|
|
|
acct.Discoverable = &discoverable
|
|
|
|
d, err := ap.ExtractDiscoverable(accountable)
|
2021-05-08 12:25:55 +00:00
|
|
|
if err == nil {
|
2022-08-15 10:35:05 +00:00
|
|
|
acct.Discoverable = &d
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 12:00:39 +00:00
|
|
|
// assume not rss feed
|
|
|
|
enableRSS := false
|
|
|
|
acct.EnableRSS = &enableRSS
|
|
|
|
|
2021-05-08 12:25:55 +00:00
|
|
|
// url property
|
2021-08-10 11:32:39 +00:00
|
|
|
url, err := ap.ExtractURL(accountable)
|
2021-06-13 16:42:28 +00:00
|
|
|
if err == nil {
|
|
|
|
// take the URL if we can find it
|
|
|
|
acct.URL = url.String()
|
|
|
|
} else {
|
|
|
|
// otherwise just take the account URI as the URL
|
|
|
|
acct.URL = uri.String()
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InboxURI
|
2021-05-21 21:04:59 +00:00
|
|
|
if accountable.GetActivityStreamsInbox() != nil && accountable.GetActivityStreamsInbox().GetIRI() != nil {
|
2021-05-09 18:34:27 +00:00
|
|
|
acct.InboxURI = accountable.GetActivityStreamsInbox().GetIRI().String()
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 20:03:05 +00:00
|
|
|
// SharedInboxURI:
|
|
|
|
// only trust shared inbox if it has at least two domains,
|
|
|
|
// from the right, in common with the domain of the account
|
|
|
|
if sharedInboxURI := ap.ExtractSharedInbox(accountable); // nocollapse
|
|
|
|
sharedInboxURI != nil && dns.CompareDomainName(acct.Domain, sharedInboxURI.Host) >= 2 {
|
|
|
|
sharedInbox := sharedInboxURI.String()
|
2022-09-23 19:27:35 +00:00
|
|
|
acct.SharedInboxURI = &sharedInbox
|
|
|
|
}
|
|
|
|
|
2021-05-08 12:25:55 +00:00
|
|
|
// OutboxURI
|
2021-05-09 18:34:27 +00:00
|
|
|
if accountable.GetActivityStreamsOutbox() != nil && accountable.GetActivityStreamsOutbox().GetIRI() != nil {
|
|
|
|
acct.OutboxURI = accountable.GetActivityStreamsOutbox().GetIRI().String()
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FollowingURI
|
2021-05-09 18:34:27 +00:00
|
|
|
if accountable.GetActivityStreamsFollowing() != nil && accountable.GetActivityStreamsFollowing().GetIRI() != nil {
|
|
|
|
acct.FollowingURI = accountable.GetActivityStreamsFollowing().GetIRI().String()
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FollowersURI
|
2021-05-09 18:34:27 +00:00
|
|
|
if accountable.GetActivityStreamsFollowers() != nil && accountable.GetActivityStreamsFollowers().GetIRI() != nil {
|
|
|
|
acct.FollowersURI = accountable.GetActivityStreamsFollowers().GetIRI().String()
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
2023-03-01 17:52:44 +00:00
|
|
|
// FeaturedURI aka pinned collection:
|
|
|
|
// Only trust featured URI if it has at least two domains,
|
|
|
|
// from the right, in common with the domain of the account
|
|
|
|
if featured := accountable.GetTootFeatured(); featured != nil && featured.IsIRI() {
|
|
|
|
if featuredURI := featured.GetIRI(); // nocollapse
|
|
|
|
featuredURI != nil && dns.CompareDomainName(acct.Domain, featuredURI.Host) >= 2 {
|
|
|
|
acct.FeaturedCollectionURI = featuredURI.String()
|
|
|
|
}
|
2021-05-08 12:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: FeaturedTagsURI
|
|
|
|
|
|
|
|
// TODO: alsoKnownAs
|
|
|
|
|
|
|
|
// publicKey
|
2023-06-13 14:47:56 +00:00
|
|
|
pkey, pkeyURL, pkeyOwnerID, err := ap.ExtractPublicKey(accountable)
|
2021-05-08 12:25:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("couldn't get public key for person %s: %s", uri.String(), err)
|
|
|
|
}
|
2023-06-13 14:47:56 +00:00
|
|
|
|
|
|
|
if pkeyOwnerID.String() != acct.URI {
|
|
|
|
return nil, fmt.Errorf("public key %s was owned by %s and not by %s", pkeyURL, pkeyOwnerID, acct.URI)
|
|
|
|
}
|
|
|
|
|
2021-05-08 12:25:55 +00:00
|
|
|
acct.PublicKey = pkey
|
|
|
|
acct.PublicKeyURI = pkeyURL.String()
|
|
|
|
|
|
|
|
return acct, nil
|
|
|
|
}
|
2021-05-15 09:58:11 +00:00
|
|
|
|
2023-02-02 15:41:02 +00:00
|
|
|
func (c *converter) extractAttachments(i ap.WithAttachment) []*gtsmodel.MediaAttachment {
|
|
|
|
attachmentProp := i.GetActivityStreamsAttachment()
|
|
|
|
if attachmentProp == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
attachments := make([]*gtsmodel.MediaAttachment, 0, attachmentProp.Len())
|
|
|
|
|
|
|
|
for iter := attachmentProp.Begin(); iter != attachmentProp.End(); iter = iter.Next() {
|
|
|
|
t := iter.GetType()
|
|
|
|
if t == nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
attachmentable, ok := t.(ap.Attachmentable)
|
|
|
|
if !ok {
|
2023-02-17 11:02:29 +00:00
|
|
|
log.Error(nil, "ap attachment was not attachmentable")
|
2023-02-02 15:41:02 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
attachment, err := ap.ExtractAttachment(attachmentable)
|
|
|
|
if err != nil {
|
2023-02-17 11:02:29 +00:00
|
|
|
log.Errorf(nil, "error extracting attachment: %s", err)
|
2023-02-02 15:41:02 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
attachments = append(attachments, attachment)
|
|
|
|
}
|
|
|
|
|
|
|
|
return attachments
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (c *converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusable) (*gtsmodel.Status, error) {
|
2023-06-24 07:32:10 +00:00
|
|
|
status := new(gtsmodel.Status)
|
2021-05-15 09:58:11 +00:00
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.URI
|
|
|
|
//
|
|
|
|
// ActivityPub ID/URI of this status.
|
|
|
|
idProp := statusable.GetJSONLDId()
|
|
|
|
if idProp == nil || !idProp.IsIRI() {
|
|
|
|
return nil, gtserror.New("no id property found, or id was not an iri")
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
2023-06-24 07:32:10 +00:00
|
|
|
status.URI = idProp.GetIRI().String()
|
2021-05-15 09:58:11 +00:00
|
|
|
|
2023-02-17 19:05:43 +00:00
|
|
|
l := log.WithContext(ctx).
|
|
|
|
WithField("statusURI", status.URI)
|
2021-08-29 10:03:08 +00:00
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.URL
|
|
|
|
//
|
|
|
|
// Web URL of this status (optional).
|
2022-05-23 15:10:48 +00:00
|
|
|
if statusURL, err := ap.ExtractURL(statusable); err == nil {
|
2021-05-15 09:58:11 +00:00
|
|
|
status.URL = statusURL.String()
|
2022-05-23 15:10:48 +00:00
|
|
|
} else {
|
2023-06-24 07:32:10 +00:00
|
|
|
status.URL = status.URI // Fall back to the URI.
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.Content
|
|
|
|
//
|
|
|
|
// The (html-formatted) content of this status.
|
2022-05-23 15:12:46 +00:00
|
|
|
status.Content = ap.ExtractContent(statusable)
|
2021-05-15 09:58:11 +00:00
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.Attachments
|
|
|
|
//
|
|
|
|
// Media attachments for later dereferencing.
|
2023-02-02 15:41:02 +00:00
|
|
|
status.Attachments = c.extractAttachments(statusable)
|
2021-05-15 09:58:11 +00:00
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.Hashtags
|
|
|
|
//
|
|
|
|
// Hashtags for later dereferencing.
|
2021-08-29 10:03:08 +00:00
|
|
|
if hashtags, err := ap.ExtractHashtags(statusable); err != nil {
|
2023-06-24 07:32:10 +00:00
|
|
|
l.Infof("error extracting hashtags: %q", err)
|
2021-08-29 10:03:08 +00:00
|
|
|
} else {
|
2021-08-20 10:26:56 +00:00
|
|
|
status.Tags = hashtags
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.Emojis
|
|
|
|
//
|
|
|
|
// Custom emojis for later dereferencing.
|
2021-08-29 10:03:08 +00:00
|
|
|
if emojis, err := ap.ExtractEmojis(statusable); err != nil {
|
2023-06-24 07:32:10 +00:00
|
|
|
l.Infof("error extracting emojis: %q", err)
|
2021-08-29 10:03:08 +00:00
|
|
|
} else {
|
2021-08-20 10:26:56 +00:00
|
|
|
status.Emojis = emojis
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.Mentions
|
|
|
|
//
|
|
|
|
// Mentions of other accounts for later dereferencing.
|
2021-08-29 10:03:08 +00:00
|
|
|
if mentions, err := ap.ExtractMentions(statusable); err != nil {
|
2023-06-24 07:32:10 +00:00
|
|
|
l.Infof("error extracting mentions: %q", err)
|
2021-08-29 10:03:08 +00:00
|
|
|
} else {
|
2021-08-20 10:26:56 +00:00
|
|
|
status.Mentions = mentions
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.ContentWarning
|
|
|
|
//
|
|
|
|
// Topic or content warning for this status;
|
|
|
|
// prefer Summary, fall back to Name.
|
2023-02-02 15:41:02 +00:00
|
|
|
if summary := ap.ExtractSummary(statusable); summary != "" {
|
|
|
|
status.ContentWarning = summary
|
2021-08-29 10:03:08 +00:00
|
|
|
} else {
|
2023-02-02 15:41:02 +00:00
|
|
|
status.ContentWarning = ap.ExtractName(statusable)
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.Published
|
|
|
|
//
|
|
|
|
// Publication time of this status. Thanks to
|
|
|
|
// db defaults, will fall back to now if not set.
|
2021-08-10 11:32:39 +00:00
|
|
|
published, err := ap.ExtractPublished(statusable)
|
2021-08-29 10:03:08 +00:00
|
|
|
if err != nil {
|
2023-06-24 07:32:10 +00:00
|
|
|
l.Infof("error extracting published: %q", err)
|
2021-08-29 10:03:08 +00:00
|
|
|
} else {
|
2021-05-15 09:58:11 +00:00
|
|
|
status.CreatedAt = published
|
2021-08-25 13:34:33 +00:00
|
|
|
status.UpdatedAt = published
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.AccountURI
|
|
|
|
// status.AccountID
|
|
|
|
// status.Account
|
|
|
|
//
|
|
|
|
// Account that created the status. Assume we have
|
|
|
|
// this in the db by the time this function is called,
|
|
|
|
// error if we don't.
|
2023-06-17 15:49:11 +00:00
|
|
|
attributedTo, err := ap.ExtractAttributedToURI(statusable)
|
2021-05-15 09:58:11 +00:00
|
|
|
if err != nil {
|
2023-06-24 07:32:10 +00:00
|
|
|
return nil, gtserror.Newf("%w", err)
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
2023-06-24 07:32:10 +00:00
|
|
|
accountURI := attributedTo.String()
|
2021-05-15 09:58:11 +00:00
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
account, err := c.db.GetAccountByURI(ctx, accountURI)
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2023-06-24 07:32:10 +00:00
|
|
|
err = gtserror.Newf("db error getting status author account %s: %w", accountURI, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
status.AccountURI = accountURI
|
|
|
|
status.AccountID = account.ID
|
|
|
|
status.Account = account
|
|
|
|
|
|
|
|
// status.InReplyToURI
|
|
|
|
// status.InReplyToID
|
|
|
|
// status.InReplyTo
|
|
|
|
// status.InReplyToAccountID
|
|
|
|
// status.InReplyToAccount
|
|
|
|
//
|
|
|
|
// Status that this status replies to, if applicable.
|
|
|
|
// If we don't have this status in the database, we
|
|
|
|
// just set the URI and assume we can deref it later.
|
|
|
|
if uri := ap.ExtractInReplyToURI(statusable); uri != nil {
|
|
|
|
inReplyToURI := uri.String()
|
|
|
|
status.InReplyToURI = inReplyToURI
|
|
|
|
|
|
|
|
// Check if we already have the replied-to status.
|
|
|
|
inReplyTo, err := c.db.GetStatusByURI(ctx, inReplyToURI)
|
|
|
|
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
|
|
|
// Real database error.
|
|
|
|
err = gtserror.Newf("db error getting replied-to status %s: %w", inReplyToURI, err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if inReplyTo != nil {
|
|
|
|
// We have it in the DB! Set
|
|
|
|
// appropriate fields here and now.
|
|
|
|
status.InReplyToID = inReplyTo.ID
|
|
|
|
status.InReplyTo = inReplyTo
|
|
|
|
status.InReplyToAccountID = inReplyTo.AccountID
|
|
|
|
status.InReplyToAccount = inReplyTo.Account
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// status.Visibility
|
|
|
|
visibility, err := ap.ExtractVisibility(
|
|
|
|
statusable,
|
|
|
|
status.Account.FollowersURI,
|
|
|
|
)
|
2021-05-15 09:58:11 +00:00
|
|
|
if err != nil {
|
2023-06-24 07:32:10 +00:00
|
|
|
err = gtserror.Newf("error extracting visibility: %w", err)
|
|
|
|
return nil, err
|
2021-05-15 09:58:11 +00:00
|
|
|
}
|
|
|
|
status.Visibility = visibility
|
|
|
|
|
2023-06-24 07:32:10 +00:00
|
|
|
// Advanced visibility toggles for this status.
|
|
|
|
//
|
|
|
|
// TODO: a lot of work to be done here -- a new type
|
|
|
|
// needs to be created for this in go-fed/activity.
|
|
|
|
// Until this is implemented, assume all true.
|
|
|
|
var trueBool = func() *bool { b := true; return &b }
|
|
|
|
status.Federated = trueBool()
|
|
|
|
status.Boostable = trueBool()
|
|
|
|
status.Replyable = trueBool()
|
|
|
|
status.Likeable = trueBool()
|
|
|
|
|
|
|
|
// status.Sensitive
|
|
|
|
status.Sensitive = func() *bool {
|
|
|
|
s := ap.ExtractSensitive(statusable)
|
|
|
|
return &s
|
|
|
|
}()
|
2021-05-15 09:58:11 +00:00
|
|
|
|
|
|
|
// language
|
2023-06-24 07:32:10 +00:00
|
|
|
// TODO: we might be able to extract this from the contentMap field
|
2021-05-15 09:58:11 +00:00
|
|
|
|
|
|
|
// ActivityStreamsType
|
2021-05-21 13:48:26 +00:00
|
|
|
status.ActivityStreamsType = statusable.GetTypeName()
|
2021-05-15 09:58:11 +00:00
|
|
|
|
|
|
|
return status, nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (c *converter) ASFollowToFollowRequest(ctx context.Context, followable ap.Followable) (*gtsmodel.FollowRequest, error) {
|
2021-05-15 09:58:11 +00:00
|
|
|
idProp := followable.GetJSONLDId()
|
|
|
|
if idProp == nil || !idProp.IsIRI() {
|
|
|
|
return nil, errors.New("no id property set on follow, or was not an iri")
|
|
|
|
}
|
|
|
|
uri := idProp.GetIRI().String()
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
origin, err := ap.ExtractActorURI(followable)
|
2021-05-15 09:58:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("error extracting actor property from follow")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
originAccount, err := c.db.GetAccountByURI(ctx, origin.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-05-15 09:58:11 +00:00
|
|
|
return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err)
|
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
target, err := ap.ExtractObjectURI(followable)
|
2021-05-15 09:58:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("error extracting object property from follow")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
targetAccount, err := c.db.GetAccountByURI(ctx, target.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-05-15 09:58:11 +00:00
|
|
|
return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
followRequest := >smodel.FollowRequest{
|
|
|
|
URI: uri,
|
|
|
|
AccountID: originAccount.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
return followRequest, nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (c *converter) ASFollowToFollow(ctx context.Context, followable ap.Followable) (*gtsmodel.Follow, error) {
|
2021-05-21 13:48:26 +00:00
|
|
|
idProp := followable.GetJSONLDId()
|
|
|
|
if idProp == nil || !idProp.IsIRI() {
|
|
|
|
return nil, errors.New("no id property set on follow, or was not an iri")
|
|
|
|
}
|
|
|
|
uri := idProp.GetIRI().String()
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
origin, err := ap.ExtractActorURI(followable)
|
2021-05-21 13:48:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("error extracting actor property from follow")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
originAccount, err := c.db.GetAccountByURI(ctx, origin.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-05-21 13:48:26 +00:00
|
|
|
return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err)
|
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
target, err := ap.ExtractObjectURI(followable)
|
2021-05-21 13:48:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("error extracting object property from follow")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
targetAccount, err := c.db.GetAccountByURI(ctx, target.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-05-21 13:48:26 +00:00
|
|
|
return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
follow := >smodel.Follow{
|
|
|
|
URI: uri,
|
|
|
|
AccountID: originAccount.ID,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
}
|
|
|
|
|
|
|
|
return follow, nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (c *converter) ASLikeToFave(ctx context.Context, likeable ap.Likeable) (*gtsmodel.StatusFave, error) {
|
2021-05-27 14:06:24 +00:00
|
|
|
idProp := likeable.GetJSONLDId()
|
|
|
|
if idProp == nil || !idProp.IsIRI() {
|
|
|
|
return nil, errors.New("no id property set on like, or was not an iri")
|
|
|
|
}
|
|
|
|
uri := idProp.GetIRI().String()
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
origin, err := ap.ExtractActorURI(likeable)
|
2021-05-27 14:06:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("error extracting actor property from like")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
originAccount, err := c.db.GetAccountByURI(ctx, origin.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-05-27 14:06:24 +00:00
|
|
|
return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err)
|
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
target, err := ap.ExtractObjectURI(likeable)
|
2021-05-27 14:06:24 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("error extracting object property from like")
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
targetStatus, err := c.db.GetStatusByURI(ctx, target.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2021-05-27 14:06:24 +00:00
|
|
|
return nil, fmt.Errorf("error extracting status with uri %s from the database: %s", target.String(), err)
|
|
|
|
}
|
|
|
|
|
2021-08-20 10:26:56 +00:00
|
|
|
var targetAccount *gtsmodel.Account
|
|
|
|
if targetStatus.Account != nil {
|
|
|
|
targetAccount = targetStatus.Account
|
|
|
|
} else {
|
2021-08-25 13:34:33 +00:00
|
|
|
a, err := c.db.GetAccountByID(ctx, targetStatus.AccountID)
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error extracting account with id %s from the database: %s", targetStatus.AccountID, err)
|
|
|
|
}
|
|
|
|
targetAccount = a
|
2021-05-27 14:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return >smodel.StatusFave{
|
2021-08-20 10:26:56 +00:00
|
|
|
AccountID: originAccount.ID,
|
|
|
|
Account: originAccount,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
TargetAccount: targetAccount,
|
|
|
|
StatusID: targetStatus.ID,
|
|
|
|
Status: targetStatus,
|
|
|
|
URI: uri,
|
2021-05-27 14:06:24 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
func (c *converter) ASBlockToBlock(ctx context.Context, blockable ap.Blockable) (*gtsmodel.Block, error) {
|
2021-07-11 14:22:21 +00:00
|
|
|
idProp := blockable.GetJSONLDId()
|
|
|
|
if idProp == nil || !idProp.IsIRI() {
|
|
|
|
return nil, errors.New("ASBlockToBlock: no id property set on block, or was not an iri")
|
|
|
|
}
|
|
|
|
uri := idProp.GetIRI().String()
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
origin, err := ap.ExtractActorURI(blockable)
|
2021-07-11 14:22:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("ASBlockToBlock: error extracting actor property from block")
|
|
|
|
}
|
2021-08-25 13:34:33 +00:00
|
|
|
originAccount, err := c.db.GetAccountByURI(ctx, origin.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err)
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
target, err := ap.ExtractObjectURI(blockable)
|
2021-07-11 14:22:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.New("ASBlockToBlock: error extracting object property from block")
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:34:33 +00:00
|
|
|
targetAccount, err := c.db.GetAccountByURI(ctx, target.String())
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error extracting account with uri %s from the database: %s", origin.String(), err)
|
2021-07-11 14:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return >smodel.Block{
|
|
|
|
AccountID: originAccount.ID,
|
|
|
|
Account: originAccount,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
TargetAccount: targetAccount,
|
|
|
|
URI: uri,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// Implementation note: this function creates and returns a boost WRAPPER
|
|
|
|
// status which references the boosted status in its BoostOf field. No
|
|
|
|
// dereferencing is done on the boosted status by this function. Callers
|
|
|
|
// should look at `status.BoostOf` to see the status being boosted, and do
|
|
|
|
// dereferencing on it as appropriate.
|
|
|
|
//
|
|
|
|
// The returned boolean indicates whether or not the boost has already been
|
|
|
|
// seen before by this instance. If it was, then status.BoostOf should be a
|
|
|
|
// fully filled-out status. If not, then only status.BoostOf.URI will be set.
|
2021-08-25 13:34:33 +00:00
|
|
|
func (c *converter) ASAnnounceToStatus(ctx context.Context, announceable ap.Announceable) (*gtsmodel.Status, bool, error) {
|
2023-06-17 15:49:11 +00:00
|
|
|
// Ensure item has an ID URI set.
|
|
|
|
_, statusURIStr, err := getURI(announceable)
|
|
|
|
if err != nil {
|
|
|
|
err = gtserror.Newf("error extracting URI: %w", err)
|
|
|
|
return nil, false, err
|
|
|
|
}
|
2021-05-28 17:57:04 +00:00
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
var (
|
|
|
|
status *gtsmodel.Status
|
|
|
|
isNew bool
|
|
|
|
)
|
|
|
|
|
|
|
|
// Check if we already have this boost in the database.
|
|
|
|
status, err = c.db.GetStatusByURI(ctx, statusURIStr)
|
|
|
|
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
|
|
|
// Real database error.
|
|
|
|
err = gtserror.Newf("db error trying to get status with uri %s: %w", statusURIStr, err)
|
|
|
|
return nil, isNew, err
|
2021-05-28 17:57:04 +00:00
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
if status != nil {
|
|
|
|
// We already have this status,
|
|
|
|
// no need to proceed further.
|
2021-05-28 17:57:04 +00:00
|
|
|
return status, isNew, nil
|
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// If we reach here, we're dealing
|
|
|
|
// with a boost we haven't seen before.
|
|
|
|
isNew = true
|
|
|
|
|
|
|
|
// Start assembling the new status
|
|
|
|
// (we already know the URI).
|
|
|
|
status = new(gtsmodel.Status)
|
|
|
|
status.URI = statusURIStr
|
|
|
|
|
|
|
|
// Get the URI of the boosted status.
|
|
|
|
boostOfURI, err := ap.ExtractObjectURI(announceable)
|
2021-05-28 17:57:04 +00:00
|
|
|
if err != nil {
|
2023-06-17 15:49:11 +00:00
|
|
|
err = gtserror.Newf("error extracting Object: %w", err)
|
|
|
|
return nil, isNew, err
|
2021-05-28 17:57:04 +00:00
|
|
|
}
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// Set the URI of the boosted status on
|
|
|
|
// the new status, for later dereferencing.
|
|
|
|
boostOf := >smodel.Status{
|
|
|
|
URI: boostOfURI.String(),
|
2021-05-28 17:57:04 +00:00
|
|
|
}
|
2023-06-17 15:49:11 +00:00
|
|
|
status.BoostOf = boostOf
|
2021-05-28 17:57:04 +00:00
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// Extract published time for the boost.
|
2021-08-10 11:32:39 +00:00
|
|
|
published, err := ap.ExtractPublished(announceable)
|
2021-05-28 17:57:04 +00:00
|
|
|
if err != nil {
|
2023-06-17 15:49:11 +00:00
|
|
|
err = gtserror.Newf("error extracting published: %w", err)
|
|
|
|
return nil, isNew, err
|
2021-05-28 17:57:04 +00:00
|
|
|
}
|
|
|
|
status.CreatedAt = published
|
|
|
|
status.UpdatedAt = published
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// Extract URI of the boosting account.
|
|
|
|
accountURI, err := ap.ExtractActorURI(announceable)
|
2021-05-28 17:57:04 +00:00
|
|
|
if err != nil {
|
2023-06-17 15:49:11 +00:00
|
|
|
err = gtserror.Newf("error extracting Actor: %w", err)
|
|
|
|
return nil, isNew, err
|
2021-05-28 17:57:04 +00:00
|
|
|
}
|
2023-06-17 15:49:11 +00:00
|
|
|
accountURIStr := accountURI.String()
|
2021-05-28 17:57:04 +00:00
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// Try to get the boosting account based on the URI.
|
|
|
|
// This should have been dereferenced already before
|
|
|
|
// we hit this point so we can confidently error out
|
|
|
|
// if we don't have it.
|
|
|
|
account, err := c.db.GetAccountByURI(ctx, accountURIStr)
|
2021-08-20 10:26:56 +00:00
|
|
|
if err != nil {
|
2023-06-17 15:49:11 +00:00
|
|
|
err = gtserror.Newf("db error trying to get account with uri %s: %w", accountURIStr, err)
|
|
|
|
return nil, isNew, err
|
2021-05-28 17:57:04 +00:00
|
|
|
}
|
2023-06-17 15:49:11 +00:00
|
|
|
status.AccountID = account.ID
|
|
|
|
status.AccountURI = account.URI
|
|
|
|
status.Account = account
|
2021-05-28 17:57:04 +00:00
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// Calculate intended visibility of the boost.
|
|
|
|
visibility, err := ap.ExtractVisibility(announceable, account.FollowersURI)
|
2021-05-28 17:57:04 +00:00
|
|
|
if err != nil {
|
2023-06-17 15:49:11 +00:00
|
|
|
err = gtserror.Newf("error extracting visibility: %w", err)
|
|
|
|
return nil, isNew, err
|
2021-05-28 17:57:04 +00:00
|
|
|
}
|
|
|
|
status.Visibility = visibility
|
|
|
|
|
2023-06-17 15:49:11 +00:00
|
|
|
// Below IDs will all be included in the
|
|
|
|
// boosted status, so set them empty here.
|
|
|
|
status.AttachmentIDs = make([]string, 0)
|
|
|
|
status.TagIDs = make([]string, 0)
|
|
|
|
status.MentionIDs = make([]string, 0)
|
|
|
|
status.EmojiIDs = make([]string, 0)
|
|
|
|
|
|
|
|
// Remaining fields on the boost status will be taken
|
|
|
|
// from the boosted status; it's not our job to do all
|
|
|
|
// that dereferencing here.
|
2021-05-28 17:57:04 +00:00
|
|
|
return status, isNew, nil
|
|
|
|
}
|
2023-01-25 10:12:27 +00:00
|
|
|
|
|
|
|
func (c *converter) ASFlagToReport(ctx context.Context, flaggable ap.Flaggable) (*gtsmodel.Report, error) {
|
|
|
|
// Extract flag uri.
|
|
|
|
idProp := flaggable.GetJSONLDId()
|
|
|
|
if idProp == nil || !idProp.IsIRI() {
|
|
|
|
return nil, errors.New("ASFlagToReport: no id property set on flaggable, or was not an iri")
|
|
|
|
}
|
|
|
|
uri := idProp.GetIRI().String()
|
|
|
|
|
|
|
|
// Extract account that created the flag / report.
|
|
|
|
// This will usually be an instance actor.
|
2023-06-17 15:49:11 +00:00
|
|
|
actor, err := ap.ExtractActorURI(flaggable)
|
2023-01-25 10:12:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ASFlagToReport: error extracting actor: %w", err)
|
|
|
|
}
|
|
|
|
account, err := c.db.GetAccountByURI(ctx, actor.String())
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ASFlagToReport: error in db fetching account with uri %s: %w", actor.String(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the content of the report.
|
|
|
|
// For Mastodon, this will just be a string, or nothing.
|
|
|
|
// In Misskey's case, it may also contain the URLs of
|
|
|
|
// one or more reported statuses, so extract these too.
|
|
|
|
content := ap.ExtractContent(flaggable)
|
|
|
|
statusURIs := []*url.URL{}
|
|
|
|
inlineURLs := misskeyReportInlineURLs(content)
|
|
|
|
statusURIs = append(statusURIs, inlineURLs...)
|
|
|
|
|
|
|
|
// Extract account and statuses targeted by the flag / report.
|
|
|
|
//
|
|
|
|
// Incoming flags from mastodon usually have a target account uri as
|
|
|
|
// first entry in objects, followed by URIs of one or more statuses.
|
|
|
|
// Misskey on the other hand will just contain the target account uri.
|
|
|
|
// We shouldn't assume the order of the objects will correspond to this,
|
|
|
|
// but we can check that he objects slice contains just one account, and
|
|
|
|
// maybe some statuses.
|
|
|
|
//
|
|
|
|
// Throw away anything that's not relevant to us.
|
2023-06-17 15:49:11 +00:00
|
|
|
objects, err := ap.ExtractObjectURIs(flaggable)
|
2023-01-25 10:12:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ASFlagToReport: error extracting objects: %w", err)
|
|
|
|
}
|
|
|
|
if len(objects) == 0 {
|
|
|
|
return nil, errors.New("ASFlagToReport: flaggable objects empty, can't create report")
|
|
|
|
}
|
|
|
|
|
|
|
|
var targetAccountURI *url.URL
|
|
|
|
for _, object := range objects {
|
|
|
|
switch {
|
|
|
|
case object.Host != config.GetHost():
|
|
|
|
// object doesn't belong to us, just ignore it
|
|
|
|
continue
|
|
|
|
case uris.IsUserPath(object):
|
|
|
|
if targetAccountURI != nil {
|
|
|
|
return nil, errors.New("ASFlagToReport: flaggable objects contained more than one target account uri")
|
|
|
|
}
|
|
|
|
targetAccountURI = object
|
|
|
|
case uris.IsStatusesPath(object):
|
|
|
|
statusURIs = append(statusURIs, object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we actually have a target account now.
|
|
|
|
if targetAccountURI == nil {
|
|
|
|
return nil, errors.New("ASFlagToReport: flaggable objects contained no recognizable target account uri")
|
|
|
|
}
|
|
|
|
targetAccount, err := c.db.GetAccountByURI(ctx, targetAccountURI.String())
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, db.ErrNoEntries) {
|
|
|
|
return nil, fmt.Errorf("ASFlagToReport: account with uri %s could not be found in the db", targetAccountURI.String())
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("ASFlagToReport: db error getting account with uri %s: %w", targetAccountURI.String(), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got some status URIs, try to get them from the db now
|
|
|
|
var (
|
|
|
|
statusIDs = make([]string, 0, len(statusURIs))
|
|
|
|
statuses = make([]*gtsmodel.Status, 0, len(statusURIs))
|
|
|
|
)
|
|
|
|
for _, statusURI := range statusURIs {
|
|
|
|
statusURIString := statusURI.String()
|
|
|
|
|
|
|
|
// try getting this status by URI first, then URL
|
|
|
|
status, err := c.db.GetStatusByURI(ctx, statusURIString)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, db.ErrNoEntries) {
|
|
|
|
return nil, fmt.Errorf("ASFlagToReport: db error getting status with uri %s: %w", statusURIString, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err = c.db.GetStatusByURL(ctx, statusURIString)
|
|
|
|
if err != nil {
|
|
|
|
if !errors.Is(err, db.ErrNoEntries) {
|
|
|
|
return nil, fmt.Errorf("ASFlagToReport: db error getting status with url %s: %w", statusURIString, err)
|
|
|
|
}
|
|
|
|
|
2023-02-17 11:02:29 +00:00
|
|
|
log.Warnf(nil, "reported status %s could not be found in the db, skipping it", statusURIString)
|
2023-01-25 10:12:27 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if status.AccountID != targetAccount.ID {
|
|
|
|
// status doesn't belong to this account, ignore it
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
statusIDs = append(statusIDs, status.ID)
|
|
|
|
statuses = append(statuses, status)
|
|
|
|
}
|
|
|
|
|
|
|
|
// id etc should be handled the caller, so just return what we got
|
|
|
|
return >smodel.Report{
|
|
|
|
URI: uri,
|
|
|
|
AccountID: account.ID,
|
|
|
|
Account: account,
|
|
|
|
TargetAccountID: targetAccount.ID,
|
|
|
|
TargetAccount: targetAccount,
|
|
|
|
Comment: content,
|
|
|
|
StatusIDs: statusIDs,
|
|
|
|
Statuses: statuses,
|
|
|
|
}, nil
|
|
|
|
}
|