Closed Bug 1207081 Opened 10 years ago Closed 10 years ago

[Messages] Make filtering better for markable thread in InboxView.markReadUnread method

Categories

(Firefox OS Graveyard :: Gaia::SMS, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
2.6 S4 - 1/1

People

(Reporter: rishav_, Assigned: martianwars, Mentored)

Details

(Whiteboard: [good first bug])

Attachments

(4 files)

Make filtering better for markable thread in InboxView.markReadUnread method Add this condition (&& !(thread.unreadCount ^ isRead)) to the [1] for better filtering of markable thread. Modify the unit test accordingly, if required. [1] https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/views/inbox/js/inbox.js#L401
Mentor: rishav006
Whiteboard: [good first bug]
Currently in InboxView.markReadUnread method (https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/views/inbox/js/inbox.js#397) To filter the markable thread, we have following condition: var markable = thread && !thread.isDraft && (isRead || !thread.getDraft()); Filtering can be better if we add this '&& !(thread.unreadCount ^ isRead) ' to it. To explain this condition: if thread has unread message and isRead==false (i.e to make it unread), this thread will be skipped and will not considered as markable as thread has already unread messsage.
Hey Kumar, can you help this contributor properly polishing his patch ?
Flags: needinfo?(rishav006)
Yeah Sure, Julien. Infact i was waiting for him to comment here so that i can proceed with guiding.
Flags: needinfo?(rishav006)
sorry
what do you want me to do
Hi Mendasanketh, Assuming this is you first Gaia bug and aware of HTML5,javascript and Bugzilla. First of all you need to build the gaia in your system, to work on the patch/code. Please follow this: https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/README.md If you feel any problem, feel free to comment or ping on irc channel-> #fxos, #gaia-messaging Regarding the patch you submitted, Whenever you submit a patch, raise feedback? (or atleast ni?) flag. and comment if you have any doubt. I saw you patch, that condition should be added in var markable = thread && !thread.isDraft && (isRead || !thread.getDraft()) && !(thread.unreadCount ^ isRead)), but what you did is wrong.
Flags: needinfo?(mendasanketh)
if you feel problem in javascript, you read it here : https://developer.mozilla.org/en-US/docs/Web/JavaScript Nice tutorial it is :)
Flags: needinfo?(mendasanketh)
Seems like you just copy and pasted the code from above comment :P (one closing bracket is extra, in above code by mistake, sorry for it) But i need you to understand the code/syntax before submitting the patch. Did you build the Gaia locally in you system? Did you run you code there? Without above step, you cannot move forward. you should have local build of gaia to test your code.
Flags: needinfo?(mendasanketh)
now i did it locally. added it and tested it also
Flags: needinfo?(mendasanketh)
Flags: needinfo?(rishav006)
I had a look on your patch. It seems you combined your patch with other commits.[i guess you messed up your master now :P so, clean it , create new branch then start your work on it] Follow these for better workflow: 1. Never work on your master branch. 2. create a new branch (say, Bug-1207081) then work on it. 3. Also, you don't have to create new pull request every time you do some change. Instead you can work on same branch/pull request. At end we can squash all the commits. 4. Once your are donw with patch, run 'make lint' to lint your patch. width (length of code in a line) shouldn't increase more than 80.you can make it to next line. something like this. var markable = thread && !thread.isDraft && (isRead || !thread.getDraft()) && !(thread.unreadCount ^ isRead); P.S - Be careful with identation. 5. After this you should modify the existing unit text also. you can find related unit test here :- Suite for markReadUnread: https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/views/inbox/test/unit/inbox_test.js#L607 you should spy on MessageManager.markThreadRead method (see markReadUnread method) to check the argument passed. (to test if expected argument[thread.id] passed or not) you can read more about the unit test here: http://sinonjs.org/
Flags: needinfo?(rishav006)
how should i modify the test
Flags: needinfo?(rishav006)
Have you worked with unit test before. If not, then i will suggest you to read about this first. You can check the link (http://sinonjs.org/) and see existing code(say for markReadUnread method). basically you have to set an spy on MessageManager.markThreadRead in the setup, then in test check if that function is called with expected argument or not. Update your patch and clean it. I wil comment there for more understanding. But i strongly recommend to read about unit test and understand it.
Flags: needinfo?(rishav006)
In setup, set spy : something like this: this.sinon.spy(MessageManager, 'markThreadRead'); then in test check like this sinon.assert.calledWith(MessageManager.markThreadRead, id, true or false whatever it is); [see existing code] Hope you read the instructions here: https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/README.md To run the unit test, Navigate to gaia folder and: bin/gaia-test
I don’t have any experience with unit tests, but ill try to learn. tests passed. check if what i did is right
Flags: needinfo?(rishav006)
I have added the comment on patch. patch is fine (except unit test part). I expect you to learn or go through the unit test first. [like what spy do, what test do, what should i test. Best way is to go through docs first to get some idea. then play around with existing code of sms unit test, to learn it. Becz sinonjs docs won't be enough to understand. Existing code are very helpful. That;s how i learnt :)] Test passed because you didn't add any test. you just added the spy. see my above comment. P.S - Please don't copy paste the code. First learn it, then if you want , you can :)
Flags: needinfo?(rishav006)
could you reassign it, cuz I lack the technical knowledge to do it.
Flags: needinfo?(rishav006)
didn't get you. what to reassign?
Flags: needinfo?(rishav006)
I am available on irc (#fxos, #gaia-messaging), you can ping me there too :) [rishav_]
Hey, How you doing on the bug? any issue?
Flags: needinfo?(mendasanketh)
hey, any update ?
comment if you need help :)
No update from contributor, Assigning to nobody for now. Hey Julienw, I am thinking to fix this in https://bugzilla.mozilla.org/show_bug.cgi?id=1215655 As both codes are related (i.e same method) and need to change a line only. Thanks
Flags: needinfo?(felash)
Assignee: nobody → rishav006
Fixed in Bug 1215655. See the bug for patch.
Mentor: rishav006 → felash
Hey Kalpesh, if you want, you can give a shot to this bug. My patch(Bug 1215655) will take more time (waiting for new UX and VD), so better to fix here only. Small bug only, need to change only one line, it will be nice if you understand the code, what that code is doing, then make changes. Add unit test too. Thanks Clearing ni? from previous contributor, as no update from him.
Flags: needinfo?(felash) → needinfo?(kalpeshk2011)
ping on irc or comment here if you need help :)
Flags: needinfo?(mendasanketh)
Assignee: rishav006 → nobody
Mentor: rishav006
Hey Kumar, I'll work on this one. :) Lots of comments here, which ones would help? Should I read the contributor's patch, or should I start from your first comment? Thanks!
Flags: needinfo?(kalpeshk2011) → needinfo?(rishav006)
Assignee: nobody → kalpeshk2011
Go with description and comment 1 . Thanks
Flags: needinfo?(rishav006)
Status: NEW → ASSIGNED
Kumar, I don't really understand what's going on. We want the following to be TRUE to make the thread markable :- #1 thread --> I guess this means that thread variable is not NULL #2 !thread.isDraft --> thread is not in drafts folder #3 isRead || !thread.getDraft() --> the thread is either read or the draft is NULL. But didn't we check for draft in condition #2? Also, What exactly are we checking using the XOR ? !(thread.unreadCount ^ isRead) --> Either thread should be unread and unreadCount should be 0 or thread should be read and unreadCount is 1. Why is this needed? I didn't really understand. What is unreadCount doing?
Flags: needinfo?(rishav006)
(In reply to Kalpesh Krishna [:martianwars] from comment #35) > Kumar, > I don't really understand what's going on. We want the following to be TRUE > to make the thread markable :- > #1 thread --> I guess this means that thread variable is not NULL > #2 !thread.isDraft --> thread is not in drafts folder i.e thread is a draft (only draft), no any other msg. > #3 isRead || !thread.getDraft() --> the thread is either read or the draft thread has draft, i.e it contains other msg other than draft. > is NULL. But didn't we check for draft in condition #2? > > Also, What exactly are we checking using the XOR ? See, we selected few threads (lets say, one unread thread and another read thread, then final icon will be mark as read, so here we can skip the thread which is already read, and mark as read only unread thread ) > !(thread.unreadCount ^ isRead) --> Either thread should be unread and > unreadCount should be 0 or thread should be read and unreadCount is 1. Why > is this needed? I didn't really understand. What is unreadCount doing? Hope you got me. If not, you can ask again, i will clarify :)
Flags: needinfo?(rishav006)
Yeah makes some sense now. So unreadCount is the number of unread messages?
Flags: needinfo?(rishav006)
Attachment #8695329 - Flags: review?(rishav006)
Yes, unreadCount contains no. of unread msg. So, if we want to make a thread unread, making unreadCount = 1, is enough to show thread as unread. !(thread.unreadCount ^ isRead) => !(have unread msg(T) ^ mark as unread(i.e F)) => !(T) => F => skip the thread. or !(thread.unreadCount ^ isRead) => !(NO unread msg(F) ^ mark as read(i.e T)) => !(T) => F => skip the thread. Hope it's clear now.
Flags: needinfo?(rishav006)
Are you unable to run unit test locally? Few suggestion, hope it help. 1. First and most important, good internet connection :D 2. Clean the profile and make again, i.e (make really-clean), make DEBUG=1 DESKTOP=0 (assuming you have updated your gaia master) 3.Have latest node, node v4.X and npm 2.X in final patch,do r=julienw (patch should go through peer or owner of app :) ) For test, here you need to assertion in existing test. https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/views/inbox/test/unit/inbox_test.js#L605 To check if this method is called with expected thread id. https://github.com/mozilla-b2g/gaia/blob/master/apps/sms/views/inbox/js/inbox.js#L414 Thanks
Flags: needinfo?(rishav006)
Comment on attachment 8695329 [details] [review] [gaia] martiansideofthemoon:my-code-fix3 > mozilla-b2g:master Hope it is okay :)
Flags: needinfo?(rishav006)
Attachment #8695329 - Flags: review?(rishav006) → feedback?(rishav006)
Comment on attachment 8695329 [details] [review] [gaia] martiansideofthemoon:my-code-fix3 > mozilla-b2g:master Looks good to me. Few nits only. Left some comments on github. Fix those (squash commits into one) and once test passed set review flag to me.
Attachment #8695329 - Flags: feedback?(rishav006) → feedback+
Comment on attachment 8695329 [details] [review] [gaia] martiansideofthemoon:my-code-fix3 > mozilla-b2g:master The nit you mentioned doesn't work :( Probably true/false refers to something else. neverCalledWith() works fine :)
Attachment #8695329 - Flags: review?(rishav006)
Comment on attachment 8695329 [details] [review] [gaia] martiansideofthemoon:my-code-fix3 > mozilla-b2g:master one more nit :P thanks for your work :)
Attachment #8695329 - Flags: review?(rishav006) → review+
Attachment #8695329 - Flags: review+ → review?(felash)
Attachment #8695329 - Flags: review?(felash) → review?(schung)
Hi Kalpesh & kumar, I left a comment on github, please let me know about your thoughts, thanks!
Hi Steve, Agree with you. Left some comments on github. Hi Kalpesh, Have a look on steve's suggestion and modify the patch accordingly. Thanks
Comment on attachment 8695329 [details] [review] [gaia] martiansideofthemoon:my-code-fix3 > mozilla-b2g:master Hey Kalpesh, please set the review again once you're ready.
Attachment #8695329 - Flags: review?(schung)
Comment on attachment 8695329 [details] [review] [gaia] martiansideofthemoon:my-code-fix3 > mozilla-b2g:master Steve, Rishav, I've fixed the PR and I hope it is correct now :)
Attachment #8695329 - Flags: review?(schung)
Look good! Please address the nit from Kumar and squash into 1 commit, thanks.
@Steve, Squashed and pushed!
Seems fine now :) gaia try green, adding checkin-needed Thanks kalpesh for ur work :)
Keywords: checkin-needed
Rishav, I've added a need info for https://bugzilla.mozilla.org/show_bug.cgi?id=1183074 . Do help me with that bug. Also, while I continue with the docs, could you tell me about some other bug I could get started with?
Flags: needinfo?(rishav006)
Comment on attachment 8695329 [details] [review] [gaia] martiansideofthemoon:my-code-fix3 > mozilla-b2g:master Thanks for the contribution \o/
Attachment #8695329 - Flags: review?(schung) → review+
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Target Milestone: --- → 2.6 S4 - 1/1
Hey Kalpesh, Thanks for your contribution. Check your docs bug, i had listed few bugs there. I will clear other ni? soon :) Thanks
Flags: needinfo?(rishav006)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: