add: blocked users page
This commit is contained in:
parent
6893aeedb5
commit
3706764437
18 changed files with 427 additions and 178 deletions
|
@ -23,7 +23,7 @@ async-recursion = "1.1.1"
|
|||
md-5 = "0.10.6"
|
||||
base16ct = { version = "0.2.0", features = ["alloc"] }
|
||||
|
||||
redis = { version = "0.30.0", features = [
|
||||
redis = { version = "0.31.0", features = [
|
||||
"aio",
|
||||
"tokio-comp",
|
||||
], optional = true }
|
||||
|
|
|
@ -43,7 +43,7 @@ impl DataManager {
|
|||
let mut out = Vec::new();
|
||||
|
||||
for member in members {
|
||||
if ignore_users.contains(&member) {
|
||||
if ignore_users.contains(member) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ impl DataManager {
|
|||
let mut users: HashMap<usize, User> = HashMap::new();
|
||||
for (i, message) in messages.iter().enumerate() {
|
||||
let next_owner: usize = match messages.get(i + 1) {
|
||||
Some(ref m) => m.owner,
|
||||
Some(m) => m.owner,
|
||||
None => 0,
|
||||
};
|
||||
|
||||
|
|
|
@ -171,10 +171,8 @@ impl DataManager {
|
|||
let stack = self.get_stack_by_id(id).await?;
|
||||
|
||||
// check user permission
|
||||
if user.id != stack.owner {
|
||||
if !user.permissions.check(FinePermission::MANAGE_STACKS) {
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
if user.id != stack.owner && !user.permissions.check(FinePermission::MANAGE_STACKS) {
|
||||
return Err(Error::NotAllowed);
|
||||
}
|
||||
|
||||
// ...
|
||||
|
|
|
@ -25,6 +25,17 @@ impl DataManager {
|
|||
|
||||
auto_method!(get_userblock_by_id()@get_userblock_from_row -> "SELECT * FROM userblocks WHERE id = $1" --name="user block" --returns=UserBlock --cache-key-tmpl="atto.userblock:{}");
|
||||
|
||||
/// Fill a vector of user blocks with their receivers.
|
||||
pub async fn fill_userblocks_receivers(&self, list: Vec<UserBlock>) -> Result<Vec<User>> {
|
||||
let mut out = Vec::new();
|
||||
|
||||
for block in list {
|
||||
out.push(self.get_user_by_id(block.receiver).await?);
|
||||
}
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// Get a user block by `initiator` and `receiver` (in that order).
|
||||
pub async fn get_userblock_by_initiator_receiver(
|
||||
&self,
|
||||
|
@ -104,6 +115,28 @@ impl DataManager {
|
|||
out
|
||||
}
|
||||
|
||||
/// Get all user blocks created by the given `initiator`.
|
||||
pub async fn get_userblocks_by_initiator(&self, initiator: usize) -> Vec<UserBlock> {
|
||||
let conn = match self.connect().await {
|
||||
Ok(c) => c,
|
||||
Err(_) => return Vec::new(),
|
||||
};
|
||||
|
||||
let res = query_rows!(
|
||||
&conn,
|
||||
"SELECT * FROM userblocks WHERE initiator = $1",
|
||||
&[&(initiator as i64)],
|
||||
|x| { Self::get_userblock_from_row(x) }
|
||||
);
|
||||
|
||||
if res.is_err() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
// return
|
||||
res.unwrap()
|
||||
}
|
||||
|
||||
/// Create a new user block in the database.
|
||||
///
|
||||
/// # Arguments
|
||||
|
|
|
@ -111,22 +111,21 @@ impl CustomEmoji {
|
|||
|
||||
let mut chars = input.chars();
|
||||
while let Some(char) = chars.next() {
|
||||
if char == '\\' && escape == false {
|
||||
if char == '\\' && !escape {
|
||||
escape = true;
|
||||
continue;
|
||||
} else if char == ':' && escape == false {
|
||||
} else if char == ':' && !escape {
|
||||
let mut community_id: String = String::new();
|
||||
let mut accepting_community_id_chars: bool = true;
|
||||
let mut emoji_name: String = String::new();
|
||||
|
||||
let mut char_count: u32 = 0; // if we're past the first 4 characters and we haven't hit a digit, stop accepting community id
|
||||
while let Some(char) = chars.next() {
|
||||
for (char_count, char) in (0_u32..).zip(chars.by_ref()) {
|
||||
if (char == ':') | (char == ' ') {
|
||||
in_emoji = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if char.is_digit(10) && accepting_community_id_chars {
|
||||
if char.is_ascii_digit() && accepting_community_id_chars {
|
||||
community_id.push(char);
|
||||
} else if char == '.' {
|
||||
// the period closes the community id
|
||||
|
@ -138,8 +137,6 @@ impl CustomEmoji {
|
|||
if char_count >= 4 && community_id.is_empty() {
|
||||
accepting_community_id_chars = false;
|
||||
}
|
||||
|
||||
char_count += 1;
|
||||
}
|
||||
|
||||
out.push((
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue