Add modmail messages to sent

In the process, move taglinetext logic for messages
into the wrapping/add_props area to reduce code
duplication
This commit is contained in:
Keith Mitchell
2012-02-14 09:40:29 -08:00
parent 2537176f53
commit 0cb9d4f106
5 changed files with 44 additions and 61 deletions

View File

@@ -711,13 +711,13 @@ def new_message(message, inbox_rels):
from_user = Account._byID(message.author_id)
for inbox_rel in tup(inbox_rels):
to = inbox_rel._thing1
add_queries([get_sent(from_user)], insert_items=message)
# moderator message
if isinstance(inbox_rel, ModeratorInbox):
add_queries([get_subreddit_messages(to)],
insert_items = inbox_rel)
# personal message
else:
add_queries([get_sent(from_user)], insert_items = message)
add_queries([get_inbox_messages(to)],
insert_items = inbox_rel)
set_unread(message, to, True)

View File

@@ -1120,7 +1120,7 @@ class Message(Thing, Printable):
c.user_is_admin):
item.author = item.subreddit
item.hide_author = True
item.is_collapsed = None
if not item.new:
if item.recipient:
@@ -1134,6 +1134,24 @@ class Message(Thing, Printable):
if not c.user_is_admin:
item.subject = _('[message from blocked user]')
item.body = _('[unblock user to see this message]')
taglinetext = ''
if item.hide_author:
taglinetext = _("subreddit message %(author)s sent %(when)s ago")
elif item.author_id == c.user._id:
taglinetext = _("to %(dest)s sent %(when)s ago")
elif item.to_id == c.user._id or item.to_id is None:
taglinetext = _("from %(author)s sent %(when)s ago")
else:
taglinetext = _("to %(dest)s from %(author)s sent %(when)s ago")
item.taglinetext = taglinetext
item.dest = item.to.name if item.to else ""
if item.sr_id:
if item.hide_author:
item.updated_author = _("via %(subreddit)s")
else:
item.updated_author = _("%(author)s via %(subreddit)s")
else:
item.updated_author = ''
# Run this last

View File

@@ -54,32 +54,21 @@
<div class="entry">
<%
taglinetext = ''
if getattr(thing, "hide_author", False):
taglinetext = _("subreddit message %(author)s sent %(when)s ago")
elif thing.to_id == c.user._id or thing.to_id is None:
taglinetext = _("from %(author)s sent %(when)s ago")
elif thing.author_id == c.user._id:
taglinetext = _("to %(dest)s sent %(when)s ago")
else:
taglinetext = _("to %(dest)s from %(author)s sent %(when)s ago")
taglinetext = taglinetext.replace(' ', '&nbsp;')
author = WrappedUser(thing.author, thing.attribs, thing).render()
if thing.sr_id:
if getattr(thing, "hide_author", False):
updated_author = _("via %(subreddit)s")
else:
updated_author = _("%(author)s via %(subreddit)s").replace(' ', '&nbsp;')
subreddit = '<a href="%s.compact">%s</a>' % (thing.subreddit.path,
thing.subreddit.name)
author = updated_author % dict(author = author, subreddit = subreddit)
if not thing.dest:
thing.dest = subreddit
author = thing.updated_author % dict(author=author, subreddit=subreddit)
taglinetext = thing.taglinetext % dict(when=thing.timesince,
author=u"<b>%s</b>" % author,
dest=u"<b>%s</b>" % thing.dest)
taglinetext = taglinetext.replace(' ', '&nbsp;')
%>
<div class="tagline">
${unsafe(taglinetext % dict(when = thing.timesince,
author= u"<b>%s</b>" % author,
dest = u"<b>%s</b>" % (thing.to.name if thing.to else "")))}
${unsafe(taglinetext)}
</div>
<a href="javascript:void(0)" class="options_link"></a>
${unsafe(safemarkdown(thing.body))}

View File

@@ -51,30 +51,20 @@ ${parent.thing_css_class(what)} ${"new" if thing.new else ""} ${"was-comment" if
</a>
<span class="head">
<%
taglinetext = ''
if getattr(thing, "hide_author", False):
taglinetext = _("subreddit message %(author)s sent %(when)s ago")
elif thing.to_id == c.user._id or thing.to_id is None:
taglinetext = _("from %(author)s sent %(when)s ago")
elif thing.author_id == c.user._id:
taglinetext = _("to %(dest)s sent %(when)s ago")
else:
taglinetext = _("to %(dest)s from %(author)s sent %(when)s ago")
taglinetext = taglinetext.replace(' ', '&nbsp;')
author = WrappedUser(thing.author, thing.attribs, thing).render()
if thing.sr_id:
if getattr(thing, "hide_author", False):
updated_author = _("via %(subreddit)s")
else:
updated_author = _("%(author)s via %(subreddit)s").replace(' ', '&nbsp;')
subreddit = '<a href="%s">%s</a>' % (thing.subreddit.path,
thing.subreddit.name)
author = updated_author % dict(author = author, subreddit = subreddit)
subreddit = '<a href="%s">%s</a>' % (thing.subreddit.path,
thing.subreddit.path)
if not thing.dest:
thing.dest = subreddit
author = thing.updated_author % dict(author=author, subreddit=subreddit)
taglinetext = thing.taglinetext % dict(when=thing.timesince,
author=u"<b>%s</b>" % author,
dest=u"<b>%s</b>" % thing.dest)
taglinetext = taglinetext.replace(' ', '&nbsp;')
%>
${unsafe(taglinetext % dict(when = thing.timesince,
author= u"<b>%s</b>" % author,
dest = u"<b>%s</b>" % (thing.to.name if thing.to else "")))}
${unsafe(taglinetext)}
</span>
%if c.user_is_admin:
${self.admintagline()}

View File

@@ -33,29 +33,15 @@
<link>${permalink}</link>
<title>
<%
taglinetext = ''
if getattr(thing, "hide_author", False):
taglinetext = _("subreddit message %(author)s sent %(when)s ago")
elif thing.to_id == c.user._id or thing.to_id is None:
taglinetext = _("from %(author)s sent %(when)s ago")
elif thing.author_id == c.user._id:
taglinetext = _("to %(dest)s sent %(when)s ago")
else:
taglinetext = _("to %(dest)s from %(author)s sent %(when)s ago")
author = thing.author.name
if thing.sr_id and not (getattr(thing, "is_child", False) or
getattr(thing, "is_parent", False)):
if getattr(thing, "hide_author", False):
updated_author = _("via %(subreddit)s")
else:
updated_author = _("%(author)s via %(subreddit)s")
subreddit = thing.subreddit.name
author = updated_author % dict(author = author, subreddit = subreddit)
author = thing.updated_author % dict(author=author, subreddit=subreddit)
%>
${thing.subject} : ${unsafe(taglinetext % dict(when = thing.timesince,
author= u"%s" % author,
dest = u"%s" % thing.to.name if thing.to else ""))}
${thing.subject} : ${unsafe(thing.taglinetext % dict(when=thing.timesince,
author=u"%s" % author,
dest=u"%s" % thing.dest))}
</title>
<pubDate>${thing._date.strftime('%a, %d %b %Y %H:%M:%S %z')}</pubDate>
<dc:date>${thing._date.isoformat()}-0700</dc:date>