From: kevinr@free-dissociation.com (Kevin Riggle)
Subject: [sup-talk] [PATCH] Add an after-add-message hook
Date: Thu, 20 Aug 2009 21:57:42 -0400 [thread overview]
Message-ID: <1250819862-4858-1-git-send-email-kevinr@free-dissociation.com> (raw)
In-Reply-To: <1250707991-sup-5429@masanjin.net>
This time the loop stores messages in an array as they're added to the
index, and passes that array to the hook.
I want to do some unrelated processing on each message I receive, but I
don't want to block the message being added to the index. This patch
adds a hook which runs /after/ the message is added to the index.
---
lib/sup/poll.rb | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/lib/sup/poll.rb b/lib/sup/poll.rb
index 8a9d218..fb3aacf 100644
--- a/lib/sup/poll.rb
+++ b/lib/sup/poll.rb
@@ -11,6 +11,12 @@ Variables:
message: the new message
EOS
+ HookManager.register "after-add-message", <<EOS
+Executes after all messages are added to the index.
+Variables:
+ messages: an array of the new messages added
+EOS
+
HookManager.register "before-poll", <<EOS
Executes immediately before a poll for new messages commences.
No variables.
@@ -138,6 +144,7 @@ EOS
begin
return if source.done? || source.has_errors?
+ messages = []
source.each do |offset, default_labels|
if source.has_errors?
Redwood::log "error loading messages from #{source}: #{source.error.message}"
@@ -145,6 +152,7 @@ EOS
end
m_new = Message.build_from_source source, offset
+ messages.push(m_new)
m_old = Index.build_message m_new.id
m_new.labels += default_labels + (source.archived? ? [] : [:inbox])
@@ -157,6 +165,8 @@ EOS
Index.sync_message m_ret, opts
UpdateManager.relay self, :added, m_ret unless m_old
end
+ HookManager.run "after-add-message", :messages => messages
+
rescue SourceError => e
Redwood::log "problem getting messages from #{source}: #{e.message}"
Redwood::report_broken_sources :force_to_top => true
--
1.6.0.4
next prev parent reply other threads:[~2009-08-21 1:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-16 21:47 Kevin Riggle
2009-08-18 17:56 ` William Morgan
2009-08-18 23:36 ` Kevin Riggle
2009-08-19 18:55 ` William Morgan
2009-08-21 1:57 ` Kevin Riggle [this message]
2009-08-24 22:44 ` William Morgan
2009-09-02 13:53 ` William Morgan
2009-08-21 2:07 ` Kevin Riggle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1250819862-4858-1-git-send-email-kevinr@free-dissociation.com \
--to=kevinr@free-dissociation.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox