Commit 21ae3227 authored by Federico Mena Quintero's avatar Federico Mena Quintero Committed by Daniel Garcia Moreno

Make Member.get_alias() always return a String, not an Option

This method actually guarantees that the result is a nonempty string,
so there is no need to expose an Option.
parent 6ecd0bcc
Pipeline #9528 passed with stage
in 13 minutes and 44 seconds
......@@ -129,12 +129,12 @@ pub fn get_avatar_async(bk: &Backend, member: Option<Member>, tx: Sender<String>
let m = member.unwrap();
let uid = m.uid.clone();
let alias = m.get_alias().clone();
let alias = m.get_alias();
let avatar = m.avatar.clone();
semaphore!(bk.limit_threads, {
match get_user_avatar_img(&baseu, uid,
alias.unwrap_or_default(),
alias,
avatar.unwrap_or_default()) {
Ok(fname) => { tx.send(fname.clone()).unwrap(); }
Err(_) => { tx.send(String::new()).unwrap(); }
......
......@@ -18,10 +18,10 @@ impl Clone for Member {
}
impl Member {
pub fn get_alias(&self) -> Option<String> {
pub fn get_alias(&self) -> String {
match self.alias {
ref a if a.is_none() || a.clone().unwrap().is_empty() => Some(self.uid.clone()),
ref a => a.clone(),
ref a if a.is_none() || a.clone().unwrap().is_empty() => self.uid.clone(),
ref a => a.as_ref().unwrap().clone(),
}
}
}
......
......@@ -798,7 +798,7 @@ impl AppOp {
let title = format!("Join {}?", room_name);
let secondary;
if let Some(ref sender) = r.inv_sender {
let sender_name = sender.get_alias().unwrap_or(sender.uid.clone());
let sender_name = sender.get_alias();
secondary = format!("You've been invited to join to <b>{}</b> room by <b>{}</b>",
room_name, sender_name);
} else {
......
......@@ -48,8 +48,8 @@ impl<'a> MemberBox<'a> {
style.add_class("member-uid");
}
username.set_text(&self.member.get_alias().unwrap_or_default());
let mut alias = self.member.get_alias().unwrap_or_default();
username.set_text(&self.member.get_alias());
let mut alias = self.member.get_alias();
alias.push_str("\n");
alias.push_str(&self.member.uid);
username.set_tooltip_text(&alias[..]);
......
......@@ -148,7 +148,7 @@ impl<'a> MessageBox<'a> {
match m {
Some(member) => {
self.username.set_text(&member.get_alias().unwrap_or_default());
self.username.set_text(&member.get_alias());
get_member_info(backend.clone(), avatar.clone(), self.username.clone(), sender.clone(), globals::MSG_ICON_SIZE, 10);
}
None => {
......@@ -163,10 +163,10 @@ impl<'a> MessageBox<'a> {
fn build_room_msg_username(&self, sender: &str, member: Option<&Member>) -> gtk::Label {
let uname = match member {
Some(m) => m.get_alias(),
None => Some(String::from(sender)),
None => String::from(sender),
};
self.username.set_text(&uname.unwrap_or_default());
self.username.set_text(&uname);
self.username.set_justify(gtk::Justification::Left);
self.username.set_halign(gtk::Align::Start);
if let Some(style) = self.username.get_style_context() {
......@@ -316,14 +316,13 @@ impl<'a> MessageBox<'a> {
let sname = match member {
Some(m) => m.get_alias(),
None => Some(String::from(sender)),
None => String::from(sender),
};
let msg_label = gtk::Label::new("");
let body: &str = &msg.body;
msg_label.set_markup(&format!("<b>{}</b> {}",
sname.unwrap_or_default(), markup_text(body)));
msg_label.set_markup(&format!("<b>{}</b> {}", sname, markup_text(body)));
self.set_msg_styles(&msg_label);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment