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

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