From a3f775222f0a168707eee2861297a805636d0111 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Fri, 1 Dec 2023 04:06:39 +0100 Subject: [PATCH] Move struct Channel to separate module --- src/channel.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 1 + src/message_log.rs | 45 ++------------------------------------------- 3 files changed, 49 insertions(+), 43 deletions(-) create mode 100644 src/channel.rs diff --git a/src/channel.rs b/src/channel.rs new file mode 100644 index 0000000..e342c4d --- /dev/null +++ b/src/channel.rs @@ -0,0 +1,46 @@ +use chrono::{DateTime, Local}; +use std::collections::HashSet; + +use crate::irc_message::IrcMessage; + +pub struct Channel { + pub channel_name: Option, + + pub messages: Vec, + pub message_ids: HashSet, + pub names: Vec, + pub topic: Option, + + pub unread_messages: i32, + pub unread_highlights: i32, + pub unread_events: i32, + + pub is_multiline: bool, + pub multiline_privmsgs: Option>, + pub multiline_timestamp: Option>, + pub multiline_nickname: Option, + pub multiline_message_id: Option, +} + +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, + } + } +} diff --git a/src/main.rs b/src/main.rs index 7d21a38..540a0a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod channel; mod cri; mod cri_flags; mod irc_handler; diff --git a/src/message_log.rs b/src/message_log.rs index c3c6bd4..33f6bc3 100644 --- a/src/message_log.rs +++ b/src/message_log.rs @@ -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, - - pub messages: Vec, - pub message_ids: HashSet, - pub names: Vec, - pub topic: Option, - - pub unread_messages: i32, - pub unread_highlights: i32, - pub unread_events: i32, - - pub is_multiline: bool, - pub multiline_privmsgs: Option>, - pub multiline_timestamp: Option>, - pub multiline_nickname: Option, - pub multiline_message_id: Option, -} - -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, Channel>,