Commit 5057f910 authored by Alejandro Domínguez's avatar Alejandro Domínguez Committed by Daniel Garcia Moreno

API: move stuff to the root of the backend module

parent 8ffa747b
Pipeline #192422 failed with stages
in 51 minutes and 10 seconds
......@@ -14,7 +14,6 @@ use crate::app::dispatch_error;
use crate::app::App;
use crate::appop::AppOp;
use crate::backend;
use crate::backend::BKResponse;
use fractal_api::util::cache_dir_path;
......@@ -394,9 +393,9 @@ impl AppOp {
.map_or(String::new(), |gstr| gstr.to_string());
// Since the switcher
let privacy = if private.get_active() {
backend::RoomType::Private
room::RoomType::Private
} else {
backend::RoomType::Public
room::RoomType::Public
};
let internal_id = RoomId::new(&login_data.server_url.to_string())
......
......@@ -18,7 +18,7 @@ use crate::r0::message::get_message_events::Parameters as GetMessagesEventsParam
use crate::r0::message::get_message_events::Response as GetMessagesEventsResponse;
use crate::types::Message;
use super::types::ThreadPool;
use super::ThreadPool;
pub fn get_thumb_async(
thread_pool: ThreadPool,
......
use ruma_identifiers::RoomId;
use std::sync::{Arc, Condvar, Mutex};
use std::thread;
use crate::error::Error;
pub mod directory;
pub mod media;
pub mod register;
pub mod room;
pub mod sync;
mod types;
pub mod user;
pub use self::types::BKResponse;
pub use self::types::RoomType;
pub use self::types::ThreadPool;
#[derive(Debug)]
pub enum BKResponse {
//errors
LoginError(Error),
GuestLoginError(Error),
SendTypingError(Error),
SetRoomError(Error),
InviteError(Error),
ChangeLanguageError(Error),
NameError(Error),
AvatarError(Error),
MarkedAsReadError(Error),
UserSearchError(Error),
LogoutError(Error),
LeaveRoomError(Error),
DirectoryProtocolsError(Error),
RoomMembersError(Error),
AddedToFavError(Error),
GetThreePIDError(Error),
AddThreePIDError(Error),
SubmitPhoneTokenError(Error),
SetUserNameError(Error),
ChangePasswordError(Error),
AccountDestructionError(Error),
DeleteThreePIDError(Error),
GetTokenPhoneError(Error),
GetTokenEmailError(Error),
SetRoomNameError(Error),
SetRoomTopicError(Error),
SetUserAvatarError(Error),
SetRoomAvatarError(Error),
RoomMessagesToError(Error),
MediaError(Error),
SentMsgRedactionError(Error),
JoinRoomError(Error),
DirectorySearchError(Error),
NewRoomError(Error, RoomId),
RoomDetailError(Error),
RoomAvatarError(Error),
SentMsgError(Error),
AttachedFileError(Error),
RoomsError(Error),
UpdateRoomsError(Error),
RoomMessagesError(Error),
RoomElementError(Error),
SyncError(Error, u64),
}
#[derive(Clone, Debug)]
pub struct ThreadPool {
thread_count: Arc<(Mutex<u8>, Condvar)>,
limit: u8,
}
impl ThreadPool {
pub fn new(limit: u8) -> Self {
ThreadPool {
thread_count: Arc::new((Mutex::new(0), Condvar::new())),
limit,
}
}
pub fn run<F>(&self, func: F)
where
F: FnOnce() + Send + 'static,
{
let thread_count = self.thread_count.clone();
let limit = self.limit;
thread::spawn(move || {
// waiting, less than {limit} threads at the same time
let &(ref num, ref cvar) = &*thread_count;
{
let mut start = num.lock().unwrap();
while *start >= limit {
start = cvar.wait(start).unwrap()
}
*start += 1;
}
func();
// freeing the cvar for new threads
{
let mut counter = num.lock().unwrap();
*counter -= 1;
}
cvar.notify_one();
});
}
}
......@@ -18,8 +18,6 @@ use crate::util::get_prev_batch_from;
use crate::util::ContentType;
use crate::util::HTTP_CLIENT;
use crate::backend::types::RoomType;
use crate::r0::config::get_global_account_data::request as get_global_account_data;
use crate::r0::config::get_global_account_data::Parameters as GetGlobalAccountDataParameters;
use crate::r0::config::set_global_account_data::request as set_global_account_data;
......@@ -401,6 +399,12 @@ pub fn upload_file(
.map_err(Into::into)
}
#[derive(Debug, Clone, Copy)]
pub enum RoomType {
Public,
Private,
}
pub fn new_room(
base: Url,
access_token: AccessToken,
......
use ruma_identifiers::RoomId;
use std::sync::{Arc, Condvar, Mutex};
use std::thread;
use crate::error::Error;
#[derive(Debug)]
pub enum BKResponse {
//errors
LoginError(Error),
GuestLoginError(Error),
SendTypingError(Error),
SetRoomError(Error),
InviteError(Error),
ChangeLanguageError(Error),
NameError(Error),
AvatarError(Error),
MarkedAsReadError(Error),
UserSearchError(Error),
LogoutError(Error),
LeaveRoomError(Error),
DirectoryProtocolsError(Error),
RoomMembersError(Error),
AddedToFavError(Error),
GetThreePIDError(Error),
AddThreePIDError(Error),
SubmitPhoneTokenError(Error),
SetUserNameError(Error),
ChangePasswordError(Error),
AccountDestructionError(Error),
DeleteThreePIDError(Error),
GetTokenPhoneError(Error),
GetTokenEmailError(Error),
SetRoomNameError(Error),
SetRoomTopicError(Error),
SetUserAvatarError(Error),
SetRoomAvatarError(Error),
RoomMessagesToError(Error),
MediaError(Error),
SentMsgRedactionError(Error),
JoinRoomError(Error),
DirectorySearchError(Error),
NewRoomError(Error, RoomId),
RoomDetailError(Error),
RoomAvatarError(Error),
SentMsgError(Error),
AttachedFileError(Error),
RoomsError(Error),
UpdateRoomsError(Error),
RoomMessagesError(Error),
RoomElementError(Error),
SyncError(Error, u64),
}
#[derive(Debug, Clone, Copy)]
pub enum RoomType {
Public,
Private,
}
#[derive(Clone, Debug)]
pub struct ThreadPool {
thread_count: Arc<(Mutex<u8>, Condvar)>,
limit: u8,
}
impl ThreadPool {
pub fn new(limit: u8) -> Self {
ThreadPool {
thread_count: Arc::new((Mutex::new(0), Condvar::new())),
limit,
}
}
pub fn run<F>(&self, func: F)
where
F: FnOnce() + Send + 'static,
{
let thread_count = self.thread_count.clone();
let limit = self.limit;
thread::spawn(move || {
// waiting, less than {limit} threads at the same time
let &(ref num, ref cvar) = &*thread_count;
{
let mut start = num.lock().unwrap();
while *start >= limit {
start = cvar.wait(start).unwrap()
}
*start += 1;
}
func();
// freeing the cvar for new threads
{
let mut counter = num.lock().unwrap();
*counter -= 1;
}
cvar.notify_one();
});
}
}
......@@ -2,7 +2,7 @@ use ruma_identifiers::UserId;
use std::fs;
use url::Url;
use crate::backend::types::ThreadPool;
use crate::backend::ThreadPool;
use crate::cache::CacheMap;
use crate::error::Error;
use crate::util::get_user_avatar;
......
......@@ -5,7 +5,6 @@ api_sources = files(
'backend/register.rs',
'backend/room.rs',
'backend/sync.rs',
'backend/types.rs',
'backend/user.rs',
'identity/r0/association/msisdn/submit_token.rs',
'identity/r0/association/msisdn.rs',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment