Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
Browse files Browse the repository at this point in the history
…nto clarapy-v4

* 'develop' of https://github.com/RocketChat/Rocket.Chat: (32 commits)
  Update HISTORY.md
  Fix previous commits
  Fix coffee indentation
  Fix url links
  Update requests.js
  Solves issue RocketChat#3 by validating image domain
  Solves issue RocketChat#2 using CSP
  Make Integration scripts work with Sandstorm
  LingoHub Update 🚀
  fix RocketChat#6334
  Solves issue RocketChat#1 at user input
  Improvements to multiline codeblock parsing
  Keep LingoHub ident style for JSON translations
  Screen sharing doesn't flip anymore
  update stylelint
  Hotfix closes RocketChat#6300
  lint fix
  fix RocketChat#6226
  Simple ignores the custom audio from being loaded
  open shoud open a private channel to
  ...
  • Loading branch information
John Hand authored and John Hand committed Mar 21, 2017
2 parents e8c73f5 + 1cf4562 commit 7ef3cd8
Show file tree
Hide file tree
Showing 43 changed files with 579 additions and 237 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ insert_final_newline = true
[*.{js,coffee,html,less,json}]
indent_style = tab

[*.i18n.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ rocketchat:ldap
rocketchat:lib
rocketchat:livechat
rocketchat:logger
rocketchat:login-token
rocketchat:mailer
rocketchat:mapview
rocketchat:markdown
Expand Down
1 change: 1 addition & 0 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ rocketchat:ldapjs@1.0.0
rocketchat:lib@0.0.1
rocketchat:livechat@0.0.1
rocketchat:logger@0.0.1
rocketchat:login-token@1.0.0
rocketchat:mailer@0.0.1
rocketchat:mapview@0.0.1
rocketchat:markdown@0.0.1
Expand Down
3 changes: 2 additions & 1 deletion .sandstorm/sandstorm-pkgdef.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const myCommand :Spk.Manifest.Command = (
(key = "SANDSTORM", value = "1"),
(key = "Statistics_reporting", value = "false"),
(key = "Accounts_AllowUserAvatarChange", value = "false"),
(key = "Accounts_AllowUserProfileChange", value = "false")
(key = "Accounts_AllowUserProfileChange", value = "false"),
(key = "BABEL_CACHE_DIR", value = "/var/babel_cache")
]
);
5 changes: 1 addition & 4 deletions .stylelintrc
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@
"number-no-trailing-zeros": true,
"property-case": "lower",
"property-no-unknown": true,
"rule-nested-empty-line-before": [ "always", {
"rule-empty-line-before": [ "always", {
except: ["first-nested"],
ignore: ["after-comment"],
} ],
"rule-non-nested-empty-line-before": [ "always", {
ignore: ["after-comment"],
} ],
"selector-attribute-brackets-space-inside": "never",
"selector-attribute-operator-space-after": "never",
"selector-attribute-operator-space-before": "never",
Expand Down
2 changes: 1 addition & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@
- Remove redundant Debug_level settings
- Remove the smicolon on end of 25 line (#3419)
- Send livechat webhooks
- Use <button/> rather than <i/> for tab buttons.
- Use `<button/>` rather than `<i/>` for tab buttons.

## 0.32.0 - 2016-May-30

Expand Down
7 changes: 4 additions & 3 deletions packages/rocketchat-autotranslate/client/lib/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ Meteor.startup(function() {
],
action() {
const message = this._arguments[1];
const subscription = RocketChat.models.Subscriptions.findOne({ rid: message.rid, 'u._id': Meteor.userId() });
const language = RocketChat.AutoTranslate.getLanguage(message.rid);
RocketChat.MessageAction.hideDropDown();
if ((!message.translations || !message.translations[subscription && subscription.autoTranslateLanguage]) && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[subscription.autoTranslateLanguage]; })) {
if ((!message.translations || !message.translations[language])) { //} && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; })) {
RocketChat.AutoTranslate.messageIdsToWait[message._id] = true;
RocketChat.models.Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message);
Meteor.call('autoTranslate.translateMessage', message, language);
} else if (message.autoTranslateShowInverse) {
RocketChat.models.Messages.update({ _id: message._id }, { $unset: { autoTranslateShowInverse: true } });
} else {
Expand Down
85 changes: 56 additions & 29 deletions packages/rocketchat-autotranslate/client/lib/autotranslate.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,82 @@
RocketChat.AutoTranslate = {
messageIdsToWait: {},
supportedLanguages: [],

getLanguage(rid) {
let subscription = {};
if (rid) {
subscription = RocketChat.models.Subscriptions.findOne({ rid: rid }, { fields: { autoTranslateLanguage: 1 } });
}
const language = subscription.autoTranslateLanguage || Meteor.user().language || window.defaultUserLanguage();
if (language.indexOf('-') !== -1) {
if (!_.findWhere(this.supportedLanguages, { language })) {
return language.substr(0, 2);
}
}
return language;
},

translateAttachments(attachments, language) {
for (const attachment of attachments) {
if (attachment.text && attachment.translations && attachment.translations[language]) {
attachment.text = attachment.translations[language];
}
if (attachment.author_name !== Meteor.user().username) {
if (attachment.text && attachment.translations && attachment.translations[language]) {
attachment.text = attachment.translations[language];
}

if (attachment.description && attachment.translations && attachment.translations[language]) {
attachment.description = attachment.translations[language];
}
if (attachment.description && attachment.translations && attachment.translations[language]) {
attachment.description = attachment.translations[language];
}

if (attachment.attachments && attachment.attachments.length > 0) {
attachment.attachments = this.translateAttachments(attachment.attachments, language);
if (attachment.attachments && attachment.attachments.length > 0) {
attachment.attachments = this.translateAttachments(attachment.attachments, language);
}
}
}
return attachments;
},

init() {
Meteor.call('autoTranslate.getSupportedLanguages', 'en', (err, languages) => {
this.supportedLanguages = languages || [];
});

Tracker.autorun(() => {
if (RocketChat.settings.get('AutoTranslate_Enabled') && RocketChat.authz.hasAtLeastOnePermission(['auto-translate'])) {
RocketChat.callbacks.add('renderMessage', (message) => {
const subscription = RocketChat.models.Subscriptions.findOne({ rid: message.rid }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1 } });
if (subscription && subscription.autoTranslateLanguage) {
const autoTranslateLanguage = subscription.autoTranslateLanguage;
if (message.u && message.u._id !== Meteor.userId()) {
if (!message.translations) {
message.translations = {};
const autoTranslateLanguage = this.getLanguage(message.rid);
if (message.u && message.u._id !== Meteor.userId()) {
if (!message.translations) {
message.translations = {};
}
if (subscription && subscription.autoTranslate !== message.autoTranslateShowInverse) {
message.translations['original'] = message.html;
if (message.translations[autoTranslateLanguage]) {
message.html = message.translations[autoTranslateLanguage];
}
if ((subscription.autoTranslate === true && message.autoTranslateShowInverse !== true) || (subscription.autoTranslate !== true && message.autoTranslateShowInverse === true)) {
message.translations['original'] = message.html;
if (message.translations[autoTranslateLanguage]) {
message.html = message.translations[autoTranslateLanguage];
}

if (message.attachments && message.attachments.length > 0) {
message.attachments = this.translateAttachments(message.attachments, autoTranslateLanguage);
}
if (message.attachments && message.attachments.length > 0) {
message.attachments = this.translateAttachments(message.attachments, autoTranslateLanguage);
}
} else if (message.attachments && message.attachments.length > 0) {
message.attachments = this.translateAttachments(message.attachments, autoTranslateLanguage);
}
return message;
} else if (message.attachments && message.attachments.length > 0) {
message.attachments = this.translateAttachments(message.attachments, autoTranslateLanguage);
}
return message;
}, RocketChat.callbacks.priority.HIGH - 3, 'autotranslate');

RocketChat.callbacks.add('streamMessage', (message) => {
const subscription = RocketChat.models.Subscriptions.findOne({ rid: message.rid }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1 } });
if (subscription && subscription.autoTranslate === true && subscription.autoTranslateLanguage && ((message.msg && (!message.translations || !message.translations[subscription.autoTranslateLanguage])) || (message.attachments && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[subscription.autoTranslateLanguage]; })))) {
RocketChat.models.Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
} else {
RocketChat.models.Messages.update({ _id: message._id, autoTranslateFetching: true }, { $unset: { autoTranslateFetching: 1 } });
if (message.u && message.u._id !== Meteor.userId()) {
const subscription = RocketChat.models.Subscriptions.findOne({ rid: message.rid }, { fields: { autoTranslate: 1, autoTranslateLanguage: 1 } });
const language = this.getLanguage(message.rid);
if (subscription && subscription.autoTranslate === true && ((message.msg && (!message.translations || !message.translations[language])))) { // || (message.attachments && !_.find(message.attachments, attachment => { return attachment.translations && attachment.translations[language]; }))
RocketChat.models.Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
} else if (this.messageIdsToWait[message._id] !== undefined && subscription && subscription.autoTranslate !== true) {
RocketChat.models.Messages.update({ _id: message._id }, { $set: { autoTranslateShowInverse: true }, $unset: { autoTranslateFetching: true } });
delete this.messageIdsToWait[message._id];
} else if (message.autoTranslateFetching === true) {
RocketChat.models.Messages.update({ _id: message._id }, { $unset: { autoTranslateFetching: true } });
}
}
}, RocketChat.callbacks.priority.HIGH - 3, 'autotranslate-stream');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Template.autoTranslateFlexTab.onCreated(function() {
RocketChat.models.Messages.update(query, { $unset: { autoTranslateShowInverse: 1 } }, { multi: true });
}

const display = field === 'autoTranslate' ? true : subscription.autoTranslate;
const display = field === 'autoTranslate' ? true : subscription && subscription.autoTranslate;
if (display) {
query.autoTranslateShowInverse = { $ne: true };
} else {
Expand Down
28 changes: 24 additions & 4 deletions packages/rocketchat-autotranslate/server/autotranslate.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ class AutoTranslate {
return message.msg;
}

translateMessage(message, room) {
translateMessage(message, room, targetLanguage) {
if (this.enabled && this.apiKey) {
const targetLanguages = RocketChat.models.Subscriptions.getAutoTranslateLanguagesByRoomAndNotUser(room._id, message.u && message.u._id);
let targetLanguages;
if (targetLanguage) {
targetLanguages = [ targetLanguage ];
} else {
targetLanguages = RocketChat.models.Subscriptions.getAutoTranslateLanguagesByRoomAndNotUser(room._id, message.u && message.u._id);
}
if (message.msg) {
Meteor.defer(() => {
const translations = {};
Expand All @@ -167,8 +172,19 @@ class AutoTranslate {
let msgs = targetMessage.msg.split('\n');
msgs = msgs.map(msg => encodeURIComponent(msg));
const query = `q=${msgs.join('&q=')}`;

const supportedLanguages = this.getSupportedLanguages('en');
targetLanguages.forEach(language => {
const result = HTTP.get('https://translation.googleapis.com/language/translate/v2', { params: { key: this.apiKey, target: language }, query: query });
if (language.indexOf('-') !== -1 && !_.findWhere(supportedLanguages, { language })) {
language = language.substr(0, 2);
}
let result;
try {
result = HTTP.get('https://translation.googleapis.com/language/translate/v2', { params: { key: this.apiKey, target: language }, query: query });
} catch (e) {
console.log('Error translating message', e);
return message;
}
if (result.statusCode === 200 && result.data && result.data.data && result.data.data.translations && Array.isArray(result.data.data.translations) && result.data.data.translations.length > 0) {
const txt = result.data.data.translations.map(translation => translation.translatedText).join('\n');
translations[language] = this.deTokenize(Object.assign({}, targetMessage, { msg: txt }));
Expand All @@ -188,7 +204,11 @@ class AutoTranslate {
const translations = {};
if (attachment.description || attachment.text) {
const query = `q=${encodeURIComponent(attachment.description || attachment.text)}`;
const supportedLanguages = this.getSupportedLanguages('en');
targetLanguages.forEach(language => {
if (language.indexOf('-') !== -1 && !_.findWhere(supportedLanguages, { language })) {
language = language.substr(0, 2);
}
const result = HTTP.get('https://translation.googleapis.com/language/translate/v2', { params: { key: this.apiKey, target: language }, query: query });
if (result.statusCode === 200 && result.data && result.data.data && result.data.data.translations && Array.isArray(result.data.data.translations) && result.data.data.translations.length > 0) {
const txt = result.data.data.translations.map(translation => translation.translatedText).join('\n');
Expand Down Expand Up @@ -223,7 +243,7 @@ class AutoTranslate {
result = HTTP.get('https://translation.googleapis.com/language/translate/v2/languages', { params: params });
} catch (e) {
if (e.response && e.response.statusCode === 400 && e.response.data && e.response.data.error && e.response.data.error.status === 'INVALID_ARGUMENT') {
delete params.target;
params.target = 'en';
target = 'en';
if (!this.supportedLanguages[target]) {
result = HTTP.get('https://translation.googleapis.com/language/translate/v2/languages', { params: params });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Meteor.methods({
'autoTranslate.translateMessage'(message) {
'autoTranslate.translateMessage'(message, targetLanguage) {
const room = RocketChat.models.Rooms.findOneById(message && message.rid);
if (message && room && RocketChat.AutoTranslate) {
return RocketChat.AutoTranslate.translateMessage(message, room);
return RocketChat.AutoTranslate.translateMessage(message, room, targetLanguage);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Template.channelSettings.onCreated ->
showConfirmButton: false
RocketChat.callbacks.run action, room
else
$(".channel-settings form [name='archived']").prop('checked', room.archived)
$(".channel-settings form [name='archived']").prop('checked', !!room.archived)

joinCode:
type: 'text'
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-custom-sounds/client/lib/CustomSounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class CustomSounds {
}

add(sound) {
if (Meteor.isCordova) {
return;
}

if (!sound.src) {
sound.src = this.getURL(sound);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-file-upload/server/lib/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ WebApp.connectHandlers.use('/file-upload/', function(req, res, next) {
}
}

res.setHeader('Content-Security-Policy', 'default-src \'none\'');

return FileUpload.get(file, req, res, next);
}
}
Expand Down
13 changes: 12 additions & 1 deletion packages/rocketchat-i18n/i18n/ca.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
"Accounts_OAuth_Wordpress_id": "Wordpress ID",
"Accounts_OAuth_Wordpress_secret": "Wordpress Secret",
"Accounts_PasswordReset": "Restablir contrasenya",
"Accounts_OAuth_Proxy_host": "Host del servidor intermediari (proxy)",
"Accounts_OAuth_Proxy_services": "Serveis del servidor intermediari (proxy)",
"Accounts_Registration_AuthenticationServices_Default_Roles": "Rols per defecte per als serveis d'autenticació",
"Accounts_Registration_AuthenticationServices_Default_Roles_Description": "Rols per defecte (separats per comes) que s'assignaran als usuaris quan es registrin a través dels serveis d'autenticació",
"Accounts_Registration_AuthenticationServices_Enabled": "Registre mitjançant serveis d'autenticació",
Expand Down Expand Up @@ -217,6 +219,12 @@
"AutoLinker_Urls_TLD": "Auto-enllaça URL TLD",
"AutoLinker_Urls_www": "Auto-enllaça URL 'www'",
"AutoLinker_UrlsRegExp": "Auto-enllaça URL d'expressions regulars",
"Automatic_Translation": "Traducció automàtica",
"Auto_Translate": "Autotraducció",
"AutoTranslate_Enabled": "Activa autotraducció",
"AutoTranslate_Enabled_Description": "Activar l'autotraducció permetrà a qui tingui el permís <code class=\"inline\">auto-translate</code> veure els missatges traduïts automàticament a l'idioma que seleccioni. Pot tenir càrrecs suplementaris, veure la <a target=\"_blank\" href=\"https://cloud.google.com/translate/pricing\">Documentació de Google</a>",
"AutoTranslate_Change_Language_Description": "Canviar l'idioma d'autotraducció no traduirà els missatges anteriors.",
"AutoTranslate_GoogleAPIKey": "API Key Google",
"Available": "En línia",
"Available_agents": "Agents disponibles",
"Avatar": "Avatar",
Expand Down Expand Up @@ -363,7 +371,7 @@
"Custom_Sound_Info": "Informació del so personalitzat",
"Custom_Sound_Saved_Successfully": "So personalitzat guardat correctament",
"Custom_Translations": "Traduccions personalitzades",
"Custom_Translations_Description": "Ha de ser un objecte JSON vàlid on les claus són el codi de l'idioma i contenen un diccionari de clau (key) i traduccions. Exemple:</br><code>{\n\"en\": {\n  \"key\": \"translation\"\n },\n\"ca\": {\n  \"key\": \"traducció\"\n }\n}</code> ",
"Custom_Translations_Description": "Ha de ser un objecte JSON vàlid on les claus són el codi de l'idioma i contenen un diccionari de clau i traducció. Exemple:</br><code>{\n\"en\": {\n  \"Channels\": \"Rooms\"\n },\n\"ca\": {\n  \"Channels\": \"Sales\"\n }\n}</code> ",
"CustomSoundsFilesystem": "Sistema d'arxius dels sons personalitzats",
"Dashboard": "Tauler",
"Date": "Data",
Expand Down Expand Up @@ -728,6 +736,7 @@
"Invalid_pass": "La contrasenya no ha d'estar buida",
"Invalid_room_name": "<strong>%s</strong> no és un nom de sala vàlid,<br/> utilitza només lletres, números, guions i guions baixos",
"Invalid_secret_URL_message": "L'adreça URL proporcionada no és vàlida.",
"Invalid_setting_s": "Opció invàlida: %s",
"invisible": "invisible",
"Invisible": "Invisible",
"Invitation": "Invitació",
Expand Down Expand Up @@ -1470,11 +1479,13 @@
"To_install_RocketChat_Livechat_in_your_website_copy_paste_this_code_above_the_last_body_tag_on_your_site": "Per instal·lar el xat en viu (livechat) de Rocket.Chat al teu lloc web, còpia i enganxa aquest codi damunt la darrera etiqueta <strong>&lt;/body&gt;</strong> del mateix.",
"to_see_more_details_on_how_to_integrate": "per a veure més detalls sobre com fer la integració.",
"To_users": "Per als usuaris",
"Toggle_original_translated": "Canvia original/traducció",
"Topic": "Tema",
"Travel_and_Places": "Viatges i llocs",
"Transcript_Enabled": "Pregunta als visitants si volen rebre la transcripció del xat després de tancar-lo",
"Transcript_message": "Missatge a mostrar per a la pregunta sobre la transcripció",
"Transcript_of_your_livechat_conversation": "Transcripció de la conversa de xat en viu.",
"Translated": "Traduït",
"Translations": "Traduccions",
"Trigger_removed": "Disparador eliminat",
"Trigger_Words": "Paraules d'activació",
Expand Down
Loading

0 comments on commit 7ef3cd8

Please sign in to comment.