diff --git a/client/ChatterApp.jsx b/client/ChatterApp.jsx index 122a504..73a88f1 100644 --- a/client/ChatterApp.jsx +++ b/client/ChatterApp.jsx @@ -5,14 +5,23 @@ import getChatHTML from "./template-helpers/getChatHTML.jsx"; import router from "./template-helpers/router.jsx"; import Widget from "./components/Widget.jsx"; -const latestRooms = function (limit, withIds, archived) { +import { + CHATTER_CACHE_LIMIT, + CHATTER_EXPIRE_IN +} from "./global-variables.js"; + +const latestRooms = function (limit, withIds) { return { - find: {"_id": {$in: withIds}, "archived": archived}, + find: {"_id": {$in: withIds}}, options: {sort: {lastActive: -1}, limit: limit} }; }; -const chatterSubs = new SubsManager(); + +const chatterSubs = new SubsManager({ + cacheLimit: CHATTER_CACHE_LIMIT, + expireIn: CHATTER_EXPIRE_IN +}); const ChatterApp = React.createClass({ mixins: [ReactMeteorData], @@ -46,10 +55,15 @@ const ChatterApp = React.createClass({ const {activeRoomLimit, archivedRoomLimit} = this.state; if (userId) { - const userRooms = Chatter.UserRoom.find({userId}).fetch(); - const roomIds = _.pluck(userRooms, "roomId"); - const activeRoomQuery = latestRooms(activeRoomLimit, roomIds, false); - const archivedRoomQuery = latestRooms(archivedRoomLimit, roomIds, true); + const archivedUserRooms = Chatter.UserRoom.find({userId, archived: true}).fetch(); + const unarchivedUserRooms = Chatter.UserRoom.find({userId, archived: false}).fetch(); + + const archivedRoomIds = _.pluck(archivedUserRooms, "roomId"); + const unarchivedRoomIds = _.pluck(unarchivedUserRooms, "roomId"); + + const activeRoomQuery = latestRooms(activeRoomLimit, unarchivedRoomIds); + const archivedRoomQuery = latestRooms(archivedRoomLimit, archivedRoomIds); + activeRooms = Chatter.Room.find(activeRoomQuery.find, activeRoomQuery.options).fetch(); archivedRooms = Chatter.Room.find(archivedRoomQuery.find, archivedRoomQuery.options).fetch(); } diff --git a/client/components/MainSettings.jsx b/client/components/MainSettings.jsx index 4a2d2e4..0ea1b25 100644 --- a/client/components/MainSettings.jsx +++ b/client/components/MainSettings.jsx @@ -2,19 +2,35 @@ import React from 'react'; import Loader from "../components/Loader.jsx" const MainSettings = React.createClass({ + mixins: [ReactMeteorData], getInitialState: function() { return { - roomUsers: [], - archived: this.props.room.archived + roomUsers: [] }; }, + getMeteorData () { + const userId = Meteor.userId(); + const userRoomsHandle = Meteor.subscribe("chatterUserRooms"); + const subsReady = userRoomsHandle.ready(); + let room = this.props.room; + let user = null; + + if (subsReady) { + const ur = Chatter.UserRoom.findOne({roomId: this.props.room._id, userId}); + user = Meteor.user(); + room.archived = ur.archived; + } + + return { + subsReady, + room, + user + } + }, + componentDidMount() { - $(".ui.toggle.checkbox").checkbox(); - if (this.state.archived) { - $(".ui.toggle.checkbox").checkbox('check'); - } Meteor.call("room.users", this.props.room._id, (error, result) => { this.setState({roomUsers: result}); }); @@ -22,93 +38,100 @@ const MainSettings = React.createClass({ toggleArchivedState() { const params = { - archived: !this.state.archived, - roomId: this.props.room._id + archived: !this.data.room.archived, + roomId: this.props.room._id, + userId: Meteor.userId() }; + Meteor.call("room.archive", params); - this.setState({archived: !this.state.archived}); }, render() { - const user = Meteor.user(); - - const addUsersHTML = ( -
- {this.props.room.description} -
-- This channel was created by {this.props.room.createdBy} on the {this.props.room.createdAt.toISOString()}. -
-- Archived chats will store the conversation and stop notifications from bothering you in the future. -
-+ {this.props.room.description} +
++ This channel was created by {this.props.room.createdBy} on the {this.props.room.createdAt.toISOString()}. +
++ Archived chats will store the conversation and stop notifications from bothering you in the future. +
+{user.chatterNickname} is currently {user.online ? "online" : "offline"}.
- {this.props.userProfile == Meteor.userId() ? form : null} + {this.props.userProfile === userId ? form : null}