Browse Source

Merge branch 'develop' into new-guest-access

pull/4076/head
Matthew Hodgson 5 years ago
parent
commit
a92d96347b
  1. 3
      .gitignore
  2. 15
      README.md
  3. 2
      config.sample.json
  4. 26
      docs/translating-dev.md
  5. 64
      docs/translating.md
  6. 121
      electron_app/src/electron-main.js
  7. 20
      electron_app/src/squirrelhooks.js
  8. 10
      electron_app/src/tray.js
  9. 170
      electron_app/src/vectormenu.js
  10. 122
      electron_app/src/webcontents-handler.js
  11. 1
      karma.conf.js
  12. 6
      package.json
  13. 1
      scripts/check-i18n.pl
  14. 101
      scripts/copy-res.js
  15. 2
      scripts/fetch-develop.deps.sh
  16. 8
      scripts/jenkins.sh
  17. 27
      src/components/structures/RightPanel.js
  18. 56
      src/components/structures/RoomDirectory.js
  19. 9
      src/components/structures/RoomSubList.js
  20. 3
      src/components/structures/SearchBox.js
  21. 88
      src/components/views/context_menus/MessageContextMenu.js
  22. 37
      src/components/views/context_menus/RoomTileContextMenu.js
  23. 13
      src/components/views/elements/ImageView.js
  24. 3
      src/components/views/globals/MatrixToolbar.js
  25. 17
      src/components/views/login/VectorCustomServerDialog.js
  26. 3
      src/components/views/login/VectorLoginFooter.js
  27. 35
      src/components/views/messages/DateSeparator.js
  28. 14
      src/components/views/messages/MessageTimestamp.js
  29. 14
      src/components/views/rooms/DNDRoomTile.js
  30. 57
      src/components/views/settings/Notifications.js
  31. 1
      src/i18n/strings/basefile.json
  32. 88
      src/i18n/strings/be.json
  33. 84
      src/i18n/strings/da.json
  34. 131
      src/i18n/strings/de_DE.json
  35. 122
      src/i18n/strings/en_EN.json
  36. 116
      src/i18n/strings/es.json
  37. 3
      src/i18n/strings/fi.json
  38. 124
      src/i18n/strings/fr.json
  39. 68
      src/i18n/strings/hu.json
  40. 5
      src/i18n/strings/ml.json
  41. 13
      src/i18n/strings/nb_NO.json
  42. 122
      src/i18n/strings/nl.json
  43. 1
      src/i18n/strings/pl.json
  44. 115
      src/i18n/strings/pt.json
  45. 122
      src/i18n/strings/pt_BR.json
  46. 129
      src/i18n/strings/ru.json
  47. 40
      src/i18n/strings/sv.json
  48. 1
      src/i18n/strings/zh_Hant.json
  49. 1
      src/skins/vector/css/matrix-react-sdk/structures/_FilePanel.scss
  50. 4
      src/skins/vector/css/matrix-react-sdk/structures/_UserSettings.scss
  51. 3
      src/skins/vector/css/matrix-react-sdk/structures/login/_Login.scss
  52. 1
      src/skins/vector/css/matrix-react-sdk/views/dialogs/_ConfirmUserActionDialog.scss
  53. 12
      src/skins/vector/css/matrix-react-sdk/views/rooms/_EventTile.scss
  54. 23
      src/vector/index.js
  55. 13
      src/vector/platform/ElectronPlatform.js
  56. 5
      test/app-tests/loading.js
  57. 2
      test/skin-sdk.js
  58. 2
      test/unit-tests/notifications/ContentRules-test.js
  59. 2
      test/unit-tests/notifications/PushRuleVectorState-test.js

3
.gitignore vendored

@ -12,5 +12,8 @@
/.npmrc
.DS_Store
npm-debug.log
electron/dist
electron/pub
/.idea
/config.json
/src/component-index.js

15
README.md

@ -281,6 +281,19 @@ If any of these steps error with, `file table overflow`, you are probably on a m
which has a very low limit on max open files. Run `ulimit -Sn 1024` and try again.
You'll need to do this in each new terminal you open before building Riot.
How to add a new translation?
=============================
[<img src="https://translate.nordgedanken.de/widgets/riot-web/-/multi-auto.svg" alt="translationsstatus" width="340">](https://translate.nordgedanken.de/engage/riot-web/?utm_source=widget)
Head to the [translating doc](docs/translating.md)
Adding Strings to the translations (Developer Guide)
====================================================
Head to the [translating dev doc](docs/translating-dev.md)
Triaging issues
===============
@ -300,7 +313,7 @@ bug or feature:
* feature
bug severity:
* cosmetic - feature works functionally but UI/UX is broken
* critical - whole app doesn't work
* major - entire feature doesn't work

2
config.sample.json

@ -11,5 +11,5 @@
"matrix.org"
]
},
"welcomeUserId": "@RiotBot:matrix.org"
"welcomeUserId": "@riot-bot:matrix.org"
}

26
docs/translating-dev.md

@ -0,0 +1,26 @@
# How to translate riot-web (Dev Guide)
## Requirements
- A working [Development Setup](../../#setting-up-a-dev-environment)
- Be able to understand English
- Be able to understand the language you want to translate riot-web into
## Adding new strings
1. Check if the import ``import _t from 'counterpart-riot'`` is present. If not add it to the other import statements.
2. Add ``_t()`` to your string. (Don't forget curly braces when you assign an expression to JSX attributes in the render method)
3. Add the String to the ``en_EN.json`` file in ``src/i18n`` or if you are working in matrix-react-sdk you can find the json file in ``src/i18n/strings``
## Adding variables inside a string.
1. Extend your ``_t()`` call. Instead of ``_t(STRING)`` use ``_t(STRING, {})``
2. Decide how to name it. Please think about if the person who has to translate it can understand what it does.
3. Add it to the array in ``_t`` for example ``_t(STRING, {variable: this.variable})``
4. Add the variable inside the string. The syntax for variables is ``%(variable)s``. Please note the s at the end. The name of the variable has to match the previous used name.
## Things to know/Style Guides
- Do not use it inside ``getDefaultProps`` at the point where ``getDefaultProps`` is initialized the translations aren't loaded yet and it causes missing translations.
- If using translated strings as constants, translated strings can't be in constants loaded at class-load time since the translations won't be loaded.
- If a string is presented in the UI with punctuation like a full stop, include this in the translation strings, since punctuation varies between languages too.

64
docs/translating.md

@ -0,0 +1,64 @@
# How to translate riot-web
## Requirements
- Web Browser
- Be able to understand English
- Be able to understand the language you want to translate riot-web into
## Step 0: Join #riotweb-translations:matrix.org
1. Come and join https://riot.im/develop/#/room/#riotweb-translations:matrix.org
2. Read scrollback and/or ask if anyone else is working on your language, and co-ordinate if needed. In general little-or-no coordination is needed though :)
## Step 1: Preparing your Weblate Profile
1. Head to https://translate.nordgedanken.de and register either via Github or email
2. After registering check if you got an email to verify your account and click the link (if there is none head to step 1.4)
3. Log into weblate
4. Head to https://translate.nordgedanken.de/accounts/profile/ and select the languages you know and maybe another language you know too.
6. Head to https://translate.nordgedanken.de/accounts/profile/#subscriptions and select Riot Web as Project
## How to check if your language already is being translated
Go to https://translate.nordgedanken.de/projects/riot-web/ and visit the 2 sub-projects.
If your language is listed go to Step 2a and if not go to Step 2b
## Step 2a: Helping on existing languages.
1. Head to one of the projects listed https://translate.nordgedanken.de/projects/riot-web/
2. Click on the ``translate`` button on the right side of your language
3. Fill in the translations in the writeable field. You will see the original English string and the string of your second language above.
Head to the explanations under Steb 2b
## Step 2b: Adding a new language
1. Go to one of the projects listed https://translate.nordgedanken.de/projects/riot-web/
2. Click the ``Start new language`` button at the bottom
3. Select a language
4. Start translating like in 2a.3
5. Repeat these steps for the other projects which are listed at the link of step 2b.1
### What means the green button under the text field?
The green button let you save our translations directly. Please only use it if you are 100% sure about that translation. If you do not know a translation please DO NOT click that button. Use the arrows above the translations field and click to the right.
### What means the yellow button under the text field?
The yellow button has to be used if you are unsure about the translation but you have a rough idea. It adds a new suggestion to the string which can than be reviewed by others.
### What are "%(something)s"?
These things are variables that are expanded when displayed by Riot. They can be room names, usernames or similar. If you find one, you can move to the right place for your language, but not delete it as the variable will be missing if you do.
A special case is `%(urlStart)s` and `%(urlEnd)s` which are used to mark the beginning of a hyperlink (i.e. `<a href="/somewhere">` and `</a>`. You must keep these markers surrounding the equivalent string in your language that needs to be hyperlinked.
### "I want to come back to this string. How?"
You can use inside the translation field "Review needed" checkbox. It will be shown as Strings that need to be reviewed.
### Further reading
The official Weblate doc provides some more in-deepth explanation on how to do translations and talks about do and don'ts. You can find it at: https://docs.weblate.org/en/latest/user/translating.html

121
electron_app/src/electron-main.js

@ -1,5 +1,3 @@
// @flow
/*
Copyright 2016 Aviral Dasgupta
Copyright 2016 OpenMarket Ltd
@ -20,15 +18,14 @@ limitations under the License.
// Squirrel on windows starts the app with various flags
// as hooks to tell us when we've been installed/uninstalled
// etc.
const check_squirrel_hooks = require('./squirrelhooks');
if (check_squirrel_hooks()) return;
const checkSquirrelHooks = require('./squirrelhooks');
if (checkSquirrelHooks()) return;
const electron = require('electron');
const url = require('url');
const tray = require('./tray');
const VectorMenu = require('./vectormenu');
const vectorMenu = require('./vectormenu');
const webContentsHandler = require('./webcontents-handler');
const windowStateKeeper = require('electron-window-state');
@ -42,12 +39,6 @@ try {
// Continue with the defaults (ie. an empty config)
}
const PERMITTED_URL_SCHEMES = [
'http:',
'https:',
'mailto:',
];
const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000;
const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
@ -59,13 +50,13 @@ function safeOpenURL(target) {
// so put fairly stringent limits on what can be opened
// (for instance, open /bin/sh does indeed open a terminal
// with a shell, albeit with no arguments)
const parsed_url = url.parse(target);
if (PERMITTED_URL_SCHEMES.indexOf(parsed_url.protocol) > -1) {
const parsedUrl = url.parse(target);
if (PERMITTED_URL_SCHEMES.indexOf(parsedUrl.protocol) > -1) {
// explicitly use the URL re-assembled by the url library,
// so we know the url parser has understood all the parts
// of the input string
const new_target = url.format(parsed_url);
electron.shell.openExternal(new_target);
const newTarget = url.format(parsedUrl);
electron.shell.openExternal(newTarget);
}
}
@ -79,20 +70,19 @@ function onWindowOrNavigate(ev, target) {
}
function onLinkContextMenu(ev, params) {
const popup_menu = new electron.Menu();
popup_menu.append(new electron.MenuItem({
const popupMenu = new electron.Menu();
popupMenu.append(new electron.MenuItem({
label: params.linkURL,
click() {
safeOpenURL(params.linkURL);
},
click() { safeOpenURL(params.linkURL); },
}));
popup_menu.append(new electron.MenuItem({
popupMenu.append(new electron.MenuItem({
label: 'Copy Link Address',
click() {
electron.clipboard.writeText(params.linkURL);
},
click() { electron.clipboard.writeText(params.linkURL); },
}));
popup_menu.popup();
popupMenu.popup();
ev.preventDefault();
}
@ -107,13 +97,13 @@ function pollForUpdates() {
try {
electron.autoUpdater.checkForUpdates();
} catch (e) {
console.log("Couldn't check for update", e);
console.log('Couldn\'t check for update', e);
}
}
function startAutoUpdate(update_base_url) {
if (update_base_url.slice(-1) !== '/') {
update_base_url = update_base_url + '/';
function startAutoUpdate(updateBaseUrl) {
if (updateBaseUrl.slice(-1) !== '/') {
updateBaseUrl = updateBaseUrl + '/';
}
try {
// For reasons best known to Squirrel, the way it checks for updates
@ -121,7 +111,7 @@ function startAutoUpdate(update_base_url) {
// hits a URL that either gives it a 200 with some json or
// 204 No Content. On windows it takes a base path and looks for
// files under that path.
if (process.platform == 'darwin') {
if (process.platform === 'darwin') {
// include the current version in the URL we hit. Electron doesn't add
// it anywhere (apart from the User-Agent) so it's up to us. We could
// (and previously did) just use the User-Agent, but this doesn't
@ -129,16 +119,15 @@ function startAutoUpdate(update_base_url) {
// and also acts as a convenient cache-buster to ensure that when the
// app updates it always gets a fresh value to avoid update-looping.
electron.autoUpdater.setFeedURL(
update_base_url +
'macos/?localVersion=' + encodeURIComponent(electron.app.getVersion())
);
} else if (process.platform == 'win32') {
electron.autoUpdater.setFeedURL(update_base_url + 'win32/' + process.arch + '/');
`${updateBaseUrl}macos/?localVersion=${encodeURIComponent(electron.app.getVersion())}`);
} else if (process.platform === 'win32') {
electron.autoUpdater.setFeedURL(`${updateBaseUrl}win32/${process.arch}/`);
} else {
// Squirrel / electron only supports auto-update on these two platforms.
// I'm not even going to try to guess which feed style they'd use if they
// implemented it on Linux, or if it would be different again.
console.log("Auto update not supported on this platform");
console.log('Auto update not supported on this platform');
}
// We check for updates ourselves rather than using 'updater' because we need to
// do it in the main process (and we don't really need to check every 10 minutes:
@ -151,7 +140,7 @@ function startAutoUpdate(update_base_url) {
setInterval(pollForUpdates, UPDATE_POLL_INTERVAL_MS);
} catch (err) {
// will fail if running in debug mode
console.log("Couldn't enable update checking", err);
console.log('Couldn\'t enable update checking', err);
}
}
@ -162,7 +151,7 @@ function startAutoUpdate(update_base_url) {
// Assuming we generally run from the console when developing,
// this is far preferable.
process.on('uncaughtException', function(error) {
console.log("Unhandled exception", error);
console.log('Unhandled exception', error);
});
electron.ipcMain.on('install_update', installUpdate);
@ -186,6 +175,24 @@ electron.ipcMain.on('setBadgeCount', function(ev, count) {
}
});
let powerSaveBlockerId;
electron.ipcMain.on('app_onAction', function(ev, payload) {
switch (payload.action) {
case 'call_state':
if (powerSaveBlockerId && powerSaveBlockerId.isStarted(powerSaveBlockerId)) {
if (payload.state === 'ended') {
electron.powerSaveBlocker.stop(powerSaveBlockerId);
}
} else {
if (payload.state === 'connected') {
powerSaveBlockerId = electron.powerSaveBlocker.start('prevent-display-sleep');
}
}
break;
}
});
electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => {
@ -198,30 +205,28 @@ const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirector
});
if (shouldQuit) {
console.log("Other instance detected: exiting");
electron.app.quit()
console.log('Other instance detected: exiting');
electron.app.quit();
}
electron.app.on('ready', () => {
if (vectorConfig.update_base_url) {
console.log("Starting auto update with base URL: " + vectorConfig.update_base_url);
console.log(`Starting auto update with base URL: ${vectorConfig.update_base_url}`);
startAutoUpdate(vectorConfig.update_base_url);
} else {
console.log("No update_base_url is defined: auto update is disabled");
console.log('No update_base_url is defined: auto update is disabled');
}
const icon_path = `${__dirname}/../img/riot.` + (
process.platform == 'win32' ? 'ico' : 'png'
);
const iconPath = `${__dirname}/../img/riot.${process.platform === 'win32' ? 'ico' : 'png'}`;
// Load the previous window state with fallback to defaults
let mainWindowState = windowStateKeeper({
const mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 768,
});
mainWindow = new electron.BrowserWindow({
icon: icon_path,
icon: iconPath,
show: false,
autoHideMenuBar: true,
@ -231,12 +236,12 @@ electron.app.on('ready', () => {
height: mainWindowState.height,
});
mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`);
electron.Menu.setApplicationMenu(VectorMenu);
electron.Menu.setApplicationMenu(vectorMenu);
// Create trayIcon icon
tray.create(mainWindow, {
icon_path: icon_path,
brand: vectorConfig.brand || 'Riot'
icon_path: iconPath,
brand: vectorConfig.brand || 'Riot',
});
if (!process.argv.includes('--hidden')) {
@ -249,7 +254,7 @@ electron.app.on('ready', () => {
mainWindow = null;
});
mainWindow.on('close', (e) => {
if (!appQuitting && (tray.hasTray() || process.platform == 'darwin')) {
if (!appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
// On Mac, closing the window just hides it
// (this is generally how single-window Mac apps
// behave, eg. Mail.app)
@ -259,15 +264,7 @@ electron.app.on('ready', () => {
}
});
mainWindow.webContents.on('new-window', onWindowOrNavigate);
mainWindow.webContents.on('will-navigate', onWindowOrNavigate);
mainWindow.webContents.on('context-menu', function(ev, params) {
if (params.linkURL) {
onLinkContextMenu(ev, params);
}
});
webContentsHandler(mainWindow.webContents);
mainWindowState.manage(mainWindow);
});

20
electron_app/src/squirrelhooks.js

@ -16,30 +16,30 @@ limitations under the License.
const path = require('path');
const spawn = require('child_process').spawn;
const app = require('electron').app;
const {app} = require('electron');
function run_update_exe(args, done) {
function runUpdateExe(args, done) {
// Invokes Squirrel's Update.exe which will do things for us like create shortcuts
// Note that there's an Update.exe in the app-x.x.x directory and one in the parent
// directory: we need to run the one in the parent directory, because it discovers
// information about the app by inspecting the directory it's run from.
const updateExe = path.resolve(path.dirname(process.execPath), '..', 'Update.exe');
console.log('Spawning `%s` with args `%s`', updateExe, args);
console.log(`Spawning '${updateExe}' with args '${args}'`);
spawn(updateExe, args, {
detached: true
detached: true,
}).on('close', done);
};
}
function check_squirrel_hooks() {
if (process.platform != 'win32') return false;
function checkSquirrelHooks() {
if (process.platform !== 'win32') return false;
const cmd = process.argv[1];
const target = path.basename(process.execPath);
if (cmd === '--squirrel-install' || cmd === '--squirrel-updated') {
run_update_exe(['--createShortcut=' + target + ''], app.quit);
runUpdateExe(['--createShortcut=' + target + ''], app.quit);
return true;
} else if (cmd === '--squirrel-uninstall') {
run_update_exe(['--removeShortcut=' + target + ''], app.quit);
runUpdateExe(['--removeShortcut=' + target + ''], app.quit);
return true;
} else if (cmd === '--squirrel-obsolete') {
app.quit();
@ -48,4 +48,4 @@ function check_squirrel_hooks() {
return false;
}
module.exports = check_squirrel_hooks;
module.exports = checkSquirrelHooks;

10
electron_app/src/tray.js

@ -25,9 +25,7 @@ exports.hasTray = function hasTray() {
exports.create = function(win, config) {
// no trays on darwin
if (process.platform === 'darwin' || trayIcon) {
return;
}
if (process.platform === 'darwin' || trayIcon) return;
const toggleWin = function() {
if (win.isVisible() && !win.isMinimized()) {
@ -41,12 +39,10 @@ exports.create = function(win, config) {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show/Hide ' + config.brand,
label: `Show/Hide ${config.brand}`,
click: toggleWin,
},
{
type: 'separator',
},
{ type: 'separator' },
{
label: 'Quit',
click: function() {

170
electron_app/src/vectormenu.js

@ -14,170 +14,112 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
const electron = require('electron');
const {app, shell, Menu} = require('electron');
// Menu template from http://electron.atom.io/docs/api/menu/, edited
const template = [
{
label: 'Edit',
submenu: [
{
role: 'undo'
},
{
role: 'redo'
},
{
type: 'separator'
},
{
role: 'cut'
},
{
role: 'copy'
},
{
role: 'paste'
},
{
role: 'pasteandmatchstyle'
},
{
role: 'delete'
},
{
role: 'selectall'
}
]
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' },
],
},
{
label: 'View',
submenu: [
{
type: 'separator'
},
{
role: 'resetzoom'
},
{
role: 'zoomin'
},
{
role: 'zoomout'
},
{
type: 'separator'
},
{
role: 'togglefullscreen'
},
{
role: 'toggledevtools'
}
]
{ type: 'separator' },
{ role: 'resetzoom' },
{ role: 'zoomin' },
{ role: 'zoomout' },
{ type: 'separator' },
{ role: 'togglefullscreen' },
{ role: 'toggledevtools' },
],
},
{
role: 'window',
submenu: [
{
role: 'minimize'
},
{
role: 'close'
}
]
{ role: 'minimize' },
{ role: 'close' },
],
},
{
role: 'help',
submenu: [
{
label: 'riot.im',
click () { electron.shell.openExternal('https://riot.im/') }
}
]
}
click() { shell.openExternal('https://riot.im/'); },
},
],
},
];
// macOS has specific menu conventions...
if (process.platform === 'darwin') {
// first macOS menu is the name of the app
const name = electron.app.getName()
const name = app.getName();
template.unshift({
label: name,
submenu: [
{
role: 'about'
},
{
type: 'separator'
},
{ role: 'about' },
{ type: 'separator' },
{
role: 'services',
submenu: []
},
{
type: 'separator'
},
{
role: 'hide'
},
{
role: 'hideothers'
},
{
role: 'unhide'
},
{
type: 'separator'
},
{
role: 'quit'
}
]
})
submenu: [],
},
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
});
// Edit menu.
// This has a 'speech' section on macOS
template[1].submenu.push(
{
type: 'separator'
},
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{
role: 'startspeaking'
},
{
role: 'stopspeaking'
}
]
}
)
{ role: 'startspeaking' },
{ role: 'stopspeaking' },
],
});
// Window menu.
// This also has specific functionality on macOS
template[3].submenu = [
{
label: 'Close',
accelerator: 'CmdOrCtrl+W',
role: 'close'
role: 'close',
},
{
label: 'Minimize',
accelerator: 'CmdOrCtrl+M',
role: 'minimize'
role: 'minimize',
},
{
label: 'Zoom',
role: 'zoom'
role: 'zoom',
},
{
type: 'separator'
type: 'separator',
},
{
label: 'Bring All to Front',
role: 'front'
}
]
role: 'front',
},
];
} else {
template.unshift({
label: 'File',
@ -186,12 +128,10 @@ if (process.platform === 'darwin') {
/*{
role: 'about'
},*/
{
role: 'quit'
}
]
{ role: 'quit' },
],
});
}
module.exports = electron.Menu.buildFromTemplate(template)
module.exports = Menu.buildFromTemplate(template);

122
electron_app/src/webcontents-handler.js

@ -0,0 +1,122 @@
const {clipboard, nativeImage, Menu, MenuItem, shell} = require('electron');
const url = require('url');
const PERMITTED_URL_SCHEMES = [
'http:',
'https:',
'mailto:',
];
function safeOpenURL(target) {
// openExternal passes the target to open/start/xdg-open,
// so put fairly stringent limits on what can be opened
// (for instance, open /bin/sh does indeed open a terminal
// with a shell, albeit with no arguments)
const parsedUrl = url.parse(target);
if (PERMITTED_URL_SCHEMES.indexOf(parsedUrl.protocol) > -1) {
// explicitly use the URL re-assembled by the url library,
// so we know the url parser has understood all the parts
// of the input string
const newTarget = url.format(parsedUrl);
shell.openExternal(newTarget);
}
}
function onWindowOrNavigate(ev, target) {
// always prevent the default: if something goes wrong,
// we don't want to end up opening it in the electron
// app, as we could end up opening any sort of random
// url in a window that has node scripting access.
ev.preventDefault();
safeOpenURL(target);
}
function onLinkContextMenu(ev, params) {
const url = params.linkURL || params.srcURL;
const popupMenu = new Menu();
popupMenu.append(new MenuItem({
label: url,
click() {
safeOpenURL(url);
},
}));
if (params.mediaType && params.mediaType === 'image' && !url.startsWith('file://')) {
popupMenu.append(new MenuItem({
label: 'Copy Image',
click() {
if (url.startsWith('data:')) {
clipboard.writeImage(nativeImage.createFromDataURL(url));
} else {
ev.sender.copyImageAt(params.x, params.y);
}
},
}));
}
popupMenu.append(new MenuItem({
label: 'Copy Link Address',
click() {
clipboard.writeText(url);
},
}));
popupMenu.popup();
ev.preventDefault();
}
function _CutCopyPasteSelectContextMenus(params) {
return [{
role: 'cut',
enabled: params.editFlags.canCut,
}, {
role: 'copy',
enabled: params.editFlags.canCopy,
}, {
role: 'paste',
enabled: params.editFlags.canPaste,
}, {
role: 'pasteandmatchstyle',
enabled: params.editFlags.canPaste,
}, {
role: 'selectall',
enabled: params.editFlags.canSelectAll,
}];
}
function onSelectedContextMenu(ev, params) {
const items = _CutCopyPasteSelectContextMenus(params);
const popupMenu = Menu.buildFromTemplate(items);
popupMenu.popup();
ev.preventDefault();
}
function onEditableContextMenu(ev, params) {
const items = [
{ role: 'undo' },
{ role: 'redo', enabled: params.editFlags.canRedo },
{ type: 'separator' },
].concat(_CutCopyPasteSelectContextMenus(params));
const popupMenu = Menu.buildFromTemplate(items);
popupMenu.popup();
ev.preventDefault();
}
module.exports = (webContents) => {
webContents.on('new-window', onWindowOrNavigate);
webContents.on('will-navigate', onWindowOrNavigate);
webContents.on('context-menu', function(ev, params) {
if (params.linkURL || params.srcURL) {
onLinkContextMenu(ev, params);
} else if (params.selectionText) {
onSelectedContextMenu(ev, params);
} else if (params.isEditable) {
onEditableContextMenu(ev, params);
}
});
};

1
karma.conf.js

@ -47,7 +47,6 @@ webpack_config.module.noParse.push(/sinon\/pkg\/sinon\.js$/);
webpack_config.resolve.alias['sinon'] = 'sinon/pkg/sinon.js';
webpack_config.resolve.root = [
path.resolve('./src'),
path.resolve('./test'),
];

6
package.json

@ -65,8 +65,8 @@
"gfm.css": "^1.1.1",
"highlight.js": "^9.0.0",
"linkifyjs": "^2.1.3",
"matrix-js-sdk": "0.7.8",
"matrix-react-sdk": "0.8.9",
"matrix-js-sdk": "matrix-org/matrix-js-sdk#develop",
"matrix-react-sdk": "matrix-org/matrix-react-sdk#develop",
"modernizr": "^3.1.0",
"pako": "^1.0.5",
"q": "^1.4.1",
@ -104,6 +104,7 @@
"emojione": "^2.2.7",
"eslint": "^3.14.0",
"eslint-config-google": "^0.7.1",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flowtype": "^2.30.0",
"eslint-plugin-react": "^6.9.0",
"expect": "^1.16.0",
@ -158,6 +159,7 @@
],
"linux": {
"target": "deb",
"category": "Network;InstantMessaging;Chat",
"maintainer": "support@riot.im",
"desktop": {
"StartupWMClass": "riot-web"

1
scripts/check-i18n.pl

@ -0,0 +1 @@
../../matrix-react-sdk/scripts/check-i18n.pl

101
scripts/copy-res.js

@ -3,6 +3,23 @@
// copies the resources into the webapp directory.
//
// Languages are listed manually so we can choose when to include
// a translation in the app (because having a translation with only
// 3 strings translated is just frustrating)
// This could readily be automated, but it's nice to explicitly
// control when we languages are available.
const INCLUDE_LANGS = [
//'be' Omitted because no translations in react-sdk
'en_EN',
'da',
'de_DE',
'fr',
'be',
'pt',
'pt_BR',
'ru',
];
// cpx includes globbed parts of the filename in the destination, but excludes
// common parents. Hence, "res/{a,b}/**": the output will be "dest/a/..." and
// "dest/b/...".
@ -14,12 +31,20 @@ const COPY_LIST = [
["src/skins/vector/{fonts,img}/**", "webapp"],
["node_modules/emojione/assets/svg/*", "webapp/emojione/svg/"],
["node_modules/emojione/assets/png/*", "webapp/emojione/png/"],
["./config.json", "webapp", {directwatch: 1}],
["./config.json", "webapp", { directwatch: 1 }],
];
INCLUDE_LANGS.forEach(function(l) {
COPY_LIST.push([
l, "webapp/i18n/", { lang: 1 },
]);
});
const parseArgs = require('minimist');
const Cpx = require('cpx');
const chokidar = require('chokidar');
const fs = require('fs');
const rimraf = require('rimraf');
const argv = parseArgs(
process.argv.slice(2), {}
@ -35,6 +60,15 @@ function errCheck(err) {
}
}
// Check if webapp exists
if (!fs.existsSync('webapp')) {
fs.mkdirSync('webapp');
}
// Check if i18n exists
if (!fs.existsSync('webapp/i18n/')) {
fs.mkdirSync('webapp/i18n/');
}
function next(i, err) {
errCheck(err);
@ -46,10 +80,13 @@ function next(i, err) {
const source = ent[0];
const dest = ent[1];
const opts = ent[2] || {};
let cpx = undefined;
const cpx = new Cpx.Cpx(source, dest);
if (!opts.lang) {
cpx = new Cpx.Cpx(source, dest);
}
if (verbose) {
if (verbose && cpx) {
cpx.on("copy", (event) => {
console.log(`Copied: ${event.srcPath} --> ${event.dstPath}`);
});
@ -58,7 +95,7 @@ function next(i, err) {
});
}
const cb = (err) => {next(i+1, err)};
const cb = (err) => { next(i + 1, err) };
if (watch) {
if (opts.directwatch) {
@ -66,20 +103,74 @@ function next(i, err) {
// which in the case of config.json is '.', which inevitably takes
// ages to crawl. So we create our own watcher on the files
// instead.
const copy = () => {cpx.copy(errCheck)};
const copy = () => { cpx.copy(errCheck) };
chokidar.watch(source)
.on('add', copy)
.on('change', copy)
.on('ready', cb)
.on('error', errCheck);
} else if (opts.lang) {
const reactSdkFile = 'node_modules/matrix-react-sdk/src/i18n/strings/' + source + '.json';
const riotWebFile = 'src/i18n/strings/' + source + '.json';
const translations = {};
const makeLang = () => { genLangFile(source, dest) };
[reactSdkFile, riotWebFile].forEach(function(f) {
chokidar.watch(f)
.on('add', makeLang)
.on('change', makeLang)
//.on('ready', cb) We'd have to do this when both files are ready
.on('error', errCheck);
});
next(i + 1, err);
} else {
cpx.on('watch-ready', cb);
cpx.on("watch-error", cb);
cpx.watch();
}
} else if (opts.lang) {
genLangFile(source, dest);
next(i + 1, err);
} else {
cpx.copy(cb);
}
}
function genLangFile(lang, dest) {
const reactSdkFile = 'node_modules/matrix-react-sdk/src/i18n/strings/' + lang + '.json';
const riotWebFile = 'src/i18n/strings/' + lang + '.json';
const translations = {};
[reactSdkFile, riotWebFile].forEach(function(f) {
if (fs.existsSync(f)) {
Object.assign(
translations,
JSON.parse(fs.readFileSync(f).toString())
);
}
});
fs.writeFileSync(dest + lang + '.json', JSON.stringify(translations, null, 4));
if (verbose) {
console.log("Generated language file: " + lang);
}
}
function genLangList() {
const languages = {};
INCLUDE_LANGS.forEach(function(lang) {
const normalizedLanguage = lang.toLowerCase().replace("_", "-");
const languageParts = normalizedLanguage.split('-');
if (languageParts.length == 2 && languageParts[0] == languageParts[1]) {
languages[languageParts[0]] = lang + '.json';
} else {
languages[normalizedLanguage] = lang + '.json';
}
});
fs.writeFile('webapp/i18n/languages.json', JSON.stringify(languages, null, 4));
if (verbose) {
console.log("Generated language list");
}
}
genLangList();
next(0);

2
scripts/fetch-develop.deps.sh

@ -40,11 +40,13 @@ dodep matrix-org matrix-react-sdk
mkdir -p node_modules
cd node_modules
rm -r matrix-js-sdk 2> /dev/null
ln -s ../matrix-js-sdk ./
pushd matrix-js-sdk
npm install
popd
rm -r matrix-react-sdk 2> /dev/null
ln -s ../matrix-react-sdk ./
pushd matrix-react-sdk
mkdir -p node_modules

8
scripts/jenkins.sh

@ -34,11 +34,9 @@ npm run lintall -- -f checkstyle -o eslint.xml || true
rm dist/riot-*.tar.gz || true # rm previous artifacts without failing if it doesn't exist
# node_modules deps from 'npm install' don't have a .git dir so can't
# rev-parse; but they do set the commit in package.json under 'gitHead' which
# we're grabbing here.
REACT_SHA=$(grep 'gitHead' node_modules/matrix-react-sdk/package.json | cut -d \" -f 4 | head -c 12)
JSSDK_SHA=$(grep 'gitHead' node_modules/matrix-js-sdk/package.json | cut -d \" -f 4 | head -c 12)
# Since the deps are fetched from git, we can rev-parse
REACT_SHA=$(cd node_modules/matrix-react-sdk; git rev-parse --short=12 HEAD)
JSSDK_SHA=$(cd node_modules/matrix-js-sdk; git rev-parse --short=12 HEAD)
VECTOR_SHA=$(git rev-parse --short=12 HEAD) # use the ACTUAL SHA rather than assume develop

27
src/components/structures/RightPanel.js

@ -16,14 +16,15 @@ limitations under the License.
'use strict';
var React = require('react');
var sdk = require('matrix-react-sdk');
var Matrix = require("matrix-js-sdk");
var dis = require('matrix-react-sdk/lib/dispatcher');
var MatrixClientPeg = require("matrix-react-sdk/lib/MatrixClientPeg");
var rate_limited_func = require('matrix-react-sdk/lib/ratelimitedfunc');
var Modal = require('matrix-react-sdk/lib/Modal');
var AccessibleButton = require('matrix-react-sdk/lib/components/views/elements/AccessibleButton');
import React from 'react';
import { _t } from 'matrix-react-sdk/lib/languageHandler';
import sdk from 'matrix-react-sdk';
import Matrix from "matrix-js-sdk";
import dis from 'matrix-react-sdk/lib/dispatcher';
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
import rate_limited_func from 'matrix-react-sdk/lib/ratelimitedfunc';
import Modal from 'matrix-react-sdk/lib/Modal';
import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton';
module.exports = React.createClass({
displayName: 'RightPanel',
@ -34,7 +35,7 @@ module.exports = React.createClass({
collapsed: React.PropTypes.bool, // currently unused property to request for a minimized view of the panel
},
Phase : {
Phase: {
MemberList: 'MemberList',
FilePanel: 'FilePanel',
NotificationPanel: 'NotificationPanel',
@ -188,7 +189,7 @@ module.exports = React.createClass({
<div className="mx_RightPanel_icon" >
<TintableSvg src="img/icon-invite-people.svg" width="35" height="35" />
</div>
<div className="mx_RightPanel_message">Invite to this room</div>
<div className="mx_RightPanel_message">{ _t('Invite to this room') }</div>
</AccessibleButton>;
}
@ -198,21 +199,21 @@ module.exports = React.createClass({
buttonGroup =
<div className="mx_RightPanel_headerButtonGroup">
<AccessibleButton className="mx_RightPanel_headerButton"
title="Members" onClick={ this.onMemberListButtonClick }>
title={ _t('Members') } onClick={ this.onMemberListButtonClick }>
<div className="mx_RightPanel_headerButton_badge">{ membersBadge ? membersBadge : <span>&nbsp;</span>}</div>
<TintableSvg src="img/icons-people.svg" width="25" height="25"/>
{ membersHighlight }
</AccessibleButton>
<AccessibleButton
className="mx_RightPanel_headerButton mx_RightPanel_filebutton"
title="Files" onClick={ this.onFileListButtonClick }>
title={ _t('Files') } onClick={ this.onFileListButtonClick }>
<div className="mx_RightPanel_headerButton_badge">&nbsp;</div>
<TintableSvg src="img/icons-files.svg" width="25" height="25"/>
{ filesHighlight }
</AccessibleButton>
<AccessibleButton
className="mx_RightPanel_headerButton mx_RightPanel_notificationbutton"
title="Notifications" onClick={ this.onNotificationListButtonClick }>
title={ _t('Notifications') } onClick={ this.onNotificationListButtonClick }>
<div className="mx_RightPanel_headerButton_badge">&nbsp;</div>
<TintableSvg src="img/icons-notifications.svg" width="25" height="25"/>
{ notificationsHighlight }

56
src/components/structures/RoomDirectory.js

@ -30,6 +30,8 @@ var linkifyMatrix = require('matrix-react-sdk/lib/linkify-matrix');
var sanitizeHtml = require('sanitize-html');
var q = require('q');
import { _t } from 'matrix-react-sdk/lib/languageHandler';
import {instanceForInstanceId, protocolNameForInstanceId} from '../../utils/DirectoryUtils';
linkifyMatrix(linkify);
@ -80,8 +82,8 @@ module.exports = React.createClass({
}
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
title: "Failed to get protocol list from Home Server",
description: "The Home Server may be too old to support third party networks",
title: _t('Failed to get protocol list from Home Server'),
description: _t('The Home Server may be too old to support third party networks'),
});
});
@ -176,8 +178,8 @@ module.exports = React.createClass({
console.error("Failed to get publicRooms: %s", JSON.stringify(err));
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
title: "Failed to get public room list",
description: ((err && err.message) ? err.message : "The server may be unavailable or overloaded"),
title: _t('Failed to get public room list'),
description: ((err && err.message) ? err.message : _t('The server may be unavailable or overloaded'))
});
});
},
@ -191,31 +193,31 @@ module.exports = React.createClass({
*/
removeFromDirectory: function(room) {
var alias = get_display_alias_for_room(room);
var name = room.name || alias || "Unnamed room";
var name = room.name || alias || _t('Unnamed room');
var QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
var desc;
if (alias) {
desc = `Delete the room alias '${alias}' and remove '${name}' from the directory?`;
desc = _t('Delete the room alias %(alias)s and remove %(name)s from the directory?', {alias: alias, name: name});
} else {
desc = `Remove '${name}' from the directory?`;
desc = _t('Remove %(name)s from the directory?', {name: name});
}
Modal.createDialog(QuestionDialog, {
title: "Remove from Directory",
title: _t('Remove from Directory'),
description: desc,
onFinished: (should_delete) => {
if (!should_delete) return;
var Loader = sdk.getComponent("elements.Spinner");
var modal = Modal.createDialog(Loader);
var step = `remove '${name}' from the directory.`;
var step = _t('remove %(name)s from the directory', {name: name}) + '.';
MatrixClientPeg.get().setRoomDirectoryVisibility(room.room_id, 'private').then(() => {
if (!alias) return;
step = 'delete the alias.';
step = _t('delete the alias') + '.';
return MatrixClientPeg.get().deleteAlias(alias);
}).done(() => {
modal.close();
@ -225,8 +227,8 @@ module.exports = React.createClass({
this.refreshRoomList();
console.error("Failed to " + step + ": " + err);
Modal.createDialog(ErrorDialog, {
title: "Failed to " + step,
description: ((err && err.message) ? err.message : "The server may be unavailable or overloaded"),
title: _t('Error'),
description: ((err && err.message) ? err.message : _t('The server may be unavailable or overloaded'))
});
});
}
@ -314,8 +316,8 @@ module.exports = React.createClass({
if (!fields) {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
title: "Unable to join network",
description: "Riot does not know how to join a room on this network",
title: _t('Unable to join network'),
description: _t('Riot does not know how to join a room on this network'),
});
return;
}
@ -325,15 +327,15 @@ module.exports = React.createClass({
} else {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
title: "Room not found",
description: "Couldn't find a matching Matrix room",
title: _t('Room not found'),
description: _t('Couldn\'t find a matching Matrix room'),
});
}
}, (e) => {
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
Modal.createDialog(ErrorDialog, {
title: "Fetching third party location failed",
description: "Unable to look up room ID from server",
title: _t('Fetching third party location failed'),
description: _t('Unable to look up room ID from server'),
});
});
}
@ -364,7 +366,7 @@ module.exports = React.createClass({
avatarUrl: room.avatar_url,
// XXX: This logic is duplicated from the JS SDK which
// would normally decide what the name is.
name: room.name || room_alias || "Unnamed room",
name: room.name || room_alias || _t('Unnamed room'),
};
}
// It's not really possible to join Matrix rooms by ID because the HS has no way to know
@ -389,18 +391,18 @@ module.exports = React.createClass({
var self = this;
var guestRead, guestJoin, perms;
for (var i = 0; i < rooms.length; i++) {