Some fixes.
- Showing correct user icon and banner after save without page reload. - Abstracting diesel update overwrite. - Adding some docs.
This commit is contained in:
parent
39a6c7d157
commit
39d75a6984
8 changed files with 39 additions and 71 deletions
4
docs/src/about_ranking.md
vendored
4
docs/src/about_ranking.md
vendored
|
@ -18,7 +18,9 @@ Score = Upvotes - Downvotes
|
|||
Time = time since submission (in hours)
|
||||
Gravity = Decay gravity, 1.8 is default
|
||||
```
|
||||
- For posts, in order to bring up active posts, it uses the latest comment time (limited to a max creation age of a month ago)
|
||||
- Lemmy uses the same `Rank` algorithm above, in two sorts: `Active`, and `Hot`.
|
||||
- `Active` uses the post votes, and latest comment time (limited to two days).
|
||||
- `Hot` uses the post votes, and the post published time.
|
||||
- Use Max(1, score) to make sure all comments are affected by time decay.
|
||||
- Add 3 to the score, so that everything that has less than 3 downvotes will seem new. Otherwise all new comments would stay at zero, near the bottom.
|
||||
- The sign and abs of the score are necessary for dealing with the log of negative scores.
|
||||
|
|
3
docs/src/contributing_websocket_http_api.md
vendored
3
docs/src/contributing_websocket_http_api.md
vendored
|
@ -330,7 +330,8 @@ curl -i -H \
|
|||
|
||||
These go wherever there is a `sort` field. The available sort types are:
|
||||
|
||||
- `Hot` - the hottest posts/communities, depending on votes, views, comments and publish date
|
||||
- `Active` - the hottest posts/communities, depending on votes, and newest comment publish date.
|
||||
- `Hot` - the hottest posts/communities, depending on votes and publish date.
|
||||
- `New` - the newest posts/communities
|
||||
- `TopDay` - the most upvoted posts/communities of the current day.
|
||||
- `TopWeek` - the most upvoted posts/communities of the current week.
|
||||
|
|
|
@ -181,6 +181,20 @@ pub fn is_email_regex(test: &str) -> bool {
|
|||
EMAIL_REGEX.is_match(test)
|
||||
}
|
||||
|
||||
pub fn diesel_option_overwrite(opt: &Option<String>) -> Option<Option<String>> {
|
||||
match opt {
|
||||
// An empty string is an erase
|
||||
Some(unwrapped) => {
|
||||
if !unwrapped.eq("") {
|
||||
Some(Some(unwrapped.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref EMAIL_REGEX: Regex =
|
||||
Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
|
||||
|
|
|
@ -28,6 +28,7 @@ pub struct SiteForm {
|
|||
pub enable_downvotes: bool,
|
||||
pub open_registration: bool,
|
||||
pub enable_nsfw: bool,
|
||||
// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
||||
pub icon: Option<Option<String>>,
|
||||
pub banner: Option<Option<String>>,
|
||||
}
|
||||
|
|
|
@ -10,7 +10,15 @@ use crate::{
|
|||
},
|
||||
DbPool,
|
||||
};
|
||||
use lemmy_db::{naive_now, Bannable, Crud, Followable, Joinable, SortType};
|
||||
use lemmy_db::{
|
||||
diesel_option_overwrite,
|
||||
naive_now,
|
||||
Bannable,
|
||||
Crud,
|
||||
Followable,
|
||||
Joinable,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_utils::{
|
||||
generate_actor_keypair,
|
||||
is_valid_community_name,
|
||||
|
@ -338,29 +346,8 @@ impl Perform for Oper<EditCommunity> {
|
|||
let edit_id = data.edit_id;
|
||||
let read_community = blocking(pool, move |conn| Community::read(conn, edit_id)).await??;
|
||||
|
||||
let icon = match &data.icon {
|
||||
// An empty string is an erase
|
||||
Some(icon) => {
|
||||
if !icon.eq("") {
|
||||
Some(Some(icon.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => Some(read_community.icon),
|
||||
};
|
||||
|
||||
let banner = match &data.banner {
|
||||
// An empty string is an erase
|
||||
Some(banner) => {
|
||||
if !banner.eq("") {
|
||||
Some(Some(banner.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => Some(read_community.banner),
|
||||
};
|
||||
let icon = diesel_option_overwrite(&data.icon);
|
||||
let banner = diesel_option_overwrite(&data.banner);
|
||||
|
||||
let community_form = CommunityForm {
|
||||
name: read_community.name,
|
||||
|
|
|
@ -21,6 +21,7 @@ use lemmy_db::{
|
|||
category::*,
|
||||
comment_view::*,
|
||||
community_view::*,
|
||||
diesel_option_overwrite,
|
||||
moderator::*,
|
||||
moderator_views::*,
|
||||
naive_now,
|
||||
|
@ -306,29 +307,8 @@ impl Perform for Oper<EditSite> {
|
|||
|
||||
let found_site = blocking(pool, move |conn| Site::read(conn, 1)).await??;
|
||||
|
||||
let icon = match &data.icon {
|
||||
// An empty string is an erase
|
||||
Some(icon) => {
|
||||
if !icon.eq("") {
|
||||
Some(Some(icon.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => Some(found_site.icon),
|
||||
};
|
||||
|
||||
let banner = match &data.banner {
|
||||
// An empty string is an erase
|
||||
Some(banner) => {
|
||||
if !banner.eq("") {
|
||||
Some(Some(banner.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => Some(found_site.banner),
|
||||
};
|
||||
let icon = diesel_option_overwrite(&data.icon);
|
||||
let banner = diesel_option_overwrite(&data.banner);
|
||||
|
||||
let site_form = SiteForm {
|
||||
name: data.name.to_owned(),
|
||||
|
|
|
@ -28,6 +28,7 @@ use lemmy_db::{
|
|||
comment_view::*,
|
||||
community::*,
|
||||
community_view::*,
|
||||
diesel_option_overwrite,
|
||||
moderator::*,
|
||||
naive_now,
|
||||
password_reset_request::*,
|
||||
|
@ -574,28 +575,8 @@ impl Perform for Oper<SaveUserSettings> {
|
|||
None => read_user.bio,
|
||||
};
|
||||
|
||||
let avatar = match &data.avatar {
|
||||
// An empty string is an erase
|
||||
Some(avatar) => {
|
||||
if !avatar.eq("") {
|
||||
Some(Some(avatar.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => Some(read_user.avatar),
|
||||
};
|
||||
|
||||
let banner = match &data.banner {
|
||||
Some(banner) => {
|
||||
if !banner.eq("") {
|
||||
Some(Some(banner.to_owned()))
|
||||
} else {
|
||||
Some(None)
|
||||
}
|
||||
}
|
||||
None => Some(read_user.banner),
|
||||
};
|
||||
let avatar = diesel_option_overwrite(&data.avatar);
|
||||
let banner = diesel_option_overwrite(&data.banner);
|
||||
|
||||
// The DB constraint should stop too many characters
|
||||
let preferred_username = match &data.preferred_username {
|
||||
|
|
2
ui/src/components/user.tsx
vendored
2
ui/src/components/user.tsx
vendored
|
@ -1082,6 +1082,8 @@ export class User extends Component<any, UserState> {
|
|||
UserService.Instance.login(data);
|
||||
this.state.user.bio = this.state.userSettingsForm.bio;
|
||||
this.state.user.preferred_username = this.state.userSettingsForm.preferred_username;
|
||||
this.state.user.banner = this.state.userSettingsForm.banner;
|
||||
this.state.user.avatar = this.state.userSettingsForm.avatar;
|
||||
this.state.userSettingsLoading = false;
|
||||
this.setState(this.state);
|
||||
|
||||
|
|
Loading…
Reference in a new issue