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.

TwitterChannelClientInfo.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
  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.addons.parser_twitter;
  23. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  24. import com.dmdirc.parser.interfaces.ChannelInfo;
  25. import com.dmdirc.parser.interfaces.ClientInfo;
  26. import java.util.Map;
  27. import java.util.HashMap;
  28. /**
  29. * ChannelClientInfo class for the Twitter plugin.
  30. *
  31. * @author shane
  32. */
  33. public class TwitterChannelClientInfo implements ChannelClientInfo {
  34. /** My ChannelInfo. */
  35. private TwitterChannelInfo myChannel;
  36. /** My ClientInfo. */
  37. private TwitterClientInfo myClient;
  38. /** Map of random objects. */
  39. final Map<Object, Object> myMap = new HashMap<Object, Object>();
  40. /**
  41. * Create a new TwitterChannelClientInfo
  42. *
  43. * @param channel Channel that this client is in.
  44. * @param ci Client that we represent.
  45. */
  46. public TwitterChannelClientInfo(final TwitterChannelInfo channel, final TwitterClientInfo ci) {
  47. this.myChannel = channel;
  48. this.myClient = ci;
  49. myClient.addChannelClient(this);
  50. }
  51. /** {@inheritDoc} */
  52. @Override
  53. public ClientInfo getClient() {
  54. return myClient;
  55. }
  56. /** {@inheritDoc} */
  57. @Override
  58. public ChannelInfo getChannel() {
  59. return myChannel;
  60. }
  61. /** {@inheritDoc} */
  62. @Override
  63. public String getImportantModePrefix() {
  64. switch (getImportantModeValue()) {
  65. case 1:
  66. return "+";
  67. case 2:
  68. return "%";
  69. default:
  70. return "";
  71. }
  72. }
  73. /** {@inheritDoc} */
  74. @Override
  75. public String getImportantMode() {
  76. switch (getImportantModeValue()) {
  77. case 1:
  78. return "v";
  79. case 2:
  80. return "h";
  81. default:
  82. return "";
  83. }
  84. }
  85. /**
  86. * Get the value for the mode this client has.
  87. * Used for sorting.
  88. *
  89. * @return Value for this clients modes.
  90. */
  91. public int getImportantModeValue() {
  92. if (myClient == null || myClient.isFake()) { return 0; }
  93. final String ourNickname = ((Twitter) myClient.getParser()).getApi().getDisplayUsername();
  94. if (ourNickname.equalsIgnoreCase(myClient.getNickname())) {
  95. // Show ourselves as half-op
  96. return 2;
  97. } else if (myClient.getUser() != null && myClient.getUser().isFollowingUs()) {
  98. // Show followers as voiced
  99. return 1;
  100. } else {
  101. // Show everyone else as nothing
  102. return 0;
  103. }
  104. }
  105. /** {@inheritDoc} */
  106. @Override
  107. public String getAllModes() {
  108. return getImportantModePrefix();
  109. }
  110. /** {@inheritDoc} */
  111. @Override
  112. public Map<Object, Object> getMap() {
  113. return myMap;
  114. }
  115. /** {@inheritDoc} */
  116. @Override
  117. public void kick(final String message) {
  118. ((Twitter)myClient.getParser()).getApi().delFriend(myClient.getUser().getScreenName());
  119. myChannel.delChannelClient(this);
  120. myClient.delChannelClient(this);
  121. }
  122. /**
  123. * Compare this TwitterChannelClientInfo to another.
  124. *
  125. * @param arg0
  126. * @return
  127. */
  128. @Override
  129. public int compareTo(final ChannelClientInfo arg0) {
  130. if (arg0 instanceof TwitterChannelClientInfo) {
  131. final TwitterChannelClientInfo other = (TwitterChannelClientInfo) arg0;
  132. return (this.getImportantModeValue() - other.getImportantModeValue());
  133. }
  134. return 0;
  135. }
  136. /**
  137. * String representation of this client.
  138. *
  139. * @return a String representation of this client.
  140. */
  141. @Override
  142. public String toString() {
  143. return getImportantModePrefix() + myClient.getNickname();
  144. }
  145. }