Skip to content

Commit 8a00727

Browse files
authored
Merge pull request #426 from jarobase/http-auth_update_9.1.1
Improvements:
2 parents 71d0330 + 464e010 commit 8a00727

1 file changed

Lines changed: 21 additions & 24 deletions

File tree

packages/http-auth/http-auth.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,25 @@ const plugin = {
7474

7575
buildResponse(responseType) {
7676
const httpAuthData = this.model.attributes.data;
77-
const response = httpAuthData['response'];
78-
let iqType = 'get';
77+
let stanzaType;
78+
let response;
79+
if (httpAuthData.stanzaType === 'message') {
80+
stanzaType = responseType === 'refuse' ? 'error' : 'normal';
81+
response = converse.env.$msg({
82+
from: httpAuthData.to, // inverse from and to
83+
to: httpAuthData.from, // inverse from and to
84+
type: stanzaType,
85+
});
86+
response.c('thread').t(httpAuthData['thread']).up();
87+
} else {
88+
stanzaType = responseType === 'refuse' ? 'error' : 'result';
89+
response = converse.env.$iq({
90+
from: httpAuthData.to, // inverse from and to
91+
to: httpAuthData.from, // inverse from and to
92+
id: httpAuthData.iqId,
93+
type: stanzaType,
94+
});
95+
};
7996
response.c('confirm', {
8097
'xmlns': 'http://jabber.org/protocol/http-auth',
8198
'id': httpAuthData['id'], 'method': httpAuthData['method'],
@@ -84,10 +101,6 @@ const plugin = {
84101
if (responseType === 'refuse') {
85102
response.c('error', { 'code': '401', 'type': 'auth' });
86103
response.c('not-authorized', { 'xmlns': 'urn:ietf:params:xml:xmpp-stanzas' });
87-
iqType = 'error';
88-
}
89-
if (httpAuthData['stanzaType'] === 'iq') {
90-
response = response.attrs({ type: iqType });
91104
}
92105
_converse.api.send(response);
93106
},
@@ -108,33 +121,17 @@ const plugin = {
108121
xmlns: confirm.getAttribute('xmlns'),
109122
method: confirm.getAttribute('method'),
110123
id: confirm.getAttribute('id'),
124+
iqId:stanza.getAttribute('id'),
111125
url: confirm.getAttribute('url'),
112126
from: stanza.getAttribute('from'),
113127
to: stanza.getAttribute('to'),
114128
confirm: confirm,
115129
message: stanza,
116130
stanzaType: stanza.localName
117131
};
118-
let httpAuthMessage;
119132
if (stanza.localName === 'message') {
120-
httpAuthMessage = converse.env.$msg({
121-
from: _converse.jid,
122-
to: stanza.getAttribute('from'),
123-
type: "normal",
124-
});
125-
const thread = stanza.getElementsByTagName('thread')[0].textContent;
126-
httpAuthMessage.c('thread').t(thread).up();
127-
httpAuthData['response'] = httpAuthMessage;
128-
} else {
129-
httpAuthMessage = converse.env.$iq({
130-
from: _converse.jid,
131-
to: stanza.getAttribute('from'),
132-
id: stanza.getAttribute('id'),
133-
type: 'error',
134-
});
135-
httpAuthData['response'] = httpAuthMessage;
133+
httpAuthData['thread'] = stanza.getElementsByTagName('thread')[0].textContent;
136134
}
137-
138135
const confirmDialog = new httpAuthDialog({ 'model': new Model({ view: _converse.rosterview, data: httpAuthData }) });
139136
confirmDialog.show();
140137
}

0 commit comments

Comments
 (0)