Changeset 2009

Show
Ignore:
Timestamp:
02/18/07 14:48:22 (2 years ago)
Author:
Blackhex
Message:

DiscussionPlugin:

  • Notification message threading.
  • Notification to topic and message authors.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • discussionplugin/0.10/tracdiscussion/api.py

    r1987 r2009  
    500500                # Get new popic and notify about creation. 
    501501                new_topic = self.get_topic_by_time(cursor, new_time) 
    502                 new_topic['moderators'] = ' '.join(forum['moderators']) 
     502                to = self.get_topic_to_recipients(cursor, topic['id']) 
     503                cc = self.get_topic_cc_recipients(cursor, topic['id']) 
    503504                notifier = DiscussionNotifyEmail(self.env) 
    504                 notifier.notify(req, cursor, mode, new_topic) 
     505                notifier.notify(req, cursor, mode, forum, new_topic, None, to, 
     506                  cc) 
    505507 
    506508            elif mode == 'topic-edit': 
     
    629631                # Get inserted message and notify about its creation. 
    630632                new_message = self.get_message_by_time(cursor, new_time) 
    631                 new_message['subject'] = topic['subject'] 
    632                 new_message['moderators'] = ' '.join(forum['moderators']) 
     633                to = self.get_topic_to_recipients(cursor, topic['id']) 
     634                cc = self.get_topic_cc_recipients(cursor, topic['id']) 
    633635                notifier = DiscussionNotifyEmail(self.env) 
    634                 notifier.notify(req, cursor, mode, new_message) 
     636                notifier.notify(req, cursor, mode, forum, topic, new_message, 
     637                  to, cc) 
    635638 
    636639            elif mode == 'message-edit': 
     
    728731            return row 
    729732        return None 
     733 
     734    def get_topic_to_recipients(self, cursor, id): 
     735        sql = "SELECT t.author FROM topic t WHERE t.id = %s UNION SELECT" \ 
     736          " m.author FROM message m WHERE m.topic = %s" 
     737        self.log.debug(sql % (id, id)) 
     738        cursor.execute(sql, (id, id)) 
     739        to_recipients = [] 
     740        for row in cursor: 
     741            to_recipients.append(row[0]) 
     742        self.log.debug(to_recipients) 
     743        return to_recipients 
     744 
     745    def get_topic_cc_recipients(self, cursor, id): 
     746        return [] 
    730747 
    731748    def get_forum(self, cursor, id): 
     
    873890        return forums 
    874891 
    875     def get_topics(self, req, cursor, forum, order_by = 'time', desc = False): 
     892    def get_topics(self, req, cursor, forum_id, order_by = 'time', desc = False): 
    876893        if not order_by in ('replies', 'lastreply',): 
    877894            order_by = 't.' + order_by 
     
    883900          " topic) m ON t.id = m.topic WHERE t.forum = %s ORDER BY " \ 
    884901          + order_by + (" ASC", " DESC")[bool(desc)] 
    885         self.log.debug(sql % (forum,)) 
    886         cursor.execute(sql, (forum,)) 
     902        self.log.debug(sql % (forum_id,)) 
     903        cursor.execute(sql, (forum_id,)) 
    887904        topics = [] 
    888905        for row in cursor: 
     
    900917        return topics 
    901918 
    902     def get_messages(self, req, cursor, topic, time, order_by = 'time', desc = False): 
     919    def get_messages(self, req, cursor, topic_id, time, order_by = 'time', desc = False): 
    903920        order_by = 'm.' + order_by 
    904921        columns = ('id', 'replyto', 'time', 'author', 'body') 
    905922        sql = "SELECT m.id, m.replyto, m.time, m.author, m.body FROM message m WHERE" \ 
    906923          " m.topic = %s ORDER BY " + order_by + (" ASC", " DESC")[bool(desc)] 
    907         self.log.debug(sql % (topic,)) 
    908         cursor.execute(sql, (topic,)) 
     924        self.log.debug(sql % (topic_id,)) 
     925        cursor.execute(sql, (topic_id,)) 
    909926        messagemap = {} 
    910927        messages = [] 
     
    932949        return messages; 
    933950 
    934     def get_flat_messages(self, req, cursor, topic, time, order_by = 
     951    def get_flat_messages(self, req, cursor, topic_id, time, order_by = 
    935952      'ORDER BY time ASC'): 
    936953        columns = ('id', 'replyto', 'time', 'author', 'body') 
    937954        sql = "SELECT m.id, m.replyto, m.time, m.author, m.body FROM message m" \ 
    938955          " WHERE m.topic = %s " + order_by 
    939         self.log.debug(sql % (topic,)) 
    940         cursor.execute(sql, (topic,)) 
     956        self.log.debug(sql % (topic_id,)) 
     957        cursor.execute(sql, (topic_id,)) 
    941958        messages = [] 
    942959        for row in cursor: 
  • discussionplugin/0.10/tracdiscussion/notification.py

    r1987 r2009  
    88 
    99    template_name = "discussion-notify-body.cs" 
     10    forum = None 
     11    topic = None 
     12    message = None 
     13    torcpts = [] 
     14    ccrcpts = [] 
    1015    COLS = 75 
    1116 
     
    1318        NotifyEmail.__init__(self, env) 
    1419 
    15     def notify(self, req, cursor, action, object): 
     20    def notify(self, req, cursor, action, forum = None, topic = None, 
     21      message = None, torcpts = [], ccrcpts = []): 
    1622        self.env.log.debug("action: %s" % action) 
    17         self.env.log.debug("object: %s" % object) 
     23        self.env.log.debug("forum: %s" % forum) 
     24        self.env.log.debug("topic: %s" % topic) 
     25        self.env.log.debug("message: %s" % message) 
     26        self.env.log.debug("torcpts: %s" % torcpts) 
     27        self.env.log.debug("ccrcpts: %s" % ccrcpts) 
    1828 
    19         # Prepare action specific email content. 
    20         if action == 'topic-post-add': 
     29        # Store link to currently notifying forum, topic and message. 
     30        self.forum = forum 
     31        self.topic = topic 
     32        self.message = message 
     33        self.torcpts = torcpts 
     34        self.ccrcpts = ccrcpts 
     35 
     36        # Get action and item of action. 
     37        index = action.find('-') 
     38        item = action[:index] 
     39        action = action[index + 1:] 
     40 
     41        # Which item notify about: 
     42        if item == 'topic': 
     43            # Prepare topic specific fields. 
     44            re = '' 
    2145            title = 'Topic' 
    22             re = '' 
    23             link = req.abs_href.discussion(object['forum'], object['id']) 
    24         elif action == 'topic-post-edit': 
    25             title = 'Topic' 
    26             re = '' 
    27             link = req.abs_href.discussion(object['forum'], object['id']) 
    28         elif action == 'message-post-add': 
     46            id = self.topic['id'] 
     47            author = "    Author:  %s" % self.topic['author'] 
     48            time = "      Time:  %s" % format_datetime(self.topic['time']) 
     49            body = self.topic['body'] 
     50            link = req.abs_href.discussion(self.forum['id'], self.topic['id']) 
     51 
     52            # Save link for bad times. 
     53            topic['link'] = link 
     54        elif item == 'message': 
     55            # Prepare message specific fields 
     56            re = 'Re: ' 
    2957            title = 'Message' 
    30             re = 'Re: ' 
    31             link = req.abs_href.discussion(object['forum'], object['topic'], 
    32               object['id']) + '#%s' % object['id'] 
    33         elif action == 'message-post-edit': 
    34             title = 'Message' 
    35             re = 'Re: ' 
    36             link = req.abs_href.discussion(object['forum'], object['topic'], 
    37               object['id']) + '#%s' % object['id'] 
     58            id = self.message['id'] 
     59            author = "    Author:  %s" % self.message['author'] 
     60            time = "      Time:  %s" % format_datetime(self.message['time']) 
     61            body = self.message['body'] 
     62            link = req.abs_href.discussion(self.forum['id'], self.topic['id'], 
     63              self.message['id']) + '#%s' % self.message['id'] 
    3864 
    39         # Format body table items. 
    40         author = "    Author:  %s" % object['author'] 
    41         time = "      Time:  %s" % format_datetime(object['time']) 
    42         moderators = "Moderators: %s" % object['moderators'] 
     65            # Save link for bad times. 
     66            message['link'] = link 
     67        else: 
     68            return 
     69 
     70        prefix = self.config.get('notification', 'smtp_subject_prefix') 
     71        if prefix == '__default__': 
     72            prefix = self.env.project_name 
     73        moderators = "Moderators:  %s" % ' '.join(self.forum['moderators']) 
     74        subject = self.topic['subject'] 
    4375 
    4476        # Set set e-mail template values. 
    4577        self.hdf.set_unescaped('discussion.re', re) 
    46         prefix = self.config.get('notification', 'smtp_subject_prefix') 
    47         if prefix != '__default__': 
    48             self.hdf.set_unescaped('discussion.prefix', prefix) 
     78        self.hdf.set_unescaped('discussion.prefix', prefix) 
    4979        self.hdf.set_unescaped('discussion.title', title) 
    50         self.hdf.set_unescaped('discussion.id', object['id']
     80        self.hdf.set_unescaped('discussion.id', id
    5181        self.hdf.set_unescaped('discussion.author', author) 
     82        self.hdf.set_unescaped('discussion.time', time) 
    5283        self.hdf.set_unescaped('discussion.moderators', moderators) 
    53         self.hdf.set_unescaped('discussion.time', time) 
    54         self.hdf.set_unescaped('discussion.subject', object['subject']) 
    55         self.hdf.set_unescaped('discussion.body', object['body']) 
     84        self.hdf.set_unescaped('discussion.subject', subject) 
     85        self.hdf.set_unescaped('discussion.body', body) 
    5686        self.hdf.set_unescaped('discussion.link', link) 
    5787 
     
    5989        subject = self.hdf.render('discussion-notify-subject.cs') 
    6090        self.env.log.debug(subject) 
    61         NotifyEmail.notify(self, object['id'], subject) 
     91        NotifyEmail.notify(self, id, subject) 
     92 
     93    def get_topic_id(self, forum_id, topic_id): 
     94        return "%s-%s-%s" % (forum_id, topic_id, 0) 
     95 
     96    def get_message_id(self, forum_id, topic_id, message_id): 
     97        return "%s-%s-%s" % (forum_id, topic_id, message_id) 
    6298 
    6399    def get_recipients(self, resid): 
    64         return ([], []) 
     100        return (self.torcpts, self.ccrcpts) 
     101 
     102    def send(self, torcpts, ccrcpts): 
     103        header = {} 
     104 
     105        # Add item specific e-mail header fields. 
     106        if self.message: 
     107            # Get this messge ID. 
     108            header['Message-ID'] = self.get_message_id(self.forum['id'], 
     109              self.topic['id'], self.message['id']) 
     110            header['X-Trac-Message-ID'] = str(self.message['id']) 
     111            header['X-Trac-Discussion-URL'] = self.message['link'] 
     112 
     113            # Get replied message ID. 
     114            if self.message['replyto'] == -1: 
     115                reply_id = self.get_topic_id(self.forum['id'], 
     116                  self.topic['id']) 
     117            else: 
     118                reply_id = self.get_message_id(self.forum['id'], 
     119                  self.topic['id'], self.message['replyto']) 
     120            header['In-Reply-To'] = reply_id 
     121            header['References'] = reply_id 
     122        else: 
     123            # Get this message ID. 
     124            header['Message-ID'] = self.get_topic_id(self.forum['id'], 
     125              self.topic['id']) 
     126            header['X-Trac-Topic-ID'] = str(self.topic['id']) 
     127            header['X-Trac-Discussion-URL'] = self.topic['link'] 
     128 
     129        # Send e-mail. 
     130        NotifyEmail.send(self, torcpts, ccrcpts, header) 
  • discussionplugin/0.10/tracdiscussion/templates/discussion-notify-subject.cs

    r1987 r2009  
    1 <?cs var:discussion.re ?><?cs alt:discussion.prefix ?>[<?cs var:project.name ?>]<?cs /alt ?> <?cs var:discussion.title ?> #<?cs var:discussion.id ?> - <?cs var:discussion.subject ?> 
     1<?cs var:discussion.re ?><?cs var:discussion.prefix ?> <?cs var:discussion.title ?> #<?cs var:discussion.id ?> - <?cs var:discussion.subject ?>