-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release_0.1.0
- Loading branch information
Showing
32 changed files
with
1,893 additions
and
922 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,4 @@ | ||
config.toml | ||
Cargo.lock | ||
target | ||
dev.log | ||
logs | ||
devlogs | ||
config_*.toml | ||
CONFIG_*.toml | ||
.vscode/settings.json | ||
.pre-commit-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,93 @@ | ||
use crate::backend::nc_request::NCReqDataMessage; | ||
use super::nc_request::NCReqDataMessage; | ||
use chrono::prelude::*; | ||
|
||
#[derive(Debug)] | ||
pub struct NCMessage { | ||
data: NCReqDataMessage, | ||
message: String, | ||
} | ||
/// `NextCloud` message interface | ||
#[derive(Debug, Default)] | ||
pub struct NCMessage(NCReqDataMessage); | ||
|
||
impl From<NCReqDataMessage> for NCMessage { | ||
fn from(data: NCReqDataMessage) -> Self { | ||
NCMessage { | ||
message: data.message.clone(), | ||
data, | ||
} | ||
NCMessage(data) | ||
} | ||
} | ||
|
||
impl NCMessage { | ||
/// return message time stamp as string | ||
pub fn get_time_str(&self) -> String { | ||
let time: DateTime<Local> = | ||
DateTime::from(DateTime::<Utc>::from_timestamp(self.data.timestamp, 0).unwrap()); | ||
let time: DateTime<Local> = DateTime::from( | ||
DateTime::<Utc>::from_timestamp(self.0.timestamp, 0) | ||
.expect("cannot convert UTC time stamp"), | ||
); | ||
time.format("%H:%M").to_string() | ||
} | ||
|
||
pub fn get_name(&self) -> String { | ||
self.data.actorDisplayName.clone() | ||
/// return opponent display name | ||
pub fn get_name(&self) -> &str { | ||
if !self.is_comment() || self.is_system() || self.is_comment_deleted() || self.is_command() | ||
{ | ||
"System" | ||
} else { | ||
&self.0.actorDisplayName | ||
} | ||
} | ||
|
||
pub fn get_message(&self) -> String { | ||
self.message.clone() | ||
/// return the message itself | ||
pub fn get_message(&self) -> &str { | ||
&self.0.message | ||
} | ||
|
||
/// get list of reactions as comma separated string | ||
pub fn get_reactions_str(&self) -> String { | ||
let mut reactions = String::new(); | ||
for (icon, number) in &self.data.reactions { | ||
reactions = reactions + "('" + icon + "' times " + &number.to_string() + "), "; | ||
} | ||
reactions | ||
self.0 | ||
.reactions | ||
.iter() | ||
.map(|(icon, number)| format!("('{icon}' times {}), ", &number.to_string())) | ||
.collect::<Vec<_>>() | ||
.join(", ") | ||
} | ||
|
||
/// get message identifier | ||
pub fn get_id(&self) -> i32 { | ||
self.data.id | ||
self.0.id | ||
} | ||
|
||
pub fn to_data(&self) -> NCReqDataMessage { | ||
self.data.clone() | ||
/// return inner data message | ||
pub fn data(&self) -> &NCReqDataMessage { | ||
&self.0 | ||
} | ||
|
||
/// return `true` if message is a comment | ||
pub fn is_comment(&self) -> bool { | ||
self.data.messageType == "comment" | ||
self.0.messageType == "comment" | ||
} | ||
|
||
/// return `true` if message is a deleted comment | ||
pub fn is_comment_deleted(&self) -> bool { | ||
self.data.messageType == "comment_deleted" | ||
self.0.messageType == "comment_deleted" | ||
} | ||
|
||
/// return `true` if message is a system message | ||
pub fn is_system(&self) -> bool { | ||
self.data.messageType == "system" | ||
self.0.messageType == "system" | ||
} | ||
|
||
/// return `true` if message is an edited message | ||
pub fn is_edit_note(&self) -> bool { | ||
if self.is_system() { | ||
self.data.systemMessage == "message_edited" | ||
} else { | ||
false | ||
} | ||
self.is_system() && self.0.systemMessage == "message_edited" | ||
} | ||
|
||
/// return `true` if message is a reaction | ||
pub fn is_reaction(&self) -> bool { | ||
if self.is_system() { | ||
self.data.systemMessage == "reaction" | ||
} else { | ||
false | ||
} | ||
self.is_system() && self.0.systemMessage == "reaction" | ||
} | ||
|
||
/// return `true` if message is a command | ||
pub fn is_command(&self) -> bool { | ||
self.data.messageType == "command" | ||
self.0.messageType == "command" | ||
} | ||
|
||
/// return `true` if message has any reactions | ||
pub fn has_reactions(&self) -> bool { | ||
!self.data.reactions.is_empty() | ||
!self.0.reactions.is_empty() | ||
} | ||
} |
Oops, something went wrong.