2013-03-19 16:14:19 -07:00
|
|
|
from bson.objectid import ObjectId
|
2021-01-04 13:33:56 -05:00
|
|
|
from newsblur_web.celeryapp import app
|
2013-03-19 16:14:19 -07:00
|
|
|
from apps.social.models import MSharedStory, MSocialProfile, MSocialServices, MSocialSubscription
|
|
|
|
from django.contrib.auth.models import User
|
2012-07-31 11:41:30 -07:00
|
|
|
from utils import log as logging
|
2012-06-27 23:58:10 -07:00
|
|
|
|
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def PostToService(shared_story_id, service):
|
|
|
|
try:
|
|
|
|
shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
|
|
|
|
shared_story.post_to_service(service)
|
|
|
|
except MSharedStory.DoesNotExist:
|
|
|
|
logging.debug(" ---> Shared story not found (%s). Can't post to: %s" % (shared_story_id, service))
|
2012-06-27 23:58:10 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def EmailNewFollower(follower_user_id, followee_user_id):
|
|
|
|
user_profile = MSocialProfile.get_user(followee_user_id)
|
|
|
|
user_profile.send_email_for_new_follower(follower_user_id)
|
2012-10-24 16:09:47 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def EmailFollowRequest(follower_user_id, followee_user_id):
|
|
|
|
user_profile = MSocialProfile.get_user(followee_user_id)
|
|
|
|
user_profile.send_email_for_follow_request(follower_user_id)
|
2013-04-22 15:24:38 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def EmailFirstShare(user_id):
|
|
|
|
user = User.objects.get(pk=user_id)
|
|
|
|
user.profile.send_first_share_to_blurblog_email()
|
2012-07-05 18:29:38 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def EmailCommentReplies(shared_story_id, reply_id):
|
|
|
|
shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
|
|
|
|
shared_story.send_emails_for_new_reply(ObjectId(reply_id))
|
2012-07-05 18:29:38 -07:00
|
|
|
|
2020-11-13 13:27:11 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def EmailStoryReshares(shared_story_id):
|
|
|
|
shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
|
|
|
|
shared_story.send_email_for_reshare()
|
2012-07-05 19:50:02 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def SyncTwitterFriends(user_id):
|
|
|
|
social_services = MSocialServices.objects.get(user_id=user_id)
|
|
|
|
social_services.sync_twitter_friends()
|
2012-07-10 15:24:54 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def SyncFacebookFriends(user_id):
|
|
|
|
social_services = MSocialServices.objects.get(user_id=user_id)
|
|
|
|
social_services.sync_facebook_friends()
|
2020-06-11 14:06:08 -04:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task(name="share-popular-stories")
|
2020-11-13 12:14:37 -05:00
|
|
|
def SharePopularStories():
|
|
|
|
logging.debug(" ---> Sharing popular stories...")
|
|
|
|
MSharedStory.share_popular_stories(interactive=False)
|
2012-09-10 13:08:12 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task(name='clean-social-spam')
|
2020-11-13 12:14:37 -05:00
|
|
|
def CleanSocialSpam():
|
|
|
|
logging.debug(" ---> Finding social spammers...")
|
|
|
|
MSharedStory.count_potential_spammers(destroy=True)
|
2015-07-15 10:25:38 -07:00
|
|
|
|
2013-03-19 16:14:19 -07:00
|
|
|
|
2020-11-13 13:26:25 -05:00
|
|
|
@app.task()
|
2020-11-13 12:14:37 -05:00
|
|
|
def UpdateRecalcForSubscription(subscription_user_id, shared_story_id):
|
|
|
|
user = User.objects.get(pk=subscription_user_id)
|
|
|
|
socialsubs = MSocialSubscription.objects.filter(subscription_user_id=subscription_user_id)
|
|
|
|
try:
|
|
|
|
shared_story = MSharedStory.objects.get(id=ObjectId(shared_story_id))
|
|
|
|
except MSharedStory.DoesNotExist:
|
|
|
|
return
|
2014-04-22 14:07:19 -07:00
|
|
|
|
2020-11-13 12:14:37 -05:00
|
|
|
logging.debug(" ---> ~FM~SNFlipping unread recalc for ~SB%s~SN subscriptions to ~SB%s's blurblog~SN" % (
|
|
|
|
socialsubs.count(),
|
|
|
|
user.username
|
|
|
|
))
|
|
|
|
for socialsub in socialsubs:
|
|
|
|
socialsub.needs_unread_recalc = True
|
|
|
|
socialsub.save()
|
|
|
|
|
|
|
|
shared_story.publish_update_to_subscribers()
|