Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.interfaces.Connection;
  24. import com.dmdirc.interfaces.GroupChat;
  25. import com.dmdirc.interfaces.User;
  26. import com.dmdirc.parser.common.AwayState;
  27. import com.dmdirc.parser.interfaces.ClientInfo;
  28. import java.util.ArrayList;
  29. import java.util.Collection;
  30. import java.util.Collections;
  31. import java.util.Optional;
  32. /**
  33. * Implementation of a {@link User}.
  34. */
  35. public class Client implements User {
  36. private final Connection connection;
  37. private final ClientInfo clientInfo;
  38. public Client(final Connection connection, final ClientInfo clientInfo) {
  39. this.connection = connection;
  40. this.clientInfo = clientInfo;
  41. }
  42. @Override
  43. public String getNickname() {
  44. return clientInfo.getNickname();
  45. }
  46. @Override
  47. public Optional<String> getUsername() {
  48. if (clientInfo.getUsername().isEmpty()) {
  49. return Optional.empty();
  50. } else {
  51. return Optional.of(clientInfo.getUsername());
  52. }
  53. }
  54. @Override
  55. public Optional<String> getHostname() {
  56. if (clientInfo.getHostname().isEmpty()) {
  57. return Optional.empty();
  58. } else {
  59. return Optional.of(clientInfo.getHostname());
  60. }
  61. }
  62. @Override
  63. public Optional<String> getRealname() {
  64. if (clientInfo.getRealname().isEmpty()) {
  65. return Optional.empty();
  66. } else {
  67. return Optional.of(clientInfo.getRealname());
  68. }
  69. }
  70. @Override
  71. public Collection<GroupChat> getGroupChats() {
  72. final Collection<GroupChat> channels = new ArrayList<>();
  73. clientInfo.getChannelClients().forEach(c -> connection.getGroupChatManager()
  74. .getChannel(c.getChannel().getName()).ifPresent(channels::add));
  75. return Collections.unmodifiableCollection(channels);
  76. }
  77. @Override
  78. public Optional<String> getAwayMessage() {
  79. if (clientInfo.getAwayReason().isEmpty()) {
  80. return Optional.empty();
  81. } else {
  82. return Optional.of(clientInfo.getAwayReason());
  83. }
  84. }
  85. @Override
  86. public AwayState getAwayState() {
  87. return clientInfo.getAwayState();
  88. }
  89. @Override
  90. public Connection getConnection() {
  91. return connection;
  92. }
  93. public ClientInfo getClientInfo() {
  94. return clientInfo;
  95. }
  96. }