PR feedback: Better handling of real name and email

This commit is contained in:
Bryan Ashby
2023-08-24 09:13:29 -06:00
parent 9205aaa9ee
commit 5a4563c799
8 changed files with 26 additions and 15 deletions

View File

@@ -124,15 +124,29 @@ module.exports = class User {
return isMember;
}
realName() {
return this.getProperty(UserProps.RealName) || this.username;
realName(withUsernameFallback = true) {
const realName = this.getProperty(UserProps.RealName);
if (realName) {
return realName;
}
if (withUsernameFallback) {
return this.username;
}
}
getSanitizedName(type = 'username') {
const name = 'real' === type ? this.realName() : this.username;
const name = 'real' === type ? this.realName(true) : this.username;
return sanatizeFilename(name) || `user${this.userId.toString()}`;
}
emailAddress() {
const email = this.getProperty(UserProps.EmailAddress);
if (email) {
const realName = this.realName(false);
return realName ? `${realName} <${email}>` : email;
}
}
isAvailable() {
return (this.statusFlags & User.StatusFlags.NotAvailable) == 0;
}