Skip to content

Commit 55cb396

Browse files
authored
Add post_thread (#173)
1 parent 74faba4 commit 55cb396

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export(parse_stream)
3838
export(post_list_accounts)
3939
export(post_list_create)
4040
export(post_status)
41+
export(post_thread)
4142
export(post_toot)
4243
export(post_user)
4344
export(rtoot)

R/post.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,51 @@ post_status <- function(
223223
}
224224
invisible(r)
225225
}
226+
227+
#' Post a thread
228+
#'
229+
#' Create a thread of your messages.
230+
#' @inheritParams post_toot
231+
#' @returns A character vector with the ids of the toots posted.
232+
#' @export
233+
#' @examples
234+
#' \dontrun{
235+
#' pt <- post_thread(visibility = "direct")
236+
#' }
237+
post_thread <- function(
238+
status = c("my first rtoot #rstats", "my first thread with rtoot"),
239+
# media = NULL,
240+
# alt_text = NULL,
241+
token = NULL,
242+
sensitive = FALSE,
243+
spoiler_text = NULL,
244+
visibility = "public",
245+
scheduled_at = NULL,
246+
language = NULL,
247+
verbose = TRUE
248+
) {
249+
token <- check_token_rtoot(token)
250+
if (!is.character(status)) {
251+
cli::cli_abort("`status` must be a string, it is a {typeof(status)}.")
252+
}
253+
toot_id <- NULL
254+
ids <- vector("character", length = length(status))
255+
for (msg_i in seq_along(status)) {
256+
toot <- post_toot(status[msg_i],
257+
in_reply_to_id = toot_id,
258+
token = token,
259+
sensitive = sensitive,
260+
spoiler_text = spoiler_text,
261+
visibility = visibility,
262+
scheduled_at = scheduled_at,
263+
language = language,
264+
verbose = FALSE)
265+
resp <- httr::content(toot)
266+
ids[msg_i] <- resp$id
267+
toot_id <- ids[msg_i]
268+
}
269+
if (sum(!nzchar(ids)) == length(status)) {
270+
sayif(verbose, "Your thread has been posted")
271+
}
272+
invisible(ids)
273+
}

man/post_thread.Rd

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)