Skip to content

Fetch avatars from different sources#469

Merged
ChristophWurst merged 18 commits into
masterfrom
avatars
Nov 16, 2017
Merged

Fetch avatars from different sources#469
ChristophWurst merged 18 commits into
masterfrom
avatars

Conversation

@jakobsack

@jakobsack jakobsack commented Aug 25, 2017

Copy link
Copy Markdown
Member

This implements parts of #463 and #236
When you open mail/avatars?email=test@example.com you get a JSON response
{ url: $url, source: $source }.
If no image has been found $url is null.

Comment thread js/models/messagecollection.js Outdated
return message.get('dateInt') * -1;
},
initialize: function() {
this.on('add', function(message) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

in regards to consistent coding style and testability I'd suggest to move this anonymous callback to a method of this class and just have the wiring in the constructor ;)

Comment thread js/models/messagecollection.js Outdated
if (avatar.source != 'none'){
message.set('senderImage', avatar.url);
}
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add a .catch(console.error.bind(this)) at the end so that errors are logged to the console

Comment thread js/models/messagecollection.js Outdated
});

Promise.resolve($.ajax(url)).then(function(avatar) {
if (avatar.source != 'none'){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use !== instead

Comment thread js/models/messagecollection.js Outdated
},
initialize: function() {
this.on('add', function(message) {
var url = OC.generateUrl('apps/mail/avatars?email={email}', {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would be great to have this logic in a service of its own because then we can test this more easily ;)

Comment thread lib/Controller/AvatarsController.php Outdated

namespace OCA\Mail\Controller;

use Exception;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unused?

Comment thread lib/Controller/AvatarsController.php Outdated
*/
public function show($email) {
// close the session to allow parallel downloads
$this->session->close();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is necessary if you don't annotate the controller with @UseSession. cc @LukasReschke

Comment thread lib/Service/AvatarService.php Outdated
}
}

__halt_compiler();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

😮

Comment thread lib/Service/AvatarService.php Outdated
use Gravatar\Gravatar;
use Mpclarkson\IconScraper\Scraper;

class AvatarService {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd really like to have this class tested. In its current form it's a bit difficult to do so. May I suggest to refactor this class into three classes for the individual avatar sources and just combine their results in this class? I can also take care of this, just let me know :)

Comment thread lib/Service/AvatarService.php Outdated
$response = $client->get($gravatarUrl);
}
catch (\Exception $exception) {
$foundGravatar = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just return null; here and remove the $foundAvatar stuff ;)

@jakobsack jakobsack changed the title Add new controller for avatar fetching [WIP] Add new controller for avatar fetching Aug 28, 2017
@jakobsack

Copy link
Copy Markdown
Member Author

The avatars are now cached in data/$user/mail/avatars. The images are loaded right from the beginning if possible.

@ChristophWurst

Copy link
Copy Markdown
Member

@jakobsack what's your current status? The title and the tags are a bit contradictory :-P

Btw, there seem to be conflicts with the composer deps.

@jakobsack

Copy link
Copy Markdown
Member Author

Sorry, I bricked my laptop last Friday. I'll try to add the last adjustments during this week.

@ChristophWurst

Copy link
Copy Markdown
Member

Sorry, I bricked my laptop last Friday. I'll try to add the last adjustments during this week.

Take your time :)

@jancborchardt

Copy link
Copy Markdown
Member

@jakobsack any update here or any way we can help? :)

@jakobsack jakobsack force-pushed the avatars branch 2 times, most recently from 5ccd8e5 to 144297a Compare October 19, 2017 18:37
@jakobsack

Copy link
Copy Markdown
Member Author

@ChristophWurst @Gomez Can you test the latest changes please? And tell me why composer won't work on travis? On my machine everything works fine :-/

@jakobsack

Copy link
Copy Markdown
Member Author

I don't know why the MySQL version fails but it seems not to be related to my changes.

@ChristophWurst ChristophWurst self-assigned this Oct 23, 2017
@ChristophWurst

Copy link
Copy Markdown
Member

Still, some ideas for that are: have a avatar service on the client-side that aggregates avatar loading and de-duplicates the requests. This is especially useful where you have many messages from the same sender and thus the current logic would send multiple requests.

Plus, we should check whether senderImage is already set and do nothing in that case.

@ChristophWurst

Copy link
Copy Markdown
Member

FYI: setting the yolo-no-review-but-merging-anyway-timeout to 2 weeks 😉

@ChristophWurst

Copy link
Copy Markdown
Member

Still, some ideas for that are: have a avatar service on the client-side that aggregates avatar loading and de-duplicates the requests. This is especially useful where you have many messages from the same sender and thus the current logic would send multiple requests.

And we could add a background job that pre-poluates the cache 😉

@jancborchardt

Copy link
Copy Markdown
Member

@ChristophWurst will start reviewing now, meanwhile Fyi there are conflicting files. (And the package-lock.json should be in .gitignore maybe?)

@ChristophWurst

Copy link
Copy Markdown
Member

meanwhile Fyi there are conflicting files.

Thanks. Will take care of it.

And the package-lock.json should be in .gitignore maybe

Nope, that makes sure everyone installs the exact same version of a dependency and additionally also speeds up the installation of npm packages: https://docs.npmjs.com/files/package-lock.json

@jancborchardt

Copy link
Copy Markdown
Member

So I did make install-composer-deps, but then on the next it fails like this:

jan@Rechenknecht:~/nextcloud/apps/mail$ make optimize-js 
npm install --production
npm WARN grunt-jscs@1.8.0 requires a peer of grunt@~0.4.2 but none is installed. You must install peer dependencies yourself.

up to date in 2.901s
./node_modules/webpack/bin/webpack.js --config js/webpack.prod.config.js
module.js:515
    throw err;
    ^

Error: Cannot find module 'json-stable-stringify'
    at Function.Module._resolveFilename (module.js:513:15)
    at Function.Module._load (module.js:463:25)
    at Module.require (module.js:556:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/jan/nextcloud/apps/mail/node_modules/ajv/lib/compile/util.js:19:20)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
    at Module.load (module.js:531:32)
    at tryModuleLoad (module.js:494:12)
    at Function.Module._load (module.js:486:3)
Makefile:39: recipe for target 'optimize-js' failed
make: *** [optimize-js] Error 1

@ChristophWurst

Copy link
Copy Markdown
Member

but then on the next it fails like this:

See #615

@jancborchardt

Copy link
Copy Markdown
Member

Doesn’t seem to work for me, even with the fixed optimize-js:
screenshot from 2017-11-16 16-40-03

@jancborchardt

Copy link
Copy Markdown
Member

After switching folders now it seemed to load. :D

@jancborchardt jancborchardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Weeeeeeee! Greaaat work!

@ChristophWurst ChristophWurst merged commit b11cdf6 into master Nov 16, 2017
@ChristophWurst ChristophWurst deleted the avatars branch November 16, 2017 16:05
@ChristophWurst

Copy link
Copy Markdown
Member

Whoops now I was too happy about the approved review that I forgot to squash the commits 🙈

@ChristophWurst

Copy link
Copy Markdown
Member

@jakobsack don't forget to claim your bounties for #463 and #236 😉

@Titan-C

Titan-C commented Mar 9, 2018

Copy link
Copy Markdown

How is this configuration activated? I have nextcloud 13 & contacs 2.1.2. I load my contacts but avatars are not fetched.

@ChristophWurst

Copy link
Copy Markdown
Member

Please file a ticket for this bug. Thanks you.

@nextcloud nextcloud locked and limited conversation to collaborators Mar 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants