summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-11-11 10:15:04 +0000
committerLibravatar GitHub <noreply@github.com>2023-11-11 10:15:04 +0000
commitdeaea100c37698893e97cf9cab159a3d220ac3cd (patch)
treef48abc96964652d1701d91c88a00174c8f1b0196 /internal/typeutils
parent[feature] Media attachment placeholders (#2331) (diff)
downloadgotosocial-deaea100c37698893e97cf9cab159a3d220ac3cd.tar.xz
[bugfix] support endless polls, and misskey's' method of inferring expiry in closed polls (#2349)
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/internaltoas.go6
-rw-r--r--internal/typeutils/internaltofrontend.go8
-rw-r--r--internal/typeutils/internaltofrontend_test.go10
3 files changed, 16 insertions, 8 deletions
diff --git a/internal/typeutils/internaltoas.go b/internal/typeutils/internaltoas.go
index 541e2f4d1..16467be40 100644
--- a/internal/typeutils/internaltoas.go
+++ b/internal/typeutils/internaltoas.go
@@ -708,8 +708,10 @@ func (c *Converter) addPollToAS(ctx context.Context, poll *gtsmodel.Poll, dst ap
optionsProp.AppendActivityStreamsNote(note)
}
- // Set poll endTime property.
- ap.SetEndTime(dst, poll.ExpiresAt)
+ if !poll.ExpiresAt.IsZero() {
+ // Set poll endTime property.
+ ap.SetEndTime(dst, poll.ExpiresAt)
+ }
if !poll.ClosedAt.IsZero() {
// Poll is closed, set closed property.
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index a7bcddac6..1a2c321f5 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -1367,6 +1367,7 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
voted *bool
ownChoices *[]int
isAuthor bool
+ expiresAt string
emojis []apimodel.Emoji
)
@@ -1428,6 +1429,11 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
}
}
+ if !poll.ExpiresAt.IsZero() {
+ // Calculate poll expiry string (if set).
+ expiresAt = util.FormatISO8601(poll.ExpiresAt)
+ }
+
// TODO: emojis used in poll options.
// For now init to empty slice to serialize as `[]`.
// In future inherit from parent status.
@@ -1435,7 +1441,7 @@ func (c *Converter) PollToAPIPoll(ctx context.Context, requester *gtsmodel.Accou
return &apimodel.Poll{
ID: poll.ID,
- ExpiresAt: util.FormatISO8601(poll.ExpiresAt),
+ ExpiresAt: expiresAt,
Expired: poll.Closed(),
Multiple: (*poll.Multiple),
VotesCount: totalVotes,
diff --git a/internal/typeutils/internaltofrontend_test.go b/internal/typeutils/internaltofrontend_test.go
index 0e5d3a45b..d386c180e 100644
--- a/internal/typeutils/internaltofrontend_test.go
+++ b/internal/typeutils/internaltofrontend_test.go
@@ -1010,7 +1010,7 @@ func (suite *InternalToFrontendTestSuite) TestReportToFrontend1() {
"header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 2,
+ "statuses_count": 3,
"last_status_at": "2021-09-11T09:40:37.000Z",
"emojis": [],
"fields": []
@@ -1127,7 +1127,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend1() {
"header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 2,
+ "statuses_count": 3,
"last_status_at": "2021-09-11T09:40:37.000Z",
"emojis": [],
"fields": []
@@ -1395,7 +1395,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
"header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 2,
+ "statuses_count": 3,
"last_status_at": "2021-09-11T09:40:37.000Z",
"emojis": [],
"fields": []
@@ -1442,7 +1442,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontend2() {
"header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 2,
+ "statuses_count": 3,
"last_status_at": "2021-09-11T09:40:37.000Z",
"emojis": [],
"fields": []
@@ -1573,7 +1573,7 @@ func (suite *InternalToFrontendTestSuite) TestAdminReportToFrontendSuspendedLoca
"header_static": "http://localhost:8080/assets/default_header.png",
"followers_count": 0,
"following_count": 0,
- "statuses_count": 2,
+ "statuses_count": 3,
"last_status_at": "2021-09-11T09:40:37.000Z",
"emojis": [],
"fields": []