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
f204be09
Commit
f204be09
authored
Jun 25, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The chatbox is now rendered completely in javascript.
parent
ef5c5b56
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
68 deletions
+60
-68
chat.js
chat.js
+2
-7
chatui.js
chatui.js
+58
-61
No files found.
chat.js
View file @
f204be09
...
@@ -153,7 +153,7 @@ var xmppchat = (function (jarnxmpp, $, console) {
...
@@ -153,7 +153,7 @@ var xmppchat = (function (jarnxmpp, $, console) {
ob
.
Collections
.
getLastMessages
=
function
(
jid
,
callback
)
{
ob
.
Collections
.
getLastMessages
=
function
(
jid
,
callback
)
{
var
that
=
this
;
var
that
=
this
;
this
.
getLastCollection
(
jid
,
function
(
result
)
{
this
.
getLastCollection
(
jid
,
function
(
result
)
{
// Retrieve the last page of a collection (30 elements).
// Retrieve the last page of a collection (
max
30 elements).
var
$collection
=
$
(
result
).
find
(
'
chat
'
),
var
$collection
=
$
(
result
).
find
(
'
chat
'
),
jid
=
$collection
.
attr
(
'
with
'
),
jid
=
$collection
.
attr
(
'
with
'
),
start
=
$collection
.
attr
(
'
start
'
),
start
=
$collection
.
attr
(
'
start
'
),
...
@@ -165,12 +165,7 @@ var xmppchat = (function (jarnxmpp, $, console) {
...
@@ -165,12 +165,7 @@ var xmppchat = (function (jarnxmpp, $, console) {
.
c
(
'
set
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/rsm
'
})
.
c
(
'
set
'
,
{
'
xmlns
'
:
'
http://jabber.org/protocol/rsm
'
})
.
c
(
'
max
'
)
.
c
(
'
max
'
)
.
t
(
'
30
'
);
.
t
(
'
30
'
);
xmppchat
.
connection
.
sendIQ
(
iq
,
xmppchat
.
connection
.
sendIQ
(
iq
,
callback
);
callback
,
function
(
result
)
{
console
.
log
(
iq
.
nodeTree
);
console
.
log
(
$
(
result
).
find
(
'
error
'
));
});
});
});
};
};
...
...
chatui.js
View file @
f204be09
...
@@ -10,7 +10,8 @@ xmppchat.UI = (function (xmppUI, $, console) {
...
@@ -10,7 +10,8 @@ xmppchat.UI = (function (xmppUI, $, console) {
ob
.
updateOnPresence
=
function
(
jid
,
status
,
presence
)
{
ob
.
updateOnPresence
=
function
(
jid
,
status
,
presence
)
{
var
user_id
=
Strophe
.
getNodeFromJid
(
jid
),
var
user_id
=
Strophe
.
getNodeFromJid
(
jid
),
bare_jid
,
resource
,
existing_user_element
,
online_count
;
bare_jid
=
Strophe
.
getBareJidFromJid
(
jid
),
resource
,
existing_user_element
,
online_count
;
if
(
xmppchat
.
isOwnUser
(
jid
))
{
return
;
}
if
(
xmppchat
.
isOwnUser
(
jid
))
{
return
;
}
...
@@ -79,48 +80,33 @@ xmppchat.UI = (function (xmppUI, $, console) {
...
@@ -79,48 +80,33 @@ xmppchat.UI = (function (xmppUI, $, console) {
});
});
};
};
ob
.
createChatbox
=
function
(
jid
,
callback
)
{
ob
.
createChatbox
=
function
(
bare_jid
,
callback
)
{
var
path
=
this
.
sanitizePath
(
'
/@@render_chat_box
'
),
var
user_id
=
Strophe
.
getNodeFromJid
(
bare_jid
);
chat_id
=
helpers
.
hash
(
jid
),
xmppchat
.
Presence
.
getUserInfo
(
user_id
,
function
(
data
)
{
that
=
this
;
xmppchat
.
Collections
.
getLastMessages
(
bare_jid
,
function
(
result
)
{
var
chat_id
=
helpers
.
hash
(
bare_jid
);
$
.
ajax
({
var
$chat
=
$
(
'
<div class="chatbox"></div>
'
).
attr
(
'
id
'
,
chat_id
).
hide
();
url
:
path
,
var
$head
=
$
(
'
<div class="chat-head chat-head-chatbox"></div>
'
)
cache
:
false
,
.
append
(
'
<div class="chat-title"></div>
'
).
text
(
data
.
fullname
)
async
:
false
,
.
append
(
$
(
'
<a href="javascript:void(0)" class="chatbox-button close-chatbox-button">X</a>
'
)
data
:
{
.
attr
(
'
data-recipient
'
,
bare_jid
))
chat_id
:
'
chatbox_
'
+
jid
,
.
append
(
'
<br clear="all"/>
'
);
box_id
:
chat_id
,
var
$content
=
$
(
'
<div class="chat-content"></div>
'
);
jid
:
jid
var
$form
=
$
(
'
<form class="sendXMPPMessage" action="" method="post">
'
)
},
.
append
(
error
:
function
(
XMLHttpRequest
,
textStatus
,
errorThrown
)
{
$
(
'
<textarea type="text"
'
+
console
.
log
(
textStatus
);
'
name="message"
'
+
console
.
log
(
errorThrown
);
'
class="chat-textarea"
'
+
return
;
'
placeholder="Personal message"/>
'
).
attr
(
'
data-recipient
'
,
bare_jid
));
},
success
:
function
(
data
)
{
$chat
.
append
(
$head
).
append
(
$content
).
append
(
$form
);
var
chat_id
=
$
(
data
).
attr
(
'
id
'
),
$
(
'
body
'
).
append
(
$chat
);
$chat
=
$
(
'
body
'
).
append
(
data
).
find
(
'
#
'
+
chat_id
);
$chat
.
find
(
'
.chat-message .time
'
).
each
(
function
()
{
var
jthis
=
$
(
this
);
var
time
=
jthis
.
text
().
split
(
'
:
'
);
var
hour
=
time
[
0
];
var
minutes
=
time
[
1
];
var
date
=
new
Date
();
date
.
setHours
(
hour
-
date
.
getTimezoneOffset
()
/
60
);
date
.
setMinutes
(
minutes
);
jthis
.
replaceWith
(
date
.
toLocaleTimeString
().
substring
(
0
,
5
));
});
xmppchat
.
Collections
.
getLastMessages
(
jid
,
function
(
result
)
{
$
(
result
).
find
(
'
chat
'
).
children
().
each
(
function
(
idx
,
el
)
{
$
(
result
).
find
(
'
chat
'
).
children
().
each
(
function
(
idx
,
el
)
{
if
(
el
.
tagName
!==
'
set
'
)
{
if
(
el
.
tagName
!==
'
set
'
)
{
// TODO: Calculate the time. We have the start time and the offset for each message...
// TODO: Calculate the time. We have the start time and the offset for each message...
var
chat_id
=
$
(
data
).
attr
(
'
id
'
);
var
text
=
$
(
el
).
find
(
'
body
'
).
text
(),
var
$chat
=
$
(
'
body
'
).
append
(
data
).
find
(
'
#
'
+
chat_id
);
now
=
new
Date
(),
var
$content
=
$chat
.
find
(
"
.chat-content
"
);
time
=
now
.
toLocaleTimeString
().
substring
(
0
,
5
),
var
text
=
$
(
el
).
find
(
'
body
'
).
text
();
var
now
=
new
Date
();
var
time
=
now
.
toLocaleTimeString
().
substring
(
0
,
5
),
div
=
$
(
'
<div class="chat-message delayed"></div>
'
);
div
=
$
(
'
<div class="chat-message delayed"></div>
'
);
if
(
el
.
tagName
==
'
to
'
)
{
if
(
el
.
tagName
==
'
to
'
)
{
...
@@ -138,11 +124,22 @@ xmppchat.UI = (function (xmppUI, $, console) {
...
@@ -138,11 +124,22 @@ xmppchat.UI = (function (xmppUI, $, console) {
$content
.
scrollTop
(
$content
[
0
].
scrollHeight
);
$content
.
scrollTop
(
$content
[
0
].
scrollHeight
);
}
}
});
});
});
callback
(
$chat
);
callback
(
$chat
);
}
}
);
});
});
};
};
/*
$chat.find('.chat-message .time').each(function () {
var jthis = $(this);
var time = jthis.text().split(':');
var hour = time[0];
var minutes = time[1];
var date = new Date();
date.setHours(hour - date.getTimezoneOffset() / 60);
date.setMinutes(minutes);
jthis.replaceWith(date.toLocaleTimeString().substring(0,5));
});
*/
ob
.
prepNewChat
=
function
(
chat
,
jid
)
{
ob
.
prepNewChat
=
function
(
chat
,
jid
)
{
// Some operations that need to be applied on a chatbox
// Some operations that need to be applied on a chatbox
...
@@ -458,7 +455,7 @@ $(document).ready(function () {
...
@@ -458,7 +455,7 @@ $(document).ready(function () {
});
});
$
(
'
a.close-chatbox-button
'
).
live
(
'
click
'
,
function
(
ev
)
{
$
(
'
a.close-chatbox-button
'
).
live
(
'
click
'
,
function
(
ev
)
{
var
jid
=
$
(
ev
.
target
).
parent
().
parent
().
attr
(
'
data-recipient
'
);
var
jid
=
$
(
ev
.
target
).
attr
(
'
data-recipient
'
);
xmppchat
.
UI
.
closeChat
(
jid
);
xmppchat
.
UI
.
closeChat
(
jid
);
});
});
...
...
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