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
ac3ac98c
Commit
ac3ac98c
authored
Sep 08, 2013
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow chat statuses to be translated.
Add conf setting for allowing OTR.
parent
e2c97e38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
61 deletions
+89
-61
converse.js
converse.js
+88
-61
index.html
index.html
+1
-0
No files found.
converse.js
View file @
ac3ac98c
...
@@ -43,6 +43,12 @@
...
@@ -43,6 +43,12 @@
}(
this
,
function
(
$
,
_
,
crypto
,
otr
,
console
)
{
}(
this
,
function
(
$
,
_
,
crypto
,
otr
,
console
)
{
var
converse
=
{};
var
converse
=
{};
converse
.
initialize
=
function
(
settings
,
callback
)
{
converse
.
initialize
=
function
(
settings
,
callback
)
{
// Constants
var
UNENCRYPTED
=
0
;
var
UNVERIFIED
=
1
;
var
VERIFIED
=
2
;
var
FINISHED
=
3
;
// Default values
// Default values
var
converse
=
this
;
var
converse
=
this
;
this
.
animate
=
true
;
this
.
animate
=
true
;
...
@@ -60,11 +66,6 @@
...
@@ -60,11 +66,6 @@
this
.
xhr_custom_status
=
false
;
this
.
xhr_custom_status
=
false
;
this
.
xhr_user_search
=
false
;
this
.
xhr_user_search
=
false
;
var
FINISHED
=
'
finished
'
;
var
UNENCRYPTED
=
'
unencrypted
'
;
var
UNVERIFIED
=
'
unverified
'
;
var
VERIFIED
=
'
verified
'
;
// Allow only the whitelisted settings attributes to be overwritten,
// Allow only the whitelisted settings attributes to be overwritten,
// nothing else.
// nothing else.
whitelist
=
[
whitelist
=
[
...
@@ -90,10 +91,9 @@
...
@@ -90,10 +91,9 @@
_
.
extend
(
this
,
_
.
pick
(
settings
,
whitelist
));
_
.
extend
(
this
,
_
.
pick
(
settings
,
whitelist
));
var
__
=
$
.
proxy
(
function
(
str
)
{
var
__
=
$
.
proxy
(
function
(
str
)
{
/* Translation factory
// Translation factory
*/
if
(
this
.
i18n
===
undefined
)
{
if
(
this
.
i18n
===
undefined
)
{
this
.
i18n
=
locales
[
'
en
'
]
;
this
.
i18n
=
locales
.
en
;
}
}
var
t
=
this
.
i18n
.
translate
(
str
);
var
t
=
this
.
i18n
.
translate
(
str
);
if
(
arguments
.
length
>
1
)
{
if
(
arguments
.
length
>
1
)
{
...
@@ -113,6 +113,17 @@
...
@@ -113,6 +113,17 @@
*/
*/
return
str
;
return
str
;
};
};
var
OTR_CLASS_MAPPING
=
{};
OTR_CLASS_MAPPING
[
UNENCRYPTED
]
=
'
unencrypted
'
;
OTR_CLASS_MAPPING
[
UNVERIFIED
]
=
'
unverified
'
;
OTR_CLASS_MAPPING
[
VERIFIED
]
=
'
verified
'
;
OTR_CLASS_MAPPING
[
FINISHED
]
=
'
finished
'
;
var
OTR_TRANSLATED_MAPPING
=
{};
OTR_TRANSLATED_MAPPING
[
UNENCRYPTED
]
=
__
(
'
unencrypted
'
);
OTR_TRANSLATED_MAPPING
[
UNVERIFIED
]
=
__
(
'
unverified
'
);
OTR_TRANSLATED_MAPPING
[
VERIFIED
]
=
__
(
'
verified
'
);
OTR_TRANSLATED_MAPPING
[
FINISHED
]
=
__
(
'
finished
'
);
this
.
msg_counter
=
0
;
this
.
msg_counter
=
0
;
this
.
autoLink
=
function
(
text
)
{
this
.
autoLink
=
function
(
text
)
{
...
@@ -129,9 +140,13 @@
...
@@ -129,9 +140,13 @@
}
}
};
};
this
.
log
=
function
(
txt
)
{
this
.
log
=
function
(
txt
,
level
)
{
if
(
this
.
debug
)
{
if
(
this
.
debug
)
{
console
.
log
(
txt
);
if
(
level
==
'
error
'
)
{
console
.
log
(
'
ERROR:
'
+
txt
);
}
else
{
console
.
log
(
txt
);
}
}
}
};
};
...
@@ -405,6 +420,13 @@
...
@@ -405,6 +420,13 @@
},
this
));
},
this
));
},
},
endOTR
:
function
()
{
if
(
this
.
otr
)
{
this
.
otr
.
endOtr
();
}
this
.
save
({
'
otr_status
'
:
UNENCRYPTED
});
},
createMessage
:
function
(
message
)
{
createMessage
:
function
(
message
)
{
var
$message
=
$
(
message
),
var
$message
=
$
(
message
),
body
=
converse
.
autoLink
(
$message
.
children
(
'
body
'
).
text
()),
body
=
converse
.
autoLink
(
$message
.
children
(
'
body
'
).
text
()),
...
@@ -449,25 +471,23 @@
...
@@ -449,25 +471,23 @@
messageReceived
:
function
(
message
)
{
messageReceived
:
function
(
message
)
{
var
$body
=
$
(
message
).
children
(
'
body
'
);
var
$body
=
$
(
message
).
children
(
'
body
'
);
var
text
=
(
$body
.
length
>
0
?
converse
.
autoLink
(
$body
.
text
())
:
undefined
);
var
text
=
(
$body
.
length
>
0
?
converse
.
autoLink
(
$body
.
text
())
:
undefined
);
if
(
text
)
{
if
((
!
text
)
||
(
!
converse
.
allow_otr
))
{
if
(
_
.
contains
([
UNVERIFIED
,
VERIFIED
],
this
.
get
(
'
otr_status
'
)))
{
return
this
.
createMessage
(
message
);
this
.
otr
.
receiveMsg
(
text
);
}
}
else
{
if
(
_
.
contains
([
UNVERIFIED
,
VERIFIED
],
this
.
get
(
'
otr_status
'
)))
{
if
(
text
.
match
(
/^
\?
OTR/
))
{
this
.
otr
.
receiveMsg
(
text
);
// They want to initiate OTR
}
else
{
if
(
!
this
.
otr
)
{
if
(
text
.
match
(
/^
\?
OTR/
))
{
this
.
initiateOTR
(
text
);
// They want to initiate OTR
}
else
{
if
(
!
this
.
otr
)
{
this
.
otr
.
receiveMsg
(
text
);
this
.
initiateOTR
(
text
);
}
}
else
{
}
else
{
// Normal unencrypted message.
this
.
otr
.
receiveMsg
(
text
);
this
.
createMessage
(
message
);
}
}
}
else
{
// Normal unencrypted message.
this
.
createMessage
(
message
);
}
}
}
else
{
// No <body>, so probably typing notification
this
.
createMessage
(
message
);
}
}
}
}
});
});
...
@@ -501,38 +521,42 @@
...
@@ -501,38 +521,42 @@
'
type="text"
'
+
'
type="text"
'
+
'
class="chat-textarea"
'
+
'
class="chat-textarea"
'
+
'
placeholder="
'
+
__
(
'
Personal message
'
)
+
'
"/>
'
+
'
placeholder="
'
+
__
(
'
Personal message
'
)
+
'
"/>
'
+
'
</form>
'
),
'
</form>
'
),
toolbar_template
:
_
.
template
(
toolbar_template
:
_
.
template
(
'
<li class="toggle-otr {{otr_status}}" title="{{otr_tooltip}}">
'
+
'
{[ if (allow_otr) { ]}
'
+
'
<span class="chat-toolbar-text">{{otr_status}}</span>
'
+
'
<li class="toggle-otr {{otr_status_class}}" title="{{otr_tooltip}}">
'
+
'
{[ if (otr_status == "
'
+
UNENCRYPTED
+
'
") { ]}
'
+
'
<span class="chat-toolbar-text">{{otr_translated_status}}</span>
'
+
'
<span class="icon-unlocked"></span>
'
+
'
{[ if (otr_status == "
'
+
UNENCRYPTED
+
'
") { ]}
'
+
'
{[ } ]}
'
+
'
<span class="icon-unlocked"></span>
'
+
'
{[ if (otr_status == "
'
+
UNVERIFIED
+
'
") { ]}
'
+
'
<span class="icon-lock"></span>
'
+
'
{[ } ]}
'
+
'
{[ if (otr_status == "
'
+
VERIFIED
+
'
") { ]}
'
+
'
<span class="icon-lock"></span>
'
+
'
{[ } ]}
'
+
'
{[ if (otr_status == "
'
+
FINISHED
+
'
") { ]}
'
+
'
<span class="icon-unlocked"></span>
'
+
'
{[ } ]}
'
+
'
<ul>
'
+
'
{[ if (otr_status === "
'
+
UNENCRYPTED
+
'
") { ]}
'
+
'
<li><a class="start-otr" href="#">
'
+
__
(
'
Start encrypted conversation
'
)
+
'
</a></li>
'
+
'
{[ } ]}
'
+
'
{[ } ]}
'
+
'
{[ if (otr_status !== "
'
+
UNENCRYPTED
+
'
") { ]}
'
+
'
{[ if (otr_status == "
'
+
UNVERIFIED
+
'
") { ]}
'
+
'
<li><a class="start-otr" href="#">
'
+
__
(
'
Refresh encrypted conversation
'
)
+
'
</a></li>
'
+
'
<span class="icon-lock"></span>
'
+
'
<li><a class="end-otr" href="#">
'
+
__
(
'
End encrypted conversation
'
)
+
'
</a></li>
'
+
'
<li><a class="auth-otr" data-scheme="smp" href="#">
'
+
__
(
'
Verify with SMP
'
)
+
'
</a></li>
'
+
'
{[ } ]}
'
+
'
{[ } ]}
'
+
'
{[ if (otr_status ==
= "
'
+
UN
VERIFIED
+
'
") { ]}
'
+
'
{[ if (otr_status ==
"
'
+
VERIFIED
+
'
") { ]}
'
+
'
<
li><a class="auth-otr" data-scheme="fingerprint" href="#">
'
+
__
(
'
Verify with fingerprints
'
)
+
'
</a></li
>
'
+
'
<
span class="icon-lock"></span
>
'
+
'
{[ } ]}
'
+
'
{[ } ]}
'
+
'
<li><a href="http://www.cypherpunks.ca/otr/help/3.2.0/levels.php" target="_blank">
'
+
__
(
"
What
\
's this?
"
)
+
'
</a></li>
'
+
'
{[ if (otr_status == "
'
+
FINISHED
+
'
") { ]}
'
+
'
</ul>
'
+
'
<span class="icon-unlocked"></span>
'
+
'
</li>
'
),
'
{[ } ]}
'
+
'
<ul>
'
+
'
{[ if (otr_status == "
'
+
UNENCRYPTED
+
'
") { ]}
'
+
'
<li><a class="start-otr" href="#">
'
+
__
(
'
Start encrypted conversation
'
)
+
'
</a></li>
'
+
'
{[ } ]}
'
+
'
{[ if (otr_status != "
'
+
UNENCRYPTED
+
'
") { ]}
'
+
'
<li><a class="start-otr" href="#">
'
+
__
(
'
Refresh encrypted conversation
'
)
+
'
</a></li>
'
+
'
<li><a class="end-otr" href="#">
'
+
__
(
'
End encrypted conversation
'
)
+
'
</a></li>
'
+
'
<li><a class="auth-otr" data-scheme="smp" href="#">
'
+
__
(
'
Verify with SMP
'
)
+
'
</a></li>
'
+
'
{[ } ]}
'
+
'
{[ if (otr_status == "
'
+
UNVERIFIED
+
'
") { ]}
'
+
'
<li><a class="auth-otr" data-scheme="fingerprint" href="#">
'
+
__
(
'
Verify with fingerprints
'
)
+
'
</a></li>
'
+
'
{[ } ]}
'
+
'
<li><a href="http://www.cypherpunks.ca/otr/help/3.2.0/levels.php" target="_blank">
'
+
__
(
"
What
\
's this?
"
)
+
'
</a></li>
'
+
'
</ul>
'
+
'
</li>
'
+
'
{[ } ]}
'
),
message_template
:
_
.
template
(
message_template
:
_
.
template
(
'
<div class="chat-message {{extra_classes}}">
'
+
'
<div class="chat-message {{extra_classes}}">
'
+
...
@@ -723,13 +747,10 @@
...
@@ -723,13 +747,10 @@
this
.
showHelpMessages
(
msgs
);
this
.
showHelpMessages
(
msgs
);
return
;
return
;
}
}
else
if
(
match
[
1
]
===
"
otr
"
)
{
else
if
((
converse
.
allow_otr
)
||
(
match
[
1
]
===
"
otr
"
))
{
this
.
model
.
initiateOTR
();
return
this
.
model
.
initiateOTR
();
return
;
}
else
if
((
converse
.
allow_otr
)
||
(
match
[
1
]
===
"
endotr
"
))
{
}
else
if
(
match
[
1
]
===
"
endotr
"
)
{
return
this
.
endOTR
();
if
(
this
.
model
.
otr
)
{
this
.
model
.
otr
.
endOtr
();
}
}
}
}
}
if
(
_
.
contains
([
UNVERIFIED
,
VERIFIED
],
this
.
model
.
get
(
'
otr_status
'
)))
{
if
(
_
.
contains
([
UNVERIFIED
,
VERIFIED
],
this
.
model
.
get
(
'
otr_status
'
)))
{
...
@@ -821,7 +842,7 @@
...
@@ -821,7 +842,7 @@
},
},
endOTR
:
function
(
ev
)
{
endOTR
:
function
(
ev
)
{
this
.
model
.
otr
.
endOtr
();
this
.
model
.
endOTR
();
},
},
authOTR
:
function
(
ev
)
{
authOTR
:
function
(
ev
)
{
...
@@ -946,6 +967,9 @@
...
@@ -946,6 +967,9 @@
}
else
if
(
data
.
otr_status
==
FINISHED
){
}
else
if
(
data
.
otr_status
==
FINISHED
){
data
.
otr_tooltip
=
__
(
'
Your buddy has closed their end of the private session, you should do the same
'
);
data
.
otr_tooltip
=
__
(
'
Your buddy has closed their end of the private session, you should do the same
'
);
}
}
data
.
allow_otr
=
converse
.
allow_otr
;
data
.
otr_translated_status
=
OTR_TRANSLATED_MAPPING
[
data
.
otr_status
];
data
.
otr_status_class
=
OTR_CLASS_MAPPING
[
data
.
otr_status
];
this
.
$el
.
find
(
'
.chat-toolbar
'
).
html
(
this
.
toolbar_template
(
data
));
this
.
$el
.
find
(
'
.chat-toolbar
'
).
html
(
this
.
toolbar_template
(
data
));
return
this
;
return
this
;
},
},
...
@@ -2058,6 +2082,9 @@
...
@@ -2058,6 +2082,9 @@
}
}
chatbox
=
this
.
get
(
partner_jid
);
chatbox
=
this
.
get
(
partner_jid
);
roster_item
=
converse
.
roster
.
get
(
partner_jid
);
roster_item
=
converse
.
roster
.
get
(
partner_jid
);
if
(
roster_item
===
undefined
)
{
converse
.
log
(
'
Could not get roster item for JID
'
+
partner_jid
,
'
error
'
);
}
if
(
!
chatbox
)
{
if
(
!
chatbox
)
{
chatbox
=
this
.
create
({
chatbox
=
this
.
create
({
'
id
'
:
partner_jid
,
'
id
'
:
partner_jid
,
...
...
index.html
View file @
ac3ac98c
...
@@ -194,6 +194,7 @@
...
@@ -194,6 +194,7 @@
converse
.
initialize
({
converse
.
initialize
({
auto_list_rooms
:
false
,
auto_list_rooms
:
false
,
auto_subscribe
:
false
,
auto_subscribe
:
false
,
allow_otr
:
true
,
bosh_service_url
:
'
https://bind.opkode.im
'
,
// Please use this connection manager only for testing purposes
bosh_service_url
:
'
https://bind.opkode.im
'
,
// Please use this connection manager only for testing purposes
hide_muc_server
:
false
,
hide_muc_server
:
false
,
i18n
:
locales
[
'
fr
'
],
// Refer to ./locale/locales.js to see which locales are supported
i18n
:
locales
[
'
fr
'
],
// Refer to ./locale/locales.js to see which locales are supported
...
...
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