mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-26 04:48:09 -06:00
Initial work to put tweets in mentions, sent and timelines
This commit is contained in:
parent
8fd3041efd
commit
ba90842185
@ -126,7 +126,7 @@ class Controller(object):
|
||||
pub.subscribe(self.update_sent_dms, "sent-dms-updated")
|
||||
pub.subscribe(self.more_dms, "more-sent-dms")
|
||||
pub.subscribe(self.manage_sent_tweets, "sent-tweet")
|
||||
pub.subscribe(self.manage_tweet_in_home, "tweet-in-home")
|
||||
pub.subscribe(self.manage_new_tweet, "newTweet")
|
||||
pub.subscribe(self.manage_friend, "friend")
|
||||
pub.subscribe(self.manage_unfollowing, "unfollowing")
|
||||
pub.subscribe(self.manage_favourite, "favourite")
|
||||
@ -1631,12 +1631,19 @@ class Controller(object):
|
||||
for i in sessions.sessions:
|
||||
sessions.sessions[i].save_persistent_data()
|
||||
|
||||
def manage_tweet_in_home(self, data, user):
|
||||
buffer = self.search_buffer("home_timeline", user)
|
||||
if buffer == None or buffer.session.db["user_name"] != user: return
|
||||
buffer.add_new_item(data)
|
||||
if "home_timeline" not in buffer.session.settings["other_buffers"]["muted_buffers"]:
|
||||
self.notify(buffer.session, "tweet_received.ogg")
|
||||
def manage_new_tweet(self, data, user, _buffers):
|
||||
sound_to_play = None
|
||||
for buff in _buffers:
|
||||
buffer = self.search_buffer(buff, user)
|
||||
if buffer == None or buffer.session.db["user_name"] != user: return
|
||||
buffer.add_new_item(data)
|
||||
if buff == "home_timeline": sound_to_play = "tweet_received.ogg"
|
||||
elif buff == "mentions_timeline": sound_to_play = "mention_received.ogg"
|
||||
elif buff == "sent_tweets": sound_to_play = "tweet_send.ogg"
|
||||
elif "timeline" in buff: sound_to_play = "tweet_timeline.ogg"
|
||||
else: sound_to_play = None
|
||||
if sound_to_play != None and buff not in buffer.session.settings["other_buffers"]["muted_buffers"]:
|
||||
self.notify(buffer.session, sound_to_play)
|
||||
|
||||
def check_streams(self):
|
||||
if self.started == False:
|
||||
|
@ -526,14 +526,28 @@ class Session(base.baseSession):
|
||||
if status.truncated:
|
||||
status._json = {**status._json, **status._json["extended_tweet"]}
|
||||
# Sends status to database, where it will be reduced and changed according to our needs.
|
||||
num = self.order_buffer("home_timeline", [status])
|
||||
if num == 1:
|
||||
# However, we have to do the "reduce and change" process here because the status we sent to the db is going to be a different object that the one sent to database.
|
||||
status = reduce.reduce_tweet(status)
|
||||
status = self.check_quoted_status(status)
|
||||
status = self.check_long_tweet(status)
|
||||
# Send it to the main controller object.
|
||||
pub.sendMessage("tweet-in-home", data=status, user=self.db["user_name"])
|
||||
buffers_to_send = []
|
||||
if status.user.id_str in self.stream_listener.users:
|
||||
buffers_to_send.append("home_timeline")
|
||||
if status.user.id == self.db["user_id"]:
|
||||
buffers_to_send.append("sent_tweets")
|
||||
for user in status.entities["user_mentions"]:
|
||||
if user["id"] == self.db["user_id"]:
|
||||
buffers_to_send.append("mentions_timeline")
|
||||
users_with_timeline = [user.split("-")[0] for user in self.db.keys() if user.endswith("-timeline")]
|
||||
for user in users_with_timeline:
|
||||
if status.user.id_str == user:
|
||||
buffers_to_send.append("{}-timeline".format(user))
|
||||
for buffer in buffers_to_send[::]:
|
||||
num = self.order_buffer(buffer, [status])
|
||||
if num == 0:
|
||||
buffers_to_send.remove(buffer)
|
||||
# However, we have to do the "reduce and change" process here because the status we sent to the db is going to be a different object that the one sent to database.
|
||||
reduced_status = reduce.reduce_tweet(status)
|
||||
status = self.check_quoted_status(status)
|
||||
status = self.check_long_tweet(status)
|
||||
# Send it to the main controller object.
|
||||
pub.sendMessage("newTweet", data=status, user=self.db["user_name"], _buffers=buffers_to_send)
|
||||
|
||||
def check_streams(self):
|
||||
log.debug("Status of running stream for user {}: {}".format(self.db["user_name"], self.stream.running))
|
||||
|
Loading…
Reference in New Issue
Block a user