Skip to content

Commit 3e8dfa6

Browse files
committed
app: add ability to change color of your nick
An input has been added on the global settings page for this. Accepts css color styles
1 parent 0974c45 commit 3e8dfa6

File tree

5 files changed

+81
-9
lines changed

5 files changed

+81
-9
lines changed

app.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const defaultSettings = new Map([
3333
, ['invites.accept.auto', false]
3434
, ['sounds.enabled', true]
3535
, ['userbar.hidden', false]
36+
, ['user.color', '#fb73fa']
3637
])
3738

3839
function App(el, currentWindow) {
@@ -302,6 +303,10 @@ App.prototype._addHandlers = function _addHandlers() {
302303
this.newConnectionTip = addConnTooltip
303304

304305
this.settings.on('settingChanged', (key, orig, val) => {
306+
// TODO(evanlucas) if key is user.color, maybe go through
307+
// and call the messageFormatter on all messages?
308+
// Not sure if it is worth it to keep the color in sync for previous
309+
// messages though
305310
this.db.settings.put(key, val, (err) => {
306311
if (err) {
307312
console.error('Unable to persist setting changed', key, val, err)
@@ -408,7 +413,7 @@ App.prototype._checkAuth = function _checkAuth() {
408413

409414
// we have saved connections
410415
var active
411-
416+
const settings = this.settings
412417
for (var i = 0; i < len; i++) {
413418
const opts = connections[i]
414419
const user = opts.user
@@ -423,8 +428,8 @@ App.prototype._checkAuth = function _checkAuth() {
423428
}
424429

425430
const chan = msg.channel || {}
426-
427-
return utils.processMessage(msg.message, chan.colorMap, chan.conn)
431+
const uc = settings.get('user.color')
432+
return utils.processMessage(msg.message, chan.colorMap, chan.conn, uc)
428433
}
429434

430435
const conn = new Connection(opts, this)

client/less/theme.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,8 @@ irc-settings {
216216
background-color: darken(@dusk, 10%);
217217
}
218218
}
219+
220+
.input-group-addon {
221+
border: 1px solid @dusklight;
222+
}
219223
}

lib/utils.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,22 @@ exports.decodeConnection = function decodeConnection(str) {
8888
return str.replace('#server_____', '')
8989
}
9090

91-
exports.processMessage = function processMessage(msg, colorMap, conn) {
91+
exports.processMessage = function processMessage(msg, colorMap, conn, uc) {
9292
let m = exports.encode(msg)
9393
// This sucks :/
9494
m = m.replace('\u0002', '<strong>').replace('\u0002', '</strong>')
9595
for (const item of colorMap.entries()) {
9696
const username = item[0]
97-
const color = item[1]
97+
const color = conn && uc && username === conn.nick
98+
? uc
99+
: item[1]
100+
101+
let mycol
102+
if (conn && uc && username === conn.nick) {
103+
console.log('ME', uc, msg)
104+
mycol = uc
105+
}
106+
98107
const unRE = username
99108
.replace(/\|/g, '\\|')
100109
.replace(/\[/g, '\\[')
@@ -107,6 +116,10 @@ exports.processMessage = function processMessage(msg, colorMap, conn) {
107116
return match
108117
}
109118

119+
if (mycol) {
120+
return `<span class="mention" style="color: ${mycol};">${match}</span>`
121+
}
122+
110123
return `<span class="mention ${color || ''}">${match}</span>`
111124
})
112125
}

lib/views/message-log.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,31 @@ inherits(Log, Base)
1515
// These are message logs
1616
Log.prototype.render = function render(log, channel) {
1717
const d = utils.date(log.ts)
18-
const color = channel.colorMap.get(log.from.toLowerCase()) || ''
18+
const lower = (log.from || '').toLowerCase()
19+
let mycol
20+
if (channel.conn) {
21+
const connNick = channel.conn.nick
22+
if (connNick && connNick.toLowerCase() === lower) {
23+
mycol = this.target.settings.get('user.color')
24+
}
25+
}
26+
27+
const color = mycol || channel.colorMap.get((log.from || '').toLowerCase())
1928
const from = log.from
2029
const m = log.formatted
2130
const cl = log.mention ? 'mention' : log.type
2231
if (from) {
32+
const formattedName = utils.formatNameForType(from, log.type)
33+
const un = mycol
34+
? h('span.username', {
35+
style: {
36+
color: mycol
37+
}
38+
}, formattedName)
39+
: h(`span.username.${color}`, formattedName)
2340
return h(`li.${cl}`, [
2441
h('span.ts', `[${d}]`)
25-
, h(`span.username.${color}`, utils.formatNameForType(from, log.type))
42+
, un
2643
, h('span.content', {
2744
innerHTML: m
2845
})

lib/views/settings.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,18 @@ Settings.prototype.reloadThemes = function reloadThemes(e) {
5151
e.target.blur()
5252
}
5353

54+
Settings.prototype.onUserColorChanged = function onUserColorChanged(e) {
55+
const val = e.target.value
56+
debug('user.color changed to %s', val)
57+
this.target.settings.set('user.color', val)
58+
this.target.needsLayout()
59+
}
60+
5461
const notes = {
55-
'playSounds': 'Sounds will be played for things like receiving' +
62+
playSounds: 'Sounds will be played for things like receiving' +
5663
' a new message.'
57-
, 'autoAcceptInvites': 'Auto join channel when invited.'
64+
, autoAcceptInvites: 'Auto join channel when invited.'
65+
, userColor: 'Set the color of your nickname in all chats'
5866
}
5967

6068
Settings.prototype.render = function render() {
@@ -111,6 +119,9 @@ Settings.prototype.render = function render() {
111119
, checkbox('autoAcceptInvites', (e) => {
112120
this.onAutoAcceptInvite(e)
113121
}, ' Auto Accept Invites', settings, notes.autoAcceptInvites)
122+
, colorPicker('user.color', (e) => {
123+
this.onUserColorChanged(e)
124+
}, 'Nickname Color', settings, notes.userColor)
114125
])
115126
])
116127
])
@@ -132,3 +143,25 @@ function checkbox(id, onchange, title, settings, note) {
132143
])
133144
])
134145
}
146+
147+
function colorPicker(id, onkeyup, title, settings, note) {
148+
return h('.form-group', [
149+
h('label.control-label', {
150+
for: id
151+
}, title)
152+
, h('.input-group', [
153+
h('span.input-group-addon', {
154+
style: {
155+
backgroundColor: settings.get(id)
156+
}
157+
})
158+
, h('input.form-control', {
159+
type: 'text'
160+
, id: id
161+
, onkeyup: onkeyup
162+
, value: settings.get(id)
163+
})
164+
])
165+
, h('p.form-control-static', note)
166+
])
167+
}

0 commit comments

Comments
 (0)