Skip to content

Commit

Permalink
Merge branch 'main' into release_0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tofubert authored Dec 17, 2024
2 parents f40258a + 7266790 commit de3e9fd
Show file tree
Hide file tree
Showing 32 changed files with 1,893 additions and 922 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: EmbarkStudios/cargo-deny-action@v2
- uses: taiki-e/install-action@cargo-make
- uses: Swatinem/rust-cache@v2
- run: cargo make audit
- run: cargo make deny


clippy:
runs-on: ubuntu-latest
Expand Down
6 changes: 0 additions & 6 deletions .gitignore
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
20 changes: 12 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "seshat-rs"
name = "sechat-rs"
description = "A TUI based chat client for Nextcloud Talk"
readme = "README.md"
license-file = "LICENSE"
Expand All @@ -20,8 +20,9 @@ exclude = [
"tags",
]

[build]
target = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
[dev-dependencies]
mockall = { version = "0.13.1" }
mockall_derive = { version = "0.13.1"}

[dependencies]
reqwest = { version = "0.12", features = ["json"] }
Expand All @@ -31,7 +32,7 @@ serde_json = "1.0"
jzon = "*"
base64 = "*"
toml = "*"
toml-example = "0.11.1"
toml-example = "0.12.0"
ratatui = {version = "0.28", features = ["serde"] }
crossterm = "*"
tui-tree-widget = "0.22"
Expand All @@ -43,18 +44,21 @@ log = "*"
log4rs = "1.3"
notify-rust = "4.11"
itertools = "*"
clap = { version = "4.5.16", features = ["derive"] }
clap = { version = "4.5.23", features = ["derive"] }
strum = "0.26"
strum_macros = "0.26"
textwrap = "0.16.1"
etcetera = "0.8.0"
better-panic = "0.3.0"
color-eyre = "0.6.3"
human-panic = "2.0.1"
libc = "0.2.158"
human-panic = "2.0.2"
libc = "0.2.168"
strip-ansi-escapes = "0.2.0"
tracing = "0.1.40"
tracing = "0.1.41"
cfg-if = "1.0.0"
tui-textarea = "0.6.1"
async-trait = "0.1.83"
serde_with = "3.11.0"

[lints.clippy]
pedantic = "warn"
27 changes: 24 additions & 3 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ alias = "ci"
description = "Run continuous integration tasks"
dependencies = ["lint", "clippy", "check", "test"]

[tasks.all]
description = "Run all tasks"
dependencies = ["format", "lint-typos", "clippy", "check", "dependencies", "build", "coverage-text"]


[tasks.clippy]
description = "Run Clippy for linting"
Expand All @@ -29,7 +33,7 @@ args = [

[tasks.lint]
description = "Lint code style (formatting, typos, docs, markdown)"
dependencies = ["lint-format"]
dependencies = ["lint-format", "lint-typos"]

[tasks.lint-format]
description = "Lint code formatting"
Expand All @@ -46,10 +50,20 @@ description = "Run typo checks"
install_crate = { crate_name = "typos-cli", binary = "typos", test_arg = "--version" }
command = "typos"

[tasks.dependencies]
description = "Lint code style (formatting, typos, docs, markdown)"
dependencies = ["audit", "deny"]

[tasks.audit]
command = "cargo"
install_crate = "cargo-audit"
args = ["audit", "-D", "warnings"]
args = ["audit", "-D", "warnings", "--ignore", "RUSTSEC-2024-0388"]


[tasks.deny]
command = "cargo"
install_crate = "cargo-deny"
args = ["deny", "check", "bans", "licenses"]


[tasks.check]
Expand All @@ -67,10 +81,17 @@ args = [
"target/lcov.info",
]

[tasks.coverage-text]
description = "Generate code coverage report"
command = "cargo"
args = [
"llvm-cov",
]

[tasks.build]
command = "cargo"
args = ["build"]
dependencies = ["format", "clippy", "audit"]
dependencies = ["lint-format", "clippy", "audit"]

[tasks.test]
command = "cargo"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ Use "?" to get to the help screen.
Please open issues in the issue tracker.
A list of planned and requested freatures is also kept there.

## The Name
Originally intended to be called seshat, after the egyptian goddess of writing, a typo became sechat.
Thank to Sebastian for sugesting the name in the first place.

## Sponsors
Thanks to [emlix gmbh](https://github.com/emlix) for allowing [@tofu](https://github.com/tofubert) and other so spend some of their work time to tinker with this.
6 changes: 6 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ coverage: # https://docs.codecov.com/docs/codecovyml-reference#coverage
project:
default:
threshold: 10% # Avoid false negatives, while numbers are so low.
patch:
default:
threshold: 2%

comment: # https://docs.codecov.com/docs/pull-request-comments
# make the comments less noisy
require_changes: true

github_checks:
annotations: false #Make commit readable again.
5 changes: 4 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
confidence-threshold = 0.8
allow = [
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"BSD-2-Clause",
"BSD-3-Clause",
"ISC",
"MIT",
"Unicode-DFS-2016",
"Unicode-3.0",
"GPL-3.0",
"Zlib"
]


[bans]
multiple-versions = "allow"
86 changes: 47 additions & 39 deletions src/backend/nc_message.rs
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()
}
}
Loading

0 comments on commit de3e9fd

Please sign in to comment.