message: use connection hook for mam plugin
diff: @@ -45,8 +45,12 @@ export default class MessageArchiveManagementPlugin extends AbstractPlugin {
  }
  });
  + pluginAPI.registerConnectionHook((status, condition) => {
  + if (status === 5 || status === 8) { //@TODO use constant for status
  this.determineServerSupport();
  }
  + });
  + }
  public getStorage() {
  return this.pluginAPI.getStorage();
  @@ -65,11 +69,15 @@ export default class MessageArchiveManagementPlugin extends AbstractPlugin {
  }
  private determineServerSupport() {
  - //@TODO
  - setTimeout(() => {
  let connection = this.pluginAPI.getConnection();
  let discoInfoRepository = this.pluginAPI.getDiscoInfoRepository();
  - let serverJid = new JID('', connection.getJID().domain, '') //@REVIEW
  + let domain = connection.getJID().domain;
  +
  + if (!domain) {
  + Log.debug('Could not get connected JID for MAM');
  + return;
  + }
  + let serverJid = new JID('', domain, '') //@REVIEW
  discoInfoRepository.getCapabilities(serverJid).then((discoInfo: DiscoInfo) => {
  if (discoInfo.hasFeature(MAM2)) {
  @@ -88,8 +96,9 @@ export default class MessageArchiveManagementPlugin extends AbstractPlugin {
  connection.registerHandler(this.onMamMessage, Namespace.get('MAM'), 'message', null);
  }
  + }).catch((err) => {
  + Log.warn('Could not determine MAM server support:', err);
  });
  - }, 2000);
  }
  private addLoadButtonIfEnabled(chatWindow: ChatWindow, contact: Contact) {
  