improve messaging for when sbot is inactive
This commit is contained in:
@ -424,8 +424,6 @@ impl ProfileContext {
|
|||||||
// retrieve go-sbot systemd process status
|
// retrieve go-sbot systemd process status
|
||||||
let sbot_status = SbotStatus::read()?;
|
let sbot_status = SbotStatus::read()?;
|
||||||
|
|
||||||
// we only want to try and interact with the sbot if it's active
|
|
||||||
if sbot_status.state == Some("active".to_string()) {
|
|
||||||
// retrieve latest go-sbot configuration parameters
|
// retrieve latest go-sbot configuration parameters
|
||||||
let sbot_config = SbotConfig::read().ok();
|
let sbot_config = SbotConfig::read().ok();
|
||||||
|
|
||||||
@ -478,9 +476,6 @@ impl ProfileContext {
|
|||||||
local_id
|
local_id
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: add relationship state context if not local profile
|
|
||||||
// ie. lookup is_following and is_blocking, set context accordingly
|
|
||||||
|
|
||||||
// retrieve the profile info for the given id
|
// retrieve the profile info for the given id
|
||||||
let info = sbot_client.get_profile_info(&id).await?;
|
let info = sbot_client.get_profile_info(&id).await?;
|
||||||
// set each context field accordingly
|
// set each context field accordingly
|
||||||
@ -512,11 +507,6 @@ impl ProfileContext {
|
|||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// the sbot is not currently active; return a helpful message
|
|
||||||
context.flash_name = Some("warning".to_string());
|
|
||||||
context.flash_msg = Some("The Sbot is currently inactive. As a result, profile data cannot be retrieved. Visit the Scuttlebutt settings menu to start the Sbot and then try again".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
context.sbot_status = Some(sbot_status);
|
context.sbot_status = Some(sbot_status);
|
||||||
|
|
||||||
@ -563,8 +553,6 @@ impl PrivateContext {
|
|||||||
// retrieve go-sbot systemd process status
|
// retrieve go-sbot systemd process status
|
||||||
let sbot_status = SbotStatus::read()?;
|
let sbot_status = SbotStatus::read()?;
|
||||||
|
|
||||||
// we only want to try and interact with the sbot if it's active
|
|
||||||
if sbot_status.state == Some("active".to_string()) {
|
|
||||||
// retrieve latest go-sbot configuration parameters
|
// retrieve latest go-sbot configuration parameters
|
||||||
let sbot_config = SbotConfig::read().ok();
|
let sbot_config = SbotConfig::read().ok();
|
||||||
|
|
||||||
@ -574,11 +562,6 @@ impl PrivateContext {
|
|||||||
|
|
||||||
let local_id = sbot_client.whoami().await?;
|
let local_id = sbot_client.whoami().await?;
|
||||||
context.id = Some(local_id);
|
context.id = Some(local_id);
|
||||||
} else {
|
|
||||||
// the sbot is not currently active; return a helpful message
|
|
||||||
context.flash_name = Some("warning".to_string());
|
|
||||||
context.flash_msg = Some("The Sbot is currently inactive. As a result, private messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again".to_string());
|
|
||||||
}
|
|
||||||
|
|
||||||
context.sbot_status = Some(sbot_status);
|
context.sbot_status = Some(sbot_status);
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ pub async fn create_invite(invite: Form<Invite>, _auth: Authenticated) -> Flash<
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, new invite codes cannot be generated. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. New invite codes cannot be generated. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// failed to retrieve go-sbot systemd process status
|
// failed to retrieve go-sbot systemd process status
|
||||||
@ -173,6 +173,24 @@ pub async fn private(
|
|||||||
flash: Option<FlashMessage<'_>>,
|
flash: Option<FlashMessage<'_>>,
|
||||||
_auth: Authenticated,
|
_auth: Authenticated,
|
||||||
) -> Template {
|
) -> Template {
|
||||||
|
// display a helpful message if the sbot is inactive
|
||||||
|
if let Ok(false) = is_sbot_active() {
|
||||||
|
// retrieve current ui theme
|
||||||
|
let theme = utils::get_theme();
|
||||||
|
|
||||||
|
let mut context = Context::new();
|
||||||
|
context.insert("theme", &theme);
|
||||||
|
context.insert("back", &Some("/".to_string()));
|
||||||
|
context.insert("title", &Some("Private Messages".to_string()));
|
||||||
|
context.insert(
|
||||||
|
"unavailable_msg",
|
||||||
|
&Some("Private messages cannot be published.".to_string()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// render the "sbot is inactive" template
|
||||||
|
return Template::render("scuttlebutt/inactive", &context.into_json());
|
||||||
|
// otherwise, build the full context and render the private message template
|
||||||
|
} else {
|
||||||
if let Some(ref key) = public_key {
|
if let Some(ref key) = public_key {
|
||||||
// `url_decode` replaces '+' with ' ', so we need to revert that
|
// `url_decode` replaces '+' with ' ', so we need to revert that
|
||||||
public_key = Some(key.replace(' ', "+"));
|
public_key = Some(key.replace(' ', "+"));
|
||||||
@ -204,6 +222,7 @@ pub async fn private(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, FromForm)]
|
#[derive(Debug, FromForm)]
|
||||||
pub struct Private {
|
pub struct Private {
|
||||||
@ -256,7 +275,7 @@ pub async fn private_post(private: Form<Private>, _auth: Authenticated) -> Flash
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, new private message cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. New private message cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// failed to retrieve go-sbot systemd process status
|
// failed to retrieve go-sbot systemd process status
|
||||||
@ -337,9 +356,13 @@ pub fn peers(flash: Option<FlashMessage>, _auth: Authenticated) -> Template {
|
|||||||
|
|
||||||
// display a helpful message if the sbot is inactive
|
// display a helpful message if the sbot is inactive
|
||||||
if let Ok(false) = is_sbot_active() {
|
if let Ok(false) = is_sbot_active() {
|
||||||
context.insert("sbot_state", &Some("inactive".to_string()));
|
context.insert(
|
||||||
context.insert("flash_name", &Some("warning".to_string()));
|
"unavailable_msg",
|
||||||
context.insert("flash_msg", &Some("The Sbot is currently inactive. As a result, social lists and interactions are unavailable. Visit the Scuttlebutt settings menu to start the Sbot and then try again".to_string()));
|
&Some("Social lists and interactions are unavailable.".to_string()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// render the "sbot is inactive" template
|
||||||
|
return Template::render("scuttlebutt/inactive", &context.into_json());
|
||||||
} else {
|
} else {
|
||||||
context.insert("sbot_state", &Some("active".to_string()));
|
context.insert("sbot_state", &Some("active".to_string()));
|
||||||
// check to see if there is a flash message to display
|
// check to see if there is a flash message to display
|
||||||
@ -396,7 +419,7 @@ pub async fn publish(post: Form<Post>, _auth: Authenticated) -> Flash<Redirect>
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, new posts cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. New posts cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => return Flash::error(Redirect::to(url), e),
|
Err(e) => return Flash::error(Redirect::to(url), e),
|
||||||
@ -439,7 +462,7 @@ pub async fn follow(peer: Form<Peer>, _auth: Authenticated) -> Flash<Redirect> {
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. Follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => return Flash::error(Redirect::to(url), e),
|
Err(e) => return Flash::error(Redirect::to(url), e),
|
||||||
@ -484,7 +507,7 @@ pub async fn unfollow(peer: Form<Peer>, _auth: Authenticated) -> Flash<Redirect>
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. Follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => return Flash::error(Redirect::to(url), e),
|
Err(e) => return Flash::error(Redirect::to(url), e),
|
||||||
@ -527,7 +550,7 @@ pub async fn block(peer: Form<Peer>, _auth: Authenticated) -> Flash<Redirect> {
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. Follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => return Flash::error(Redirect::to(url), e),
|
Err(e) => return Flash::error(Redirect::to(url), e),
|
||||||
@ -571,7 +594,7 @@ pub async fn unblock(peer: Form<Peer>, _auth: Authenticated) -> Flash<Redirect>
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. Follow messages cannot be published. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => return Flash::error(Redirect::to(url), e),
|
Err(e) => return Flash::error(Redirect::to(url), e),
|
||||||
@ -590,6 +613,23 @@ pub async fn profile(
|
|||||||
flash: Option<FlashMessage<'_>>,
|
flash: Option<FlashMessage<'_>>,
|
||||||
_auth: Authenticated,
|
_auth: Authenticated,
|
||||||
) -> Template {
|
) -> Template {
|
||||||
|
// display a helpful message if the sbot is inactive
|
||||||
|
if let Ok(false) = is_sbot_active() {
|
||||||
|
// retrieve current ui theme
|
||||||
|
let theme = utils::get_theme();
|
||||||
|
|
||||||
|
let mut context = Context::new();
|
||||||
|
context.insert("theme", &theme);
|
||||||
|
context.insert("back", &Some("/".to_string()));
|
||||||
|
context.insert("title", &Some("Profile".to_string()));
|
||||||
|
context.insert(
|
||||||
|
"unavailable_msg",
|
||||||
|
&Some("Profile data cannot be retrieved.".to_string()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// render the "sbot is inactive" template
|
||||||
|
return Template::render("scuttlebutt/inactive", &context.into_json());
|
||||||
|
} else {
|
||||||
if let Some(ref key) = public_key {
|
if let Some(ref key) = public_key {
|
||||||
// `url_decode` replaces '+' with ' ', so we need to revert that
|
// `url_decode` replaces '+' with ' ', so we need to revert that
|
||||||
public_key = Some(key.replace(' ', "+"));
|
public_key = Some(key.replace(' ', "+"));
|
||||||
@ -628,6 +668,7 @@ pub async fn profile(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// HELPERS AND ROUTES FOR /profile/update
|
// HELPERS AND ROUTES FOR /profile/update
|
||||||
|
|
||||||
@ -635,6 +676,23 @@ pub async fn profile(
|
|||||||
/// for the local Scuttlebutt profile.
|
/// for the local Scuttlebutt profile.
|
||||||
#[get("/profile/update")]
|
#[get("/profile/update")]
|
||||||
pub async fn update_profile(flash: Option<FlashMessage<'_>>, _auth: Authenticated) -> Template {
|
pub async fn update_profile(flash: Option<FlashMessage<'_>>, _auth: Authenticated) -> Template {
|
||||||
|
// display a helpful message if the sbot is inactive
|
||||||
|
if let Ok(false) = is_sbot_active() {
|
||||||
|
// retrieve current ui theme
|
||||||
|
let theme = utils::get_theme();
|
||||||
|
|
||||||
|
let mut context = Context::new();
|
||||||
|
context.insert("theme", &theme);
|
||||||
|
context.insert("back", &Some("/".to_string()));
|
||||||
|
context.insert("title", &Some("Profile".to_string()));
|
||||||
|
context.insert(
|
||||||
|
"unavailable_msg",
|
||||||
|
&Some("Profile data cannot be retrieved.".to_string()),
|
||||||
|
);
|
||||||
|
|
||||||
|
// render the "sbot is inactive" template
|
||||||
|
return Template::render("scuttlebutt/inactive", &context.into_json());
|
||||||
|
} else {
|
||||||
// build the profile context object
|
// build the profile context object
|
||||||
let context = ProfileContext::build(None).await;
|
let context = ProfileContext::build(None).await;
|
||||||
|
|
||||||
@ -663,6 +721,7 @@ pub async fn update_profile(flash: Option<FlashMessage<'_>>, _auth: Authenticate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, FromForm)]
|
#[derive(Debug, FromForm)]
|
||||||
pub struct Profile<'f> {
|
pub struct Profile<'f> {
|
||||||
@ -780,7 +839,7 @@ pub async fn update_profile_post(
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
return Flash::warning(
|
return Flash::warning(
|
||||||
Redirect::to(url),
|
Redirect::to(url),
|
||||||
"The Sbot is currently inactive. As a result, profile data cannot be updated. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
"The Sbot is inactive. Profile data cannot be updated. Visit the Scuttlebutt settings menu to start the Sbot and then try again",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(e) => return Flash::error(Redirect::to(url), e),
|
Err(e) => return Flash::error(Redirect::to(url), e),
|
||||||
|
11
peach-web/templates/scuttlebutt/inactive.html.tera
Normal file
11
peach-web/templates/scuttlebutt/inactive.html.tera
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{%- extends "nav" -%}
|
||||||
|
{%- block card %}
|
||||||
|
<!-- SBOT INACTIVE -->
|
||||||
|
<div class="card center">
|
||||||
|
<div class="capsule capsule-container border-warning center-text">
|
||||||
|
<p class="card-text" style="font-size: var(--font-size-4);">Sbot Inactive</p>
|
||||||
|
<p>{{ unavailable_msg }}</p>
|
||||||
|
<p class="card-text">Visit the <strong><a href="/settings/scuttlebutt" class="link font-near-black">Scuttlebutt settings menu</a></strong> to start the Sbot and then try again.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{%- endblock card -%}
|
@ -2,7 +2,7 @@
|
|||||||
{%- block card %}
|
{%- block card %}
|
||||||
<div class="card center">
|
<div class="card center">
|
||||||
{%- if peers %}
|
{%- if peers %}
|
||||||
<ul class="list">
|
<ul class="center list">
|
||||||
{%- for peer in peers %}
|
{%- for peer in peers %}
|
||||||
{# set a fall-back value for name in case the data is unavailable #}
|
{# set a fall-back value for name in case the data is unavailable #}
|
||||||
{%- if not peer['name'] %}
|
{%- if not peer['name'] %}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{%- extends "nav" -%}
|
{%- extends "nav" -%}
|
||||||
{%- block card %}
|
{%- block card %}
|
||||||
<!-- SCUTTLEBUTT PRIVATE MESSAGE FORM -->
|
<!-- SCUTTLEBUTT PRIVATE MESSAGE FORM -->
|
||||||
<div class="card center">
|
<div class="card card-wide center">
|
||||||
{# only render the private message elements if the sbot is active #}
|
{# only render the private message elements if the sbot is active #}
|
||||||
{%- if sbot_status and sbot_status.state == "active" %}
|
{%- if sbot_status and sbot_status.state == "active" %}
|
||||||
<form id="sbotConfig" class="center" action="/scuttlebutt/private" method="post">
|
<form id="sbotConfig" class="center" action="/scuttlebutt/private" method="post">
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{%- extends "nav" -%}
|
{%- extends "nav" -%}
|
||||||
{%- block card %}
|
{%- block card %}
|
||||||
<!-- USER PROFILE -->
|
<!-- USER PROFILE -->
|
||||||
<div class="card center">
|
<div class="card card-wide center">
|
||||||
{# only render the profile info elements if the sbot is active #}
|
{# only render the profile info elements if the sbot is active #}
|
||||||
{%- if sbot_status and sbot_status.state == "active" %}
|
{%- if sbot_status and sbot_status.state == "active" %}
|
||||||
<!-- PROFILE INFO BOX -->
|
<!-- PROFILE INFO BOX -->
|
||||||
@ -38,12 +38,12 @@
|
|||||||
<!-- TODO: each of these buttons needs to be a form with a public key -->
|
<!-- TODO: each of these buttons needs to be a form with a public key -->
|
||||||
<div id="buttons" style="margin-top: 2rem;">
|
<div id="buttons" style="margin-top: 2rem;">
|
||||||
{% if following == false %}
|
{% if following == false %}
|
||||||
<form id="followForm" action="/scuttlebutt/follow" method="post">
|
<form id="followForm" class="center" action="/scuttlebutt/follow" method="post">
|
||||||
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
||||||
<input id="followPeer" class="button button-primary center" type="submit" title="Follow Peer" value="Follow">
|
<input id="followPeer" class="button button-primary center" type="submit" title="Follow Peer" value="Follow">
|
||||||
</form>
|
</form>
|
||||||
{% elif following == true %}
|
{% elif following == true %}
|
||||||
<form id="unfollowForm" action="/scuttlebutt/unfollow" method="post">
|
<form id="unfollowForm" class="center" action="/scuttlebutt/unfollow" method="post">
|
||||||
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
||||||
<input id="unfollowPeer" class="button button-primary center" type="submit" title="Unfollow Peer" value="Unfollow">
|
<input id="unfollowPeer" class="button button-primary center" type="submit" title="Unfollow Peer" value="Unfollow">
|
||||||
</form>
|
</form>
|
||||||
@ -51,19 +51,21 @@
|
|||||||
<p>Unable to determine follow state</p>
|
<p>Unable to determine follow state</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if blocking == false %}
|
{% if blocking == false %}
|
||||||
<form id="blockForm" action="/scuttlebutt/block" method="post">
|
<form id="blockForm" class="center" action="/scuttlebutt/block" method="post">
|
||||||
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
||||||
<input id="blockPeer" class="button button-primary center" type="submit" title="Block Peer" value="Block">
|
<input id="blockPeer" class="button button-primary center" type="submit" title="Block Peer" value="Block">
|
||||||
</form>
|
</form>
|
||||||
{% elif blocking == true %}
|
{% elif blocking == true %}
|
||||||
<form id="unblockForm" action="/scuttlebutt/unblock" method="post">
|
<form id="unblockForm" class="center" action="/scuttlebutt/unblock" method="post">
|
||||||
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
<input type="hidden" id="publicKey" name="public_key" value="{{ id }}">
|
||||||
<input id="unblockPeer" class="button button-primary center" type="submit" title="Unblock Peer" value="Unblock">
|
<input id="unblockPeer" class="button button-primary center" type="submit" title="Unblock Peer" value="Unblock">
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Unable to determine block state</p>
|
<p>Unable to determine block state</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<form class="center">
|
||||||
<a id="privateMessage" class="button button-primary center" href="/scuttlebutt/private?public_key={{ id }}" title="Private Message">Send Private Message</a>
|
<a id="privateMessage" class="button button-primary center" href="/scuttlebutt/private?public_key={{ id }}" title="Private Message">Send Private Message</a>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
Reference in New Issue
Block a user