Skip to content

Commit

Permalink
Improve formatting of whois events.
Browse files Browse the repository at this point in the history
  • Loading branch information
csmith committed Feb 6, 2016
1 parent 174ad64 commit bc37a9d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
10 changes: 2 additions & 8 deletions res/com/dmdirc/ui/messages/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ UnknownCommandEvent:
UserInfoResponseEvent:
before: "---------- User info for {{user.nickname}} ----------"
after: "--------- End of info for {{user.nickname}} ---------"
iterate: "entries"
format: "{{key}}: {{value}}"
iterate: "properties"
format: "{{friendlyName}}: {{rawValue}}"
colour: 10

################## TODO ############################################################################
Expand All @@ -237,12 +237,6 @@ UserInfoResponseEvent:
# numeric_290=%4$s
# numeric_292=%4$s
# numeric_294=%4$s
# numeric_301=%4$s is away: %5$s
# numeric_311=-\n%4$s is %5$s@%6$s (%8$s).
# numeric_312=%4$s is connected to %5$s (%6$s).
# numeric_317=%4$s has been idle for %5$u; signed on at %6$TT on %6$TF.
# numeric_318=End of WHOIS info for %4$s.\n-
# numeric_319=%4$s is on: %5$s
# numeric_401=6A7000%4$s: %5$s
# numeric_404=6A7000%5$s
# numeric_405=6A7000%4$s: %5$s
Expand Down
39 changes: 32 additions & 7 deletions src/com/dmdirc/events/UserInfoResponseEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
public class UserInfoResponseEvent extends ServerDisplayableEvent {

private final User user;
private final Map<UserInfoEvent.UserInfoType, String> info;
private final Map<UserInfoEvent.UserInfoType, UserInfoProperty> info;

public UserInfoResponseEvent(final Connection connection, final long date,
final User user, final Map<UserInfoEvent.UserInfoType, String> info) {
super(date, connection);
this.user = user;
this.info = new EnumMap<>(info);
this.info = new EnumMap<>(UserInfoEvent.UserInfoType.class);
info.forEach((key, value) -> this.info.put(key, new UserInfoProperty(key, value)));
}

/**
Expand All @@ -63,16 +64,40 @@ public User getUser() {
* @return An optional containing the information, if it was provided.
*/
public Optional<String> getInfo(final UserInfoEvent.UserInfoType type) {
return Optional.ofNullable(info.get(type));
return Optional.ofNullable(info.get(type)).map(UserInfoProperty::getRawValue);
}

/**
* Gets a collection of all info entries in the response.
* Gets a collection of all info properties in the response.
*
* @return A collection of all user info entries.
* @return A collection of all user info properties.
*/
public Collection<Map.Entry<UserInfoEvent.UserInfoType, String>> getEntries() {
return info.entrySet();
public Collection<UserInfoProperty> getProperties() {
return info.values();
}

public static class UserInfoProperty {

private final UserInfoEvent.UserInfoType type;
private final String rawValue;

public UserInfoProperty(final UserInfoEvent.UserInfoType type, final String rawValue) {
this.type = type;
this.rawValue = rawValue;
}

public UserInfoEvent.UserInfoType getType() {
return type;
}

public String getRawValue() {
return rawValue;
}

public String getFriendlyName() {
return type.name().charAt(0) + type.name().substring(1).toLowerCase().replace('_', ' ');
}

}

}

0 comments on commit bc37a9d

Please sign in to comment.