def follow(user_id, other_id): if is_following(user_id, other_id): return False follow_relation = FollowRelation(follower_id=user_id, user_id=other_id) db.session.add(follow_relation) db.session.commit() pubsub.publish(Event.FOLLOWING_UPDATED, user_id) pubsub.publish(Event.FOLLOWER_UPDATED, other_id) return True
def follow(self, user_id, other_id): if self.is_following(user_id, other_id): return False follow_relation = FollowRelation(follower_id = user_id, user_id = other_id) db.session.add(follow_relation) db.session.commit() pubsub.publish(Event.FOLLOWING_UPDATED, user_id) pubsub.publish(Event.FOLLOWER_UPDATED, other_id) return True
def post_feed(user_id, content, time_created=None): if not time_created: time_created = int(time.time()) feed = Feed(user_id=user_id, content=content, time_created=time_created) db.session.add(feed) db.session.commit() pubsub.publish(Event.USER_FEEDS_UPDATED, user_id) for u in get_followers(user_id): pubsub.publish(Event.FRIEND_FEEDS_UPDATED, u['id']) return feed.to_dict()
def post_feed(self, user_id, content, time_created=None): if not time_created: time_created = int(time.time()) feed = Feed(user_id=user_id, content=content, time_created=time_created) db.session.add(feed) db.session.commit() pubsub.publish(Event.USER_FEEDS_UPDATED, user_id) for u in self.get_followers(user_id): pubsub.publish(Event.FRIEND_FEEDS_UPDATED, u['id']) return feed.to_dict()
def unfollow(self, user_id, other_id): follow_relation = FollowRelation.query.filter_by(follower_id=user_id, user_id=other_id).one() if follow_relation: db.session.delete(follow_relation) db.session.commit() pubsub.publish(Event.FOLLOWING_UPDATED, user_id) pubsub.publish(Event.FOLLOWER_UPDATED, other_id) return True else: return False
def unfollow(user_id, other_id): follow_relation = FollowRelation.query.filter_by(follower_id=user_id, user_id=other_id).one() if follow_relation: db.session.delete(follow_relation) db.session.commit() pubsub.publish(Event.FOLLOWING_UPDATED, user_id) pubsub.publish(Event.FOLLOWER_UPDATED, other_id) return True else: return False