forked from rDrama/rDrama
fdfd
parent
7f70f89ec2
commit
097a4404be
|
@ -422,8 +422,7 @@ class User(Base, Stndrd, Age_times):
|
||||||
|
|
||||||
def has_follower(self, user):
|
def has_follower(self, user):
|
||||||
|
|
||||||
return g.db.query(Follow).filter_by(
|
return g.db.query(Follow).filter_by(target_id=self.id, user_id=user.id).first()
|
||||||
target_id=self.id, user_id=user.id).first()
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -431,18 +431,15 @@ def follow_user(username, v):
|
||||||
|
|
||||||
target = get_user(username)
|
target = get_user(username)
|
||||||
|
|
||||||
if target.id==v.id:
|
if target.id==v.id: return jsonify({"error": "You can't follow yourself!"}), 400
|
||||||
return jsonify({"error": "You can't follow yourself!"}), 400
|
|
||||||
|
|
||||||
# check for existing follow
|
# check for existing follow
|
||||||
if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first():
|
if g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first(): abort(409)
|
||||||
abort(409)
|
|
||||||
|
|
||||||
new_follow = Follow(user_id=v.id,
|
|
||||||
target_id=target.id)
|
|
||||||
|
|
||||||
|
new_follow = Follow(user_id=v.id, target_id=target.id)
|
||||||
g.db.add(new_follow)
|
g.db.add(new_follow)
|
||||||
target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id)
|
|
||||||
|
target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count()
|
||||||
g.db.add(target)
|
g.db.add(target)
|
||||||
|
|
||||||
existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first()
|
existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first()
|
||||||
|
@ -457,14 +454,12 @@ def unfollow_user(username, v):
|
||||||
target = get_user(username)
|
target = get_user(username)
|
||||||
|
|
||||||
# check for existing follow
|
# check for existing follow
|
||||||
follow = g.db.query(Follow).filter_by(
|
follow = g.db.query(Follow).filter_by(user_id=v.id, target_id=target.id).first()
|
||||||
user_id=v.id, target_id=target.id).first()
|
|
||||||
|
|
||||||
if not follow:
|
if not follow: abort(409)
|
||||||
abort(409)
|
|
||||||
|
|
||||||
g.db.delete(follow)
|
g.db.delete(follow)
|
||||||
target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id)
|
target.stored_subscriber_count = g.db.query(Follow).filter_by(target_id=target.id).count()
|
||||||
g.db.add(target)
|
g.db.add(target)
|
||||||
|
|
||||||
existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first()
|
existing = g.db.query(Notification).filter_by(followsender=v.id, user_id=target.id).first()
|
||||||
|
|
Loading…
Reference in New Issue