diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index f8150030..5c753db1 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -570,14 +570,28 @@ class baseBufferController(bufferController): users = utils.get_all_users(tweet, self.session.db) dm = messages.dm(self.session, _(u"Direct message to %s") % (screen_name,), _(u"New direct message"), users) if dm.message.get_response() == widgetUtils.OK: - val = self.session.api_call(call_name="send_direct_message", text=dm.message.get_text(), screen_name=dm.message.get("cb")) - # let's avoid this for now as sent dm's are quite different to new dm objects. -# if val != None: -# if self.session.settings["general"]["reverse_timelines"] == False: -# self.session.db["sent_direct_messages"].append(val) -# else: -# self.session.db["sent_direct_messages"].insert(0, val) -# pub.sendMessage("sent-dm", data=val, user=self.session.db["user_name"]) + screen_name = dm.message.get("cb") + user = self.session.get_user_by_screen_name(screen_name) + event_data = { + 'event': { + 'type': 'message_create', + 'message_create': { + 'target': { + 'recipient_id': user, + }, + 'message_data': { + 'text': dm.message.get_text(), + } + } + } +} + val = self.session.api_call(call_name="send_direct_message", **event_data) + if val != None: + if self.session.settings["general"]["reverse_timelines"] == False: + self.session.db["direct_messages"]["items"].append(val["event"]) + else: + self.session.db["direct_messages"]["items"].insert(0, val["event"]) + pub.sendMessage("sent-dm", data=val["event"], user=self.session.db["user_name"]) if hasattr(dm.message, "destroy"): dm.message.destroy() @_tweets_exist diff --git a/src/controller/mainController.py b/src/controller/mainController.py index a70a4f69..64054a05 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -1313,10 +1313,10 @@ class Controller(object): buffer.add_new_item(data) def manage_sent_dm(self, data, user): - buffer = self.search_buffer("sent_direct_messages", user) + buffer = self.search_buffer("direct_messages", user) if buffer == None: return play_sound = "dm_sent.ogg" - if "sent_direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]: + if "direct_messages" not in buffer.session.settings["other_buffers"]["muted_buffers"]: self.notify(buffer.session, play_sound=play_sound) buffer.add_new_item(data) diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index 6d98bceb..2d62685f 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -546,4 +546,17 @@ class Session(object): self.db["users"][user["id_str"]] = user return user else: - return self.db["users"][id] \ No newline at end of file + return self.db["users"][id] + + def get_user_by_screen_name(self, screen_name): + if self.db.has_key("users") == False: + user = utils.if_user_exists(self.twitter.twitter, screen_name) + self.db["users"][user["id_str"]] = user + return user["id_str"] + else: + for i in self.db["users"].keys(): + if self.db["users"][i]["screen_name"] == screen_name: + return self.db["users"][i]["id_str"] + user = utils.if_user_exists(self.twitter.twitter, screen_name) + self.db["users"][user["id_str"]] = user + return user["id_str"] \ No newline at end of file