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

show only related notifications for specific user? #20

Closed
vmcilwain opened this issue Jun 28, 2012 · 3 comments
Closed

show only related notifications for specific user? #20

vmcilwain opened this issue Jun 28, 2012 · 3 comments

Comments

@vmcilwain
Copy link

I'm sorry if this is the wrong place to post this but I didn't see another place in the documentation. I am curious if there is a way to show only gritter notifications related to a specific user? An example I can think of is if I am sending a message to another user, I would like only for that user to get a gritter notification.

Can this be done?

@RobinBrouwer
Copy link
Owner

I'm not really sure what you're trying to do. You want to show one user a gritter notification when he/she receives a message? That should be possible with the add_gritter helper. You can change the message depending on the user it's being sent to (presumably via the current_user method). Not really sure if that's what you're asking. If not, please explain yourself further.

BTW, I'm going on vacation in about 7 hours. So if you leave a reply after 7 hours, I won't be able to reply until I'm back.

@vmcilwain
Copy link
Author

Yes that is exactly what I want. I want the person I send a message to to get a grittier notification in their view that tells them that I sent a message. I do have a current_user method but couldn't figure out how to make this happen. I will take a closer look at the add grittier message. I guess the problem I couldn't figure out is how to target the user with grittier. How would I tell grittier to show this to the given user.

Enjoy your vacation :)

@RobinBrouwer
Copy link
Owner

What you want to do is have some kind of Controller action that's repeatedly being called by a JavaScript timer. Within this action you check if the user has new messages. When there's a new message, you just send JavaScript back to the browser showing a Gritter notification. Here's an example:

# app/assets/javascripts/application.js
$(function(){
  setInterval(function(){
    $.getScript("/messages/check");
  }, 2000);
});

# config/routes.rb
get "messages/check" => "messages#check"

# app/controllers/messages_controller.rb
class MessagesController < ApplicationController
  def check
    render :nothing => true unless current_user.new_messages?
  end
end

# app/views/messages/check.js.erb
<%= add_gritter("There's a new message!") %>

Inside the User Model you can have a new_messages? method that checks for new messages. When a user sends a message you make sure this new_messages? method returns true for the receiving user. When this is the case, the getScript() jQuery function receives '/messages/check' with the messages/check.js.erb view. It's probably not the best example, but it should work. Hope it helps. :)

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

No branches or pull requests

2 participants