Skip to content

Commit

Permalink
add: show if the current user has already liked a response
Browse files Browse the repository at this point in the history
add: response relationship check on profiles and circles
add: change site icons
add: change site font
add: more coherent buttons
add: response "Boost" button
remove: reply_intent
  • Loading branch information
trisuaso committed Nov 17, 2024
1 parent fbed9c1 commit 4884fc5
Show file tree
Hide file tree
Showing 82 changed files with 1,175 additions and 3,265 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ crates/rainbeam/static/site/about.md
crates/rainbeam/static/fonts/
crates/rainbeam/static/manifest.json
crates/rainbeam/static/images/logo/
crates/rainbeam/static/images/ui/logo.*
crates/rainbeam/static/favicon.svg
crates/rainbeam/static/build/
*.db
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rainbeam-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rainbeam-core"
version = "1.15.5"
version = "1.16.0"
edition = "2021"
authors = ["trisuaso", "swmff"]
description = "Rainbeam backend core"
Expand Down
15 changes: 1 addition & 14 deletions crates/rainbeam-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,16 +1379,6 @@ impl Database {
return Err(DatabaseError::ContentTooShort);
}

// check reply_intent
if !props.reply_intent.is_empty() {
if let Err(e) = self
.get_response(props.reply_intent.trim().to_string())
.await
{
return Err(e);
}
}

// ...
let question = Question {
author: match self.get_profile(author).await {
Expand All @@ -1403,10 +1393,7 @@ impl Database {
id: utility::random_id(),
timestamp: utility::unix_epoch_timestamp(),
ip: ip.clone(),
context: QuestionContext {
reply_intent: props.reply_intent,
media: props.media,
},
context: QuestionContext { media: props.media },
};

// create question
Expand Down
8 changes: 0 additions & 8 deletions crates/rainbeam-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ impl Question {
/// Basic information which changes the way the response is deserialized
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct QuestionContext {
/// The ID of the response in which this question is replying to
///
/// Will fill into the "reply" field of the response that is posted to this question
#[serde(default)]
pub reply_intent: String,
/// The media property of the question
///
/// Media is prefixed to decide what its type is:
Expand All @@ -116,7 +111,6 @@ impl Context for QuestionContext {}
impl Default for QuestionContext {
fn default() -> Self {
Self {
reply_intent: String::new(),
media: String::new(),
}
}
Expand Down Expand Up @@ -523,8 +517,6 @@ pub struct QuestionCreate {
pub content: String,
pub anonymous: bool,
#[serde(default)]
pub reply_intent: String,
#[serde(default)]
pub media: String,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rainbeam/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rainbeam"
version = "1.15.5"
version = "1.16.0"
edition = "2021"
authors = ["trisuaso", "swmff"]
description = "Ask, share, socialize!"
Expand Down
124 changes: 123 additions & 1 deletion crates/rainbeam/src/routing/pages/circles.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::collections::HashMap;

use ammonia::Builder;
use askama_axum::Template;
use axum::extract::{Path, Query};
use axum::response::{IntoResponse, Redirect};
use axum::{extract::State, response::Html};
use axum_extra::extract::CookieJar;

use authbeam::model::{Permission, Profile};
use authbeam::model::{Permission, Profile, RelationshipStatus};

use crate::config::Config;
use crate::database::Database;
Expand Down Expand Up @@ -174,6 +176,8 @@ struct ProfileTemplate {
notifs: usize,
circle: Circle,
responses: Vec<FullResponse>,
reactions: Vec<String>,
relationships: HashMap<String, RelationshipStatus>,
member_count: usize,
metadata: String,
pinned: Option<Vec<FullResponse>>,
Expand Down Expand Up @@ -290,6 +294,62 @@ pub async fn profile_request(
false
};

// build relationships list
let mut relationships: HashMap<String, RelationshipStatus> = HashMap::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if relationships.contains_key(&response.1.author.id) {
continue;
}

if is_helper {
// make sure staff can view your responses
relationships.insert(response.1.author.id.clone(), RelationshipStatus::Friends);
continue;
}

if response.1.author.id == ua.id {
// make sure we can view our own responses
relationships.insert(response.1.author.id.clone(), RelationshipStatus::Friends);
continue;
};

relationships.insert(
response.1.author.id.clone(),
database
.auth
.get_user_relationship(response.1.author.id.clone(), ua.id.clone())
.await
.0,
);
}
} else {
for response in &responses {
// no user, no relationships
if relationships.contains_key(&response.1.author.id) {
continue;
}

relationships.insert(response.1.author.id.clone(), RelationshipStatus::Unknown);
}
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}
}

// ...
Html(
ProfileTemplate {
config: database.server_options.clone(),
Expand All @@ -298,6 +358,8 @@ pub async fn profile_request(
notifs,
circle: circle.clone(),
responses,
reactions,
relationships,
member_count: database
.get_circle_memberships_count(circle.id.clone())
.await,
Expand All @@ -322,6 +384,8 @@ struct PartialProfileTemplate {
profile: Option<Profile>,
other: Circle,
responses: Vec<FullResponse>,
reactions: Vec<String>,
relationships: HashMap<String, RelationshipStatus>,
// ...
is_powerful: bool, // at least "manager"
is_helper: bool, // at least "helper"
Expand Down Expand Up @@ -372,12 +436,70 @@ pub async fn partial_profile_request(
false
};

// build relationships list
let mut relationships: HashMap<String, RelationshipStatus> = HashMap::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if relationships.contains_key(&response.1.author.id) {
continue;
}

if is_helper {
// make sure staff can view your responses
relationships.insert(response.1.author.id.clone(), RelationshipStatus::Friends);
continue;
}

if response.1.author.id == ua.id {
// make sure we can view our own responses
relationships.insert(response.1.author.id.clone(), RelationshipStatus::Friends);
continue;
};

relationships.insert(
response.1.author.id.clone(),
database
.auth
.get_user_relationship(response.1.author.id.clone(), ua.id.clone())
.await
.0,
);
}
} else {
for response in &responses {
// no user, no relationships
if relationships.contains_key(&response.1.author.id) {
continue;
}

relationships.insert(response.1.author.id.clone(), RelationshipStatus::Unknown);
}
}

// collect all responses we've reacted to
let mut reactions: Vec<String> = Vec::new();

if let Some(ref ua) = auth_user {
for response in &responses {
if let Ok(_) = database
.get_reaction(ua.id.clone(), response.1.id.clone())
.await
{
reactions.push(response.1.id.clone())
}
}
}

// ...
Html(
PartialProfileTemplate {
config: database.server_options.clone(),
profile: auth_user.clone(),
other: circle.clone(),
responses,
reactions,
relationships,
// ...
is_powerful,
is_helper,
Expand Down
Loading

0 comments on commit 4884fc5

Please sign in to comment.