Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'develop'

  • Loading branch information...
commit 5fa9b23298b34b9dd0b358bea7a1b584d8b964ec 2 parents 5a7b8d2 + b4b6603
@stiletto authored
View
21 bnw_core/post.py
@@ -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:
@@ -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
@@ -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 Список тегов.
@@ -132,7 +132,7 @@ 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:
@@ -140,9 +140,9 @@ def postMessage(user,tags,clubs,text,anon=False,anoncom=False,sfrom=None):
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):
@@ -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:
@@ -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(),
@@ -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)))
@@ -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)
@@ -263,4 +265,3 @@ def publish(etype,*args,**kwargs):
for listener in listeners[rtype].itervalues():
reactor.callLater(0,listener,*args,**kwargs)
-
View
2  bnw_handlers/base.py
@@ -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')
)
View
8 bnw_handlers/command_delete.py
@@ -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()
@@ -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.')
)
@@ -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.')
)
View
8 bnw_handlers/command_post.py
@@ -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
@@ -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
View
2  bnw_xmpp/handlers.py
@@ -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."),
View
8 bnw_xmpp/xmpp_notifier.py
@@ -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
@@ -19,7 +19,7 @@ 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']
@@ -27,5 +27,5 @@ def notify(self,user,event_type,event):
dict(comment=comment)
)
user.send_plain(formatted,sfrom)
- defer.returnValue(1)
- defer.returnValue(0)
+ return 1 #defer.returnValue(1)
+ return 0 #defer.returnValue(0)
Please sign in to comment.
Something went wrong with that request. Please try again.