Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2019-09-18 09:27:43 +01:00
parent 54ea85f235
commit e502558f7d
8 changed files with 46 additions and 52 deletions

View file

@ -40,18 +40,13 @@ src/components/views/settings/DevicesPanel.js
src/components/views/settings/Notifications.js src/components/views/settings/Notifications.js
src/HtmlUtils.js src/HtmlUtils.js
src/ImageUtils.js src/ImageUtils.js
src/linkify-matrix.js
src/Markdown.js src/Markdown.js
src/MatrixClientPeg.js
src/notifications/ContentRules.js src/notifications/ContentRules.js
src/notifications/PushRuleVectorState.js src/notifications/PushRuleVectorState.js
src/Notifier.js
src/PlatformPeg.js src/PlatformPeg.js
src/Presence.js
src/rageshake/rageshake.js src/rageshake/rageshake.js
src/rageshake/submit-rageshake.js src/rageshake/submit-rageshake.js
src/ratelimitedfunc.js src/ratelimitedfunc.js
src/Roles.js
src/Rooms.js src/Rooms.js
src/Unread.js src/Unread.js
src/utils/DecryptFile.js src/utils/DecryptFile.js
@ -60,9 +55,7 @@ src/utils/DMRoomMap.js
src/utils/FormattingUtils.js src/utils/FormattingUtils.js
src/utils/MultiInviter.js src/utils/MultiInviter.js
src/utils/Receipt.js src/utils/Receipt.js
src/VectorConferenceHandler.js
src/Velociraptor.js src/Velociraptor.js
src/WhoIsTyping.js
test/components/structures/MessagePanel-test.js test/components/structures/MessagePanel-test.js
test/components/views/dialogs/InteractiveAuthDialog-test.js test/components/views/dialogs/InteractiveAuthDialog-test.js
test/components/views/rooms/MessageComposerInput-test.js test/components/views/rooms/MessageComposerInput-test.js

View file

@ -16,9 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
'use strict'; import {MatrixClient, MemoryStore} from 'matrix-js-sdk';
import Matrix from 'matrix-js-sdk';
import utils from 'matrix-js-sdk/lib/utils'; import utils from 'matrix-js-sdk/lib/utils';
import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline'; import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline';
@ -27,7 +25,6 @@ import sdk from './index';
import createMatrixClient from './utils/createMatrixClient'; import createMatrixClient from './utils/createMatrixClient';
import SettingsStore from './settings/SettingsStore'; import SettingsStore from './settings/SettingsStore';
import MatrixActionCreators from './actions/MatrixActionCreators'; import MatrixActionCreators from './actions/MatrixActionCreators';
import {phasedRollOutExpiredForUser} from "./PhasedRollOut";
import Modal from './Modal'; import Modal from './Modal';
import {verificationMethods} from 'matrix-js-sdk/lib/crypto'; import {verificationMethods} from 'matrix-js-sdk/lib/crypto';
import MatrixClientBackedSettingsHandler from "./settings/handlers/MatrixClientBackedSettingsHandler"; import MatrixClientBackedSettingsHandler from "./settings/handlers/MatrixClientBackedSettingsHandler";
@ -87,7 +84,7 @@ class MatrixClientPeg {
MatrixActionCreators.stop(); MatrixActionCreators.stop();
} }
/* /**
* If we've registered a user ID we set this to the ID of the * If we've registered a user ID we set this to the ID of the
* user we've just registered. If they then go & log in, we * user we've just registered. If they then go & log in, we
* can send them to the welcome user (obviously this doesn't * can send them to the welcome user (obviously this doesn't
@ -99,7 +96,7 @@ class MatrixClientPeg {
this._justRegisteredUserId = uid; this._justRegisteredUserId = uid;
} }
/* /**
* Returns true if the current user has just been registered by this * Returns true if the current user has just been registered by this
* client as determined by setJustRegisteredUserId() * client as determined by setJustRegisteredUserId()
* *
@ -112,7 +109,7 @@ class MatrixClientPeg {
); );
} }
/** /*
* Replace this MatrixClientPeg's client with a client instance that has * Replace this MatrixClientPeg's client with a client instance that has
* homeserver / identity server URLs and active credentials * homeserver / identity server URLs and active credentials
*/ */
@ -131,7 +128,7 @@ class MatrixClientPeg {
} catch (err) { } catch (err) {
if (dbType === 'indexeddb') { if (dbType === 'indexeddb') {
console.error('Error starting matrixclient store - falling back to memory store', err); console.error('Error starting matrixclient store - falling back to memory store', err);
this.matrixClient.store = new Matrix.MemoryStore({ this.matrixClient.store = new MemoryStore({
localStorage: global.localStorage, localStorage: global.localStorage,
}); });
} else { } else {
@ -195,7 +192,7 @@ class MatrixClientPeg {
}; };
} }
/** /*
* Return the server name of the user's homeserver * Return the server name of the user's homeserver
* Throws an error if unable to deduce the homeserver name * Throws an error if unable to deduce the homeserver name
* (eg. if the user is not logged in) * (eg. if the user is not logged in)

View file

@ -203,7 +203,8 @@ const Notifier = {
// The permission request was dismissed or denied // The permission request was dismissed or denied
// TODO: Support alternative branding in messaging // TODO: Support alternative branding in messaging
const description = result === 'denied' const description = result === 'denied'
? _t('Riot does not have permission to send you notifications - please check your browser settings') ? _t('Riot does not have permission to send you notifications - ' +
'please check your browser settings')
: _t('Riot was not given permission to send notifications - please try again'); : _t('Riot was not given permission to send notifications - please try again');
const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog'); const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog');
Modal.createTrackedDialog('Unable to enable Notifications', result, ErrorDialog, { Modal.createTrackedDialog('Unable to enable Notifications', result, ErrorDialog, {

View file

@ -15,8 +15,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const MatrixClientPeg = require("./MatrixClientPeg"); import MatrixClientPeg from "./MatrixClientPeg";
const dis = require("./dispatcher"); import dis from "./dispatcher";
import Timer from './utils/Timer'; import Timer from './utils/Timer';
// Time in ms after that a user is considered as unavailable/away // Time in ms after that a user is considered as unavailable/away
@ -24,7 +24,6 @@ const UNAVAILABLE_TIME_MS = 3 * 60 * 1000; // 3 mins
const PRESENCE_STATES = ["online", "offline", "unavailable"]; const PRESENCE_STATES = ["online", "offline", "unavailable"];
class Presence { class Presence {
constructor() { constructor() {
this._activitySignal = null; this._activitySignal = null;
this._unavailableTimer = null; this._unavailableTimer = null;
@ -88,7 +87,7 @@ class Presence {
if (PRESENCE_STATES.indexOf(newState) === -1) { if (PRESENCE_STATES.indexOf(newState) === -1) {
throw new Error("Bad presence state: " + newState); throw new Error("Bad presence state: " + newState);
} }
const old_state = this.state; const oldState = this.state;
this.state = newState; this.state = newState;
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
@ -100,7 +99,7 @@ class Presence {
console.log("Presence: %s", newState); console.log("Presence: %s", newState);
} catch (err) { } catch (err) {
console.error("Failed to set presence: %s", err); console.error("Failed to set presence: %s", err);
this.state = old_state; this.state = oldState;
} }
} }
} }

View file

@ -26,7 +26,7 @@ export function levelRoleMap(usersDefault) {
} }
export function textualPowerLevel(level, usersDefault) { export function textualPowerLevel(level, usersDefault) {
const LEVEL_ROLE_MAP = this.levelRoleMap(usersDefault); const LEVEL_ROLE_MAP = levelRoleMap(usersDefault);
if (LEVEL_ROLE_MAP[level]) { if (LEVEL_ROLE_MAP[level]) {
return LEVEL_ROLE_MAP[level] + (level !== undefined ? ` (${level})` : ` (${usersDefault})`); return LEVEL_ROLE_MAP[level] + (level !== undefined ? ` (${level})` : ` (${usersDefault})`);
} else { } else {

View file

@ -14,12 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
"use strict";
import Promise from 'bluebird'; import Promise from 'bluebird';
const Matrix = require("matrix-js-sdk"); import {createNewMatrixCall, Room} from "matrix-js-sdk";
const Room = Matrix.Room; import CallHandler from './CallHandler';
const CallHandler = require('./CallHandler'); import MatrixClientPeg from "./MatrixClientPeg";
// FIXME: this is Riot (Vector) specific code, but will be removed shortly when // FIXME: this is Riot (Vector) specific code, but will be removed shortly when
// we switch over to jitsi entirely for video conferencing. // we switch over to jitsi entirely for video conferencing.
@ -45,7 +43,7 @@ ConferenceCall.prototype.setup = function() {
// return a call for *this* room to be placed. We also tack on // return a call for *this* room to be placed. We also tack on
// confUserId to speed up lookups (else we'd need to loop every room // confUserId to speed up lookups (else we'd need to loop every room
// looking for a 1:1 room with this conf user ID!) // looking for a 1:1 room with this conf user ID!)
const call = Matrix.createNewMatrixCall(self.client, room.roomId); const call = createNewMatrixCall(self.client, room.roomId);
call.confUserId = self.confUserId; call.confUserId = self.confUserId;
call.groupRoomId = self.groupRoomId; call.groupRoomId = self.groupRoomId;
return call; return call;
@ -84,7 +82,7 @@ ConferenceCall.prototype._getConferenceUserRoom = function() {
preset: "private_chat", preset: "private_chat",
invite: [this.confUserId], invite: [this.confUserId],
}).then(function(res) { }).then(function(res) {
return new Room(res.room_id, null, client.getUserId()); return new Room(res.room_id, null, MatrixClientPeg.get().getUserId());
}); });
}; };

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
const MatrixClientPeg = require("./MatrixClientPeg"); import MatrixClientPeg from "./MatrixClientPeg";
import { _t } from './languageHandler'; import { _t } from './languageHandler';
module.exports = { module.exports = {
@ -33,6 +33,9 @@ module.exports = {
/** /**
* Given a Room object and, optionally, a list of userID strings * Given a Room object and, optionally, a list of userID strings
* to exclude, return a list of user objects who are typing. * to exclude, return a list of user objects who are typing.
* @param {Room} room: room object to get users from.
* @param {string[]} exclude: list of user mxids to exclude.
* @returns {string[]} list of user objects who are typing.
*/ */
usersTyping: function(room, exclude) { usersTyping: function(room, exclude) {
const whoIsTyping = []; const whoIsTyping = [];
@ -46,7 +49,7 @@ module.exports = {
const userId = memberKeys[i]; const userId = memberKeys[i];
if (room.currentState.members[userId].typing) { if (room.currentState.members[userId].typing) {
if (exclude.indexOf(userId) == -1) { if (exclude.indexOf(userId) === -1) {
whoIsTyping.push(room.currentState.members[userId]); whoIsTyping.push(room.currentState.members[userId]);
} }
} }
@ -60,16 +63,19 @@ module.exports = {
if (whoIsTyping.length > limit) { if (whoIsTyping.length > limit) {
othersCount = whoIsTyping.length - limit + 1; othersCount = whoIsTyping.length - limit + 1;
} }
if (whoIsTyping.length == 0) { if (whoIsTyping.length === 0) {
return ''; return '';
} else if (whoIsTyping.length == 1) { } else if (whoIsTyping.length === 1) {
return _t('%(displayName)s is typing …', {displayName: whoIsTyping[0].name}); return _t('%(displayName)s is typing …', {displayName: whoIsTyping[0].name});
} }
const names = whoIsTyping.map(function(m) { const names = whoIsTyping.map(function(m) {
return m.name; return m.name;
}); });
if (othersCount>=1) { if (othersCount>=1) {
return _t('%(names)s and %(count)s others are typing …', {names: names.slice(0, limit - 1).join(', '), count: othersCount}); return _t('%(names)s and %(count)s others are typing …', {
names: names.slice(0, limit - 1).join(', '),
count: othersCount,
});
} else { } else {
const lastPerson = names.pop(); const lastPerson = names.pop();
return _t('%(names)s and %(lastPerson)s are typing …', {names: names.join(', '), lastPerson: lastPerson}); return _t('%(names)s and %(lastPerson)s are typing …', {names: names.join(', '), lastPerson: lastPerson});

View file

@ -44,7 +44,7 @@ function matrixLinkify(linkify) {
const S_ROOMALIAS_COLON = new linkify.parser.State(); const S_ROOMALIAS_COLON = new linkify.parser.State();
const S_ROOMALIAS_COLON_NUM = new linkify.parser.State(ROOMALIAS); const S_ROOMALIAS_COLON_NUM = new linkify.parser.State(ROOMALIAS);
const roomname_tokens = [ const roomnameTokens = [
TT.DOT, TT.DOT,
TT.PLUS, TT.PLUS,
TT.NUM, TT.NUM,
@ -58,8 +58,8 @@ function matrixLinkify(linkify) {
TT.LOCALHOST, TT.LOCALHOST,
]; ];
S_HASH.on(roomname_tokens, S_HASH_NAME); S_HASH.on(roomnameTokens, S_HASH_NAME);
S_HASH_NAME.on(roomname_tokens, S_HASH_NAME); S_HASH_NAME.on(roomnameTokens, S_HASH_NAME);
S_HASH_NAME.on(TT.DOMAIN, S_HASH_NAME); S_HASH_NAME.on(TT.DOMAIN, S_HASH_NAME);
S_HASH_NAME.on(TT.COLON, S_HASH_NAME_COLON); S_HASH_NAME.on(TT.COLON, S_HASH_NAME_COLON);
@ -92,7 +92,7 @@ function matrixLinkify(linkify) {
const S_USERID_COLON = new linkify.parser.State(); const S_USERID_COLON = new linkify.parser.State();
const S_USERID_COLON_NUM = new linkify.parser.State(USERID); const S_USERID_COLON_NUM = new linkify.parser.State(USERID);
const username_tokens = [ const usernameTokens = [
TT.DOT, TT.DOT,
TT.UNDERSCORE, TT.UNDERSCORE,
TT.PLUS, TT.PLUS,
@ -100,12 +100,12 @@ function matrixLinkify(linkify) {
TT.DOMAIN, TT.DOMAIN,
TT.TLD, TT.TLD,
// as in roomname_tokens // as in roomnameTokens
TT.LOCALHOST, TT.LOCALHOST,
]; ];
S_AT.on(username_tokens, S_AT_NAME); S_AT.on(usernameTokens, S_AT_NAME);
S_AT_NAME.on(username_tokens, S_AT_NAME); S_AT_NAME.on(usernameTokens, S_AT_NAME);
S_AT_NAME.on(TT.DOMAIN, S_AT_NAME); S_AT_NAME.on(TT.DOMAIN, S_AT_NAME);
S_AT_NAME.on(TT.COLON, S_AT_NAME_COLON); S_AT_NAME.on(TT.COLON, S_AT_NAME_COLON);
@ -138,7 +138,7 @@ function matrixLinkify(linkify) {
const S_GROUPID_COLON = new linkify.parser.State(); const S_GROUPID_COLON = new linkify.parser.State();
const S_GROUPID_COLON_NUM = new linkify.parser.State(GROUPID); const S_GROUPID_COLON_NUM = new linkify.parser.State(GROUPID);
const groupid_tokens = [ const groupIdTokens = [
TT.DOT, TT.DOT,
TT.UNDERSCORE, TT.UNDERSCORE,
TT.PLUS, TT.PLUS,
@ -146,12 +146,12 @@ function matrixLinkify(linkify) {
TT.DOMAIN, TT.DOMAIN,
TT.TLD, TT.TLD,
// as in roomname_tokens // as in roomnameTokens
TT.LOCALHOST, TT.LOCALHOST,
]; ];
S_PLUS.on(groupid_tokens, S_PLUS_NAME); S_PLUS.on(groupIdTokens, S_PLUS_NAME);
S_PLUS_NAME.on(groupid_tokens, S_PLUS_NAME); S_PLUS_NAME.on(groupIdTokens, S_PLUS_NAME);
S_PLUS_NAME.on(TT.DOMAIN, S_PLUS_NAME); S_PLUS_NAME.on(TT.DOMAIN, S_PLUS_NAME);
S_PLUS_NAME.on(TT.COLON, S_PLUS_NAME_COLON); S_PLUS_NAME.on(TT.COLON, S_PLUS_NAME_COLON);
@ -179,14 +179,14 @@ const escapeRegExp = function(string) {
// Recognise URLs from both our local vector and official vector as vector. // Recognise URLs from both our local vector and official vector as vector.
// anyone else really should be using matrix.to. // anyone else really should be using matrix.to.
matrixLinkify.VECTOR_URL_PATTERN = "^(?:https?:\/\/)?(?:" matrixLinkify.VECTOR_URL_PATTERN = "^(?:https?://)?(?:"
+ escapeRegExp(window.location.host + window.location.pathname) + "|" + escapeRegExp(window.location.host + window.location.pathname) + "|"
+ "(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/" + "(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/"
+ ")(#.*)"; + ")(#.*)";
matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/(([#@!+]).*)"; matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?://)?(?:www\\.)?matrix\\.to/#/(([#@!+]).*)";
matrixLinkify.MATRIXTO_MD_LINK_PATTERN = matrixLinkify.MATRIXTO_MD_LINK_PATTERN =
'\\[([^\\]]*)\\]\\((?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/([#@!+][^\\)]*)\\)'; '\\[([^\\]]*)\\]\\((?:https?://)?(?:www\\.)?matrix\\.to/#/([#@!+][^\\)]*)\\)';
matrixLinkify.MATRIXTO_BASE_URL= baseUrl; matrixLinkify.MATRIXTO_BASE_URL= baseUrl;
const matrixToEntityMap = { const matrixToEntityMap = {