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
Add a shortcut to get the unread conversations number #24
Comments
@Roendal Does this solve it? mailbox.inbox.unread |
Hi @fabianoalmeida! The code you suggests ... mailbox.inbox.unread ... returns the unread messages. I mean, the messages themself. What I was looking for is the number of them. If there are 3 new messages, I want a "3", not the 3 messages. This is achieved with: mailbox.inbox(:unread => true).count(:id, :distinct => true) But thi code is awfully large and not developer friendly. With this issue I meant there is a need for an alias to this code. Something like mailboxer.unread_count
#or
mailboxer.inbox_unread_count Which internally executed the awful and unfriendly code. Does this help? :) Thanks for the interest! |
@Roendal Whether I understood what you said... I wrote a test to demonstrate my idea (this test is green 😜): first = FactoryGirl.create(:user)
second = FactoryGirl.create(:user)
first_conversation = first.send_message(second, "Body", "Subject").conversation
second_conversation = second.send_message(first, "Body", "Subject").conversation
third_conversation = first.send_message(second, "Body", "Subject").conversation
first.mailbox.inbox(:unread => true).to_a.should have(1).items
first.mailbox.inbox.unread(first).to_a.should have(1).items
first.mailbox.inbox(:unread => true).first.should eql(first.mailbox.inbox.unread(first).first)
first.mailbox.inbox(:unread => true).count.should eql(1)
first.mailbox.inbox.unread(first).count.should eql(1)
second.mailbox.inbox(:unread => true).to_a.should have(2).items
second.mailbox.inbox.unread(second).to_a.should have(2).items
second.mailbox.inbox(:unread => true).first.should eql(second.mailbox.inbox.unread(second).first)
second.mailbox.inbox(:unread => true).count.should eql(2)
second.mailbox.inbox.unread(second).count.should eql(2) In the other words, we could use mailbox.inbox(unread: true).count Or mailbox.inbox.unread(user_instance).count Am I correct? This example helps? |
Hi @fabianoalmeida! Now I understand what you mean ;) We used this code mailbox.inbox(:unread => true).count(:id, :distinct => true) because some time messages got counted twice (or even more). I don't remember the exact way to replicate it, and maybe, as It has almost a year, this issue is not legit anymore. Feel free to do some testing with more populated conversations (4 o 5 users and messages) trying to see anything strange in the counting. If you are confident it is ok now, I leave you the pleasure of closing the issue ;) Thanks again @fabianoalmeida and sorry for my misunderstanding! |
Hmmm... I understood now. Ok @Roendal, I'll try simulate this issue and whether I get reproduce it I'll send a pull request. Don't worry about the misunderstanding... When we're writing It's normal to write things dubious. 😉 BTW... Can I try to refactor this gem? Try to create a better DSL, you know? |
Of course @fabianoalmeida, every help is welcome. I moved to other project not related with rails almost a year ago and can't do any major work on Mailboxer. Its really good to see people trying to improve it ;) |
Nice! @Roendal, I have a question... In my test above, first_conversation = first.send_message(second, "Body", "Subject").conversation
second_conversation = second.send_message(first, "Body", "Subject").conversation
|
Each time yo doy a In order to send other messages to a particular conversation you must use The idea of Conversation is pretty similar to the way Gmail handles the email conversations. |
Hi @fabianoalmeida, as @Roendal says every help making Mailboxer better is awesome. I will only request that, if a better DSL is designed, the old one is keeped for a while along with deprecation warnings, so projects that are already using Mailboxer are given the chance to upgrade in a smooth way |
I was studying and rewriting some code... What do you think about it? # other_users could be an unique User or a list of Users
User.message('Body', 'Subject').to(other_users).ship I guess this option is more "readable", not? |
Yeah, It totally changes the way Mailboxer was implemented but its more readable. The problem I see is that the bigger the gap between codes is, the more difficult is to readapt your code. Please, make sure to add a good documentation for the sake of the users ;) About |
@Roendal I can see your point, but what do you think about the @atd suggestion?
After I saw the code and read your explanation about I see a I'm launching a lot of new ideas that could be used to refactor it, because this is a great gem for me, however this could be better to work with. 😊 |
I am really really happy you want to work with mailboxer :) The main problem with your idea is what you understand by I don't know if this is clear, but Maybe they could be more unplugged, or more asynchronous, or even with a better structure, but we should try to avoid any bigger change to the DB. If you want to support the old way with deprecation warnings and make any update as smooth as possible, as @atd asked, maybe making a great change on Notification behaviour and/or data structure could be a bit disruptive. Keep on with the great work and throw any singe idea you have to the arena ;) |
@Roendal sorry, but I didn't understand the idea about And you also said:
But I can see this, ie I understood the idea about class Message < ActiveRecord::Base
after_save :notify
def notify
# Depending the type of notification, of course... :added, :commented, :replied...
Notification.send
end
end Using this way to send a new notification, we could send a notification from any place: What do you think? |
Hi @fabianoalmeida!
When you send a When you notify something (and I mean, you tell the user something from your app like "User B likes your post", "Your credit is about to expire", etc. ) you create a
If this doen't clarify a bit the matter, you should explain me with some use cases what you understand of Mailboxer models in order to see what I missed when designing it ;) I dont get your code to "send a notification from any place". They are not intended to be used from within Mailboxer, but from the outside application. Maybe they should be packed In a "Notifier" gem, but we packed them together as a "Messaging and notifying system". Take your time and make the reply as long as you need. If you prefer to discuss this by email, don't mind telling me ;) |
@Roendal I sent an email to you. It's better continuing this discussion by there. Take a look when you can. BTW, I'm loving discuss possibilities about refactoring this gem. ❤️ 😉 |
Thanks for all your help and your willing to improve the gem 😃 I will close this issue and continue the discussion by email ;) |
@Roendal, sorry, I forgot to say... This issue still exists. I got it after simulating to send and responding a lot of messages. So, you can close this one, but we need solve that after. 😐 |
My fault! I am a quick closer ;) I will reopen it in order to be aware of it. |
This code
should have a method in mailbox or messageable in order to make it easier.
Similar methods should be taken into account.
The text was updated successfully, but these errors were encountered: