Ignore hashtags when sorting channels
This commit is contained in:
parent
fc937aaac8
commit
4694e66e98
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@ import { createSelector } from 'reselect';
|
||||
import get from 'lodash/get';
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import createReducer from 'utils/createReducer';
|
||||
import { find, findIndex } from 'utils';
|
||||
import { trimPrefixChar, find, findIndex } from 'utils';
|
||||
import { getSelectedTab, updateSelection } from './tab';
|
||||
import * as actions from './actions';
|
||||
|
||||
@ -100,7 +100,9 @@ export const getSortedChannels = createSelector(getChannels, channels =>
|
||||
sortBy(
|
||||
Object.keys(channels).map(network => ({
|
||||
address: network,
|
||||
channels: sortBy(channels[network], channel => channel.name.toLowerCase())
|
||||
channels: sortBy(channels[network], channel =>
|
||||
trimPrefixChar(channel.name, '#').toLowerCase()
|
||||
)
|
||||
})),
|
||||
network => network.address.toLowerCase()
|
||||
)
|
||||
|
@ -1,10 +1,24 @@
|
||||
import React from 'react';
|
||||
import TestRenderer from 'react-test-renderer';
|
||||
import { isChannel, isValidNick, isValidChannel, isValidUsername } from '..';
|
||||
import {
|
||||
trimPrefixChar,
|
||||
isChannel,
|
||||
isValidNick,
|
||||
isValidChannel,
|
||||
isValidUsername
|
||||
} from '..';
|
||||
import linkify from '../linkify';
|
||||
|
||||
const render = el => TestRenderer.create(el).toJSON();
|
||||
|
||||
describe('trimPrefixChar()', () => {
|
||||
it('trims prefix characters', () => {
|
||||
expect(trimPrefixChar('##chan', '#')).toBe('chan');
|
||||
expect(trimPrefixChar('#chan', '#')).toBe('chan');
|
||||
expect(trimPrefixChar('chan', '#')).toBe('chan');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isChannel()', () => {
|
||||
it('it handles strings', () => {
|
||||
expect(isChannel('#cake')).toBe(true);
|
||||
|
@ -3,14 +3,6 @@ import padStart from 'lodash/padStart';
|
||||
export { findBreakpoints, messageHeight } from './messageHeight';
|
||||
export { default as linkify } from './linkify';
|
||||
|
||||
export function normalizeChannel(channel) {
|
||||
if (channel.indexOf('#') !== 0) {
|
||||
return channel;
|
||||
}
|
||||
|
||||
return channel.split('#').join('').toLowerCase();
|
||||
}
|
||||
|
||||
export function isChannel(name) {
|
||||
// TODO: Handle other channel types
|
||||
if (typeof name === 'object') {
|
||||
@ -42,6 +34,22 @@ function isString(s, maxLength) {
|
||||
return true;
|
||||
}
|
||||
|
||||
export function trimPrefixChar(str, char) {
|
||||
if (!isString(str)) {
|
||||
return str;
|
||||
}
|
||||
|
||||
let start = 0;
|
||||
while (str[start] === char) {
|
||||
start++;
|
||||
}
|
||||
|
||||
if (start > 0) {
|
||||
return str.slice(start);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
// RFC 2812
|
||||
// nickname = ( letter / special ) *( letter / digit / special / "-" )
|
||||
// letter = A-Z / a-z
|
||||
|
Loading…
Reference in New Issue
Block a user