Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
997bcdc5
Commit
997bcdc5
authored
Jul 04, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better roster support (adding/removing of contacts).
parent
8cdc8d30
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
24 deletions
+83
-24
chat.js
chat.js
+63
-11
chatui.js
chatui.js
+20
-13
No files found.
chat.js
View file @
997bcdc5
...
...
@@ -234,13 +234,18 @@ var xmppchat = (function (jarnxmpp, $, console) {
if
(
ptype
===
'
subscribe
'
)
{
// User wants to subscribe to us. Always approve and
// ask to subscribe to him
xmppchat
.
Roster
.
authorize
(
jid
);
xmppchat
.
Roster
.
subscribe
(
jid
);
xmppchat
.
Roster
.
authorize
(
bare_
jid
);
xmppchat
.
Roster
.
subscribe
(
bare_
jid
);
}
else
if
(
ptype
===
'
unsubscribe
'
)
{
xmppchat
.
ChatPartners
.
removeAll
(
bare_jid
);
xmppchat
.
Roster
.
unauthorize
(
bare_jid
);
$
(
document
).
trigger
(
'
jarnxmpp.presence
'
,
[
jid
,
status
,
presence
]);
if
(
_
.
indexOf
(
xmppchat
.
Roster
.
getCachedJids
(),
bare_jid
)
!=
-
1
)
{
xmppchat
.
Roster
.
unauthorize
(
bare_jid
);
xmppchat
.
Roster
.
unsubscribe
(
bare_jid
);
$
(
document
).
trigger
(
'
jarnxmpp.presence
'
,
[
jid
,
'
unsubscribe
'
,
presence
]);
}
}
else
if
(
ptype
===
'
unsubscribed
'
)
{
return
;
}
else
if
(
ptype
!==
'
error
'
)
{
// Presence has changed
if
(
ptype
===
'
unavailable
'
)
{
...
...
@@ -269,7 +274,12 @@ var xmppchat = (function (jarnxmpp, $, console) {
};
ob
.
Taskbuffer
=
(
function
(
$
)
{
// Executes tasks one after another (i.e next task is started only when
// the previous one has been completed).
buffer
=
{};
// Tasks must be objects with keys: 'that', 'method' and 'parameters'
// 'that' the context for the method, while 'parameters' is the list of arguments
// passed to it.
buffer
.
tasks
=
[];
buffer
.
deferred
=
$
.
when
();
buffer
.
handleTasks
=
function
()
{
...
...
@@ -292,6 +302,51 @@ var xmppchat = (function (jarnxmpp, $, console) {
return
ob
;
})(
jarnxmpp
||
{},
jQuery
,
console
||
{
log
:
function
(){}});
xmppchat
.
Roster
=
(
function
(
roster
,
jquery
,
console
)
{
var
contacts
=
{},
ob
=
roster
;
_updateCache
=
function
()
{
if
(
this
.
subscription
===
'
none
'
)
{
delete
contacts
[
this
.
jid
];
}
else
{
contacts
[
this
.
jid
]
=
this
;
}
};
_triggerEvent
=
function
()
{
$
(
document
).
trigger
(
'
xmppchat.roster_updated
'
);
};
ob
.
_connection
=
xmppchat
.
connection
;
ob
.
update
=
function
(
items
,
item
)
{
old_cache
=
ob
.
getCached
();
for
(
var
i
=
0
;
i
<
items
.
length
;
i
++
)
{
if
(
items
[
i
].
subscription
===
'
none
'
)
{
delete
contacts
[
items
[
i
].
jid
];
}
else
{
contacts
[
items
[
i
].
jid
]
=
items
[
i
];
}
}
console
.
log
(
'
update, size is:
'
+
_
.
size
(
contacts
));
if
(
!
_
.
isEqual
(
old_cache
,
ob
.
getCached
()))
{
console
.
log
(
'
triggering event
'
);
$
(
document
).
trigger
(
'
xmppchat.roster_updated
'
);
}
};
ob
.
getCached
=
function
()
{
return
_
.
values
(
contacts
);
};
ob
.
getCachedJids
=
function
()
{
return
_
.
keys
(
contacts
);
};
return
ob
;
});
// Event handlers
// --------------
...
...
@@ -311,12 +366,9 @@ $(document).ready(function () {
xmppchat
.
UI
.
restoreOpenChats
();
xmppchat
.
Roster
=
Strophe
.
_connectionPlugins
.
roster
;
xmppchat
.
Roster
.
_connection
=
xmppchat
.
connection
;
xmppchat
.
Roster
.
get
(
function
(
contacts
)
{
xmppchat
.
Roster
.
contacts
=
contacts
;
$
(
document
).
trigger
(
'
xmppchat.roster_updated
'
);
});
xmppchat
.
Roster
=
xmppchat
.
Roster
(
Strophe
.
_connectionPlugins
.
roster
,
$
,
console
);
xmppchat
.
Roster
.
registerCallback
(
xmppchat
.
Roster
.
update
);
xmppchat
.
Roster
.
get
();
xmppchat
.
Presence
.
sendPresence
();
});
});
chatui.js
View file @
997bcdc5
...
...
@@ -472,6 +472,19 @@ xmppchat.UI = (function (xmppUI, $, console) {
}
};
ob
.
setOwnStatus
=
function
(
el
)
{
var
jid
=
xmppchat
.
connection
.
jid
,
value
=
$
(
el
).
find
(
'
span
'
).
text
();
$
(
"
.dropdown dt a
"
).
html
(
'
I am
'
+
value
);
$
(
"
.dropdown dt a
"
).
attr
(
'
class
'
,
value
);
$
(
"
.dropdown dd ul
"
).
hide
();
$
(
"
#source
"
).
val
(
$
(
el
).
find
(
"
span.value
"
).
html
());
xmppchat
.
Presence
.
sendPresence
(
value
);
xmppchat
.
Storage
.
set
(
xmppchat
.
username
+
'
-xmpp-status
'
,
value
);
};
ob
.
createStatusSelectWidget
=
function
()
{
var
select
=
$
(
'
select#select-xmpp-status
'
),
selected
=
select
.
find
(
'
option[selected]
'
),
...
...
@@ -521,8 +534,8 @@ $(document).ready(function () {
});
$
(
document
).
bind
(
'
xmppchat.roster_updated
'
,
function
(
event
)
{
var
contacts
=
xmppchat
.
Roster
.
contacts
;
$
(
contacts
).
each
(
function
(
idx
,
contact
)
{
$
(
'
#xmpp-contacts
'
).
empty
()
;
$
(
xmppchat
.
Roster
.
getCached
()
).
each
(
function
(
idx
,
contact
)
{
if
(
contact
.
subscription
!==
'
none
'
)
{
var
user_id
=
Strophe
.
getNodeFromJid
(
contact
.
jid
),
bare_jid
=
Strophe
.
getBareJidFromJid
(
contact
.
jid
);
...
...
@@ -625,19 +638,13 @@ $(document).ready(function () {
$
(
"
a.subscribe-to-user
"
).
live
(
'
click
'
,
function
(
ev
)
{
ev
.
preventDefault
();
xmppchat
.
Roster
.
subscribe
(
$
(
this
).
attr
(
'
data-recipient
'
));
$
(
this
).
remove
();
$
(
'
form.search-xmpp-contact
'
).
hide
();
});
$
(
"
.dropdown dd ul li a
"
).
click
(
function
()
{
var
jid
=
xmppchat
.
connection
.
jid
,
value
=
$
(
this
).
find
(
'
span
'
).
text
();
$
(
"
.dropdown dt a
"
).
html
(
'
I am
'
+
value
);
$
(
"
.dropdown dt a
"
).
attr
(
'
class
'
,
value
);
$
(
"
.dropdown dd ul
"
).
hide
();
$
(
"
#source
"
).
val
(
$
(
this
).
find
(
"
span.value
"
).
html
());
xmppchat
.
Presence
.
sendPresence
(
value
);
xmppchat
.
Storage
.
set
(
xmppchat
.
username
+
'
-xmpp-status
'
,
value
);
$
(
"
.dropdown dd ul li a
"
).
click
(
function
(
ev
)
{
ev
.
preventDefault
();
xmppchat
.
UI
.
setOwnStatus
(
this
);
});
$
(
'
select#select-xmpp-status
'
).
bind
(
'
change
'
,
function
(
ev
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment