samczsun / Skype4J

Skype API written in Java. Does not support P2P chats
Apache License 2.0
145 stars 48 forks source link

Initialization delay when first message received from chat #64

Closed vemacs closed 8 years ago

vemacs commented 8 years ago

When the first message is received from a chat, the API takes around 5 seconds to process it. This is not an issue with subsequent messages. Could this initialization delay be fixed? I'm assuming the API is preloading display names or something, which should be done in the subscribe() method for all chats.

samczsun commented 8 years ago

The API will lazy load all chats unless you preload them

vemacs commented 8 years ago

How would I preload them?

samczsun commented 8 years ago

https://github.com/samczsun/Skype4J/blob/master/src/main/java/com/samczsun/skype4j/Skype.java#L122

vemacs commented 8 years ago

429s whenever I try it. Why does it need to load all this data from the chats in the first place to start listening? Is all of the data strictly necessary?

samczsun commented 8 years ago

The data includes users in the chat, their roles, the chat's displayname, etc. Things that you would expect to return a valid value when you request it.

If you're hitting a 429, then request a bigger amount per load. There's not much I can do against a Too Many Requests response.

vemacs commented 8 years ago

Loading all of those shouldn't be necessary for simply receiving messages. The message handler would presumably load all of that data "on-demand" via method calls, Skype4j loading that isn't needed and only serves to block.

samczsun commented 8 years ago

So what would happen when you get a message and try to get the user? There's no way of getting a data for a single user from a Skype conversation, and if there was you would end up hitting that 429 a lot more often as you would be overly lazy-loading data.

vemacs commented 8 years ago

Oh, wasn't aware of that. How come other implementations (EzSkype) don't have as noticeable of an initialization delay?

samczsun commented 8 years ago

On chat load, all the users are loaded too, which means their contact data is also loaded. This may be the delay you're experiencing. I'll add in a lazy load for contact data. See if that helps

vemacs commented 8 years ago

Thanks, the change removes the initialization delay. Can the getUsername() method return the username field (and schedule the data to be loaded async or just not load the data)? I'm currently working around it with reflection.

vemacs commented 8 years ago

Perfect <3

You should release 0.1.5 proper, the current "stable" 0.1.4 doesn't log in properly