Skip to content

Commit

Permalink
Remove [bot] user name suffix also in event lists.
Browse files Browse the repository at this point in the history
Events API doesn't return user type :-(
  • Loading branch information
maniac103 committed Aug 21, 2020
1 parent c419cee commit 830cfdc
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions app/src/main/java/com/gh4a/utils/ApiHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ public static boolean authorEqualsCommitter(Commit commit) {
}

public static String getUserLogin(Context context, User user) {
if (user != null && user.login() != null) {
if (user.type() == UserType.Bot && user.login().endsWith("[bot]")) {
return user.login().substring(0, user.login().length() - 5);
}
return user.login();
User actualUser = adjustUserForBotSuffix(user);
if (actualUser.login() != null) {
return actualUser.login();
}
return context.getString(R.string.deleted);
}
Expand All @@ -116,13 +114,28 @@ public static SpannableStringBuilder getUserLoginWithType(Context context, User
if (boldifyLogin) {
builder.setSpan(new StyleSpan(Typeface.BOLD), 0, builder.length(), 0);
}
if (user != null && user.type() == UserType.Bot) {
final User actualUser = adjustUserForBotSuffix(user);
if (actualUser != null && actualUser.type() == UserType.Bot) {
StringUtils.addUserTypeSpan(context, builder, builder.length(),
context.getString(R.string.user_type_bot));
}
return builder;
}

private static User adjustUserForBotSuffix(User user) {
final String login = user != null ? user.login() : null;
if (login != null && login.endsWith("[bot]")) {
UserType type = user.type();
if (type == null || type == UserType.Bot) {
return user.toBuilder()
.login(login.substring(0, login.length() - 5))
.type(UserType.Bot)
.build();
}
}
return user;
}

public static String formatRepoName(Context context, Repository repository) {
if (repository == null || TextUtils.isEmpty(repository.name())) {
return context.getString(R.string.deleted);
Expand Down

0 comments on commit 830cfdc

Please sign in to comment.