Move struct Channel to separate module

This commit is contained in:
Sijmen 2023-12-01 04:06:39 +01:00
parent ce5b4fb2ac
commit a3f775222f
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
3 changed files with 49 additions and 43 deletions

46
src/channel.rs Normal file
View file

@ -0,0 +1,46 @@
use chrono::{DateTime, Local};
use std::collections::HashSet;
use crate::irc_message::IrcMessage;
pub struct Channel {
pub channel_name: Option<String>,
pub messages: Vec<IrcMessage>,
pub message_ids: HashSet<String>,
pub names: Vec<String>,
pub topic: Option<String>,
pub unread_messages: i32,
pub unread_highlights: i32,
pub unread_events: i32,
pub is_multiline: bool,
pub multiline_privmsgs: Option<Vec<String>>,
pub multiline_timestamp: Option<DateTime<Local>>,
pub multiline_nickname: Option<String>,
pub multiline_message_id: Option<String>,
}
impl Channel {
pub fn new(channel_name: Option<&str>) -> Self {
Self {
channel_name: channel_name.map(String::from),
messages: Vec::new(),
message_ids: HashSet::new(),
names: Vec::new(),
topic: None,
unread_messages: 0,
unread_highlights: 0,
unread_events: 0,
is_multiline: false,
multiline_privmsgs: None,
multiline_timestamp: None,
multiline_nickname: None,
multiline_message_id: None,
}
}
}

View file

@ -1,3 +1,4 @@
mod channel;
mod cri;
mod cri_flags;
mod irc_handler;

View file

@ -1,4 +1,5 @@
use crate::{
channel::Channel,
irc_message::{IrcMessage, MessageDetail},
util::{self, BATCH_SUB_COMMAND_CHATHISTORY},
};
@ -10,49 +11,7 @@ use iced::{
Background, Color, Element, Length,
};
use irc::proto::BatchSubCommand;
use std::collections::{HashMap, HashSet};
pub struct Channel {
pub channel_name: Option<String>,
pub messages: Vec<IrcMessage>,
pub message_ids: HashSet<String>,
pub names: Vec<String>,
pub topic: Option<String>,
pub unread_messages: i32,
pub unread_highlights: i32,
pub unread_events: i32,
pub is_multiline: bool,
pub multiline_privmsgs: Option<Vec<String>>,
pub multiline_timestamp: Option<chrono::DateTime<Local>>,
pub multiline_nickname: Option<String>,
pub multiline_message_id: Option<String>,
}
impl Channel {
fn new(channel_name: Option<&str>) -> Self {
Self {
channel_name: channel_name.map(String::from),
messages: Vec::new(),
message_ids: HashSet::new(),
names: Vec::new(),
topic: None,
unread_messages: 0,
unread_highlights: 0,
unread_events: 0,
is_multiline: false,
multiline_privmsgs: None,
multiline_timestamp: None,
multiline_nickname: None,
multiline_message_id: None,
}
}
}
use std::collections::HashMap;
pub struct MessageLog {
channels: HashMap<Option<String>, Channel>,