Follow-up to #1244: underscore cleanup
This commit is contained in:
parent
380316e9ad
commit
b6ca906192
|
@ -4,6 +4,7 @@ import * as Favico from "favico.js";
|
|||
|
||||
|
||||
import { connectionFactory } from './connection';
|
||||
import { sortBy } from './misc';
|
||||
|
||||
/* debounce helper so we dont have to use underscore.js */
|
||||
const debounce = function (func, wait, immediate) {
|
||||
|
@ -19,10 +20,6 @@ const debounce = function (func, wait, immediate) {
|
|||
};
|
||||
};
|
||||
|
||||
const sortBy = (key) => {
|
||||
return (a, b) => (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0);
|
||||
};
|
||||
|
||||
var weechat = angular.module('weechat', ['ngRoute', 'localStorage', 'weechatModels', 'bufferResume', 'plugins', 'IrcUtils', 'ngSanitize', 'ngWebsockets', 'ngTouch'], ['$compileProvider', function($compileProvider) {
|
||||
// hacky way to be able to find out if we're in debug mode
|
||||
weechat.compileProvider = $compileProvider;
|
||||
|
|
|
@ -104,7 +104,7 @@ weechat.directive('inputBar', function() {
|
|||
var completion_suffix = models.wconfig['weechat.completion.nick_completer'];
|
||||
var add_space = models.wconfig['weechat.completion.nick_add_space'];
|
||||
var nickComp = IrcUtils.completeNick(input, caretPos, $scope.iterCandidate,
|
||||
activeBuffer.getNicklistByTime(),
|
||||
activeBuffer.getNicklistByTime().reverse(),
|
||||
completion_suffix, add_space);
|
||||
|
||||
// remember iteration candidate
|
||||
|
|
|
@ -16,19 +16,6 @@ IrcUtils.service('IrcUtils', [function() {
|
|||
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a new version of a nick list
|
||||
*
|
||||
* @param nickList Original nick list
|
||||
* @return list of nick names
|
||||
*/
|
||||
var _ciNickList = function(nickList) {
|
||||
|
||||
let newList = nickList.map((el) => el.name);
|
||||
|
||||
return newList;
|
||||
};
|
||||
|
||||
/**
|
||||
* Completes a single nick.
|
||||
*
|
||||
|
@ -118,7 +105,7 @@ IrcUtils.service('IrcUtils', [function() {
|
|||
var addSpaceChar = (addSpace === undefined || addSpace === 'on') ? ' ' : '';
|
||||
|
||||
// new nick list to search in
|
||||
var searchNickList = _ciNickList(nickList);
|
||||
var searchNickList = nickList.map((el) => el.name);
|
||||
|
||||
// text before and after caret
|
||||
var beforeCaret = text.substring(0, caretPos);
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
export const sortBy = (key) => {
|
||||
return (a, b) => (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0);
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
|
||||
import * as weeChat from './weechat';
|
||||
import { sortBy } from './misc';
|
||||
|
||||
var models = angular.module('weechatModels', []);
|
||||
|
||||
|
@ -219,9 +220,10 @@ models.service('models', ['$rootScope', '$filter', 'bufferResume', function($roo
|
|||
}
|
||||
for (let groupIdx in nicklist) {
|
||||
let nicks = nicklist[groupIdx].nicks;
|
||||
for (let nickIdx in nicks) {
|
||||
if (nicks[nickIdx].name === nick) {
|
||||
nicks[nickIdx].spokeAt = Date.now();
|
||||
for (let curr_nick of nicks) {
|
||||
if (curr_nick.name === nick) {
|
||||
curr_nick.spokeAt = Date.now();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -235,15 +237,10 @@ models.service('models', ['$rootScope', '$filter', 'bufferResume', function($roo
|
|||
var getNicklistByTime = function() {
|
||||
var newlist = [];
|
||||
for (let groupIdx in nicklist) {
|
||||
let nicks = nicklist[groupIdx].nicks;
|
||||
for (let nickIdx in nicks) {
|
||||
newlist.push(nicks[nickIdx]);
|
||||
}
|
||||
newlist = newlist.concat(nicklist[groupIdx].nicks);
|
||||
}
|
||||
|
||||
newlist.sort(function(a, b) {
|
||||
return a.spokeAt < b.spokeAt;
|
||||
});
|
||||
newlist.sort(sortBy('spokeAt'));
|
||||
|
||||
return newlist;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue