update friends list handler and remove followers

This commit is contained in:
2022-02-28 16:25:31 +02:00
parent 03028a2278
commit 814162ce7d
3 changed files with 24 additions and 83 deletions

View File

@ -75,7 +75,6 @@ pub fn mount_peachpub_routes(rocket: Rocket<Build>) -> Rocket<Build> {
peer_lookup,
friends,
follows,
followers,
blocks,
profile,
update_profile,

View File

@ -16,7 +16,7 @@ use rocket_dyn_templates::{tera::Context, Template};
use crate::{
context::{
sbot,
sbot::{FollowsContext, ProfileContext},
sbot::{FollowsContext, FriendsContext, ProfileContext},
},
routes::authentication::Authenticated,
utils,
@ -535,47 +535,35 @@ pub async fn update_profile_post(
// HELPERS AND ROUTES FOR /friends
#[derive(Debug, Serialize)]
pub struct FriendsContext {
pub back: Option<String>,
pub flash_name: Option<String>,
pub flash_msg: Option<String>,
pub title: Option<String>,
pub theme: Option<String>,
}
impl FriendsContext {
pub fn build() -> FriendsContext {
FriendsContext {
back: None,
flash_name: None,
flash_msg: None,
title: None,
theme: None,
}
}
}
/// A list of friends (mutual follows), with each list item displaying the
/// name, image and public key of the peer.
#[get("/friends")]
pub fn friends(flash: Option<FlashMessage>, _auth: Authenticated) -> Template {
// retrieve current ui theme
let theme = utils::get_theme();
pub async fn friends(flash: Option<FlashMessage<'_>>, _auth: Authenticated) -> Template {
// build the friends context object
let context = FriendsContext::build().await;
let mut context = FriendsContext::build();
context.back = Some("/scuttlebutt/peers".to_string());
context.title = Some("Friends".to_string());
context.theme = Some(theme);
match context {
// we were able to build the context without errors
Ok(mut context) => {
// check to see if there is a flash message to display
if let Some(flash) = flash {
// add flash message contents to the context object
context.flash_name = Some(flash.kind().to_string());
context.flash_msg = Some(flash.message().to_string());
};
// check to see if there is a flash message to display
if let Some(flash) = flash {
// add flash message contents to the context object
context.flash_name = Some(flash.kind().to_string());
context.flash_msg = Some(flash.message().to_string());
};
Template::render("scuttlebutt/peers_list", &context)
}
// an error occurred while building the context
Err(e) => {
// build the default context and pass along the error message
let mut context = FriendsContext::default();
context.flash_name = Some("error".to_string());
context.flash_msg = Some(e.to_string());
Template::render("scuttlebutt/peers_list", &context)
Template::render("scuttlebutt/peers_list", &context)
}
}
}
// HELPERS AND ROUTES FOR /follows
@ -611,51 +599,6 @@ pub async fn follows(flash: Option<FlashMessage<'_>>, _auth: Authenticated) -> T
}
}
// HELPERS AND ROUTES FOR /followers
#[derive(Debug, Serialize)]
pub struct FollowersContext {
pub back: Option<String>,
pub flash_name: Option<String>,
pub flash_msg: Option<String>,
pub title: Option<String>,
pub theme: Option<String>,
}
impl FollowersContext {
pub fn build() -> FollowersContext {
FollowersContext {
back: None,
flash_name: None,
flash_msg: None,
title: None,
theme: None,
}
}
}
/// A list of followers (peers who follow us but who we do not follow), with each list item displaying the name, image and public
/// key of the peer.
#[get("/followers")]
pub fn followers(flash: Option<FlashMessage>, _auth: Authenticated) -> Template {
// retrieve current ui theme
let theme = utils::get_theme();
let mut context = FollowersContext::build();
context.back = Some("/scuttlebutt/peers".to_string());
context.title = Some("Followers".to_string());
context.theme = Some(theme);
// check to see if there is a flash message to display
if let Some(flash) = flash {
// add flash message contents to the context object
context.flash_name = Some(flash.kind().to_string());
context.flash_msg = Some(flash.message().to_string());
};
Template::render("scuttlebutt/peers_list", &context)
}
// HELPERS AND ROUTES FOR /blocks
#[derive(Debug, Serialize)]

View File

@ -9,7 +9,6 @@
<a id="lookup" class="button button-primary center" href="/scuttlebutt/peer/lookup" title="Define Peer Relationship">Peer Lookup</a>
<a id="friends" class="button button-primary center" href="/scuttlebutt/friends" title="List Friends">Friends</a>
<a id="follows" class="button button-primary center" href="/scuttlebutt/follows" title="List Follows">Follows</a>
<a id="followers" class="button button-primary center" href="/scuttlebutt/followers" title="List Followers">Followers</a>
<a id="blocks" class="button button-primary center" href="/scuttlebutt/blocks" title="List Blocks">Blocks</a>
<a id="invites" class="button button-primary center" href="/scuttlebutt/invites" title="Invites">Invites</a>
</div>