Move pinned rooms check to the RoomListStore
This commit is contained in:
parent
103ed71eb5
commit
3d8f0adf56
2 changed files with 26 additions and 19 deletions
|
@ -19,7 +19,6 @@ limitations under the License.
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import sdk from '../../index';
|
import sdk from '../../index';
|
||||||
import SettingsStore from "../../settings/SettingsStore";
|
|
||||||
import { Droppable } from 'react-beautiful-dnd';
|
import { Droppable } from 'react-beautiful-dnd';
|
||||||
import { _t } from '../../languageHandler';
|
import { _t } from '../../languageHandler';
|
||||||
import dis from '../../dispatcher';
|
import dis from '../../dispatcher';
|
||||||
|
@ -100,10 +99,8 @@ const RoomSubList = React.createClass({
|
||||||
componentWillReceiveProps: function(newProps) {
|
componentWillReceiveProps: function(newProps) {
|
||||||
// order the room list appropriately before we re-render
|
// order the room list appropriately before we re-render
|
||||||
//if (debug) console.log("received new props, list = " + newProps.list);
|
//if (debug) console.log("received new props, list = " + newProps.list);
|
||||||
const filteredRooms = this.applySearchFilter(newProps.list, newProps.searchFilter);
|
|
||||||
const sortedRooms = newProps.order === "recent" ? this.applyPinnedTileRules(filteredRooms) : filteredRooms;
|
|
||||||
this.setState({
|
this.setState({
|
||||||
sortedList: sortedRooms,
|
sortedList: this.applySearchFilter(newProps.list, newProps.searchFilter),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -116,21 +113,6 @@ const RoomSubList = React.createClass({
|
||||||
(filter[0] === '#' && room.getAliases().some((alias) => alias.toLowerCase().startsWith(lcFilter))));
|
(filter[0] === '#' && room.getAliases().some((alias) => alias.toLowerCase().startsWith(lcFilter))));
|
||||||
},
|
},
|
||||||
|
|
||||||
applyPinnedTileRules: function(list) {
|
|
||||||
const pinUnread = SettingsStore.getValue("pinUnreadRooms");
|
|
||||||
const pinMentioned = SettingsStore.getValue("pinMentionedRooms");
|
|
||||||
if (!pinUnread && !pinMentioned) {
|
|
||||||
return list; // Nothing to sort
|
|
||||||
}
|
|
||||||
|
|
||||||
const mentioned = !pinMentioned ? [] : list.filter(room => room.getUnreadNotificationCount("highlight") > 0);
|
|
||||||
const unread = !pinUnread ? [] : list.filter(room => Unread.doesRoomHaveUnreadMessages(room));
|
|
||||||
|
|
||||||
return mentioned
|
|
||||||
.concat(unread.filter(room => !mentioned.find(other => other === room)))
|
|
||||||
.concat(list.filter(room => !unread.find(other => other === room)));
|
|
||||||
},
|
|
||||||
|
|
||||||
// The header is collapsable if it is hidden or not stuck
|
// The header is collapsable if it is hidden or not stuck
|
||||||
// The dataset elements are added in the RoomList _initAndPositionStickyHeaders method
|
// The dataset elements are added in the RoomList _initAndPositionStickyHeaders method
|
||||||
isCollapsableOnClick: function() {
|
isCollapsableOnClick: function() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import {Store} from 'flux/utils';
|
||||||
import dis from '../dispatcher';
|
import dis from '../dispatcher';
|
||||||
import DMRoomMap from '../utils/DMRoomMap';
|
import DMRoomMap from '../utils/DMRoomMap';
|
||||||
import Unread from '../Unread';
|
import Unread from '../Unread';
|
||||||
|
import SettingsStore from "../settings/SettingsStore";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for storing application state for categorising rooms in
|
* A class for storing application state for categorising rooms in
|
||||||
|
@ -263,6 +264,30 @@ class RoomListStore extends Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
_recentsComparator(roomA, roomB) {
|
_recentsComparator(roomA, roomB) {
|
||||||
|
const pinUnread = SettingsStore.getValue("pinUnreadRooms");
|
||||||
|
const pinMentioned = SettingsStore.getValue("pinMentionedRooms");
|
||||||
|
|
||||||
|
// We try and set the ordering to be Mentioned > Unread > Recent
|
||||||
|
// assuming the user has the right settings, of course
|
||||||
|
|
||||||
|
if (pinMentioned) {
|
||||||
|
const mentionsA = roomA.getUnreadNotificationCount("highlight") > 0;
|
||||||
|
const mentionsB = roomB.getUnreadNotificationCount("highlight") > 0;
|
||||||
|
if (mentionsA && !mentionsB) return -1;
|
||||||
|
if (!mentionsA && mentionsB) return 1;
|
||||||
|
if (mentionsA && mentionsB) return 0;
|
||||||
|
// If neither have mentions, fall through to remaining checks
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pinUnread) {
|
||||||
|
const unreadA = Unread.doesRoomHaveUnreadMessages(roomA);
|
||||||
|
const unreadB = Unread.doesRoomHaveUnreadMessages(roomB);
|
||||||
|
if (unreadA && !unreadB) return -1;
|
||||||
|
if (!unreadA && unreadB) return 1;
|
||||||
|
if (unreadA && unreadB) return 0;
|
||||||
|
// If neither have unread messages, fall through to remaining checks
|
||||||
|
}
|
||||||
|
|
||||||
// XXX: We could use a cache here and update it when we see new
|
// XXX: We could use a cache here and update it when we see new
|
||||||
// events that trigger a reorder
|
// events that trigger a reorder
|
||||||
return this._tsOfNewestEvent(roomB) - this._tsOfNewestEvent(roomA);
|
return this._tsOfNewestEvent(roomB) - this._tsOfNewestEvent(roomA);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue