Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Bug 918970 - display existing thread when sending a sms from contact app #24886

Closed
wants to merge 2 commits into from

Conversation

autra
Copy link
Contributor

@autra autra commented Oct 7, 2014

old PR : #16216

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

.catch(function() {
ActivityHandler.toView(viewInfo);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can rewrite this like this (I remove the "this" and object names so that it's shorter to write and read :) ):

return findThreadFromNumber(viewInfo.number).then(
  function onresolve(threadId) {
    viewInfo.threadId = threadId;
  },
  function onreject() {
    // we return the result so that we wait that it's finished before going on
    return findContactByNumber(viewInfo.number)
      .then((contact) => viewInfo.contact = contact);
  }
)
.catch(() => {}) // gobble errors
.then(() => {
  return this.toView(viewInfo); // final action
});

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

}
deferred.reject('No contact found with number: ' + number);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read somewhere (at the end of the paragraph) that I should reject with a real error, not a string. What do you think about that? Do we care about that?

Related to this blog, does Promise.reject return in Firefox? The author is mentioning that some library does not return when you reject, which means that if you have a resolve later in the code, the promise could end up being fullfilled. For me this behaviour breaks the specs of Promise, but better ask confirmation :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To answer your questions:

  • yes, it's always better to reject with a real Error than with a string. This has the added useful property to have a stack :) so we know where the Error comes from when (for example) we display it
  • .reject does not return; it's a normal function call. so you need to reject and then return. However you can never change a promise state nor value. Once it's been rejected, you can't resolve it, and vice versa.

I've made a jsbin to show all this: http://jsbin.com/qobacicijo/1/edit
The first case is interesting: I actually didn't really know what it meant to throw from inside the Promise constructor's callback :) Now I know it's the same than throwing.

There is something I dislike in Remy Sharp's example: if compare is asynchronous, throwing in the callback won't throw in the Promise constructor's callback. In the end, the promise will never be fulfilled, and there is no way to catch the exception in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so yeah, in the end, it's better to reject with an error here :)

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

@@ -292,7 +323,7 @@ var ActivityHandler = {
return;
}

Navigation.toPanel('thread', { id: threadId });
Navigation.toPanel('thread', { id: threadId }).then(Compose.focus);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've put this in another commit, but I can squash if you want.

I did not add a test. Is it necessary according to you?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep a test could be nice :)

@autra
Copy link
Contributor Author

autra commented Dec 4, 2014

I don't know why but gaia-try-hook didn't run on my last push.

}).then(done,done);
});

test('when there is an existing thread, Composer should be focused',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy my comment on the commit. Don't know why it didn't happen here as well :

So for this test, I relied on stubbing focus (which is mocked anyway) because Navigation.toPanel is called before Compose.focus. So spying toPanel was not enough to wait for focus to be called.

The main drawback of this solution is that is case Compose.focus is not called, the test fails because of the timeout, which is not ideal. Do you have a better idea? I didn't see anything to spy on to make things better.

@julienw
Copy link
Contributor

julienw commented Dec 6, 2014

I don't know why but gaia-try-hook didn't run on my last push.

Sometimes it doesn't when some conditions are not met (http://ftp.mozilla.org/pub/mozilla.org/b2g/tinderbox-builds/mozilla-central-linux64_gecko/latest/ does not have a build, or gaia is closed)

@try-server-hook
Copy link

autra Augustin Trancart (autra) started tests. Results

@julienw
Copy link
Contributor

julienw commented Dec 9, 2014

landed in bd4dcc8

@julienw julienw closed this Dec 9, 2014
@autra autra deleted the bug918970_2 branch September 29, 2015 19:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants