2022-12-24 21:16:23 +11:00
|
|
|
use serde::{Serialize, Deserialize};
|
2023-01-02 13:25:05 +11:00
|
|
|
use std::collections::VecDeque;
|
|
|
|
use crate::regular_tasks::queued_command::QueueCommand;
|
2023-01-28 23:00:53 +11:00
|
|
|
use chrono::{DateTime, Utc};
|
2022-12-24 21:16:23 +11:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
2023-01-02 13:25:05 +11:00
|
|
|
#[serde(default)]
|
2022-12-24 21:16:23 +11:00
|
|
|
pub struct Session {
|
|
|
|
pub source: String,
|
|
|
|
pub less_explicit_mode: bool,
|
2023-01-02 13:25:05 +11:00
|
|
|
pub queue: VecDeque<QueueCommand>,
|
2023-01-28 23:00:53 +11:00
|
|
|
pub last_active: Option<DateTime<Utc>>,
|
2022-12-24 21:16:23 +11:00
|
|
|
// Reminder: Consider backwards compatibility when updating this. New fields should generally
|
2023-01-02 13:25:05 +11:00
|
|
|
// be an Option, or you should ensure the default value is sensible, or things will
|
|
|
|
// crash out for existing sessions.
|
2022-12-24 21:16:23 +11:00
|
|
|
}
|
|
|
|
|
2022-12-31 00:59:14 +11:00
|
|
|
impl Session {
|
|
|
|
pub fn explicit_if_allowed<'l>(self: &Self, explicit: &'l str, non_explicit: Option<&'l str>) -> &'l str {
|
|
|
|
if self.less_explicit_mode {
|
|
|
|
non_explicit.unwrap_or(explicit)
|
|
|
|
} else {
|
|
|
|
explicit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-24 21:16:23 +11:00
|
|
|
impl Default for Session {
|
|
|
|
fn default() -> Self {
|
2023-01-02 13:25:05 +11:00
|
|
|
Session { source: "unknown".to_owned(), less_explicit_mode: false,
|
2023-01-28 23:00:53 +11:00
|
|
|
queue: VecDeque::new(), last_active: None }
|
2022-12-24 21:16:23 +11:00
|
|
|
}
|
|
|
|
}
|