Ver código fonte

Update Twitter parser for new methods

Change-Id: I1dac30977798780148eb27b8279a56a86b3bf890
Depends-On: Ia0b147cfe1af5d5d5d1eae34c82e50ce23578d10
Reviewed-on: http://gerrit.dmdirc.com/980
Automatic-Compile: Chris Smith <chris@dmdirc.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Chris Smith 14 anos atrás
pai
commit
19d31707ed
1 arquivos alterados com 42 adições e 31 exclusões
  1. 42
    31
      src/com/dmdirc/addons/parser_twitter/Twitter.java

+ 42
- 31
src/com/dmdirc/addons/parser_twitter/Twitter.java Ver arquivo

@@ -34,6 +34,7 @@ import com.dmdirc.config.IdentityManager;
34 34
 import com.dmdirc.interfaces.ConfigChangeListener;
35 35
 import com.dmdirc.logger.ErrorManager;
36 36
 import com.dmdirc.parser.common.CallbackManager;
37
+import com.dmdirc.parser.common.ChannelJoinRequest;
37 38
 import com.dmdirc.parser.common.DefaultStringConverter;
38 39
 import com.dmdirc.parser.common.IgnoreList;
39 40
 import com.dmdirc.parser.common.MyInfo;
@@ -221,44 +222,54 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
221 222
     /** {@inheritDoc} */
222 223
     @Override
223 224
     public void joinChannel(final String channel) {
224
-        joinChannel(channel, "");
225
+        joinChannels(new ChannelJoinRequest(channel));
225 226
     }
226 227
 
227 228
     /** {@inheritDoc} */
228 229
     @Override
229 230
     public void joinChannel(final String channel, final String key) {
230
-        if (isValidChannelName(channel) && getChannel(channel) == null && !channel.equalsIgnoreCase(mainChannelName)) {
231
-            final TwitterChannelInfo newChannel = new TwitterChannelInfo(channel, this);
232
-            newChannel.addChannelClient(new TwitterChannelClientInfo(newChannel, myself));
233
-            if (channel.matches("^&[0-9]+$")) {
234
-                try {
235
-                    long id = Long.parseLong(channel.substring(1));
236
-                    final TwitterStatus status = api.getStatus(id);
237
-                    if (status != null) {
238
-                        if (status.getReplyTo() > 0) {
239
-                            newChannel.setLocalTopic(status.getText()+" [Reply to: &"+status.getReplyTo()+"]");
231
+        joinChannels(new ChannelJoinRequest(channel, key));
232
+    }
233
+
234
+    /** {@inheritDoc} */
235
+    @Override
236
+    public void joinChannels(final ChannelJoinRequest ... channels) {
237
+        for (ChannelJoinRequest request : channels) {
238
+            final String channel = request.getName();
239
+
240
+            if (isValidChannelName(channel) && getChannel(channel) == null && !channel.equalsIgnoreCase(mainChannelName)) {
241
+                final TwitterChannelInfo newChannel = new TwitterChannelInfo(channel, this);
242
+                newChannel.addChannelClient(new TwitterChannelClientInfo(newChannel, myself));
243
+                if (channel.matches("^&[0-9]+$")) {
244
+                    try {
245
+                        long id = Long.parseLong(channel.substring(1));
246
+                        final TwitterStatus status = api.getStatus(id);
247
+                        if (status != null) {
248
+                            if (status.getReplyTo() > 0) {
249
+                                newChannel.setLocalTopic(status.getText()+" [Reply to: &"+status.getReplyTo()+"]");
250
+                            } else {
251
+                                newChannel.setLocalTopic(status.getText());
252
+                            }
253
+                            newChannel.setTopicSetter(status.getUser().getScreenName());
254
+                            newChannel.setTopicTime(status.getTime());
255
+                            final TwitterClientInfo client = (TwitterClientInfo) getClient(status.getUser().getScreenName());
256
+                            if (client.isFake()) {
257
+                                client.setFake(false);
258
+                                clients.put(client.getNickname().toLowerCase(), client);
259
+                            }
260
+                            newChannel.addChannelClient(new TwitterChannelClientInfo(newChannel, client));
240 261
                         } else {
241
-                            newChannel.setLocalTopic(status.getText());
262
+                            newChannel.setLocalTopic("Unknown status, or you do not have access to see it.");
242 263
                         }
243
-                        newChannel.setTopicSetter(status.getUser().getScreenName());
244
-                        newChannel.setTopicTime(status.getTime());
245
-                        final TwitterClientInfo client = (TwitterClientInfo) getClient(status.getUser().getScreenName());
246
-                        if (client.isFake()) {
247
-                            client.setFake(false);
248
-                            clients.put(client.getNickname().toLowerCase(), client);
264
+                        synchronized (this.channels) {
265
+                            this.channels.put(channel, newChannel);
249 266
                         }
250
-                        newChannel.addChannelClient(new TwitterChannelClientInfo(newChannel, client));
251
-                    } else {
252
-                        newChannel.setLocalTopic("Unknown status, or you do not have access to see it.");
253
-                    }
254
-                    synchronized (channels) {
255
-                        channels.put(channel, newChannel);
256
-                    }
257
-                } catch (NumberFormatException nfe) { }
267
+                    } catch (NumberFormatException nfe) { }
268
+                }
269
+                doJoinChannel(newChannel);
270
+            } else {
271
+                sendNumericOutput(474, new String[]{":"+myServerName, "474", myself.getNickname(), channel, "Cannot join channel - name is not valid, or you are already there."});
258 272
             }
259
-            doJoinChannel(newChannel);
260
-        } else {
261
-            sendNumericOutput(474, new String[]{":"+myServerName, "474", myself.getNickname(), channel, "Cannot join channel - name is not valid, or you are already there."});
262 273
         }
263 274
     }
264 275
 
@@ -1449,8 +1460,8 @@ public class Twitter implements Parser, TwitterErrorHandler, TwitterRawHandler,
1449 1460
 
1450 1461
     /** {@inheritDoc} */
1451 1462
     @Override
1452
-    public void updateURI(final URI uri) {
1453
-        // Do nothing
1463
+    public Collection<? extends ChannelJoinRequest> extractChannels(final URI uri) {
1464
+        return new ArrayList<ChannelJoinRequest>();
1454 1465
     }
1455 1466
 
1456 1467
 }

Carregando…
Cancelar
Salvar