Phase 10, part 7: posting accounts, and who may post to which
Social accounts become posting accounts: several per network, the company's and each person's own, with their tokens kept per account. The old sign-ins are adopted as the company's. Admins say who may post to which (Settings → Posting accounts); a draft can go out from one account or a copy to several, each recording who posted it and as what. Signing an account out, or removing its owner, holds the posts scheduled to it and tells whoever scheduled them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,8 +24,24 @@ type Publisher interface {
|
||||
Publish(ctx context.Context, p Post) (string, error)
|
||||
}
|
||||
|
||||
// Publishers are the channels that can post now, by channel ID.
|
||||
type Publishers map[string]Publisher
|
||||
// Publishers find where a draft goes out: its publisher and the account's
|
||||
// name, or why it can't.
|
||||
type Publishers interface {
|
||||
For(dr *Draft) (Publisher, string, error)
|
||||
}
|
||||
|
||||
// ChannelPublishers is a publisher per channel: for tests, and anything
|
||||
// without posting accounts.
|
||||
type ChannelPublishers map[string]Publisher
|
||||
|
||||
// For is the draft's channel's publisher.
|
||||
func (c ChannelPublishers) For(dr *Draft) (Publisher, string, error) {
|
||||
p := c[dr.Channel]
|
||||
if p == nil {
|
||||
return nil, "", fmt.Errorf("%s isn't connected: sign in under Settings → Social accounts", dr.ChannelName())
|
||||
}
|
||||
return p, "", nil
|
||||
}
|
||||
|
||||
// ErrBusy means the draft is already being published.
|
||||
var ErrBusy = errors.New("this draft is already being published, or was published")
|
||||
@@ -44,9 +60,9 @@ func Publish(ctx context.Context, d *db.DB, pubs Publishers, tags *utm.Tagger, i
|
||||
if !dr.Editable() && dr.Status != StatusScheduled {
|
||||
return dr, ErrBusy
|
||||
}
|
||||
pub := pubs[dr.Channel]
|
||||
if pub == nil {
|
||||
return dr, fmt.Errorf("%s isn't connected: sign in under Settings → Social accounts", dr.ChannelName())
|
||||
pub, as, err := pubs.For(dr)
|
||||
if err != nil {
|
||||
return dr, err
|
||||
}
|
||||
if problem := dr.Problem(); problem != "" {
|
||||
return dr, fmt.Errorf("%s. Fix it first", problem)
|
||||
@@ -73,8 +89,8 @@ func Publish(ctx context.Context, d *db.DB, pubs Publishers, tags *utm.Tagger, i
|
||||
dr.Status, dr.Error = StatusFailed, pubErr.Error()
|
||||
return dr, pubErr
|
||||
}
|
||||
if _, err := d.Exec(`UPDATE drafts SET status = ?, post_url = ?, published_at = ?, updated_at = ? WHERE id = ?`,
|
||||
StatusPublished, postURL, now, now, id); err != nil {
|
||||
if _, err := d.Exec(`UPDATE drafts SET status = ?, post_url = ?, published_at = ?, updated_at = ?, posted_as = ? WHERE id = ?`,
|
||||
StatusPublished, postURL, now, now, as, id); err != nil {
|
||||
// It went out: say so, so the user doesn't post it again.
|
||||
return dr, fmt.Errorf("published to %s (%s), but couldn't record it: %w", dr.ChannelName(), postURL, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user