rudimentary follow checker for debugging

something is off.
somehow unfollowing once doesn't make sbot return false on the next follow check
This commit is contained in:
Daan Wynen 2022-09-28 18:52:49 +02:00
parent 85824b87e4
commit e4f9357819
5 changed files with 95 additions and 7 deletions

View File

@ -25,5 +25,5 @@ async fn rocket() -> _ {
rocket::build()
.manage(db)
.attach(Template::fairing())
.mount("/", routes![home, subscribe_form, unsubscribe_form])
.mount("/", routes![home, subscribe_form, unsubscribe_form, about_start, about_form])
}

View File

@ -21,6 +21,58 @@ pub async fn home(flash: Option<FlashMessage<'_>>) -> Template {
Template::render("base", context! { whoami, flash })
}
#[get("/about")]
pub async fn about_start() -> Template {
Template::render("about", context! {})
}
#[post("/about", data = "<peer>")]
pub async fn about_form(peer: Form<PeerForm>) -> Result<Template, Flash<Redirect>> {
info!("Showing follow information about peer {}", &peer.public_key);
let whoami = match sbot::whoami().await {
Ok(value) => value,
Err(e) => return Err(Flash::error(Redirect::to(uri!(about_start)), e)),
};
if let Err(e) = utils::validate_public_key(&peer.public_key) {
let validation_err_msg = format!("Public key {} is invalid: {}", &peer.public_key, e);
warn!("{}", validation_err_msg);
return Err(Flash::error(Redirect::to(uri!(about_start)), validation_err_msg));
}
info!("Public key {} is valid.", &peer.public_key);
// let peer_name = match sbot::get_name(&peer.public_key).await {
// Ok(name) if name == peer.public_key => "<no known handle>".to_string(),
// Ok(name) => name,
// Err(e) => {
// warn!("Failed to fetch name for peer {}: {}", &peer.public_key, e);
// String::from("")
// }
// };
//
// info!("Peer name: {}", peer_name);
let follow_status = match sbot::is_following(&whoami, &peer.public_key).await {
Ok(status) => {
let success_msg = format!(
"Follow status for {} : '{}'",
&peer.public_key,
status,
);
info!("{}", success_msg);
status
},
Err(e) => {
warn!("{}", e);
return Err(Flash::error(Redirect::to(uri!(about_start)), e));
}
};
Ok(Template::render("about", context! { whoami, peer_pubkey: &peer.public_key, status: follow_status }))
}
#[post("/subscribe", data = "<peer>")]
pub async fn subscribe_form(db: &State<Database>, peer: Form<PeerForm>) -> Result<Redirect, Flash<Redirect>> {
info!("Subscribing to peer {}", &peer.public_key);

View File

@ -87,12 +87,12 @@ pub async fn unfollow_if_not_following(remote_peer: &str) -> Result<(), String>
info!("Seeing whether we should unfollow {}", remote_peer);
if let Ok(whoami) = whoami().await {
match is_following(&whoami, remote_peer).await {
Ok(status) if status.as_str() != "true" => {
Ok(status) if status != "true" => {
info!("Status: '{}'", status);
info!("Already not following peer {}. No further action taken", &remote_peer);
Ok(())
},
Ok(status) if status.as_str() == "true" => {
Ok(status) if status == "true" => {
info!("Status: '{}'", status);
match unfollow_peer(remote_peer).await {
Ok(_) => {

35
templates/about.html.tera Normal file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>lykin check</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>lykin <code>follow</code> checker</h1>
<form action="/about" method="post">
<label for="public_key">Public Key</label>
<input type="text"
id="public_key"
name="public_key"
maxlength=53
style="font-family: monospace; width: 55ch;"
{% if peer_pubkey %}
value="{{ peer_pubkey }}"
{% endif %}
>
<input type="submit" value="Check">
</form>
{% if flash and flash.kind == "error" %}
<p style="color: red;">[ {{ flash.message }} ]</p>
{% endif %}</p>
{% if peer_pubkey and whoami and status %}
<pre>
me: {{ whoami }}
peer: {{ peer_pubkey }}
status: {{ status }}
</pre>
{% endif %}</p>
</body>
</html>

View File

@ -7,12 +7,13 @@
</head>
<body>
<h1>lykin</h1>
<p>{{ whoami }}</p>
<p><code>{{ whoami }}</code></p>
<form action="/subscribe" method="post">
<label for="public_key">Public Key</label>
<input type="text" id="public_key" name="public_key" maxlength=53>
<input type="submit" value="subscribe">
<input type="submit" value="unsubscribe" formaction="/unsubscribe">
<input type="text" id="public_key" name="public_key" maxlength=53 style="font-family: monospace; width: 55ch;" >
<br />
<input type="submit" value="Subscribe">
<input type="submit" value="Unsubscribe" formaction="/unsubscribe">
</form>
{% if flash and flash.kind == "error" %}
<p style="color: red;">[ {{ flash.message }} ]</p>