mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 12:53:12 -06:00
Switched to new method for sending Direct messages #215
This commit is contained in:
parent
931cadfffa
commit
28b6d554e2
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -547,3 +547,16 @@ class Session(object):
|
||||
return user
|
||||
else:
|
||||
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"]
|
Loading…
Reference in New Issue
Block a user