LinkedIn publishing works again; rename Inbox to Posts
LinkedIn: - The API version was fixed at 202501, retired by LinkedIn (426 NONEXISTENT_VERSION). It's now the month before last, stepping back a month (up to four) if LinkedIn says a version isn't active. - The versioned Posts API needs a title for a link's article card (422). Supermarket reads the linked page's title and description and sends them, falling back to the page's address as the title. Tested for real: a post with a link went out to the member's profile. Inbox is now Posts: the menu, page, messages and docs; the page moves to /posts, and /inbox redirects there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,19 +7,32 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var apiBase = "https://api.linkedin.com" // a variable for tests
|
||||
|
||||
// LinkedIn's REST API is versioned by month (YYYYMM), and each version is
|
||||
// retired after about a year. Rather than a fixed version that goes stale,
|
||||
// Supermarket asks for the month before last (surely released), and steps
|
||||
// back a month if LinkedIn says that one isn't active.
|
||||
const (
|
||||
apiBase = "https://api.linkedin.com"
|
||||
linkedinVersion = "202501"
|
||||
versionLag = 2 // months before now
|
||||
versionAttempts = 4 // versions tried before giving up
|
||||
)
|
||||
|
||||
// version is the LinkedIn-Version for the month back months before now.
|
||||
func version(now time.Time, back int) string {
|
||||
return now.AddDate(0, -back, -now.Day()+1).Format("200601")
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
accessToken string
|
||||
authorURN string
|
||||
http *http.Client
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
func New(accessToken, authorURN string) *Client {
|
||||
@@ -27,12 +40,23 @@ func New(accessToken, authorURN string) *Client {
|
||||
accessToken: accessToken,
|
||||
authorURN: authorURN,
|
||||
http: &http.Client{Timeout: 15 * time.Second},
|
||||
now: time.Now,
|
||||
}
|
||||
}
|
||||
|
||||
// PostUpdate creates a LinkedIn post. If sourceURL is non-empty it is attached
|
||||
// as an article card (LinkedIn will fetch the title and thumbnail automatically).
|
||||
func (c *Client) PostUpdate(ctx context.Context, text, sourceURL string) (string, error) {
|
||||
// Link is a page attached to a post as an article card. LinkedIn's API
|
||||
// doesn't read the page itself: the card shows the title and description
|
||||
// given here (a title is required).
|
||||
type Link struct {
|
||||
URL, Title, Description string
|
||||
}
|
||||
|
||||
// maxArticleTitle keeps a card's title to a sensible length.
|
||||
const maxArticleTitle = 200
|
||||
|
||||
// PostUpdate creates a LinkedIn post, with link (if not nil) attached as an
|
||||
// article card.
|
||||
func (c *Client) PostUpdate(ctx context.Context, text string, link *Link) (string, error) {
|
||||
pr := postRequest{
|
||||
Author: c.authorURN,
|
||||
Commentary: text,
|
||||
@@ -45,8 +69,16 @@ func (c *Client) PostUpdate(ctx context.Context, text, sourceURL string) (string
|
||||
LifecycleState: "PUBLISHED",
|
||||
IsReshareDisabledByAuthor: false,
|
||||
}
|
||||
if sourceURL != "" {
|
||||
pr.Content = &postContent{Article: articleContent{Source: sourceURL}}
|
||||
if link != nil && link.URL != "" {
|
||||
title := strings.TrimSpace(link.Title)
|
||||
if title == "" {
|
||||
title = fallbackTitle(link.URL)
|
||||
}
|
||||
if r := []rune(title); len(r) > maxArticleTitle {
|
||||
title = string(r[:maxArticleTitle-1]) + "…"
|
||||
}
|
||||
pr.Content = &postContent{Article: articleContent{Source: link.URL, Title: title,
|
||||
Description: strings.TrimSpace(link.Description)}}
|
||||
}
|
||||
|
||||
body, err := json.Marshal(pr)
|
||||
@@ -54,22 +86,34 @@ func (c *Client) PostUpdate(ctx context.Context, text, sourceURL string) (string
|
||||
return "", err
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, apiBase+"/rest/posts", strings.NewReader(string(body)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.accessToken)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("LinkedIn-Version", linkedinVersion)
|
||||
req.Header.Set("X-Restli-Protocol-Version", "2.0.0")
|
||||
var (
|
||||
res *http.Response
|
||||
raw []byte
|
||||
)
|
||||
for attempt := 0; ; attempt++ {
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, apiBase+"/rest/posts", strings.NewReader(string(body)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req.Header.Set("Authorization", "Bearer "+c.accessToken)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("LinkedIn-Version", version(c.now(), versionLag+attempt))
|
||||
req.Header.Set("X-Restli-Protocol-Version", "2.0.0")
|
||||
|
||||
res, err := c.http.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
res, err = c.http.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
raw, _ = io.ReadAll(res.Body)
|
||||
res.Body.Close()
|
||||
// 426: that version isn't active. Nothing was posted; try an
|
||||
// earlier one.
|
||||
if res.StatusCode == http.StatusUpgradeRequired && attempt+1 < versionAttempts {
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
raw, _ := io.ReadAll(res.Body)
|
||||
if res.StatusCode == http.StatusUnauthorized {
|
||||
return "", ErrUnauthorized
|
||||
}
|
||||
@@ -141,5 +185,16 @@ type postContent struct {
|
||||
}
|
||||
|
||||
type articleContent struct {
|
||||
Source string `json:"source"`
|
||||
Source string `json:"source"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
// fallbackTitle is a card title for a page whose own title couldn't be
|
||||
// read: its address without the scheme.
|
||||
func fallbackTitle(u string) string {
|
||||
if p, err := url.Parse(u); err == nil && p.Host != "" {
|
||||
return strings.TrimSuffix(strings.TrimPrefix(p.Host, "www.")+p.Path, "/")
|
||||
}
|
||||
return u
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package linkedin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
now := time.Date(2026, 11, 30, 12, 0, 0, 0, time.UTC)
|
||||
for back, want := range map[int]string{0: "202611", 2: "202609", 11: "202512"} {
|
||||
if got := version(now, back); got != want {
|
||||
t.Errorf("version(%d) = %s, want %s", back, got, want)
|
||||
}
|
||||
}
|
||||
// 31 March minus one month mustn't land in March again.
|
||||
if got := version(time.Date(2026, 3, 31, 0, 0, 0, 0, time.UTC), 1); got != "202602" {
|
||||
t.Errorf("from 31 March: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostStepsBackFromRetiredVersions(t *testing.T) {
|
||||
var asked []string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
v := r.Header.Get("LinkedIn-Version")
|
||||
asked = append(asked, v)
|
||||
if v > "202608" { // pretend only August and earlier are active
|
||||
w.WriteHeader(http.StatusUpgradeRequired)
|
||||
w.Write([]byte(`{"status":426,"code":"NONEXISTENT_VERSION"}`))
|
||||
return
|
||||
}
|
||||
w.Header().Set("X-RestLi-Id", "urn:li:share:1")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
}))
|
||||
defer srv.Close()
|
||||
old := apiBase
|
||||
apiBase = srv.URL
|
||||
defer func() { apiBase = old }()
|
||||
|
||||
c := New("tok", "urn:li:person:1")
|
||||
c.now = func() time.Time { return time.Date(2026, 11, 21, 0, 0, 0, 0, time.UTC) }
|
||||
url, err := c.PostUpdate(context.Background(), "hi", nil)
|
||||
if err != nil || !strings.Contains(url, "urn:li:share:1") {
|
||||
t.Fatalf("post: %q %v", url, err)
|
||||
}
|
||||
if strings.Join(asked, ",") != "202609,202608" {
|
||||
t.Errorf("versions asked: %v", asked)
|
||||
}
|
||||
|
||||
// Gives up after a few, with LinkedIn's answer.
|
||||
asked = nil
|
||||
c.now = func() time.Time { return time.Date(2027, 12, 1, 0, 0, 0, 0, time.UTC) }
|
||||
if _, err := c.PostUpdate(context.Background(), "hi", nil); err == nil || !strings.Contains(err.Error(), "426") || len(asked) != versionAttempts {
|
||||
t.Errorf("give up: %v after %v", err, asked)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostSendsTheArticleTitle(t *testing.T) {
|
||||
var bodies []map[string]any
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var b map[string]any
|
||||
json.NewDecoder(r.Body).Decode(&b)
|
||||
bodies = append(bodies, b)
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
}))
|
||||
defer srv.Close()
|
||||
old := apiBase
|
||||
apiBase = srv.URL
|
||||
defer func() { apiBase = old }()
|
||||
c := New("tok", "urn:li:person:1")
|
||||
|
||||
article := func(i int) map[string]any {
|
||||
return bodies[i]["content"].(map[string]any)["article"].(map[string]any)
|
||||
}
|
||||
if _, err := c.PostUpdate(context.Background(), "hi", &Link{URL: "https://acme.example/w?utm_source=linkedin", Title: " Widget 2 ", Description: "Faster."}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a := article(0); a["title"] != "Widget 2" || a["description"] != "Faster." || a["source"] != "https://acme.example/w?utm_source=linkedin" {
|
||||
t.Errorf("article: %v", a)
|
||||
}
|
||||
// No title read: the address stands in, as LinkedIn requires one.
|
||||
if _, err := c.PostUpdate(context.Background(), "hi", &Link{URL: "https://www.acme.example/blog/post/"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a := article(1); a["title"] != "acme.example/blog/post" {
|
||||
t.Errorf("fallback title: %v", a["title"])
|
||||
}
|
||||
if _, has := article(1)["description"]; has {
|
||||
t.Error("an empty description should be left out")
|
||||
}
|
||||
// No link: no content at all.
|
||||
if _, err := c.PostUpdate(context.Background(), "hi", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, has := bodies[2]["content"]; has {
|
||||
t.Error("a post without a link has no content")
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func ChannelByID(id string) (Channel, bool) {
|
||||
|
||||
// Draft statuses.
|
||||
const (
|
||||
StatusDraft = "draft" // waiting for review, in the Inbox
|
||||
StatusDraft = "draft" // waiting for review, in Posts
|
||||
StatusScheduled = "scheduled" // approved, goes out at PublishAt
|
||||
StatusPublishing = "publishing" // claimed by a publish in progress
|
||||
StatusPublished = "published"
|
||||
@@ -320,7 +320,7 @@ func Schedule(d *db.DB, id int64, at time.Time) error {
|
||||
return oneRow(res, err)
|
||||
}
|
||||
|
||||
// Unschedule sends a scheduled draft back to the Inbox, to edit or drop.
|
||||
// Unschedule sends a scheduled draft back to Posts, to edit or drop.
|
||||
func Unschedule(d *db.DB, id int64) error {
|
||||
res, err := d.Exec(`UPDATE drafts SET status = ?, publish_at = NULL, updated_at = ? WHERE id = ? AND status = ?`,
|
||||
StatusDraft, formatTime(time.Now()), id, StatusScheduled)
|
||||
@@ -329,11 +329,11 @@ func Unschedule(d *db.DB, id int64) error {
|
||||
|
||||
// MaxLate is how late a scheduled post may still go out, if the app was
|
||||
// stopped when it was due. Later than that, news is stale: it goes back to
|
||||
// the Inbox instead.
|
||||
// Posts instead.
|
||||
const MaxLate = 12 * time.Hour
|
||||
|
||||
// Due returns the scheduled drafts whose time has come, oldest first. Ones
|
||||
// more than MaxLate overdue are sent back to the Inbox with a note.
|
||||
// more than MaxLate overdue are sent back to Posts with a note.
|
||||
func Due(d *db.DB, now time.Time) ([]Draft, error) {
|
||||
if _, err := d.Exec(`UPDATE drafts SET status = ?, error = ?, updated_at = ?
|
||||
WHERE status = ? AND publish_at < ?`,
|
||||
@@ -350,7 +350,7 @@ func Due(d *db.DB, now time.Time) ([]Draft, error) {
|
||||
}
|
||||
|
||||
// FailScheduled sends a scheduled draft that couldn't go out (its channel
|
||||
// was signed out, say) back to the Inbox with the reason.
|
||||
// was signed out, say) back to Posts with the reason.
|
||||
func FailScheduled(d *db.DB, id int64, reason string) error {
|
||||
res, err := d.Exec(`UPDATE drafts SET status = ?, error = ?, updated_at = ? WHERE id = ? AND status = ?`,
|
||||
StatusFailed, reason, formatTime(time.Now()), id, StatusScheduled)
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ ALTER TABLE drafts ADD COLUMN publish_at TEXT;
|
||||
CREATE INDEX drafts_due ON drafts (status, publish_at);
|
||||
`,
|
||||
// 4: Reddit. A Reddit draft has a title and is for one subreddit
|
||||
// (target). Subreddits' rules are cached so the Inbox can show them.
|
||||
// (target). Subreddits' rules are cached so Posts can show them.
|
||||
`
|
||||
ALTER TABLE drafts ADD COLUMN title TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE drafts ADD COLUMN target TEXT NOT NULL DEFAULT '';
|
||||
|
||||
@@ -15,6 +15,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"supermarket/internal/api/sitemap"
|
||||
)
|
||||
|
||||
// Page is one page read.
|
||||
@@ -266,3 +268,18 @@ func FindAccounts(links []string) Accounts {
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// PageInfo reads one page's title and description (its <title>, or
|
||||
// og:title, and its meta or og:description), for a link's preview card.
|
||||
func PageInfo(ctx context.Context, pageURL, userAgent string) (title, desc string, err error) {
|
||||
u, err := Normalize(pageURL)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
_, src, err := fetchPage(ctx, &http.Client{Timeout: 10 * time.Second}, u.String(), userAgent)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
title, desc = sitemap.PageInfo(src)
|
||||
return title, desc, nil
|
||||
}
|
||||
|
||||
@@ -80,3 +80,15 @@ func TestNormalize(t *testing.T) {
|
||||
t.Error("ftp accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPageInfo(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(`<head><title>Widget 2 & more</title><meta name="description" content="Faster widgets."></head>`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
title, desc, err := PageInfo(context.Background(), srv.URL+"/w", "test")
|
||||
if err != nil || title != "Widget 2 & more" || desc != "Faster widgets." {
|
||||
t.Errorf("got %q %q %v", title, desc, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"supermarket/internal/fetcher"
|
||||
"supermarket/internal/oauth"
|
||||
"supermarket/internal/secrets"
|
||||
"supermarket/internal/site"
|
||||
)
|
||||
|
||||
// fetchMaxResults is how many posts or videos one source returns per fetch.
|
||||
@@ -99,7 +100,16 @@ type linkedInPublisher struct{ c *linkedin.Client }
|
||||
|
||||
// Publish attaches the source link as an article preview.
|
||||
func (p linkedInPublisher) Publish(ctx context.Context, post content.Post) (string, error) {
|
||||
return p.c.PostUpdate(ctx, post.Text, post.SourceURL)
|
||||
if post.SourceURL == "" {
|
||||
return p.c.PostUpdate(ctx, post.Text, nil)
|
||||
}
|
||||
// LinkedIn wants the card's title from us. A page that can't be read
|
||||
// still gets a card, titled with its address.
|
||||
link := &linkedin.Link{URL: post.SourceURL}
|
||||
ictx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||
defer cancel()
|
||||
link.Title, link.Description, _ = site.PageInfo(ictx, post.SourceURL, "Supermarket/1 (link preview)")
|
||||
return p.c.PostUpdate(ctx, post.Text, link)
|
||||
}
|
||||
|
||||
type redditPublisher struct {
|
||||
|
||||
@@ -270,7 +270,7 @@ func (s *Server) contentItems(w http.ResponseWriter, r *http.Request) {
|
||||
showErr(err.Error())
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/inbox", "drafted")
|
||||
redirect(w, r, "/posts", "drafted")
|
||||
default:
|
||||
http.Error(w, "unknown action", http.StatusBadRequest)
|
||||
}
|
||||
@@ -319,7 +319,7 @@ func (s *Server) writeDrafts(r *http.Request, e *inventory.Entry, ids []string)
|
||||
return errors.New("choose a subreddit for the Reddit post")
|
||||
}
|
||||
// The rules go into the prompt; without them the model is told
|
||||
// to be careful, and the Inbox warns.
|
||||
// to be careful, and Posts warns.
|
||||
info, err := s.subreddit(r.Context(), req.Subreddit, false)
|
||||
if err != nil {
|
||||
s.Log.Warn("reddit: couldn't read the subreddit's rules", "subreddit", req.Subreddit, "err", err)
|
||||
|
||||
@@ -94,10 +94,10 @@ func TestDraftsPage(t *testing.T) {
|
||||
ids[d.Channel] = strconv.FormatInt(d.ID, 10)
|
||||
}
|
||||
|
||||
if rec := do(h, http.MethodGet, "/drafts?msg=drafted", nil, nil); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/inbox?msg=drafted" {
|
||||
if rec := do(h, http.MethodGet, "/drafts?msg=drafted", nil, nil); rec.Code != http.StatusSeeOther || rec.Header().Get("Location") != "/posts?msg=drafted" {
|
||||
t.Errorf("old drafts page: %d %s", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
rec := do(h, http.MethodGet, "/inbox", nil, nil)
|
||||
rec := do(h, http.MethodGet, "/posts", nil, nil)
|
||||
body := rec.Body.String()
|
||||
if rec.Code != 200 || strings.Index(body, "X text") > strings.Index(body, "LinkedIn text") ||
|
||||
!strings.Contains(body, "31 / 280 including the link") || !strings.Contains(body, `data-reserve="25"`) ||
|
||||
@@ -162,7 +162,7 @@ func TestScheduleFromInbox(t *testing.T) {
|
||||
if !strings.Contains(body, "Soon, edited") || !strings.Contains(body, when.Format("15:04")) || !strings.Contains(body, "not connected") {
|
||||
t.Errorf("scheduled page:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(do(h, http.MethodGet, "/inbox", nil, nil).Body.String(), "Nothing waiting") {
|
||||
if !strings.Contains(do(h, http.MethodGet, "/posts", nil, nil).Body.String(), "Nothing waiting") {
|
||||
t.Error("a scheduled draft is still in the Inbox")
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ func TestRedditInInbox(t *testing.T) {
|
||||
Rules: []reddit.Rule{{Name: "No self-promotion", Description: "Limit it."}}, FetchedAt: time.Now()}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := do(h, http.MethodGet, "/inbox", nil, nil).Body.String()
|
||||
body := do(h, http.MethodGet, "/posts", nil, nil).Body.String()
|
||||
for _, want := range []string{"Reddit r/selfhosted", `name="title" value="Jitsi 3"`, "Flair it.", "No self-promotion",
|
||||
"has a rule about this", "Couldn't read r/homelab's rules", `action="/reddit/rules/homelab"`, "Read rules", "text only"} {
|
||||
if !strings.Contains(body, want) {
|
||||
@@ -334,7 +334,7 @@ func TestPostRedditByHand(t *testing.T) {
|
||||
for _, d := range ds {
|
||||
ids[d.Target] = strconv.FormatInt(d.ID, 10)
|
||||
}
|
||||
if body := do(h, http.MethodGet, "/inbox", nil, nil).Body.String(); !strings.Contains(body, "Open in Reddit") ||
|
||||
if body := do(h, http.MethodGet, "/posts", nil, nil).Body.String(); !strings.Contains(body, "Open in Reddit") ||
|
||||
!strings.Contains(body, "can't post to Reddit for you yet") || !strings.Contains(body, `action="/drafts/`+ids["selfhosted"]+`/posted"`) {
|
||||
t.Error("inbox lacks the by-hand controls")
|
||||
}
|
||||
@@ -381,7 +381,7 @@ func TestPostRedditByHand(t *testing.T) {
|
||||
// Supermarket's own record; nothing about the whole account is claimed.
|
||||
_, _ = content.CreateDrafts(s.DB, []content.Draft{{InventoryName: "Acme", Kind: "product", Channel: content.ChannelReddit,
|
||||
Title: "Again", Target: "selfhosted", Content: "More."}})
|
||||
body := do(h, http.MethodGet, "/inbox", nil, nil).Body.String()
|
||||
body := do(h, http.MethodGet, "/posts", nil, nil).Body.String()
|
||||
if !strings.Contains(body, "You posted in r/selfhosted 1 time in the past week through Supermarket") {
|
||||
t.Error("no same-subreddit warning from the recorded post")
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ import (
|
||||
"supermarket/internal/utm"
|
||||
)
|
||||
|
||||
// --- The Inbox: everything waiting for the user's approval ---
|
||||
// --- Posts: everything waiting for the user's approval ---
|
||||
|
||||
// inboxSection is one module's share of the Inbox. Later phases add their
|
||||
// inboxSection is one module's share of Posts. Later phases add their
|
||||
// own (prospects to send to the CRM, SEO changes to open as pull requests).
|
||||
type inboxSection struct {
|
||||
Module string
|
||||
@@ -95,7 +95,7 @@ func (s *Server) renderInbox(w http.ResponseWriter, r *http.Request, errMsg stri
|
||||
if len(pending) > 0 {
|
||||
sections = append(sections, inboxSection{Module: "Content", Batches: groupBatches(pending)})
|
||||
}
|
||||
s.render(w, r, "inbox", page{Title: "Inbox", Nav: "content/inbox", Error: errMsg, Data: map[string]any{
|
||||
s.render(w, r, "inbox", page{Title: "Posts", Nav: "content/posts", Error: errMsg, Data: map[string]any{
|
||||
"Reminders": s.reminders(),
|
||||
"Sections": sections,
|
||||
"Reddit": s.redditViews(r.Context(), pending),
|
||||
@@ -106,7 +106,7 @@ func (s *Server) renderInbox(w http.ResponseWriter, r *http.Request, errMsg stri
|
||||
}})
|
||||
}
|
||||
|
||||
// redditView is what the Inbox shows with a Reddit draft.
|
||||
// redditView is what Posts shows with a Reddit draft.
|
||||
type redditView struct {
|
||||
Info *reddit.Subreddit
|
||||
Warnings []string
|
||||
@@ -153,7 +153,7 @@ func (s *Server) refreshRules(w http.ResponseWriter, r *http.Request) {
|
||||
s.renderInbox(w, r, "Couldn't read the subreddit's rules: "+err.Error())
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/inbox", "rules-refreshed")
|
||||
redirect(w, r, "/posts", "rules-refreshed")
|
||||
}
|
||||
|
||||
// The Content module's own lists of approved and published drafts.
|
||||
@@ -213,9 +213,9 @@ func (s *Server) draftAction(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// Where the form was: the Inbox, or the Scheduled list.
|
||||
// Where the form was: Posts, or the Scheduled list.
|
||||
fromScheduled := r.PostForm.Get("from") == "scheduled"
|
||||
back := "/inbox"
|
||||
back := "/posts"
|
||||
if fromScheduled {
|
||||
back = "/content/scheduled"
|
||||
}
|
||||
@@ -315,7 +315,7 @@ func (s *Server) draftAction(w http.ResponseWriter, r *http.Request) {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
redirect(w, r, "/inbox", "unscheduled")
|
||||
redirect(w, r, "/posts", "unscheduled")
|
||||
case "discard":
|
||||
if err := content.DiscardDraft(s.DB, id); err != nil {
|
||||
fail(err)
|
||||
@@ -389,7 +389,7 @@ func (s *Server) publishDue(ctx context.Context, now time.Time) {
|
||||
if err != nil {
|
||||
// A failed post is recorded on the draft by Publish. One refused
|
||||
// before posting (not connected, too long) is still scheduled:
|
||||
// send it back to the Inbox rather than retry it forever.
|
||||
// send it back to Posts rather than retry it forever.
|
||||
if ferr := content.FailScheduled(s.DB, d.ID, err.Error()); ferr != nil && !errors.Is(ferr, content.ErrNotEditable) {
|
||||
s.Log.Error("scheduler: recording a failure", "draft", d.ID, "err", ferr)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ func (s *Server) linkedInExpiry() *Expiry {
|
||||
}
|
||||
|
||||
// reminders are the sign-ins running out soon, or already, for the
|
||||
// Overview and the Inbox.
|
||||
// Overview and Posts.
|
||||
func (s *Server) reminders() []Expiry {
|
||||
if e := s.linkedInExpiry(); e != nil && e.Soon() {
|
||||
return []Expiry{*e}
|
||||
|
||||
@@ -125,7 +125,7 @@ func (s *Server) search(q string) ([]hitGroup, error) {
|
||||
}
|
||||
var posts []hit
|
||||
for _, d := range drafts {
|
||||
link := "/inbox"
|
||||
link := "/posts"
|
||||
switch d.Status {
|
||||
case content.StatusScheduled:
|
||||
link = "/content/scheduled"
|
||||
|
||||
@@ -116,9 +116,13 @@ func (s *Server) Handler() (http.Handler, error) {
|
||||
mux.HandleFunc("POST /content/{id}/items", s.contentItems)
|
||||
mux.HandleFunc("GET /content/scheduled", s.scheduledPage)
|
||||
mux.HandleFunc("GET /content/published", s.publishedPage)
|
||||
mux.HandleFunc("GET /inbox", s.inboxPage)
|
||||
mux.HandleFunc("GET /posts", s.inboxPage)
|
||||
// Posts was called the Inbox, and before that Drafts.
|
||||
mux.HandleFunc("GET /inbox", func(w http.ResponseWriter, r *http.Request) {
|
||||
redirect(w, r, "/posts", r.URL.Query().Get("msg"))
|
||||
})
|
||||
mux.HandleFunc("GET /drafts", func(w http.ResponseWriter, r *http.Request) {
|
||||
redirect(w, r, "/inbox", r.URL.Query().Get("msg"))
|
||||
redirect(w, r, "/posts", r.URL.Query().Get("msg"))
|
||||
})
|
||||
mux.HandleFunc("POST /drafts/{id}/{action}", s.draftAction)
|
||||
mux.HandleFunc("POST /reddit/rules/{name}", s.refreshRules)
|
||||
@@ -247,7 +251,7 @@ func (s *Server) loadTemplates() error {
|
||||
// page is what every template gets.
|
||||
type page struct {
|
||||
Title string
|
||||
Nav string // which menu item is current: "home", "content/inbox", "settings/ai"…
|
||||
Nav string // which menu item is current: "home", "content/posts", "settings/ai"…
|
||||
Version string
|
||||
Flash string
|
||||
Error string
|
||||
@@ -337,7 +341,7 @@ var flashes = map[string]string{
|
||||
"discarded": "Discarded.",
|
||||
"scheduled": "Scheduled.",
|
||||
"posted": "Marked as posted: it's under Content → Published.",
|
||||
"unscheduled": "Back in the Inbox: edit it, then publish or schedule it again.",
|
||||
"unscheduled": "Back in Posts: edit it, then publish or schedule it again.",
|
||||
}
|
||||
|
||||
func redirect(w http.ResponseWriter, r *http.Request, path, msg string) {
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestEveryPageRenders(t *testing.T) {
|
||||
for _, path := range []string{"/", "/?msg=saved", "/settings/profile", "/inventory", "/inventory?relationship=partner",
|
||||
"/inventory/new", "/inventory/1", "/inventory/import", "/inventory/export",
|
||||
"/settings/ai", "/settings/accounts", "/settings/core", "/static/app.css", "/favicon.ico", "/static/favicon.png", "/static/logo.png", "/static/apple-touch-icon.png", "/search", "/search?q=rival", "/search?q=nothing+here", "/static/htmx.min.js", "/healthz",
|
||||
"/content", "/content/1", "/content/1?dismissed=1", "/inbox", "/inbox?msg=drafted",
|
||||
"/content", "/content/1", "/content/1?dismissed=1", "/posts", "/posts?msg=drafted",
|
||||
"/content/scheduled", "/content/published"} {
|
||||
rec := do(h, http.MethodGet, path, nil, nil)
|
||||
if rec.Code != http.StatusOK {
|
||||
@@ -260,7 +260,7 @@ func TestAIKeysOnTheAITab(t *testing.T) {
|
||||
|
||||
func TestOldAddressesRedirect(t *testing.T) {
|
||||
_, h := newTestServer(t, nil)
|
||||
for old, now := range map[string]string{"/profile": "/settings/profile", "/core": "/settings/core",
|
||||
for old, now := range map[string]string{"/profile": "/settings/profile", "/core": "/settings/core", "/inbox": "/posts",
|
||||
"/settings/credentials": "/settings/accounts", "/settings": "/settings/profile"} {
|
||||
rec := do(h, http.MethodGet, old, nil, nil)
|
||||
if rec.Code/100 != 3 || rec.Header().Get("Location") != now {
|
||||
@@ -283,7 +283,7 @@ func TestSearch(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := do(h, http.MethodGet, "/search?q=GADGET", nil, nil).Body.String()
|
||||
for _, want := range []string{"Rival Corp", "Gadget 2 launches", "Our widgets beat any gadget", `href="/content/1"`, `href="/inbox"`} {
|
||||
for _, want := range []string{"Rival Corp", "Gadget 2 launches", "Our widgets beat any gadget", `href="/content/1"`, `href="/posts"`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("search for gadget: missing %q", want)
|
||||
}
|
||||
@@ -422,7 +422,7 @@ func TestLinkedInExpiryReminders(t *testing.T) {
|
||||
|
||||
// Saved before expiries were recorded, 50 days ago: 10 days left.
|
||||
_ = s.saveConnection("linkedin", Connection{At: time.Now().Add(-50 * day)})
|
||||
for _, path := range []string{"/", "/inbox"} {
|
||||
for _, path := range []string{"/", "/posts"} {
|
||||
if body := get(path); !strings.Contains(body, "LinkedIn's sign-in expires in 9 days") && !strings.Contains(body, "LinkedIn's sign-in expires in 10 days") {
|
||||
t.Errorf("%s: no 10-day reminder", path)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{{define "content"}}{{with .Data}}{{$conn := .Connected}}
|
||||
<h1>Scheduled</h1>
|
||||
<p class="lede">Approved posts, in the order they go out ({{.Zone}}). Supermarket publishes them on time as long as it's running; one more than 12 hours late goes back to the Inbox instead.</p>
|
||||
<p class="lede">Approved posts, in the order they go out ({{.Zone}}). Supermarket publishes them on time as long as it's running; one more than 12 hours late goes back to Posts instead.</p>
|
||||
|
||||
{{if .Drafts}}
|
||||
<table class="list">
|
||||
@@ -26,6 +26,6 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{{else}}
|
||||
<section class="card empty"><p>Nothing scheduled. Schedule drafts from the <a href="/inbox">Inbox</a>.</p></section>
|
||||
<section class="card empty"><p>Nothing scheduled. Schedule drafts from the <a href="/posts">Posts</a>.</p></section>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{{define "content"}}{{with .Data}}
|
||||
<h1>Sources</h1>
|
||||
<p class="lede">Pick an inventory entry to fetch its latest news, choose what to write about, and get a draft for each channel to review in the <a href="/inbox">Inbox</a>.</p>
|
||||
<p class="lede">Pick an inventory entry to fetch its latest news, choose what to write about, and get a draft for each channel to review under <a href="/posts">Posts</a>.</p>
|
||||
|
||||
{{if .Rows}}
|
||||
<table class="list">
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<a class="card module" href="{{.Link}}">
|
||||
<h3>{{template "icon" .ID}}{{.Name}} <span class="badge">{{.Phase}}</span></h3>
|
||||
<p>{{.Body}}</p>
|
||||
{{if eq .ID "content"}}<span class="stat">{{if $inbox}}{{$inbox}} waiting in the Inbox{{else}}Inbox empty{{end}}{{with $.Data.Scheduled}} · {{.}} scheduled{{end}}</span>{{end}}
|
||||
{{if eq .ID "content"}}<span class="stat">{{if $inbox}}{{$inbox}} waiting in Posts{{else}}No posts waiting{{end}}{{with $.Data.Scheduled}} · {{.}} scheduled{{end}}</span>{{end}}
|
||||
</a>
|
||||
{{else}}
|
||||
<section class="card module later">
|
||||
@@ -55,7 +55,7 @@
|
||||
<details class="card">
|
||||
<summary>Imported from the old terminal app {{ago .ImportStatus.At}}</summary>
|
||||
<ul>{{range .ImportStatus.Summary}}<li>{{.}}</li>{{end}}</ul>
|
||||
{{if .QueuedPosts}}<p>Its queued posts are now drafts: <a href="/inbox">{{.QueuedPosts}} waiting in the Inbox</a>.</p>{{end}}
|
||||
{{if .QueuedPosts}}<p>Its queued posts are now drafts: <a href="/posts">{{.QueuedPosts}} waiting in Posts</a>.</p>{{end}}
|
||||
</details>
|
||||
{{end}}
|
||||
{{end}}{{end}}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{define "content"}}{{with .Data}}{{$conn := .Connected}}{{$now := .Now}}{{$zone := .Zone}}{{$reddit := .Reddit}}
|
||||
<h1>Inbox</h1>
|
||||
<h1>Posts</h1>
|
||||
<p class="lede">Everything waiting for your approval. Nothing is published until you say so: publish a draft now, or schedule it.
|
||||
{{if .Tagged}}Links to your own sites get UTM tags when published.{{end}}</p>
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<a href="{{.Link}}" {{if eq $nav .ID}}aria-current="page"{{end}} class="{{if hasPrefix $nav .ID}}open{{end}}">{{template "icon" .ID}}<span>{{.Name}}</span></a>
|
||||
{{if eq .ID "content"}}
|
||||
<div class="subnav">
|
||||
<a href="/inbox" {{if eq $nav "content/inbox"}}aria-current="page"{{end}}>Inbox{{if $inbox}} <span class="count-badge" title="{{$inbox}} waiting for review">{{$inbox}}</span>{{end}}</a>
|
||||
<a href="/posts" {{if eq $nav "content/posts"}}aria-current="page"{{end}}>Posts{{if $inbox}} <span class="count-badge" title="{{$inbox}} waiting for review">{{$inbox}}</span>{{end}}</a>
|
||||
<a href="/content" {{if eq $nav "content/sources"}}aria-current="page"{{end}}>Sources</a>
|
||||
<a href="/content/scheduled" {{if eq $nav "content/scheduled"}}aria-current="page"{{end}}>Scheduled</a>
|
||||
<a href="/content/published" {{if eq $nav "content/published"}}aria-current="page"{{end}}>Published</a>
|
||||
@@ -98,7 +98,7 @@
|
||||
{{define "reminders"}}{{range .}}
|
||||
<section class="card warn reminder" role="status">
|
||||
<p><strong>{{if .Expired}}{{.Network}}'s sign-in expired on {{.At.Local.Format "2 Jan 2006"}}.{{else}}{{.Network}}'s sign-in expires {{if eq .Days 0}}today{{else if eq .Days 1}}tomorrow{{else}}in {{.Days}} days{{end}}, on {{.At.Local.Format "2 Jan 2006"}}.{{end}}</strong>
|
||||
{{if .Expired}}Nothing can be published to {{.Network}} until you reconnect; scheduled posts for it come back to the Inbox.{{else}}After that, nothing can be published to {{.Network}} until you reconnect.{{end}}</p>
|
||||
{{if .Expired}}Nothing can be published to {{.Network}} until you reconnect; scheduled posts for it come back to Posts.{{else}}After that, nothing can be published to {{.Network}} until you reconnect.{{end}}</p>
|
||||
<a class="button" href="/settings/accounts#network-{{.Network}}">Reconnect {{.Network}}</a>
|
||||
</section>
|
||||
{{end}}{{end}}
|
||||
|
||||
Reference in New Issue
Block a user