Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create a guard that tracks all presence changes #83

Closed
bklang opened this issue Feb 29, 2012 · 2 comments
Closed

Unable to create a guard that tracks all presence changes #83

bklang opened this issue Feb 29, 2012 · 2 comments
Assignees
Labels
Milestone

Comments

@bklang
Copy link
Member

bklang commented Feb 29, 2012

I am trying to write something to keep track of the state of contacts on my roster. I wanted to create a guard that would get me all status transitions so I could track who is online and who is offline. However I cannot find a guard that works for showing "available" status. The XMPP spec allows an essentially empty <presence/> tag to imply a status of "available". But writing a guard for <presence> results in catching much more information.

Here's the code I am trying to use:

status { |s| logger.warn "JID #{s.from} is going #{s.state}" }

This works for all state changes except "available"

So then I tried looking adding a second guard to track <presence/> packets and use those to assume "available" state. However, that led to packets like this:

<presence from='bklang@mojolingo.com/blast' to='arabbit@mojolingo.com/29839699401330542861775967'>
  <show>away</show>
  <c xmlns='http://jabber.org/protocol/caps' node='http://pidgin.im/' hash='sha-1' ver='DdnydQG7RGhP9E3k9Sf+b+bF0zo='/>
  <x xmlns='vcard-temp:x:update'>
    <photo>064ab5aeb91c609c8a0bd5609a077f5bfa88e816</photo>
  </x>
</presence>

These are converted to Blather::Stanza::C objects which have no accessor for the <show/> element. This results in my code detecting this obviously "away" message as being an "available" message.

benlangfeld added a commit that referenced this issue Mar 1, 2012
@ghost ghost assigned benlangfeld Mar 1, 2012
@benlangfeld
Copy link
Member

So now imported stanzas will all be Presence instances, and will be decorated with the correct methods. This is a step towards moving Blather entirely to decorators. Right now, there are two issues:

  • Handlers don't work with decorators. You can only handle presence right now.
  • Creating a Presence::Status object using .new returns a decorated Presence instance. This is weird. We need factories.

@bklang
Copy link
Member Author

bklang commented Mar 1, 2012

Regarding the original report, I've modified my guard like this:

presence { |p| logger.warn "JID #{p.from} is going #{p.state}" }

And it looks to work perfectly. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants