Skip to content

Commit

Permalink
Принудительная анонимность комментариев - опция --anoncomments или -q
Browse files Browse the repository at this point in the history
  • Loading branch information
stiletto committed Apr 10, 2012
1 parent 999cba7 commit b4b6603
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
21 changes: 11 additions & 10 deletions bnw_core/post.py
Expand Up @@ -38,7 +38,7 @@ def subscribe(user,target_type,target,fast=False,sfrom=None):
defer.returnValue((False,'No such message.'))
else:
adddesc=' (%d replies)' % (msg['replycount'],)

feedel_val = dict(user=user['name'],message=target)
feedel = None if fast else (yield objs.FeedElement.find_one(feedel_val))
if not feedel:
Expand Down Expand Up @@ -98,7 +98,7 @@ def send_to_subscribers(queries,message,recommender=None,recocomment=None):
print recipients
bl_items = frozenset([('user',message['user'])] + [('tag',x) for x in message.get('tags',[])] +
[('club',x) for x in message.get('clubs',[])])

for target_name,subscription in recipients.iteritems():
target=yield objs.User.find_one({'name': target_name})
qn+=1
Expand All @@ -111,7 +111,7 @@ def send_to_subscribers(queries,message,recommender=None,recocomment=None):
defer.returnValue((qn,reccount))

@defer.inlineCallbacks
def postMessage(user,tags,clubs,text,anon=False,anoncom=False,sfrom=None):
def postMessage(user,tags,clubs,text,anon=False,anoncomments=False,sfrom=None):
"""!Это дерьмо создает новое сообщение и рассылает его.
@param user Объект-пользователь.
@param tags Список тегов.
Expand All @@ -132,17 +132,17 @@ def postMessage(user,tags,clubs,text,anon=False,anoncom=False,sfrom=None):
'replycount': 0,
'text': text,
'anonymous': anon,
'anoncomments': anoncom,
'anoncomments': anoncomments,
'recommendations': [],
}
if anon:
message['real_user']=message['user']
message['user']='anonymous'
stored_message = objs.Message(message)
stored_message_id = yield stored_message.save()

sub_result = yield subscribe(user,'sub_message',message['id'],True,sfrom)

queries=[{'target': tag, 'type': 'sub_tag'} for tag in tags]
queries+=[{'target': club, 'type': 'sub_club'} for club in clubs]
if ('@' in clubs) or (len(clubs)==0):
Expand All @@ -166,6 +166,8 @@ def postComment(message_id,comment_id,text,user,anon=False,sfrom=None):
if len(text)>4096:
defer.returnValue((False,'Comment is too long. %d/4096' % (len(text),)))
message=yield objs.Message.find_one({'id': message_id})
if message.get('anoncomments'):
anon=True
if comment_id:
old_comment=yield objs.Comment.find_one({'id': comment_id, 'message': message_id})
else:
Expand All @@ -174,7 +176,7 @@ def postComment(message_id,comment_id,text,user,anon=False,sfrom=None):
defer.returnValue((False,'No such comment.'))
if not message:
defer.returnValue((False,'No such message.'))

comment={ 'user': user['name'],
'message': message_id,
'date': time.time(),
Expand Down Expand Up @@ -203,7 +205,7 @@ def postComment(message_id,comment_id,text,user,anon=False,sfrom=None):
defer.returnValue((False,'Looks like this message has reached its bumplimit.'))
sub_result = yield subscribe(user,'sub_message',message_id,False,sfrom)
_ = (yield objs.Message.mupdate({'id':message_id},{'$inc': { 'replycount': 1}}))

qn,recipients = yield send_to_subscribers([{'target': message_id, 'type': 'sub_message'}],comment)
publish('comments-'+message_id,comment.filter_fields()) # ALARM
defer.returnValue((True,(comment['id'],comment['num'],qn,recipients)))
Expand All @@ -225,7 +227,7 @@ def recommendMessage(user,message_id,comment="",sfrom=None):
defer.returnValue((False,'Recommendation is too long. %d/256' % (len(comment),)))

sub_result = yield subscribe(user,'sub_message',message_id,False,sfrom)

queries=[{'target': user['name'], 'type': 'sub_user'}]
qn,recipients = yield send_to_subscribers(queries,message,user['name'],comment)

Expand Down Expand Up @@ -263,4 +265,3 @@ def publish(etype,*args,**kwargs):
for listener in listeners[rtype].itervalues():
reactor.callLater(0,listener,*args,**kwargs)


2 changes: 1 addition & 1 deletion bnw_handlers/base.py
Expand Up @@ -38,7 +38,7 @@ def _(s,user):
def require_auth(fun):
@defer.inlineCallbacks
def newfun(request,*args,**kwargs):
if request.user is None:
if request.user is None or not request.user.get('name'):
defer.returnValue(
dict(ok=False,desc='Only for registered users')
)
Expand Down
8 changes: 4 additions & 4 deletions bnw_handlers/command_delete.py
Expand Up @@ -14,9 +14,9 @@ def _(s,user):
@defer.inlineCallbacks
def cmd_delete(request,message="",last=False):
""" Удаление
Удаление поста или коммента.
redeye: delete --message=123456, d -m ABCDEF/123, d --last, d -l
simple: D #123456, D #ABDEF/123, D L"""
message=canonic_message_comment(message).upper()
Expand Down Expand Up @@ -50,7 +50,7 @@ def cmd_delete(request,message="",last=False):
defer.returnValue(
dict(ok=False,desc='No such comment')
)
if comment['user']!=request.user['name'] and post['user']!=request.user['name']:
if request.user['name'] not in (comment['user'],post['user'],comment.get('real_user'),post.get('real_user')):
defer.returnValue(
dict(ok=False,desc='Not your comment and not your message.')
)
Expand All @@ -64,7 +64,7 @@ def cmd_delete(request,message="",last=False):
defer.returnValue(
dict(ok=False,desc='No such message.')
)
if post['user']!=request.user['name']:
if request.user['name'] not in (post['user'],post.get('real_user')):
defer.returnValue(
dict(ok=False,desc='Not your message.')
)
Expand Down
8 changes: 4 additions & 4 deletions bnw_handlers/command_post.py
Expand Up @@ -30,9 +30,9 @@ def throttle_update(user,post_throttle):
defer.returnValue(None)

@defer.inlineCallbacks
def postMessage(request,tags,clubs,text,anon=False,anoncom=False):
def postMessage(request,tags,clubs,text,anon=False,anoncomments=False):
post_throttle=yield throttle_check(request.user['name'])
ok,rest = yield bnw_core.post.postMessage(request.user,tags,clubs,text,anon,anoncom,sfrom=request.to)
ok,rest = yield bnw_core.post.postMessage(request.user,tags,clubs,text,anon,anoncomments,sfrom=request.to)
_ = yield throttle_update(request.user['name'],post_throttle)
if ok:
msgid,qn,recepients = rest
Expand All @@ -48,14 +48,14 @@ def postMessage(request,tags,clubs,text,anon=False,anoncom=False):

@require_auth
@defer.inlineCallbacks
def cmd_post(request,tags="",clubs="",anonymous="",text=""):
def cmd_post(request,tags="",clubs="",anonymous="",anoncomments="",text=""):
""" Отправка псто """
tags=tags.split(',')[:5]
clubs=clubs.split(',')[:5]
tags=filter(None,set([x.lower().strip().replace('\n',' ')[:256] for x in tags]))
clubs=filter(None,set([x.lower().strip().replace('\n',' ')[:256] for x in clubs]))
defer.returnValue(
(yield postMessage(request,tags,clubs,text,anonymous,False)))
(yield postMessage(request,tags,clubs,text,anonymous,anoncomments)))


@defer.inlineCallbacks
Expand Down
2 changes: 1 addition & 1 deletion bnw_xmpp/handlers.py
Expand Up @@ -54,7 +54,7 @@
("t", "tags", True, u"Mark post with this tag(s) (comma-separated)."),
("c", "clubs", True, u"Post to this club(s) (comma-separated)."),
("a", "anonymous", False, u"Anonymous post."),
("q", "anonymous-comments", False, u"Make all comments to this post anonymous (doesn''t work at all yet)."),
("q", "anoncomments", False, u"Make all comments to this post anonymous."),
)
comment_args = (
("m", "message", True, u"Message to comment."),
Expand Down
8 changes: 4 additions & 4 deletions bnw_xmpp/xmpp_notifier.py
Expand Up @@ -5,7 +5,7 @@
import deliver_formatters
import base
class XmppNotifier(object):
@defer.inlineCallbacks
#@defer.inlineCallbacks
def notify(self,user,event_type,event):
if event_type=='message' and not user.get('off',False):
message,recommender,recocomment,sfrom = event
Expand All @@ -19,13 +19,13 @@ def notify(self,user,event_type,event):
recocomment=recocomment)
)
user.send_plain(formatted,sfrom)
defer.returnValue(1)
return 1 #defer.returnValue(1)
elif event_type=='comment' and not user.get('off',False):
comment,sfrom = event
formatter = deliver_formatters.parsers[user.get('interface','redeye')]['comment']
formatted = formatter(None,
dict(comment=comment)
)
user.send_plain(formatted,sfrom)
defer.returnValue(1)
defer.returnValue(0)
return 1 #defer.returnValue(1)
return 0 #defer.returnValue(0)

0 comments on commit b4b6603

Please sign in to comment.