summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-02-25 13:16:30 +0100
committerLibravatar GitHub <noreply@github.com>2023-02-25 12:16:30 +0000
commitc27b4d7ed02cdabac00c3ddedb8201b74f745ec6 (patch)
treed80f621241fd67a4e5de2d21a8c24776552175f5 /internal/typeutils
parent[chore] Update gin to v1.9.0 (#1553) (diff)
downloadgotosocial-c27b4d7ed02cdabac00c3ddedb8201b74f745ec6.tar.xz
[feature] Client API endpoints + v. basic web view for pinned posts (#1547)
* implement status pin client api + web handler * make test names + comments more descriptive * don't use separate table for status pins * remove unused add + remove checking * tidy up + add some more tests
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/astointernal.go3
-rw-r--r--internal/typeutils/internal.go2
-rw-r--r--internal/typeutils/internaltoas_test.go2
-rw-r--r--internal/typeutils/internaltofrontend.go2
-rw-r--r--internal/typeutils/util.go7
5 files changed, 10 insertions, 6 deletions
diff --git a/internal/typeutils/astointernal.go b/internal/typeutils/astointernal.go
index 459f3402d..11633ad4e 100644
--- a/internal/typeutils/astointernal.go
+++ b/internal/typeutils/astointernal.go
@@ -346,17 +346,16 @@ func (c *converter) ASStatusToStatus(ctx context.Context, statusable ap.Statusab
// advanced visibility 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 using ASTOOL
// for now we just set everything to true
- pinned := false
federated := true
boostable := true
replyable := true
likeable := true
- status.Pinned = &pinned
status.Federated = &federated
status.Boostable = &boostable
status.Replyable = &replyable
status.Likeable = &likeable
+
// sensitive
sensitive := ap.ExtractSensitive(statusable)
status.Sensitive = &sensitive
diff --git a/internal/typeutils/internal.go b/internal/typeutils/internal.go
index 62e43f8c7..cf490e88d 100644
--- a/internal/typeutils/internal.go
+++ b/internal/typeutils/internal.go
@@ -37,7 +37,6 @@ func (c *converter) StatusToBoost(ctx context.Context, s *gtsmodel.Status, boost
}
sensitive := *s.Sensitive
- pinned := false // can't pin a boost
federated := *s.Federated
boostable := *s.Boostable
replyable := *s.Replyable
@@ -75,7 +74,6 @@ func (c *converter) StatusToBoost(ctx context.Context, s *gtsmodel.Status, boost
BoostOfID: s.ID,
BoostOfAccountID: s.AccountID,
Visibility: s.Visibility,
- Pinned: &pinned,
Federated: &federated,
Boostable: &boostable,
Replyable: &replyable,
diff --git a/internal/typeutils/internaltoas_test.go b/internal/typeutils/internaltoas_test.go
index 0bbb80dac..2ea393db3 100644
--- a/internal/typeutils/internaltoas_test.go
+++ b/internal/typeutils/internaltoas_test.go
@@ -433,7 +433,7 @@ func (suite *InternalToASTestSuite) TestStatusesToASOutboxPage() {
ctx := context.Background()
// get public statuses from testaccount
- statuses, err := suite.db.GetAccountStatuses(ctx, testAccount.ID, 30, true, true, "", "", false, false, true)
+ statuses, err := suite.db.GetAccountStatuses(ctx, testAccount.ID, 30, true, true, "", "", false, true)
suite.NoError(err)
page, err := suite.typeconverter.StatusesToASOutboxPage(ctx, testAccount.OutboxURI, "", "", statuses)
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 40837ad6b..ebea023cf 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -628,7 +628,7 @@ func (c *converter) StatusToAPIStatus(ctx context.Context, s *gtsmodel.Status, r
Bookmarked: interacts.Bookmarked,
Muted: interacts.Muted,
Reblogged: interacts.Reblogged,
- Pinned: *s.Pinned,
+ Pinned: interacts.Pinned,
Content: s.Content,
Reblog: nil,
Application: apiApplication,
diff --git a/internal/typeutils/util.go b/internal/typeutils/util.go
index 40001e913..d11cccb2c 100644
--- a/internal/typeutils/util.go
+++ b/internal/typeutils/util.go
@@ -32,6 +32,7 @@ type statusInteractions struct {
Muted bool
Bookmarked bool
Reblogged bool
+ Pinned bool
}
func (c *converter) interactionsWithStatusForAccount(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*statusInteractions, error) {
@@ -61,6 +62,12 @@ func (c *converter) interactionsWithStatusForAccount(ctx context.Context, s *gts
return nil, fmt.Errorf("error checking if requesting account has bookmarked status: %s", err)
}
si.Bookmarked = bookmarked
+
+ // The only time 'pinned' should be true is if the
+ // requesting account is looking at its OWN status.
+ if s.AccountID == requestingAccount.ID {
+ si.Pinned = !s.PinnedAt.IsZero()
+ }
}
return si, nil
}