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:
@@ -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