added join channel function

This commit is contained in:
Ren Amamiya
2023-04-11 14:46:00 +07:00
parent 4729250550
commit ac5e78a6b8
5 changed files with 112 additions and 7 deletions

View File

@@ -111,6 +111,12 @@ struct GetActiveChannelData {
active: bool,
}
#[derive(Deserialize, Type)]
struct UpdateChannelData {
event_id: String,
active: bool,
}
#[tauri::command]
#[specta::specta]
async fn get_accounts(db: DbState<'_>) -> Result<Vec<account::Data>, ()> {
@@ -264,6 +270,19 @@ async fn create_channel(db: DbState<'_>, data: CreateChannelData) -> Result<chan
.map_err(|_| ())
}
#[tauri::command]
#[specta::specta]
async fn update_channel(db: DbState<'_>, data: UpdateChannelData) -> Result<channel::Data, ()> {
db.channel()
.update(
channel::event_id::equals(data.event_id), // Unique filter
vec![channel::active::set(data.active)], // Vec of updates
)
.exec()
.await
.map_err(|_| ())
}
#[tauri::command]
#[specta::specta]
async fn get_channels(db: DbState<'_>, data: GetChannelData) -> Result<Vec<channel::Data>, ()> {
@@ -335,6 +354,7 @@ async fn main() {
get_latest_notes,
get_note_by_id,
create_channel,
update_channel,
get_channels,
get_active_channels,
create_chat,
@@ -382,6 +402,7 @@ async fn main() {
get_note_by_id,
count_total_notes,
create_channel,
update_channel,
get_channels,
get_active_channels,
create_chat,