Localize residual notices: logout, channel release, password change, founder-language expiry mail, and DiceServ prompts and errors
All checks were successful
CI / check (push) Successful in 5m40s
All checks were successful
CI / check (push) Successful in 5m40s
This commit is contained in:
parent
621bba00f2
commit
fadd4f37cd
10 changed files with 143 additions and 26 deletions
|
|
@ -842,8 +842,9 @@ impl Db {
|
|||
}
|
||||
|
||||
/// Channels entering the warning window, paired with their founder's email
|
||||
/// (skipped when the founder has none). Returns (channel, email, seconds left).
|
||||
pub fn channels_to_warn(&self, now: u64, ttl: u64, lead: u64) -> Vec<(String, String, u64)> {
|
||||
/// (skipped when the founder has none) and preferred language. Returns
|
||||
/// (channel, email, seconds left, founder language).
|
||||
pub fn channels_to_warn(&self, now: u64, ttl: u64, lead: u64) -> Vec<(String, String, u64, String)> {
|
||||
let floor = ttl.saturating_sub(lead);
|
||||
self.channels
|
||||
.values()
|
||||
|
|
@ -853,8 +854,10 @@ impl Db {
|
|||
if idle <= floor || idle > ttl {
|
||||
return None;
|
||||
}
|
||||
let email = self.accounts.get(&key(&c.founder)).and_then(|a| a.email.clone())?;
|
||||
Some((c.name.clone(), email, ttl - idle))
|
||||
let acc = self.accounts.get(&key(&c.founder))?;
|
||||
let email = acc.email.clone()?;
|
||||
let lang = acc.language.clone().unwrap_or_else(|| self.default_language());
|
||||
Some((c.name.clone(), email, ttl - idle, lang))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -727,11 +727,8 @@ impl Engine {
|
|||
self.logout_uid(&uid, account, reason);
|
||||
if !orphaned.is_empty() {
|
||||
if let Some(ns) = &ns {
|
||||
self.emit_irc(NetAction::Notice {
|
||||
from: ns.clone(),
|
||||
to: uid,
|
||||
text: format!("Channels you had registered as \x02{account}\x02 were released: {}.", orphaned.join(", ")),
|
||||
});
|
||||
let text = echo_api::render(&self.lang_for_uid(&uid), "Channels you had registered as \x02{account}\x02 were released: {list}.", &[("account", account.to_string()), ("list", orphaned.join(", "))]);
|
||||
self.emit_irc(NetAction::Notice { from: ns.clone(), to: uid.clone(), text });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -773,11 +770,10 @@ impl Engine {
|
|||
self.network.clear_account(uid);
|
||||
self.emit_irc(NetAction::Metadata { target: uid.to_string(), key: "accountname".to_string(), value: String::new() });
|
||||
if let Some(ns) = self.nick_service.clone() {
|
||||
self.emit_irc(NetAction::Notice {
|
||||
from: ns,
|
||||
to: uid.to_string(),
|
||||
text: format!("Your account \x02{account}\x02 {reason}. You have been logged out."),
|
||||
});
|
||||
let lang = self.lang_for_uid(uid);
|
||||
let reason = echo_api::render(&lang, reason, &[]);
|
||||
let text = echo_api::render(&lang, "Your account \x02{account}\x02 {reason}. You have been logged out.", &[("account", account.to_string()), ("reason", reason)]);
|
||||
self.emit_irc(NetAction::Notice { from: ns, to: uid.to_string(), text });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -859,8 +855,8 @@ impl Engine {
|
|||
}
|
||||
}
|
||||
if let Some(ttl) = self.channel_ttl {
|
||||
for (channel, email, left) in self.db.channels_to_warn(now, ttl, lead) {
|
||||
let mail = echo_api::email::expiry_warning(self.db.email_brand(), self.db.email_accent(), self.db.email_logo(), echo_api::email::ExpiryTarget::Channel, &channel, &human_duration(left), &self.db.default_language());
|
||||
for (channel, email, left, lang) in self.db.channels_to_warn(now, ttl, lead) {
|
||||
let mail = echo_api::email::expiry_warning(self.db.email_brand(), self.db.email_accent(), self.db.email_logo(), echo_api::email::ExpiryTarget::Channel, &channel, &human_duration(left), &lang);
|
||||
self.emit_irc(NetAction::SendEmail { to: email, subject: mail.subject, text: mail.text, html: Some(mail.html) });
|
||||
self.db.mark_channel_warned(&channel);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -356,9 +356,10 @@ impl Engine {
|
|||
|
||||
// Commit a password change the link layer derived off-thread, then notice the user.
|
||||
pub fn complete_password_change(&mut self, account: &str, creds: Option<db::Credentials>, agent: &str, uid: &str) -> Vec<NetAction> {
|
||||
let lang = self.lang_for_account(account);
|
||||
let text = match creds.and_then(|c| self.db.set_credentials(account, c).ok()) {
|
||||
Some(()) => format!("Your password for \x02{account}\x02 has been changed."),
|
||||
None => "Sorry, that didn't work. Please try again in a moment.".to_string(),
|
||||
Some(()) => echo_api::render(&lang, "Your password for \x02{account}\x02 has been changed.", &[("account", account.to_string())]),
|
||||
None => echo_api::render(&lang, "Sorry, that didn't work. Please try again in a moment.", &[]),
|
||||
};
|
||||
vec![NetAction::Notice { from: agent.to_string(), to: uid.to_string(), text }]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue