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
a912068e
Commit
a912068e
authored
Jul 28, 2012
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for message actions (/me command).
parent
d1efb1c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
33 deletions
+91
-33
converse.js
converse.js
+91
-33
No files found.
converse.js
View file @
a912068e
...
...
@@ -115,31 +115,51 @@ xmppchat.ChatBoxView = Backbone.View.extend({
'
<span class="chat-message-content"><%=message%></span>
'
+
'
</div>
'
),
action_template
:
_
.
template
(
'
<div class="chat-message <%=extra_classes%>">
'
+
'
<span class="chat-message-<%=sender%>"><%=time%>: </span>
'
+
'
<span class="chat-message-content"><%=message%></span>
'
+
'
</div>
'
),
appendMessage
:
function
(
message
)
{
var
time
,
now
=
new
Date
(),
minutes
=
now
.
getMinutes
().
toString
(),
list
,
$chat_content
;
message
=
message
.
replace
(
/</g
,
"
<
"
).
replace
(
/>/g
,
"
>
"
).
replace
(
/
\"
/g
,
"
"
"
);
$chat_content
,
match
;
message
=
message
.
replace
(
/</g
,
"
<
"
).
replace
(
/>/g
,
"
>
"
).
replace
(
/
\"
/g
,
"
"
"
)
.
replace
(
/^
\s
*/
,
""
)
;
list
=
message
.
match
(
/
\b(
http:
\/\/
www
\.\S
+
\.\w
+|www
\.\S
+
\.\w
+|http:
\/\/(?=[^
w
]){3}\S
+
[\.
:
]\S
+
)[^
]
+
\b
/g
);
if
(
list
)
{
for
(
i
=
0
;
i
<
list
.
length
;
i
++
)
{
message
=
message
.
replace
(
list
[
i
],
"
<a target='_blank' href='
"
+
escape
(
list
[
i
]
)
+
"
'>
"
+
list
[
i
]
+
"
</a>
"
);
}
}
if
(
minutes
.
length
==
1
)
{
minutes
=
'
0
'
+
minutes
;}
time
=
now
.
toLocaleTimeString
().
substring
(
0
,
5
);
$chat_content
=
$
(
this
.
el
).
find
(
'
.chat-content
'
);
$chat_content
.
find
(
'
div.chat-event
'
).
remove
();
$chat_content
.
append
(
this
.
message_template
({
'
sender
'
:
'
me
'
,
'
time
'
:
time
,
'
message
'
:
message
,
'
username
'
:
'
me
'
,
'
extra_classes
'
:
''
}));
match
=
message
.
match
(
/^
\/(
.*
?)(?:
(
.*
))?
$/
);
if
((
match
)
&&
(
match
[
1
]
===
'
me
'
))
{
message
=
message
.
replace
(
/^
\/
me/
,
'
*
'
+
xmppchat
.
username
);
$chat_content
.
append
(
this
.
action_template
({
'
sender
'
:
'
me
'
,
'
time
'
:
time
,
'
message
'
:
message
,
'
username
'
:
xmppchat
.
username
,
'
extra_classes
'
:
''
}));
}
else
{
$chat_content
.
append
(
this
.
message_template
({
'
sender
'
:
'
me
'
,
'
time
'
:
time
,
'
message
'
:
message
,
'
username
'
:
'
me
'
,
'
extra_classes
'
:
''
}));
}
$chat_content
.
scrollTop
(
$chat_content
[
0
].
scrollHeight
);
},
...
...
@@ -175,48 +195,83 @@ xmppchat.ChatBoxView = Backbone.View.extend({
// TODO: ClientStorage
xmppchat
.
messages
.
ClientStorage
.
addMessage
(
jid
,
body
,
'
from
'
);
$chat_content
.
find
(
'
div.chat-event
'
).
remove
();
$chat_content
.
append
(
this
.
message_template
({
'
sender
'
:
'
them
'
,
'
time
'
:
(
new
Date
()).
toLocaleTimeString
().
substring
(
0
,
5
),
'
message
'
:
body
.
replace
(
/<br
\/
>/g
,
""
),
'
username
'
:
user_id
,
'
extra_classes
'
:
(
$
(
message
).
find
(
'
delay
'
).
length
>
0
)
&&
'
delayed
'
||
''
}));
match
=
body
.
match
(
/^
\/(
.*
?)(?:
(
.*
))?
$/
);
if
((
match
)
&&
(
match
[
1
]
===
'
me
'
))
{
$chat_content
.
append
(
this
.
action_template
({
'
sender
'
:
'
them
'
,
'
time
'
:
(
new
Date
()).
toLocaleTimeString
().
substring
(
0
,
5
),
'
message
'
:
body
.
replace
(
/^
\/
me/
,
'
*
'
+
user_id
).
replace
(
/<br
\/
>/g
,
""
),
'
username
'
:
xmppchat
.
username
,
'
extra_classes
'
:
(
$
(
message
).
find
(
'
delay
'
).
length
>
0
)
&&
'
delayed
'
||
''
}));
}
else
{
$chat_content
.
append
(
this
.
message_template
({
'
sender
'
:
'
them
'
,
'
time
'
:
(
new
Date
()).
toLocaleTimeString
().
substring
(
0
,
5
),
'
message
'
:
body
.
replace
(
/<br
\/
>/g
,
""
),
'
username
'
:
user_id
,
'
extra_classes
'
:
(
$
(
message
).
find
(
'
delay
'
).
length
>
0
)
&&
'
delayed
'
||
''
}));
}
$chat_content
.
scrollTop
(
$chat_content
[
0
].
scrollHeight
);
}
},
insertClientStoredMessages
:
function
()
{
var
that
=
this
;
xmppchat
.
messages
.
getMessages
(
this
.
model
.
get
(
'
jid
'
),
function
(
msgs
)
{
var
$content
=
that
.
$el
.
find
(
'
.chat-content
'
);
xmppchat
.
messages
.
getMessages
(
this
.
model
.
get
(
'
jid
'
),
$
.
proxy
(
function
(
msgs
)
{
var
$content
=
this
.
$el
.
find
(
'
.chat-content
'
);
for
(
var
i
=
0
;
i
<
_
.
size
(
msgs
);
i
++
)
{
var
msg
=
msgs
[
i
],
msg_array
=
msg
.
split
(
'
'
,
2
),
date
=
msg_array
[
0
];
date
=
msg_array
[
0
],
match
;
msg
=
String
(
msg
).
replace
(
/
(
.*
?\s
.*
?\s)
/
,
''
);
match
=
msg
.
match
(
/^
\/(
.*
?)(?:
(
.*
))?
$/
);
if
(
msg_array
[
1
]
==
'
to
'
)
{
$content
.
append
(
that
.
message_template
({
if
((
match
)
&&
(
match
[
1
]
===
'
me
'
))
{
$content
.
append
(
this
.
action_template
({
'
sender
'
:
'
me
'
,
'
time
'
:
new
Date
(
Date
.
parse
(
date
)).
toLocaleTimeString
().
substring
(
0
,
5
),
'
message
'
:
msg
.
replace
(
/^
\/
me/
,
'
*
'
+
xmppchat
.
username
),
'
username
'
:
xmppchat
.
username
,
'
extra_classes
'
:
'
delayed
'
}));
}
else
{
$content
.
append
(
this
.
message_template
({
'
sender
'
:
'
me
'
,
'
time
'
:
new
Date
(
Date
.
parse
(
date
)).
toLocaleTimeString
().
substring
(
0
,
5
),
'
message
'
:
String
(
msg
).
replace
(
/
(
.*
?\s
.*
?\s)
/
,
''
),
'
message
'
:
msg
,
'
username
'
:
'
me
'
,
'
extra_classes
'
:
'
delayed
'
}));
}));
}
}
else
{
$content
.
append
(
that
.
message_template
({
if
((
match
)
&&
(
match
[
1
]
===
'
me
'
))
{
$content
.
append
(
this
.
action_template
({
'
sender
'
:
'
them
'
,
'
time
'
:
new
Date
(
Date
.
parse
(
date
)).
toLocaleTimeString
().
substring
(
0
,
5
),
'
message
'
:
msg
.
replace
(
/^
\/
me/
,
'
*
'
+
this
.
model
.
get
(
'
user_id
'
)),
'
username
'
:
this
.
model
.
get
(
'
user_id
'
),
'
extra_classes
'
:
'
delayed
'
}));
}
else
{
$content
.
append
(
this
.
message_template
({
'
sender
'
:
'
them
'
,
'
time
'
:
new
Date
(
Date
.
parse
(
date
)).
toLocaleTimeString
().
substring
(
0
,
5
),
'
message
'
:
String
(
msg
).
replace
(
/
(
.*
?\s
.*
?\s)
/
,
''
)
,
'
username
'
:
th
at
.
model
.
get
(
'
user_id
'
),
'
message
'
:
msg
,
'
username
'
:
th
is
.
model
.
get
(
'
user_id
'
),
'
extra_classes
'
:
'
delayed
'
}));
}
}
}
});
}
,
this
)
);
},
sendMessage
:
function
(
text
)
{
...
...
@@ -226,6 +281,7 @@ xmppchat.ChatBoxView = Backbone.View.extend({
// TODO: Look in ChatPartners to see what resources we have for the recipient.
// if we have one resource, we sent to only that resources, if we have multiple
// we send to the bare jid.
var
bare_jid
=
this
.
model
.
get
(
'
jid
'
);
var
message
=
$msg
({
to
:
bare_jid
,
type
:
'
chat
'
})
.
c
(
'
body
'
).
t
(
text
).
up
()
...
...
@@ -576,7 +632,9 @@ xmppchat.ChatRoomView = xmppchat.ChatBoxView.extend({
}
else
if
(
match
[
1
]
===
"
deop
"
)
{
xmppchat
.
connection
.
muc
.
deop
(
this
.
model
.
get
(
'
jid
'
),
match
[
2
]);
}
}
else
{
this
.
last_msgid
=
xmppchat
.
connection
.
muc
.
groupchat
(
this
.
model
.
get
(
'
jid
'
),
body
);
}
}
else
{
this
.
last_msgid
=
xmppchat
.
connection
.
muc
.
groupchat
(
this
.
model
.
get
(
'
jid
'
),
body
);
}
...
...
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