feat: add global search while searching message closes # 1615

pull/7274/head
Nishchal Gautam 8 years ago
parent b618894714
commit 472ba850f4
  1. 16
      packages/rocketchat-ui-flextab/client/tabs/messageSearch.js
  2. 15
      server/methods/messageSearch.js

@ -8,8 +8,16 @@ Meteor.startup(function() {
],
action() {
const message = this._arguments[1];
RocketChat.MessageAction.hideDropDown();
if (Session.get('openedRoom') === message.rid) {
return RoomHistoryManager.getSurroundingMessages(message, 50);
}
FlowRouter.goToRoomById(message.rid);
RocketChat.MessageAction.hideDropDown();
window.setTimeout(() => {
RoomHistoryManager.getSurroundingMessages(message, 50);
}, 400);
// 400ms is popular among game devs as a good delay before transition starts
// ie. 50, 100, 200, 400, 800 are the favored timings
},
order: 100
});
@ -65,7 +73,7 @@ Template.messageSearch.events({
t.hasMore.set(true);
t.limit.set(20);
return t.search();
return t.search(true);
}
, 500),
@ -108,11 +116,11 @@ Template.messageSearch.onCreated(function() {
this.limit = new ReactiveVar(20);
this.ready = new ReactiveVar(true);
return this.search = () => {
return this.search = (globalSearch = false) => {
this.ready.set(false);
const value = this.$('#message-search').val();
return Tracker.nonreactive(() => {
return Meteor.call('messageSearch', value, Session.get('openedRoom'), this.limit.get(), (error, result) => {
return Meteor.call('messageSearch', value, (globalSearch) ? undefined: Session.get('openedRoom'), this.limit.get(), (error, result) => {
this.currentSearchTerm.set(value);
this.ready.set(true);
if ((result != null) && (((result.messages != null ? result.messages.length : undefined) > 0) || ((result.users != null ? result.users.length : undefined) > 0) || ((result.channels != null ? result.channels.length : undefined) > 0))) {

@ -14,7 +14,7 @@ Meteor.methods({
};
check(text, String);
check(rid, String);
check(rid, Match.Maybe(String));
check(limit, Match.Optional(Number));
const currentUserId = Meteor.userId();
@ -182,9 +182,16 @@ Meteor.methods({
query._hidden = {
$ne: true // don't return _hidden messages
};
if (rid != null) {
if (rid) {
query.rid = rid;
if (Meteor.call('canAccessRoom', rid, currentUserId) !== false) {
// check if user can access rid room
} else {
query.rid = {
$in : RocketChat.models.Rooms.findByContainingUsername(currentUserName)
.fetch()
.map(room => room._id)
};
}
if (!RocketChat.settings.get('Message_ShowEditedStatus')) {
options.fields = {
'editedAt': 0
@ -192,8 +199,6 @@ Meteor.methods({
}
result.messages = RocketChat.models.Messages.find(query, options).fetch();
}
}
}
return result;
}

Loading…
Cancel
Save