Skip to content
This repository was archived by the owner on May 18, 2025. It is now read-only.

Commit 95d15b7

Browse files
committed
Fix tinting of notification icon and use a more reliable notification source
The js-sdk's placement of the notification change was unreliable and could cause stuck notifications. The new location (piggybacking the Notifier) is a lot more reliable. The tinting has been changed fairly invasively in order to support the changing of the `fill` attribute. What was happening before was the `fill` property would happily get set to the forced color value, but when it came time to reset it it wouldn't be part of the colors array and fail the check, therefore never being changed back. By using a second field we can ensure we are checking the not-forced value where possible, falling back to the potentially forced value if needed. In addition to fixing which color the Tinter was checking against, something noticed during development is that `this.colors` might not always be a set of hex color codes. This is problematic when the attribute we're looking to replace is a rgb color code but we're only looking at `keyHex` - the value won't be reset. It appears as though this happens when people use custom tinting in places as `this.colors` often gets set to the rgb values throughout the file. To fix it, we just check against `keyHex` and `keyRgb`.
1 parent 173669b commit 95d15b7

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

src/Notifier.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ const Notifier = {
289289
const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
290290
const actions = MatrixClientPeg.get().getPushActionsForEvent(ev);
291291
if (actions && actions.notify) {
292+
dis.dispatch({
293+
action: "event_notification",
294+
event: ev,
295+
room: room,
296+
});
292297
if (this.isEnabled()) {
293298
this._displayPopupNotification(ev, room);
294299
}

src/Tinter.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,18 @@ class Tinter {
419419
for (let k = 0; k < this.svgAttrs.length; k++) {
420420
const attr = this.svgAttrs[k];
421421
for (let m = 0; m < this.keyHex.length; m++) { // dev note: don't use L please.
422-
if (tag.getAttribute(attr) &&
423-
tag.getAttribute(attr).toUpperCase() === this.keyHex[m]) {
422+
// We use a different attribute from the one we're setting
423+
// because we may also be using forceColors. If we were to
424+
// check the keyHex against a forceColors value, it may not
425+
// match and therefore not change when we need it to.
426+
const valAttrName = "mx-val-" + attr;
427+
let attribute = tag.getAttribute(valAttrName);
428+
if (!attribute) attribute = tag.getAttribute(attr); // fall back to the original
429+
if (attribute && (attribute.toUpperCase() === this.keyHex[m] || attribute.toLowerCase() === this.keyRgb[m])) {
424430
fixups.push({
425431
node: tag,
426432
attr: attr,
433+
refAttr: valAttrName,
427434
index: m,
428435
forceColors: forceColors,
429436
});
@@ -442,8 +449,8 @@ class Tinter {
442449
for (let i = 0; i < fixups.length; i++) {
443450
const svgFixup = fixups[i];
444451
const forcedColor = svgFixup.forceColors ? svgFixup.forceColors[svgFixup.index] : null;
445-
if (forcedColor) console.log(forcedColor);
446452
svgFixup.node.setAttribute(svgFixup.attr, forcedColor ? forcedColor : this.colors[svgFixup.index]);
453+
svgFixup.node.setAttribute(svgFixup.refAttr, this.colors[svgFixup.index]);
447454
}
448455
if (DEBUG) console.log("applySvgFixups end");
449456
}

src/components/structures/RightPanel.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ module.exports = React.createClass({
124124
this.dispatcherRef = dis.register(this.onAction);
125125
const cli = this.context.matrixClient;
126126
cli.on("RoomState.members", this.onRoomStateMember);
127-
cli.on("Room.notificationCounts", this.onRoomNotifications);
128127
this._initGroupStore(this.props.groupId);
129128
},
130129

@@ -212,16 +211,15 @@ module.exports = React.createClass({
212211
}
213212
},
214213

215-
onRoomNotifications: function(room, type, count) {
216-
if (type === "highlight") this.forceUpdate();
217-
},
218-
219214
_delayedUpdate: new RateLimitedFunc(function() {
220215
this.forceUpdate(); // eslint-disable-line babel/no-invalid-this
221216
}, 500),
222217

223218
onAction: function(payload) {
224-
if (payload.action === "view_user") {
219+
if (payload.action === "event_notification") {
220+
// Try and re-caclulate any badge counts we might have
221+
this.forceUpdate();
222+
} else if (payload.action === "view_user") {
225223
dis.dispatch({
226224
action: 'show_right_panel',
227225
});

src/components/views/elements/TintableSvg.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,26 @@ var TintableSvg = React.createClass({
5151
delete TintableSvg.mounts[this.id];
5252
},
5353

54+
componentDidUpdate: function(prevProps, prevState) {
55+
if (prevProps.forceColors !== this.props.forceColors) {
56+
this.calcAndApplyFixups(this.refs.svgContainer);
57+
}
58+
},
59+
5460
tint: function() {
5561
// TODO: only bother running this if the global tint settings have changed
5662
// since we loaded!
5763
Tinter.applySvgFixups(this.fixups);
5864
},
5965

6066
onLoad: function(event) {
61-
// console.log("TintableSvg.onLoad for " + this.props.src);
62-
this.fixups = Tinter.calcSvgFixups([event.target], this.props.forceColors);
67+
this.calcAndApplyFixups(event.target);
68+
},
69+
70+
calcAndApplyFixups: function(target) {
71+
if (!target) return;
72+
// console.log("TintableSvg.calcAndApplyFixups for " + this.props.src);
73+
this.fixups = Tinter.calcSvgFixups([target], this.props.forceColors);
6374
Tinter.applySvgFixups(this.fixups);
6475
},
6576

@@ -72,6 +83,7 @@ var TintableSvg = React.createClass({
7283
height={this.props.height}
7384
onLoad={this.onLoad}
7485
tabIndex="-1"
86+
ref="svgContainer"
7587
/>
7688
);
7789
},

0 commit comments

Comments
 (0)