OutgoingEmail#getName{Email}For: Use helpers from Account

The getNameEmailFor and getNameFor methods do almost the same as the
helper methods Account.getNameEmail and Account.getName but with a
slight difference in the formatting. When the name/email is not set,
the getNameEmailFor and getNameFor methods format the name as:

  Anonymous Coward #123

where "123" is the account number. The Account methods format it as:

  Anonymous Coward (123)

Using the Account methods reduces duplicate code, and also makes the
formatting consistent with the rest of the application.

Change-Id: I9d55ec3f1eb09152548afb975ce29df14b0d21c3
This commit is contained in:
David Pursehouse
2018-06-20 10:03:10 +09:00
parent ccaf58b6a9
commit ddf27f44c8

View File

@@ -347,15 +347,7 @@ public abstract class OutgoingEmail {
return args.gerritPersonIdent.getName(); return args.gerritPersonIdent.getName();
} }
final Account userAccount = args.accountCache.get(accountId).getAccount(); return args.accountCache.get(accountId).getAccount().getName(args.anonymousCowardName);
String name = userAccount.getFullName();
if (name == null) {
name = userAccount.getPreferredEmail();
}
if (name == null) {
name = args.anonymousCowardName + " #" + accountId;
}
return name;
} }
/** /**
@@ -366,21 +358,7 @@ public abstract class OutgoingEmail {
* @return name/email of account, or Anonymous Coward if unset. * @return name/email of account, or Anonymous Coward if unset.
*/ */
public String getNameEmailFor(Account.Id accountId) { public String getNameEmailFor(Account.Id accountId) {
AccountState who = args.accountCache.get(accountId); return args.accountCache.get(accountId).getAccount().getNameEmail(args.anonymousCowardName);
String name = who.getAccount().getFullName();
String email = who.getAccount().getPreferredEmail();
if (name != null && email != null) {
return name + " <" + email + ">";
} else if (name != null) {
return name;
} else if (email != null) {
return email;
} else /* (name == null && email == null) */ {
return args.anonymousCowardName + " #" + accountId;
}
} }
/** /**