Merge commit 'upstream/0.2.85' into experimental
[debian/pino.git] / src / twitter_recursive_reply.vala
1 using RestCustom;
2 using Gee;
3
4 namespace Twitter {
5
6 public class RecursiveReply : GLib.Object  {
7         
8         public signal void new_reply(Status status, string sid);
9         
10         private Rest.Proxy proxy;
11         private string s_name = "";
12         private Status fstatus;
13         //private string stream_hash = "";
14         
15         public RecursiveReply(Rest.Proxy proxy, Status fstatus, string s_name) {
16                 
17                 this.proxy = proxy;
18                 this.fstatus = fstatus;
19                 this.s_name = s_name;
20                 //this.stream_hash = stream_hash;
21         }
22         
23         public void run() {
24                 debug("ok");
25                 get_reply(fstatus);
26         }
27         
28         private void get_reply(Status status) {
29                 if(status.reply == null) {
30                         debug("the end");
31                         fstatus.end_reply();
32                         return;
33                 }
34                 
35                 Rest.ProxyCall call = proxy.new_call();
36                 call.set_function("statuses/show/%s.xml".printf(status.reply.status_id));
37                 call.set_method("GET");
38                 //debug("statuses/show/%s.xml".printf(status.id));
39                 Rest.ProxyCallAsyncCallback callback = status_get_respose;
40                 call.run_async(callback, this);
41         }
42         
43         protected void status_get_respose(Rest.ProxyCall call, Error? error, Object? obj) {
44                 //debug(call.get_status_code().to_string());
45                 Status? status = Parser.get_status_from_string(call.get_payload(), s_name);
46                 
47                 if(status == null)
48                         return;
49                 
50                 new_reply(status, fstatus.id);
51                 
52                 if(fstatus.conversation == null)
53                         fstatus.conversation = new ArrayList<Status>();
54                 
55                 fstatus.conversation.add(status);
56                 fstatus.new_reply(status); //signal
57                 
58                 get_reply(status);
59         }
60 }
61 }