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
8b0670d3
Commit
8b0670d3
authored
Jul 22, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the available rooms list when users join or leave.
parent
2fb4a885
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
18 deletions
+47
-18
chat.js
chat.js
+47
-18
No files found.
chat.js
View file @
8b0670d3
/*!
* Converse.js (Web-based instant messaging with XMPP)
* http://opkode.com
*
* Copyright (c) 2012 Jan-Carel Brand
* Dual licensed under the MIT and GPL Licenses
*/
var
xmppchat
=
(
function
(
jarnxmpp
,
$
,
console
)
{
var
ob
=
jarnxmpp
;
/* FIXME: XEP-0136 specifies 'urn:xmpp:archive' but the mod_archive_odbc
* add-on for ejabberd wants the URL below. This might break for other
* Jabber servers.
*/
ob
.
Collections
=
{
'
URI
'
:
'
http://www.xmpp.org/extensions/xep-0136.html#ns
'
};
ob
.
Messages
=
{};
ob
.
Messages
.
ClientStorage
=
(
function
()
{
ob
.
messages
=
{};
ob
.
messages
.
ClientStorage
=
(
function
()
{
// TODO: Messages must be encrypted with a key and salt
methods
=
{};
...
...
@@ -31,13 +34,16 @@ var xmppchat = (function (jarnxmpp, $, console) {
return
methods
;
})();
ob
.
M
essages
.
getMessages
=
function
(
jid
,
callback
)
{
ob
.
m
essages
.
getMessages
=
function
(
jid
,
callback
)
{
var
bare_jid
=
Strophe
.
getBareJidFromJid
(
jid
),
msgs
=
this
.
ClientStorage
.
getMessages
(
bare_jid
);
callback
(
msgs
);
};
ob
.
Collections
.
getLastCollection
=
function
(
jid
,
callback
)
{
ob
.
collections
=
{
'
URI
'
:
'
http://www.xmpp.org/extensions/xep-0136.html#ns
'
};
ob
.
collections
.
getLastCollection
=
function
(
jid
,
callback
)
{
var
bare_jid
=
Strophe
.
getBareJidFromJid
(
jid
),
iq
=
$iq
({
'
type
'
:
'
get
'
})
.
c
(
'
list
'
,
{
'
xmlns
'
:
this
.
URI
,
...
...
@@ -55,7 +61,7 @@ var xmppchat = (function (jarnxmpp, $, console) {
});
};
ob
.
C
ollections
.
getLastMessages
=
function
(
jid
,
callback
)
{
ob
.
c
ollections
.
getLastMessages
=
function
(
jid
,
callback
)
{
var
that
=
this
;
this
.
getLastCollection
(
jid
,
function
(
result
)
{
// Retrieve the last page of a collection (max 30 elements).
...
...
@@ -155,6 +161,10 @@ xmppchat.ChatBoxView = Backbone.View.extend({
$chat_content
=
$
(
this
.
el
).
find
(
'
.chat-content
'
),
user_id
=
Strophe
.
getNodeFromJid
(
jid
);
if
(
xmppchat
.
xmppstatus
.
getOwnStatus
()
===
'
offline
'
)
{
// only update the UI if the user is not offline
return
;
}
if
(
!
body
)
{
if
(
composing
.
length
>
0
)
{
this
.
insertStatusNotification
(
'
is typing
'
);
...
...
@@ -162,11 +172,7 @@ xmppchat.ChatBoxView = Backbone.View.extend({
}
}
else
{
// TODO: ClientStorage
xmppchat
.
Messages
.
ClientStorage
.
addMessage
(
jid
,
body
,
'
from
'
);
if
(
xmppchat
.
xmppstatus
.
getOwnStatus
()
===
'
offline
'
)
{
// only update the UI if the user is not offline
return
;
}
xmppchat
.
messages
.
ClientStorage
.
addMessage
(
jid
,
body
,
'
from
'
);
$chat_content
.
find
(
'
div.chat-event
'
).
remove
();
$chat_content
.
append
(
this
.
message_template
({
...
...
@@ -182,7 +188,7 @@ xmppchat.ChatBoxView = Backbone.View.extend({
insertClientStoredMessages
:
function
()
{
var
that
=
this
;
xmppchat
.
M
essages
.
getMessages
(
this
.
model
.
get
(
'
jid
'
),
function
(
msgs
)
{
xmppchat
.
m
essages
.
getMessages
(
this
.
model
.
get
(
'
jid
'
),
function
(
msgs
)
{
var
$content
=
that
.
$el
.
find
(
'
.chat-content
'
);
for
(
var
i
=
0
;
i
<
_
.
size
(
msgs
);
i
++
)
{
var
msg
=
msgs
[
i
],
...
...
@@ -224,7 +230,7 @@ xmppchat.ChatBoxView = Backbone.View.extend({
.
c
(
'
body
'
).
t
(
text
).
up
()
.
c
(
'
active
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/chatstates
'
});
xmppchat
.
connection
.
send
(
message
);
xmppchat
.
M
essages
.
ClientStorage
.
addMessage
(
bare_jid
,
text
,
'
to
'
);
xmppchat
.
m
essages
.
ClientStorage
.
addMessage
(
bare_jid
,
text
,
'
to
'
);
this
.
appendMessage
(
text
);
},
...
...
@@ -423,9 +429,18 @@ xmppchat.RoomsPanel = Backbone.View.extend({
'
<%=name%></a></dd>
'
),
initialize
:
function
()
{
this
.
on
(
'
update-rooms-list
'
,
function
(
ev
)
{
this
.
updateRoomsList
();
});
this
.
trigger
(
'
update-rooms-list
'
);
},
updateRoomsList
:
function
()
{
// FIXME: Hardcoded
xmppchat
.
connection
.
muc
.
listRooms
(
'
conference.devbox
'
,
$
.
proxy
(
function
(
iq
)
{
var
room
,
name
,
jid
,
rooms
=
$
(
iq
).
find
(
'
query
'
).
find
(
'
item
'
);
this
.
$el
.
find
(
'
#available-chatrooms
'
).
find
(
'
dd.chatroom
'
).
remove
();
if
(
rooms
.
length
)
{
this
.
$el
.
find
(
'
#available-chatrooms dt
'
).
show
();
}
else
{
...
...
@@ -519,8 +534,11 @@ xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
xmppchat
.
connection
.
muc
.
leave
(
this
.
model
.
get
(
'
jid
'
),
this
.
model
.
get
(
'
nick
'
),
function
()
{}
,
this
.
onLeave
,
undefined
);
delete
xmppchat
.
chatboxesview
.
views
[
this
.
model
.
get
(
'
jid
'
)];
xmppchat
.
chatboxesview
.
model
.
remove
(
this
.
model
.
get
(
'
jid
'
));
this
.
remove
();
},
keyPressed
:
function
(
ev
)
{
...
...
@@ -578,6 +596,13 @@ xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
$
.
proxy
(
this
.
onRoster
,
this
));
},
onLeave
:
function
()
{
var
controlboxview
=
xmppchat
.
chatboxesview
.
views
[
'
online-users-container
'
];
if
(
controlboxview
)
{
controlboxview
.
roomspanel
.
trigger
(
'
update-rooms-list
'
);
}
},
onPresence
:
function
(
presence
,
room
)
{
var
nick
=
room
.
nick
,
from
=
$
(
presence
).
attr
(
'
from
'
);
...
...
@@ -628,6 +653,10 @@ xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
},
onRoster
:
function
(
roster
,
room
)
{
var
controlboxview
=
xmppchat
.
chatboxesview
.
views
[
'
online-users-container
'
];
if
(
controlboxview
)
{
controlboxview
.
roomspanel
.
trigger
(
'
update-rooms-list
'
);
}
this
.
$el
.
find
(
'
.participant-list
'
).
empty
();
for
(
var
i
=
0
;
i
<
_
.
size
(
roster
);
i
++
)
{
this
.
$el
.
find
(
'
.participant-list
'
).
append
(
'
<li>
'
+
_
.
keys
(
roster
)[
i
]
+
'
</li>
'
);
...
...
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