Code

7b309c6090f4f0152a7b4346084925a529425382
[roundup.git] / roundup / templates / extended / detectors / nosyreaction.py
1 #$Id: nosyreaction.py,v 1.1 2001-07-23 03:50:47 anthonybaxter Exp $
3 def nosyreaction(db, cl, nodeid, oldvalues):
4     ''' A standard detector is provided that watches for additions to the
5         "messages" property.
6         
7         When a new message is added, the detector sends it to all the users on
8         the "nosy" list for the issue that are not already on the "recipients"
9         list of the message.
10         
11         Those users are then appended to the "recipients" property on the
12         message, so multiple copies of a message are never sent to the same
13         user.
14         
15         The journal recorded by the hyperdatabase on the "recipients" property
16         then provides a log of when the message was sent to whom. 
17     '''
18     messages = []
19     if oldvalues is None:
20         # the action was a create, so use all the messages in the create
21         messages = cl.get(nodeid, 'messages')
22     elif oldvalues.has_key('messages'):
23         # the action was a set (so adding new messages to an existing issue)
24         m = {}
25         for msgid in oldvalues['messages']:
26             m[msgid] = 1
27         messages = []
28         # figure which of the messages now on the issue weren't there before
29         for msgid in cl.get(nodeid, 'messages'):
30             if not m.has_key(msgid):
31                 messages.append(msgid)
32     if not messages:
33         return
35     # send a copy to the nosy list
36     for msgid in messages:
37         cl.sendmessage(nodeid, msgid)
39     # update the nosy list with the recipients from the new messages
40     nosy = cl.get(nodeid, 'nosy')
41     n = {}
42     for nosyid in nosy: n[nosyid] = 1
43     change = 0
44     # but don't add admin to the nosy list
45     for msgid in messages:
46         for recipid in db.msg.get(msgid, 'recipients'):
47             if recipid != '1' and not n.has_key(recipid):
48                 change = 1
49                 nosy.append(recipid)
50         authid = db.msg.get(msgid, 'author')
51         if authid != '1' and not n.has_key(authid):
52             change = 1
53             nosy.append(authid)
54     if change:
55         cl.set(nodeid, nosy=nosy)
58 def init(db):
59     db.issue.react('create', nosyreaction)
60     db.issue.react('set', nosyreaction)
62 #
63 #$Log: not supported by cvs2svn $
64 #Revision 1.1  2001/07/22 12:09:32  richard
65 #Final commit of Grande Splite
66 #
67 #