Last active
August 29, 2015 14:25
-
-
Save RichardLitt/ae96154bdcb34a17cc22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| componentWillMount: function () { | |
| let dummyImage = 'http://upload.wikimedia.org/wikipedia/en/4/42/Richard_Feynman_Nobel.jpg' | |
| let userPromises = [] | |
| let clone = _.each(this.state.conversations.slice(), function (conversation) { | |
| conversation.avatars = [] | |
| _.each(_.keys(conversation.participants), function (key) { | |
| if (conversation.participants.hasOwnProperty(key)) { | |
| // Suggestion: Only show avatars for participants who have actively contributed to conversation | |
| let getAvatar = db.getUser(key).then(function (err, res) { | |
| if (res.avatar) { | |
| conversation.avatars.push(res.avatar) | |
| return | |
| } else if (err) { | |
| console.log(err) | |
| } | |
| }).catch(function (err) { | |
| if (err.status === 404) { | |
| if (conversation.avatars.indexOf(dummyImage) === -1) { | |
| conversation.avatars.push(dummyImage) | |
| } | |
| return | |
| } else { | |
| console.log(err) | |
| } | |
| }) | |
| userPromises.push(getAvatar) | |
| } | |
| }) | |
| }) | |
| Promise.all(userPromises).then(function () { | |
| this.setState({conversations: clone}) | |
| }.bind(this)).catch(function (err) { | |
| console.log('Catch promise err', err) | |
| }) | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment