You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChannelClient.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. package com.dmdirc;
  18. import com.dmdirc.events.DisplayProperty;
  19. import com.dmdirc.events.DisplayPropertyMap;
  20. import com.dmdirc.interfaces.GroupChat;
  21. import com.dmdirc.interfaces.GroupChatUser;
  22. import com.dmdirc.interfaces.User;
  23. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  24. import java.util.Comparator;
  25. import java.util.Optional;
  26. /**
  27. * Implementation of a {@link GroupChatUser}.
  28. */
  29. public class ChannelClient implements GroupChatUser {
  30. private final User user;
  31. private final GroupChat groupChat;
  32. private final ChannelClientInfo clientInfo;
  33. private final DisplayPropertyMap properties;
  34. public ChannelClient(final User user, final GroupChat groupChat,
  35. final ChannelClientInfo clientInfo) {
  36. this.user = user;
  37. this.groupChat = groupChat;
  38. this.clientInfo = clientInfo;
  39. properties = new DisplayPropertyMap();
  40. properties.put(DisplayProperty.LINK_USER, user);
  41. }
  42. @Override
  43. public User getUser() {
  44. return user;
  45. }
  46. @Override
  47. public GroupChat getGroupChat() {
  48. return groupChat;
  49. }
  50. @Override
  51. public String getImportantMode() {
  52. return clientInfo.getImportantModePrefix();
  53. }
  54. @Override
  55. public String getAllModes() {
  56. return clientInfo.getAllModes();
  57. }
  58. @Override
  59. public String getNickname() {
  60. return getUser().getNickname();
  61. }
  62. @Override
  63. public String getModePrefixedNickname() {
  64. return getImportantMode() + getNickname();
  65. }
  66. @Override
  67. public Optional<String> getUsername() {
  68. return getUser().getUsername();
  69. }
  70. @Override
  71. public Optional<String> getHostname() {
  72. return getUser().getHostname();
  73. }
  74. @Override
  75. public Optional<String> getRealname() {
  76. return getUser().getRealname();
  77. }
  78. public ChannelClientInfo getClientInfo() {
  79. return clientInfo;
  80. }
  81. @Override
  82. public Comparator<String> getModeComparator() {
  83. return clientInfo.getImportantModeComparator();
  84. }
  85. @Override
  86. public <T> void setDisplayProperty(final DisplayProperty<T> property, final T value) {
  87. properties.put(property, value);
  88. }
  89. @Override
  90. public <T> Optional<T> getDisplayProperty(final DisplayProperty<T> property) {
  91. return properties.get(property);
  92. }
  93. @Override
  94. public <T> void removeDisplayProperty(final DisplayProperty<T> property) {
  95. properties.remove(property);
  96. }
  97. @Override
  98. public DisplayPropertyMap getDisplayProperties() {
  99. return properties;
  100. }
  101. }