Mercurial > xmpp-account-manager
annotate nickname.js @ 10:e47b9bd55192
Also use a spinner on nickname get/set.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 22 Dec 2018 16:13:01 +0100 |
parents | 13e8e4ea53c0 |
children | aedf80eefc19 |
rev | line source |
---|---|
0 | 1 'use strict'; |
2 | |
3 function initNickname(connection) { | |
4 const nick_input = document.getElementById('nick'); | |
10
e47b9bd55192
Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
5 const spinner_img = document.getElementById('nick-spinner'); |
0 | 6 |
7 const iq = $iq({type: 'get'}) | |
8 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | |
9 .c('items', {node: 'http://jabber.org/protocol/nick'}); | |
10 connection.sendIQ(iq, onNickname, onNicknameRetrievalError.bind(null, 'PubSub query failed.')); | |
11 | |
12 function onNickname(result_iq) | |
13 { | |
14 const item = parseXPath(result_iq, './pubsub:pubsub/pubsub:items/pubsub:item'); | |
15 if (item == null) | |
16 return onNicknameRetrievalError('no item found.'); | |
17 const id = item.getAttributeNS(null, 'id'); | |
18 const nick = parseXPath(item, './nickname:nick'); | |
19 nick_input.value = nick.textContent; | |
10
e47b9bd55192
Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
20 spinner_img.hidden = true; |
0 | 21 } |
22 | |
23 function onNicknameRetrievalError(string) | |
24 { | |
25 console.log('Failed to retrieve nickname: ' + string); | |
10
e47b9bd55192
Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
26 spinner_img.hidden = true; |
0 | 27 } |
28 | |
7
13e8e4ea53c0
Change nickname on blur, remove the button.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
1
diff
changeset
|
29 nick_input.addEventListener('blur', function (evt) { |
0 | 30 const iq = $iq({type: 'set'}) |
31 .c('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) | |
32 .c('publish', {node: 'http://jabber.org/protocol/nick'}) | |
33 .c('item', {id: 'current'}) | |
34 .c('nick', {xmlns: 'http://jabber.org/protocol/nick'}) | |
35 .t(nick_input.value); | |
36 connection.sendIQ(iq, onNicknameChanged, onNicknameChangeError); | |
10
e47b9bd55192
Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
37 spinner_img.hidden = false; |
0 | 38 }); |
39 | |
40 function onNicknameChanged(iq) | |
41 { | |
42 console.log("onNicknameChanged", iq); | |
10
e47b9bd55192
Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
43 spinner_img.hidden = true; |
0 | 44 } |
45 | |
46 function onNicknameChangeError(iq) | |
47 { | |
48 console.log("onNicknameChangeError", iq); | |
10
e47b9bd55192
Also use a spinner on nickname get/set.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
7
diff
changeset
|
49 spinner_img.hidden = true; |
0 | 50 } |
51 } |