Reddit: posted by hand, with the rules pasted
Reddit's API isn't open to apps like this one, so Supermarket no longer signs in to Reddit, publishes or schedules there, or reads subreddits and the account's posts. The internal/api/reddit client, Reddit's OAuth, its keys and its Social accounts card are gone. Supermarket still writes the post. Each Reddit draft in Posts has a box for its subreddit's rules, with a link to them on Reddit: pasted once, they're kept (subreddits.data, as pasted_rules) and given to the model for later drafts. Open in Reddit saves the edits and opens the submit page filled in; Copy title and Copy text (with the tagged source link) cover a box that comes up empty; Mark as posted records it. Warnings come from the pasted rules and the posts marked as posted. Fill's subreddit suggestions are kept unchecked, and say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+4
-35
@@ -11,7 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"supermarket/internal/api/linkedin"
|
||||
"supermarket/internal/api/reddit"
|
||||
"supermarket/internal/api/twitter"
|
||||
"supermarket/internal/appmail"
|
||||
"supermarket/internal/content"
|
||||
@@ -32,7 +31,7 @@ var adoptMu sync.Mutex
|
||||
// the company's accounts, the first time they're seen.
|
||||
func (s *Server) adoptLegacy() {
|
||||
if !s.Secrets.Has(secrets.XAccessToken) && !s.Secrets.Has(secrets.LinkedInAccessToken) &&
|
||||
!s.Secrets.Has(secrets.LinkedInPageAccessToken) && !s.Secrets.Has(secrets.RedditAccessToken) {
|
||||
!s.Secrets.Has(secrets.LinkedInPageAccessToken) {
|
||||
return
|
||||
}
|
||||
adoptMu.Lock()
|
||||
@@ -59,9 +58,6 @@ func (s *Server) adoptLegacy() {
|
||||
return o.Name, o.URN, expiry(conns[liPageProvider])
|
||||
}
|
||||
return "the company page", "", expiry(conns[liPageProvider])
|
||||
case posting.Reddit:
|
||||
u := s.Secrets.Get(secrets.RedditUsername)
|
||||
return "u/" + u, u, time.Time{}
|
||||
}
|
||||
return "", "", time.Time{}
|
||||
}, time.Now())
|
||||
@@ -127,7 +123,9 @@ func (s *Server) working(a *posting.Account) bool {
|
||||
func (s *Server) usableAccounts(v *viewer) map[string][]*posting.Account {
|
||||
out := map[string][]*posting.Account{}
|
||||
for _, a := range s.postingAccounts() {
|
||||
if s.working(a) && s.mayPostAs(v, a) {
|
||||
// Reddit accounts signed in before are left unused: Reddit is
|
||||
// posted to by hand.
|
||||
if a.Network != posting.Reddit && s.working(a) && s.mayPostAs(v, a) {
|
||||
ch := posting.Channel(a.Network)
|
||||
out[ch] = append(out[ch], a)
|
||||
}
|
||||
@@ -236,39 +234,10 @@ func (s *Server) publisherFor(a *posting.Account) (content.Publisher, error) {
|
||||
return nil, errors.New("choose which company page " + a.Label() + " posts as, under Settings → Social accounts")
|
||||
}
|
||||
return asPublisher{linkedInPublisher{page: linkedin.New(tok, a.External)}, true}, nil
|
||||
case posting.Reddit:
|
||||
return redditPublisher{s: s, c: s.redditClient(a)}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("no network %q", a.Network)
|
||||
}
|
||||
|
||||
// redditClient is signed in as a Reddit account; refused tokens are
|
||||
// refreshed and saved.
|
||||
func (s *Server) redditClient(a *posting.Account) *reddit.Client {
|
||||
id, ua := a.ID, reddit.UserAgent(s.Version, a.External)
|
||||
return reddit.New(s.Secrets.Get(posting.AccessName(id)), ua, func(ctx context.Context) (string, error) {
|
||||
res, err := oauth.RefreshReddit(ctx, s.Secrets.Get(secrets.RedditClientID), s.Secrets.Get(secrets.RedditClientSecret), ua, s.Secrets.Get(posting.RefreshName(id)))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := posting.SaveTokens(s.Secrets, id, res.AccessToken, res.RefreshToken); err != nil {
|
||||
s.Log.Error("reddit: couldn't save the refreshed token", "account", id, "err", err)
|
||||
}
|
||||
return res.AccessToken, nil
|
||||
})
|
||||
}
|
||||
|
||||
// companyReddit is the company's Reddit account, for reading rules and
|
||||
// the account's history; nil if none.
|
||||
func (s *Server) companyReddit() *posting.Account {
|
||||
s.adoptLegacy()
|
||||
a, err := posting.Company(s.DB, posting.Reddit)
|
||||
if err != nil || a == nil || !s.Secrets.Has(posting.AccessName(a.ID)) {
|
||||
return nil
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
// removeAccount signs an account out: scheduled posts to it go back to
|
||||
// Posts, and their writers are told.
|
||||
func (s *Server) removeAccount(a *posting.Account, why string) error {
|
||||
|
||||
Reference in New Issue
Block a user