Skip to content

Commit ae30827

Browse files
committed
Include anonymous posts in posts when auth'd
This lists the anonymous posts owned by the currently-authenticated user in addition to any local posts, with titles marking both sections. Ref T604
1 parent 08c7201 commit ae30827

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

api/posts.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func GetPosts(c *cli.Context) *[]Post {
112112
return &posts
113113
}
114114

115-
func GetUserPosts(c *cli.Context) ([]RemotePost, error) {
115+
func GetUserPosts(c *cli.Context, draftsOnly bool) ([]RemotePost, error) {
116116
waposts, err := DoFetchPosts(c)
117117
if err != nil {
118118
return nil, err
@@ -124,6 +124,9 @@ func GetUserPosts(c *cli.Context) ([]RemotePost, error) {
124124

125125
posts := []RemotePost{}
126126
for _, p := range waposts {
127+
if draftsOnly && p.Collection != nil {
128+
continue
129+
}
127130
post := RemotePost{
128131
Post: Post{
129132
ID: p.ID,

cmd/writeas/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ func main() {
164164
Name: "md",
165165
Usage: "Use with --url to return URLs with Markdown enabled",
166166
},
167+
cli.BoolFlag{
168+
Name: "tor, t",
169+
Usage: "Get posts via Tor hidden service, if authenticated",
170+
},
167171
cli.BoolFlag{
168172
Name: "url",
169173
Usage: "Show list with URLs",

commands/commands.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,42 @@ func CmdListPosts(c *cli.Context) error {
192192

193193
posts := api.GetPosts(c)
194194

195+
u, _ := config.LoadUser(config.UserDataDir(c.App.ExtraInfo()["configDir"]))
196+
if u != nil {
197+
if config.IsTor(c) {
198+
log.Info(c, "Getting posts via hidden service...")
199+
} else {
200+
log.Info(c, "Getting posts...")
201+
}
202+
remotePosts, err := api.GetUserPosts(c, true)
203+
if err != nil {
204+
return cli.NewExitError(fmt.Sprintf("error getting posts: %v", err), 1)
205+
}
206+
207+
if len(remotePosts) > 0 {
208+
fmt.Println("Anonymous Posts")
209+
if details {
210+
identifier := "URL"
211+
if ids || !urls {
212+
identifier = "ID"
213+
}
214+
fmt.Println(identifier)
215+
}
216+
}
217+
for _, p := range remotePosts {
218+
identifier := getPostURL(c, p.ID)
219+
if ids || !urls {
220+
identifier = p.ID
221+
}
222+
223+
fmt.Println(identifier)
224+
}
225+
226+
if len(*posts) > 0 {
227+
fmt.Printf("\nUnclaimed Posts\n")
228+
}
229+
}
230+
195231
if details {
196232
var p api.Post
197233
tw := tabwriter.NewWriter(os.Stdout, 10, 0, 2, ' ', tabwriter.TabIndent)

0 commit comments

Comments
 (0)