0

I am using converse.js 7.0.6 version. I am trying to set the subject topic button to be by default hidden, currently, it is visible by default. I have investigated I need to override this function toggleSubjectHiddenState, when I try to use _converse.api.user. I get an error TypeError: Cannot read properties of undefined (reading 'user')

This is how I tried, maybe I am doing wrong something.

export const addModifyHideTopicPlugin = () => {
  window.converse.plugins.add('modify-hide-topic', {
    overrides: {
      ChatRoom: {
        toggleSubjectHiddenState: async function () {
          const _converse: any = this;
          //   const muc_jid = this.get('jid');
          const jids = await _converse.api.user.settings.get(
            'mucs_with_hidden_subject',
            [],
          );

          return _converse.toggleSubjectHiddenState
            .apply(_converse, arguments)
            .then((response: any) => {
              console.log(response, 'response');

              return response;
            });
        },
      },
    },
  });
};

This is the toggleSubjectHiddenState function I am trying to override because this function is handleing the show topic or hide topic.

            async toggleSubjectHiddenState () {
                const muc_jid = this.get('jid');
                const jids = await api.user.settings.get('mucs_with_hidden_subject', []);
                if (jids.includes(this.get('jid'))) {
                    api.user.settings.set('mucs_with_hidden_subject', jids.filter(jid => jid !== muc_jid));
                } else {
                    api.user.settings.set('mucs_with_hidden_subject', [...jids, muc_jid]);
                }
            },
Jerin
  • 717
  • 1
  • 7
  • 28

0 Answers0