Monday, 30 April 2012

XMPP roster problems

Updating roster data should be easy:
  1. update data
  2. send to roster
  3. wait for confirmation
But of course it is not. For example, Facebook reports 501 not implemented on each roster operation. We have added code in 0.12.0 to support this - when 501 result is received we don't try to update this roster entry anymore. Kadu just uses data (nickname and list of groups) entered by enduser. So this is not a problem anymore.

Google+ has the worst behavior possible. It accepts our changes, sending OK response. But after a second it sends roster entry update to client restoring previous data. This means if someone for some reason decides to join two Google+ contacts into one buddy in Kadu he/she will get nickname dance on this buddy - changing from one to another. Only way to get rid of it is to manually disable synchronizing of these contacts with remote roster.

Thankfully this is all possible in incoming Kadu 0.12 (already in beta1).

Tuesday, 17 April 2012

Composition > Inheritance

In some cases composition is much better than inheritance.

Some classes in Kadu must emit signals after each change of its properties. When change is made to a lot of properties at once only one signal should be emitted (for performance reasons). So three classes got separate implementations of this behavior. Even worse, one of these classes was parametrized (it was template class). Qt does not support signals and slots on parametrized classes, so a workaround was created by adding virtual method emitUpdated that was reimplemented in every subclass to emit proper signal.

It was a lot of work. And it was error-prone.

Then a new simple class was born: ChangeNotifier. It has only one job - notify about changes. It support emitting only one signal per bulk of changes. It was added as member to these three classes mentioned above. A lot of duplicated code was removed. Strange emitUpdated method was also removed - ChangeNotifier is not parametrizedm, so it can emit signals without problems. Other classes just connect to ChangeNotifier signal instead of one of original class. And this class can be easily unit-tested and reviewed.

Really great. Next time I'll think twice before creating inheritance.