[fractal/fix-display-name] Return only the local part of the user ID as the display name
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fix-display-name] Return only the local part of the user ID as the display name
- Date: Wed, 28 Jul 2021 05:09:42 +0000 (UTC)
commit 4600bb679af52eff39657c334c8608b7f376b5c4
Author: Alejandro Domínguez <adomu net-c com>
Date: Wed Jul 28 07:09:25 2021 +0200
Return only the local part of the user ID as the display name
src/session/user.rs | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
---
diff --git a/src/session/user.rs b/src/session/user.rs
index c5ecb3a8..df6c7de9 100644
--- a/src/session/user.rs
+++ b/src/session/user.rs
@@ -14,11 +14,11 @@ use crate::session::Avatar;
mod imp {
use super::*;
use once_cell::sync::{Lazy, OnceCell};
- use std::cell::RefCell;
+ use std::{cell::RefCell, convert::TryFrom};
#[derive(Debug, Default)]
pub struct User {
- pub user_id: OnceCell<String>,
+ pub user_id: OnceCell<UserId>,
pub display_name: RefCell<Option<String>>,
pub session: OnceCell<Session>,
pub avatar: OnceCell<Avatar>,
@@ -78,8 +78,10 @@ mod imp {
) {
match pspec.name() {
"user-id" => {
- let user_id = value.get().unwrap();
- self.user_id.set(user_id).unwrap();
+ let user_id: &str = value.get().unwrap();
+ if let Ok(user_id) = UserId::try_from(user_id) {
+ self.user_id.set(user_id).unwrap();
+ }
}
"session" => self.session.set(value.get().unwrap()).unwrap(),
_ => unimplemented!(),
@@ -89,7 +91,7 @@ mod imp {
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
match pspec.name() {
"display-name" => obj.display_name().to_value(),
- "user-id" => self.user_id.get().to_value(),
+ "user-id" => self.user_id.get().map(UserId::as_str).to_value(),
"session" => obj.session().to_value(),
"avatar" => obj.avatar().to_value(),
_ => unimplemented!(),
@@ -138,12 +140,7 @@ impl User {
if let Some(display_name) = priv_.display_name.borrow().to_owned() {
display_name
} else {
- priv_
- .user_id
- .get()
- .unwrap()
- .trim_start_matches("@")
- .to_owned()
+ priv_.user_id.get().unwrap().localpart().to_owned()
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]