Skip to content

Instantly share code, notes, and snippets.

@takuo
Created November 30, 2009 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuo/245312 to your computer and use it in GitHub Desktop.
Save takuo/245312 to your computer and use it in GitHub Desktop.
Gwibber Native Retweet patch
diff -uNr gwibber.orig/actions.py gwibber/actions.py
--- gwibber.orig/actions.py 2009-08-28 16:28:19.000000000 +0900
+++ gwibber/actions.py 2009-11-30 16:36:42.000000000 +0900
@@ -65,6 +65,26 @@
def include(self, client, msg):
return msg.account.supports(microblog.can.RETWEET)
+
+class RetweetNative(MessageAction):
+ icon = "mail-forward"
+ label = "_Native Retweet"
+
+ @classmethod
+ def action(self, w, client, msg):
+ d = gtk.MessageDialog(None, gtk.MESSAGE_QUESTION, 0, buttons=gtk.BUTTONS_OK)
+ d.add_button("Cancel(_C)", gtk.RESPONSE_CANCEL)
+ d.set_markup("Are you sure to Retweet this tweet?\n\n%s by %s" % (msg.text, msg.sender_nick))
+ if d.run() == gtk.RESPONSE_OK:
+ msg.account.get_client().send_retweet(msg.id)
+
+ d.destroy()
+
+ @classmethod
+ def include(self, client, msg):
+ return msg.account.supports(microblog.can.RETWEET_NATIVE) and \
+ msg.sender_nick != msg.account['username']
+
class Like(MessageAction):
icon = "bookmark_add"
label = "_Like this message"
@@ -111,4 +131,4 @@
def include(self, client, msg):
return gintegration.service_is_running("org.gnome.Tomboy")
-MENU_ITEMS = [Reply, ViewThread, Retweet, Like, Delete, Tomboy]
+MENU_ITEMS = [Reply, ViewThread, Retweet, RetweetNative, Like, Delete, Tomboy]
diff -uNr gwibber.orig/microblog/__init__.py gwibber/microblog/__init__.py
--- gwibber.orig/microblog/__init__.py 2009-08-28 16:28:19.000000000 +0900
+++ gwibber/microblog/__init__.py 2009-11-30 16:31:54.000000000 +0900
@@ -74,6 +74,13 @@
# Indicates with wich action the error happened
lambda c: c.send_thread(message, target), _("send message"), filter, False))
+ def send_retweet(self, id, filter=list(PROTOCOLS.keys())):
+ return list(self.get_data(
+ lambda a: a["send_enabled"] and supports(a, can.RETWEET_NATIVE),
+ # Translators: this message appears in the Errors dialog
+ # Indicates with wich action the error happened
+ lambda c: c.send_retweet(id), _("send retweet native"), filter, False))
+
def reply(self, message, filter=list(PROTOCOLS.keys())):
return list(self.get_data(
lambda a: supports(a, can.SEND),
diff -uNr gwibber.orig/microblog/can.py gwibber/microblog/can.py
--- gwibber.orig/microblog/can.py 2009-08-28 16:28:19.000000000 +0900
+++ gwibber/microblog/can.py 2009-11-30 16:33:13.000000000 +0900
@@ -22,3 +22,5 @@
LIKE = 14
PUBLIC = 15
GEO_FRIEND_POSITIONS = 50
+RETWEET_NATIVE = 99
+
diff -uNr gwibber.orig/microblog/twitter.py gwibber/microblog/twitter.py
--- gwibber.orig/microblog/twitter.py 2009-08-28 16:28:19.000000000 +0900
+++ gwibber/microblog/twitter.py 2009-11-30 17:55:06.000000000 +0900
@@ -42,6 +42,7 @@
can.SEARCH_URL,
can.USER_MESSAGES,
can.PUBLIC,
+ can.RETWEET_NATIVE,
],
}
@@ -51,6 +52,7 @@
class Message:
def __init__(self, client, data):
try:
+ rt = None
self.client = client
self.account = client.account
self.protocol = client.account["protocol"]
@@ -75,6 +77,10 @@
elif "name" in data:
user = data
+ if "retweeted_status" in data:
+ rt = data["retweeted_status"]
+ user = rt["user"]
+
self.sender = user["name"]
self.sender_nick = user["screen_name"]
self.sender_id = user["id"]
@@ -85,7 +91,16 @@
self.profile_url = "gwibber:user/%s/%s" % (self.account.id, user["screen_name"])
self.external_profile_url = "https://twitter.com/%s" % user["screen_name"]
- if "text" in data:
+ if rt:
+ self.text = u"<b>\u267a%s</b><br>\n%s" % (data["user"]["screen_name"], rt["text"])
+ self.html_string = '<span class="text">%s</span>' % \
+ HASH_PARSE.sub('#<a class="inlinehash" href="gwibber:tag/\\1">\\1</a>',
+ NICK_PARSE.sub('@<a class="inlinenick" href="gwibber:user/'+self.account.id+'/\\1">\\1</a>',
+ support.linkify(self.text)))
+ self.is_reply = re.compile("@%s[\W]+|@%s$" % (self.username, self.username)).search(self.text)
+ self.reply_nick = ''
+ self.reply_url = ''
+ elif "text" in data:
self.text = data["text"]
self.html_string = '<span class="text">%s</span>' % \
HASH_PARSE.sub('#<a class="inlinehash" href="gwibber:tag/\\1">\\1</a>',
@@ -169,7 +184,7 @@
def get_messages(self):
return simplejson.loads(self.connect(
- "https://twitter.com/statuses/friends_timeline.json" +'?'+
+ "https://twitter.com/statuses/home_timeline.json" +'?'+
urllib.urlencode({"count": self.account["receive_count"] or "20"})))
def get_public_timeline(self):
@@ -256,3 +271,9 @@
urllib.urlencode({"status":message,
"in_reply_to_status_id":target.id, "source": "gwibbernet"})))
return Message(self, data)
+
+ def send_retweet(self, id):
+ data = simplejson.loads(self.connect(
+ "https://twitter.com/statuses/retweet/%s.json" % id,
+ urllib.urlencode({"source":"gwibbernet"})))
+ return Message(self, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment