def send_post_notifications(obj, event):
    if event.action != 'publish':
        return

    workspace = obj.aq_parent
    while not IWorkspace.providedBy(workspace):
        workspace = workspace.aq_parent

    messenger = IMessenger(workspace)

    recipients = workspace.getMemberIds()
    for uid in recipients:
        if messenger.getAttrForUid(uid, 'recieveNotifications', True):
            try:
                messenger.notifyAboutNewPost(uid, obj)
            except:
                pass
def send_reply_notifications(obj, event):
    workspace = obj.aq_parent
    while not IWorkspace.providedBy(workspace):
        workspace = workspace.aq_parent

    messenger = IMessenger(workspace)

    root = obj.aq_parent
    while IThreaded.providedBy(root.aq_parent):
        root = root.aq_parent

    catalog = getToolByName(obj, 'portal_catalog')
    replies = catalog({
        'object_provides': IThreaded.__identifier__,
        'path': '/'.join(root.getPhysicalPath()), })
    recipients = set([b.Creator for b in replies])
    for uid in recipients:
        if messenger.getAttrForUid(uid, 'recieveNotifications', True):
            try:
                messenger.notifyAboutNewReply(uid, obj)
            except:
                pass