Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed avatars #285

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ssr/src/component/video_player.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use leptos::*;
use leptos_dom::{html::Video, NodeRef};
use leptos_dom::html::Video;

#[component]
pub fn VideoPlayer(
Expand Down
3 changes: 3 additions & 0 deletions ssr/src/consts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ use reqwest::Url;

pub const CF_STREAM_BASE: &str = "https://customer-2p3jflss4r4hmpnz.cloudflarestream.com";
pub const FALLBACK_PROPIC_BASE: &str = "https://api.dicebear.com/7.x/big-smile/svg";
// an example URL is "https://imagedelivery.net/abXI9nS4DYYtyR1yFFtziA/gob.5/public";
pub const GOBGOB_PROPIC_URL: &str = "https://imagedelivery.net/abXI9nS4DYYtyR1yFFtziA/gob.";
pub const GOBGOB_TOTAL_COUNT: u32 = 18557;
pub const CF_WATERMARK_UID: &str = "c094ef579b950a6a5ae3e482268b81ca";
pub const ACCOUNT_CONNECTED_STORE: &str = "account-connected-1";
pub static CF_BASE_URL: Lazy<Url> =
Expand Down
24 changes: 10 additions & 14 deletions ssr/src/utils/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
UserProfileDetailsForFrontend,
},
component::infinite_scroller::{CursoredDataProvider, KeyedData, PageEntry},
consts::FALLBACK_PROPIC_BASE,
consts::{GOBGOB_PROPIC_URL, GOBGOB_TOTAL_COUNT},
state::canisters::Canisters,
};

Expand Down Expand Up @@ -44,9 +44,9 @@ impl From<UserProfileDetailsForFrontend> for ProfileDetails {
}
}

fn color_from_principal(principal: Principal) -> String {
let col_int = crc32fast::hash(principal.as_slice()) & 0xFFFFFF;
format!("{col_int:06x}")
fn index_from_principal(principal: Principal) -> u32 {
let hash_value = crc32fast::hash(principal.as_slice());
(hash_value % GOBGOB_TOTAL_COUNT) + 1
}

impl ProfileDetails {
Expand All @@ -63,22 +63,18 @@ impl ProfileDetails {
}

pub fn profile_pic_or_random(&self) -> String {
let propic = self.profile_pic.clone().unwrap_or_default();
if !propic.is_empty() {
return propic;
}
// let propic = self.profile_pic.clone().unwrap_or_default();
// if !propic.is_empty() {
// return propic;
// }

propic_from_principal(self.principal)
}
}

pub fn propic_from_principal(principal: Principal) -> String {
let background_color = color_from_principal(principal);
format!(
"{FALLBACK_PROPIC_BASE}?seed={}&backgroundColor={}&backgroundType=solid",
principal.to_text(),
background_color
)
let index = index_from_principal(principal);
format!("{GOBGOB_PROPIC_URL}{}/public", index)
}

#[derive(Clone, Copy)]
Expand Down
Loading