Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

TwitterChannelClientInfo.java 5.2KB

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