dev #25

Merged
akulij merged 38 commits from dev into main 2025-06-18 17:10:44 +00:00
Showing only changes of commit 1edaac9d8a - Show all commits

View File

@ -2,7 +2,7 @@ pub mod application;
pub mod db; pub mod db;
pub mod message_info; pub mod message_info;
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, Mutex}; use std::sync::Mutex;
use std::time::Duration; use std::time::Duration;
use crate::db::raw_calls::RawCallError; use crate::db::raw_calls::RawCallError;
@ -827,9 +827,13 @@ impl NotificationMessage {
NotificationMessage::Literal { literal } => Ok(db.get_literal_value(literal).await?), NotificationMessage::Literal { literal } => Ok(db.get_literal_value(literal).await?),
NotificationMessage::Text { text } => Ok(Some(text.to_string())), NotificationMessage::Text { text } => Ok(Some(text.to_string())),
NotificationMessage::BotFunction(f) => { NotificationMessage::BotFunction(f) => {
let jsuser = to_js(f.context().expect("Function is not js"), user).unwrap(); let jsuser = to_js(f.context().expect("Function is not js"), user)?;
let text = f.call_args(vec![jsuser])?; let text = f.call_args(vec![jsuser])?;
let text = from_js(f.context().unwrap(), &text)?; let text = from_js(
f.context()
.expect("Context was not provided after function call"),
&text,
)?;
Ok(text) Ok(text)
} }
} }
@ -999,9 +1003,8 @@ impl Parcelable<BotFunction> for RunnerConfig {
} }
} }
#[derive(Clone)]
pub struct Runner { pub struct Runner {
context: Arc<Mutex<Context>>, context: Mutex<Context>,
} }
impl Runner { impl Runner {
@ -1015,7 +1018,7 @@ impl Runner {
})?; })?;
Ok(Runner { Ok(Runner {
context: Arc::new(Mutex::new(context)), context: Mutex::new(context),
}) })
} }
@ -1030,7 +1033,7 @@ impl Runner {
where where
F: FnOnce(&Context, &mut OwnedJsObject) -> R, F: FnOnce(&Context, &mut OwnedJsObject) -> R,
{ {
let context = self.context.lock().unwrap(); let context = self.context.lock().expect("Can't lock context");
let mut global = context.global()?; let mut global = context.global()?;
let res = f(&context, &mut global); let res = f(&context, &mut global);