Browse Source

Use Unidecode library to handle non-Unicode nicks (0.2.0 bump)

- The version number was changed to 0.2.0, purely because rpm doesn't
  like '0.2.0-pre' and I got tired of switching it around.
- We now use the Unidecode library to produce ASCII representations of
  non-ASCII names, making life easier for people with umlauts and such
  in their contact names.
master
eta 3 years ago
parent
commit
72c7799505
  1. 9
      Cargo.lock
  2. 3
      Cargo.toml
  3. 2
      src/util.rs
  4. 2
      src/whatsapp.rs

9
Cargo.lock generated

@ -1953,7 +1953,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1953,7 +1953,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "sms-irc"
version = "0.2.0-pre"
version = "0.1.0"
dependencies = [
"base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
"chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1983,6 +1983,7 @@ dependencies = [ @@ -1983,6 +1983,7 @@ dependencies = [
"tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unidecode 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
"whatsappweb-eta 0.5.0-pre1 (git+https://git.theta.eu.org/whatsappweb-rs.git/)",
]
@ -2465,6 +2466,11 @@ name = "unicode-xid" @@ -2465,6 +2466,11 @@ name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unidecode"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "untrusted"
version = "0.6.2"
@ -2882,6 +2888,7 @@ dependencies = [ @@ -2882,6 +2888,7 @@ dependencies = [
"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9"
"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc"
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
"checksum unidecode 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "402bb19d8e03f1d1a7450e2bd613980869438e0666331be3e073089124aa1adc"
"checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f"
"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
"checksum utf8-ranges 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ae116fef2b7fea257ed6440d3cfcff7f190865f170cdad00bb6465bf18ecba"

3
Cargo.toml

@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
authors = ["eeeeeta <eeeeeta@users.noreply.github.com>"]
name = "sms-irc"
edition = "2018"
version = "0.2.0-pre"
version = "0.2.0"
description = "A WhatsApp/SMS to IRC bridge"
license = "AGPL-3.0"
@ -32,6 +32,7 @@ tokio-signal = "0.2.7" @@ -32,6 +32,7 @@ tokio-signal = "0.2.7"
tokio-timer = "0.2"
toml = "0.5"
unicode-segmentation = "1.3"
unidecode = "0.3"
[dependencies.chrono]
features = ["serde"]

2
src/util.rs

@ -63,6 +63,7 @@ pub fn un_normalize_address(addr: &str) -> Option<PduAddress> { @@ -63,6 +63,7 @@ pub fn un_normalize_address(addr: &str) -> Option<PduAddress> {
}
pub fn string_to_irc_chan(inp: &str) -> String {
let mut ret = String::new();
let inp = unidecode::unidecode(inp);
for ch in inp.chars() {
match ch {
'_' => ret.push('_'),
@ -77,6 +78,7 @@ pub fn string_to_irc_chan(inp: &str) -> String { @@ -77,6 +78,7 @@ pub fn string_to_irc_chan(inp: &str) -> String {
}
pub fn string_to_irc_nick(inp: &str) -> String {
let mut ret = "S".to_string();
let inp = unidecode::unidecode(inp);
for ch in inp.chars() {
match ch {
'+' => ret.push('I'),

2
src/whatsapp.rs

@ -717,6 +717,8 @@ impl WhatsappManager { @@ -717,6 +717,8 @@ impl WhatsappManager {
(Recipient::NICKSRC_WA_NOTIFY, Recipient::NICKSRC_WA_CONTACT) => true,
// Allow users to update their address book names.
(Recipient::NICKSRC_WA_CONTACT, Recipient::NICKSRC_WA_CONTACT) => true,
// Update WA notify values as well.
(Recipient::NICKSRC_WA_NOTIFY, Recipient::NICKSRC_WA_NOTIFY) => true,
// Other changes are probably unwanted.
_ => false
};

Loading…
Cancel
Save