Fixed reply support in Qaiku
authorRyan Paul <segphault@arstechnica.com>
Sat, 27 Jun 2009 02:29:11 +0000 (19:29 -0700)
committerRyan Paul <segphault@arstechnica.com>
Sat, 27 Jun 2009 02:29:11 +0000 (19:29 -0700)
gwibber/microblog/qaiku.py
gwibber/microblog/support/__init__.py

index 45cc084..1a859bb 100644 (file)
@@ -8,11 +8,12 @@ SegPhault (Ryan
 
 from . import can, support
 import urllib2, urllib, re, simplejson, base64
+#import markdown
 from gettext import lgettext as _
 
 PROTOCOL_INFO = {
   "name": "Qaiku",
-  "version": 0.1,
+  "version": 0.2,
   
   "config": [
     "private:password",
@@ -28,8 +29,8 @@ PROTOCOL_INFO = {
     can.RECEIVE,
     can.SEARCH,
     can.REPLY,
-    #can.RESPONSES,
-    can.DELETE,
+    can.RESPONSES,
+    #can.DELETE,
     can.THREAD,
     can.THREAD_REPLY,
     can.USER_MESSAGES,
@@ -60,7 +61,7 @@ class Message:
     self.sender_id = user["id"]
     self.sender_location = user["location"]
     self.sender_followers_count = user["followers_count"]
-    self.image = user["profile_image_url"]
+    self.image = "http://qiaku.com/" + user["profile_image_url"] if user["profile_image_url"].startswith("/") else user["profile_image_url"]
     self.url = "http://qaiku.com/home/%s/show/%s" % (user["screen_name"], data["id"])
     self.profile_url = "gwibber:user/%s/%s" % (self.account.id, user["screen_name"])
     self.external_profile_url = user["url"]
@@ -119,6 +120,13 @@ class Client:
     for data in self.get_thread_data(msg):
       yield Message(self, data)
 
+  def get_replies(self):
+    return simplejson.load(self.connect("/statuses/mentions.json"))
+
+  def responses(self):
+    for data in self.get_replies():
+      yield Message(self, data)
+
   def search(self, query):
     for data in self.get_search_data(query):
       if data["user"]:
@@ -135,7 +143,7 @@ class Client:
 
   def delete(self, message):
     return simplejson.load(self.connect(
-      "/statuses/destroy/%s.json" % message.id, {}))
+      "/statuses/destroy/%s.json" % message.id, ""))
   
   def send(self, message):
     data = simplejson.load(self.connect("/statuses/update.json",
@@ -144,6 +152,7 @@ class Client:
 
   def send_thread(self, message, target):
     data = simplejson.load(self.connect("/statuses/update.json",
-      urllib.urlencode({"status":message, "in_reply_to_status_id": target.id})))
+      urllib.urlencode({"status":message,
+        "in_reply_to_status_id": target.reply_id or target.id})))
     return Message(self, data)
 
index c9b6771..fbf5b7a 100644 (file)
@@ -32,6 +32,7 @@ URL_FORMAT = (r'(?<!\w)((?:%s):' # protocol + :
     '){2,}' # at least two characters in the main url part
     ')') % ('|'.join(SCHEMES),)
 LINK_PARSE = re.compile(URL_FORMAT)
+MARKDOWN_LINK_PARSE = re.compile("\[([^\]\[]\+)\](\(%s\))" % URL_FORMAT)
 
 def linkify(t):
   return LINK_PARSE.sub('<a href="\\1">\\1</a>', t)