Resolve "Remember last used chat channel" Closes #1352 See merge request Isleward/isleward!441tags/v0.4.3^2
@@ -9,7 +9,8 @@ define([ | |||
showEvents: true, | |||
playAudio: true, | |||
qualityIndicators: 'off', | |||
unusableIndicators: 'off' | |||
unusableIndicators: 'off', | |||
rememberChatChannel: true | |||
}; | |||
const valueChains = { | |||
@@ -4,14 +4,16 @@ define([ | |||
'html!ui/templates/messages/tplTab', | |||
'css!ui/templates/messages/styles', | |||
'js/input', | |||
'js/system/client' | |||
'js/system/client', | |||
'js/config' | |||
], function ( | |||
events, | |||
template, | |||
tplTab, | |||
styles, | |||
input, | |||
client | |||
client, | |||
config | |||
) { | |||
return { | |||
tpl: template, | |||
@@ -29,6 +31,8 @@ define([ | |||
blockedPlayers: [], | |||
lastChannel: null, | |||
postRender: function () { | |||
this.onEvent('onGetMessages', this.onGetMessages.bind(this)); | |||
this.onEvent('onDoWhisper', this.onDoWhisper.bind(this)); | |||
@@ -36,6 +40,7 @@ define([ | |||
this.onEvent('onLeaveChannel', this.onLeaveChannel.bind(this)); | |||
this.onEvent('onGetCustomChatChannels', this.onGetCustomChatChannels.bind(this)); | |||
this.onEvent('onGetBlockedPlayers', this.onGetBlockedPlayers.bind(this)); | |||
this.onEvent('onToggleLastChannel', this.onToggleLastChannel.bind(this)); | |||
this | |||
.find('.filter:not(.channel):not(.btn)') | |||
@@ -248,8 +253,10 @@ define([ | |||
}, | |||
onKeyDown: function (key) { | |||
if (key === 'enter') | |||
if (key === 'enter') { | |||
this.toggle(true); | |||
this.find('input').val(this.lastChannel || ''); | |||
} | |||
else if (key === 'shift') | |||
this.showItemTooltip(); | |||
}, | |||
@@ -393,14 +400,14 @@ define([ | |||
} | |||
let textbox = this.find('input'); | |||
let config = { | |||
let msgConfig = { | |||
success: true, | |||
message: textbox.val() | |||
}; | |||
events.emit('onBeforeChat', config); | |||
events.emit('onBeforeChat', msgConfig); | |||
let val = config.message | |||
let val = msgConfig.message | |||
.split('<') | |||
.join('<') | |||
.split('>') | |||
@@ -408,12 +415,27 @@ define([ | |||
textbox.blur(); | |||
if (!config.success) | |||
if (!msgConfig.success) | |||
return; | |||
if (val.trim() === '') | |||
return; | |||
if (config.rememberChatChannel) { | |||
const firstChar = val[0]; | |||
let lastChannel = null; | |||
if ('@$'.includes(firstChar)) { | |||
const firstSpace = val.indexOf(' '); | |||
if (firstSpace === -1) | |||
lastChannel = val + ' '; | |||
else | |||
lastChannel = val.substr(0, firstSpace) + ' '; | |||
} else if (firstChar === '%') | |||
lastChannel = '%'; | |||
this.lastChannel = lastChannel; | |||
} | |||
client.request({ | |||
cpn: 'social', | |||
method: 'chat', | |||
@@ -421,6 +443,12 @@ define([ | |||
message: val | |||
} | |||
}); | |||
}, | |||
onToggleLastChannel: function (isOn) { | |||
if (!isOn) { | |||
this.lastChannel = null; | |||
} | |||
} | |||
}; | |||
}); |
@@ -37,6 +37,7 @@ define([ | |||
this.find('.item.quality .name').on('click', this.toggleQualityIndicators.bind(this)); | |||
this.find('.item.unusable .name').on('click', this.toggleUnusableIndicators.bind(this)); | |||
this.find('.item.audio .name').on('click', this.toggleAudio.bind(this)); | |||
this.find('.item.lastChannel .name').on('click', this.toggleLastChannel.bind(this)); | |||
this.onEvent('onResize', this.onResize.bind(this)); | |||
this.onEvent('onUiKeyDown', this.onKeyDown.bind(this)); | |||
@@ -46,6 +47,7 @@ define([ | |||
this.onEvent('onToggleUnusableIndicators', this.onToggleUnusableIndicators.bind(this)); | |||
this.onEvent('onToggleEventsVisibility', this.onToggleEventsVisibility.bind(this)); | |||
this.onEvent('onToggleQuestsVisibility', this.onToggleQuestsVisibility.bind(this)); | |||
this.onEvent('onToggleLastChannel', this.onToggleLastChannel.bind(this)); | |||
}, | |||
toggleUnusableIndicators: function () { | |||
@@ -138,6 +140,18 @@ define([ | |||
this.find('.item.audio .value').html(newValue); | |||
}, | |||
toggleLastChannel: function () { | |||
config.toggle('rememberChatChannel'); | |||
events.emit('onToggleLastChannel', config.rememberChatChannel); | |||
}, | |||
onToggleLastChannel: function (state) { | |||
const newValue = state ? 'On' : 'Off'; | |||
this.find('.item.lastChannel .value').html(newValue); | |||
}, | |||
build: function () { | |||
this.onToggleNameplates(config.showNames); | |||
this.onToggleAudio(config.playAudio); | |||
@@ -145,6 +159,7 @@ define([ | |||
this.onToggleQuestsVisibility(config.showQuests); | |||
this.onToggleQualityIndicators(config.qualityIndicators); | |||
this.onToggleUnusableIndicators(config.unusableIndicators); | |||
this.onToggleLastChannel(config.rememberChatChannel); | |||
}, | |||
toggle: function () { | |||
@@ -35,6 +35,11 @@ | |||
<div class="name">Unusable Indicators</div> | |||
<div class="value">Off</div> | |||
</div> | |||
<div class="heading inventory">Chat</div> | |||
<div class="item lastChannel"> | |||
<div class="name">Remember Last Chat Channel</div> | |||
<div class="value">On</div> | |||
</div> | |||
</div> | |||
</div> | |||
</div> |