ActivityState, CursorPosition, LogicalAction, OurKey, OurKey::*,
};
use super::text::*;
-use super::types::Visibility;
+use super::types::{Account, Visibility};
use super::editor::EditableMenuLine;
#[derive(Debug, PartialEq, Eq, Clone)]
pub m: PostMetadata,
}
-fn default_language() -> String {
- get_locale().as_deref()
- .and_then(|s| s.split('-').next())
- .map(|s| if s.is_empty() { "en" } else { s })
- .unwrap_or("en")
- .to_owned()
+fn default_language(ac: &Account) -> String {
+ ac.source.as_ref().and_then(|s| s.language.clone()).unwrap_or_else(
+ || get_locale().as_deref()
+ .and_then(|s| s.split('-').next())
+ .map(|s| if s.is_empty() { "en" } else { s })
+ .unwrap_or("en")
+ .to_owned())
}
impl Post {
- pub fn new() -> Self {
- Post {
+ pub fn new(client: &mut Client) -> Result<Self, ClientError> {
+ let ac = client.account_by_id(&client.our_account_id())?;
+
+ // Take the default visibility from your account settings
+ let visibility = ac.source.as_ref().map_or(
+ Visibility::Public, |s| s.privacy);
+
+ // Set the 'sensitive' flag if the account is marked as
+ // 'posts are sensitive by default'.
+ //
+ // I don't really approve of _just_ setting the sensitive flag
+ // without also giving a textual content warning saying why,
+ // so it would be nice here to encourage the user to write
+ // one, or fill in a default one. But the former is horribly
+ // intrusive (to the code structure _as well_ as to the UX!),
+ // and the latter is language-dependent (software shouldn't
+ // auto-fill an English message if the user is posting in
+ // Korean). So if the user has set that as their defaults, we
+ // sigh, and go with 'sensitive but no message'.
+ let content_warning = ac.source.as_ref().and_then(|s| {
+ if s.sensitive { Some("".to_owned()) } else { None }
+ });
+
+ Ok(Post {
text: "".to_owned(),
m: PostMetadata {
in_reply_to_id: None,
- visibility: Visibility::Public,
- content_warning: None,
- language: default_language(),
+ visibility,
+ content_warning,
+ language: default_language(&ac),
},
- }
+ })
}
#[cfg(test)]
in_reply_to_id: None,
visibility: Visibility::Public,
content_warning: None,
- language: default_language(),
+ language: "dummy".to_owned(),
},
}
}
pub fn reply_to(id: &str, client: &mut Client) ->
Result<Self, ClientError>
{
+ let ac = client.account_by_id(&client.our_account_id())?;
let st = client.status_by_id(id)?.strip_boost();
let ourself = client.our_account_fq();
in_reply_to_id: Some(id.to_owned()),
visibility: st.visibility, // match the existing vis
content_warning: None,
- language: default_language(),
+ language: default_language(&ac),
},
})
}
examine_user(client, name),
Activity::Util(UtilityActivity::InfoStatus(ref id)) =>
view_single_post(self.unfolded_posts.clone(), client, id),
- Activity::NonUtil(NonUtilityActivity::ComposeToplevel) =>
- compose_post(client, post.unwrap_or_else(Post::new)),
+ Activity::NonUtil(NonUtilityActivity::ComposeToplevel) => (|| {
+ let post = match post {
+ Some(post) => post,
+ None => Post::new(client)?,
+ };
+ compose_post(client, post)
+ })(),
Activity::NonUtil(NonUtilityActivity::PostComposeMenu) =>
Ok(post_menu(post.expect(
"how did we get here without a Post?"))),