commit
ecb3de6734
@ -0,0 +1,23 @@ |
||||
<template name="toolbar"> |
||||
<div class="toolbar"> |
||||
<div class="toolbar-search"> |
||||
<i class="toolbar-search__icon icon-search"></i> |
||||
<input type="text" name="toolbar-input" class="toolbar-search__input background-transparent-light color-content-background-color border-transparent-lighter" placeholder="{{_ "Search"}}"> |
||||
<i class="toolbar-search__icon toolbar-search__icon--cancel icon-cancel"></i> |
||||
</div> |
||||
|
||||
{{> messagePopup popupConfig}} |
||||
</div> |
||||
</template> |
||||
|
||||
<template name="toolbarSearchList"> |
||||
<i class="{{icon}} {{userStatus}}"></i> |
||||
{{name}} |
||||
{{#if unread}} |
||||
<span class="unread">{{unread}}</span> |
||||
{{/if}} |
||||
</template> |
||||
|
||||
<template name="toolbarSearchListEmpty"> |
||||
{{_ "Room_not_found"}} |
||||
</template> |
||||
@ -0,0 +1,149 @@ |
||||
let isLoading; |
||||
let filterText = ''; |
||||
let usernamesFromClient; |
||||
let resultsFromClient; |
||||
|
||||
Meteor.startup(() => { |
||||
isLoading = new ReactiveVar(false); |
||||
}); |
||||
|
||||
const toolbarSearch = { |
||||
clear() { |
||||
$('.toolbar-search__input').val(''); |
||||
$('.toolbar-search__input').trigger({ |
||||
type: 'keyup', |
||||
which: 27 |
||||
}); |
||||
}, |
||||
|
||||
focus() { |
||||
$('.toolbar-search__input').focus(); |
||||
} |
||||
}; |
||||
|
||||
this.toolbarSearch = toolbarSearch; |
||||
|
||||
const getFromServer = (cb) => { |
||||
isLoading.set(true); |
||||
const currentFilter = filterText; |
||||
|
||||
Meteor.call('spotlight', currentFilter, usernamesFromClient, (err, results) => { |
||||
if (currentFilter !== filterText) { |
||||
return; |
||||
} |
||||
|
||||
isLoading.set(false); |
||||
|
||||
if (err) { |
||||
console.log(err); |
||||
return false; |
||||
} |
||||
|
||||
const resultsFromServer = []; |
||||
const usersLength = results.users.length; |
||||
const roomsLength = results.rooms.length; |
||||
|
||||
if (usersLength) { |
||||
for (let i = 0; i < usersLength; i++) { |
||||
resultsFromServer.push({ |
||||
_id: results.users[i]._id, |
||||
t: 'd', |
||||
name: results.users[i].username |
||||
}); |
||||
} |
||||
} |
||||
|
||||
if (roomsLength) { |
||||
for (let i = 0; i < roomsLength; i++) { |
||||
resultsFromServer.push({ |
||||
_id: results.rooms[i]._id, |
||||
t: results.rooms[i].t, |
||||
name: results.rooms[i].name |
||||
}); |
||||
} |
||||
} |
||||
|
||||
if (resultsFromServer.length) { |
||||
cb(resultsFromClient.concat(resultsFromServer)); |
||||
} |
||||
}); |
||||
}; |
||||
|
||||
const getFromServerThrottled = _.throttle(getFromServer, 500); |
||||
|
||||
Template.toolbar.helpers({ |
||||
results() { |
||||
return Template.instance().resultsList.get(); |
||||
}, |
||||
popupConfig() { |
||||
const config = { |
||||
cls: 'search-results-list', |
||||
collection: RocketChat.models.Subscriptions, |
||||
template: 'toolbarSearchList', |
||||
emptyTemplate: 'toolbarSearchListEmpty', |
||||
input: '.toolbar-search__input', |
||||
closeOnEsc: false, |
||||
blurOnSelectItem: true, |
||||
isLoading: isLoading, |
||||
getFilter: function(collection, filter, cb) { |
||||
filterText = filter; |
||||
resultsFromClient = collection.find({name: new RegExp((RegExp.escape(filter)), 'i'), rid: {$ne: Session.get('openedRoom')}}, {limit: 10, sort: {unread: -1, ls: -1}}).fetch(); |
||||
|
||||
const resultsFromClientLength = resultsFromClient.length; |
||||
usernamesFromClient = [Meteor.user().username]; |
||||
|
||||
for (let i = 0; i < resultsFromClientLength; i++) { |
||||
if (resultsFromClient[i].t === 'd') { |
||||
usernamesFromClient.push(resultsFromClient[i].name); |
||||
} |
||||
} |
||||
|
||||
cb(resultsFromClient); |
||||
|
||||
getFromServerThrottled(cb); |
||||
}, |
||||
getValue: function(_id, collection, records) { |
||||
const doc = _.findWhere(records, {_id: _id}); |
||||
|
||||
RocketChat.roomTypes.openRouteLink(doc.t, doc, FlowRouter.current().queryParams); |
||||
} |
||||
}; |
||||
|
||||
return config; |
||||
} |
||||
}); |
||||
|
||||
Template.toolbar.events({ |
||||
'blur .toolbar-search__input'() { |
||||
toolbarSearch.clear(); |
||||
}, |
||||
|
||||
'keyup .toolbar-search__input'(e) { |
||||
if (e.which === 27) { |
||||
e.preventDefault(); |
||||
e.stopPropagation(); |
||||
|
||||
const $inputMessage = $('textarea.input-message'); |
||||
|
||||
if (0 === $inputMessage.length) { |
||||
return; |
||||
} |
||||
|
||||
$inputMessage.focus(); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
Template.toolbarSearchList.helpers({ |
||||
icon() { |
||||
return RocketChat.roomTypes.getIcon(this.t); |
||||
}, |
||||
|
||||
userStatus() { |
||||
if (this.t === 'd') { |
||||
return 'status-' + (Session.get(`user_${this.name}_status`) || 'offline'); |
||||
} else { |
||||
return 'status-' + (RocketChat.roomTypes.getUserStatus(this.t, this.rid || this._id) || 'offline'); |
||||
} |
||||
} |
||||
}); |
||||
@ -1,59 +0,0 @@ |
||||
@mobileMessageMenu = |
||||
show: (message, template, e, scope) -> |
||||
if not window.plugins?.actionsheet? |
||||
return |
||||
|
||||
options = |
||||
'androidTheme': window.plugins.actionsheet.ANDROID_THEMES.THEME_HOLO_LIGHT |
||||
'buttonLabels': [ |
||||
TAPi18n.__('Report Abuse') |
||||
] |
||||
androidEnableCancelButton: true |
||||
addCancelButtonWithLabel: TAPi18n.__('Cancel') |
||||
# 'position': [20, 40] // for iPad pass in the [x, y] position of the popover |
||||
|
||||
buttonActions = [ |
||||
mobileMessageMenu.reportAbuse |
||||
] |
||||
|
||||
buttons = RocketChat.MessageAction.getButtons message, (message.customClass or 'message-mobile') |
||||
for button in buttons |
||||
if button.id is 'delete-message' |
||||
options.addDestructiveButtonWithLabel = TAPi18n.__(button.i18nLabel) |
||||
buttonActions.unshift button.action |
||||
else |
||||
buttonActions.push button.action |
||||
options.buttonLabels.push TAPi18n.__(button.i18nLabel) |
||||
|
||||
window.plugins.actionsheet.show options, (buttonIndex) -> |
||||
if buttonActions[buttonIndex-1]? |
||||
buttonActions[buttonIndex-1].call scope, e, template, message |
||||
|
||||
reportAbuse: (e, t, message) -> |
||||
swal { |
||||
title: TAPi18n.__('Report_this_message_question_mark') |
||||
text: message.msg |
||||
inputPlaceholder: TAPi18n.__('Why_do_you_want_to_report_question_mark') |
||||
type: 'input' |
||||
showCancelButton: true |
||||
confirmButtonColor: '#DD6B55' |
||||
confirmButtonText: TAPi18n.__("Report_exclamation_mark") |
||||
cancelButtonText: TAPi18n.__('Cancel') |
||||
closeOnConfirm: false |
||||
html: false |
||||
}, (inputValue) -> |
||||
if inputValue is false |
||||
return false |
||||
|
||||
if inputValue is "" |
||||
swal.showInputError(TAPi18n.__("You_need_to_write_something")) |
||||
return false |
||||
|
||||
Meteor.call 'reportMessage', message, inputValue |
||||
|
||||
swal |
||||
title: TAPi18n.__("Report_sent") |
||||
text: TAPi18n.__("Thank_you_exclamation_mark") |
||||
type: 'success' |
||||
timer: 1000 |
||||
showConfirmButton: false |
||||
@ -1,64 +0,0 @@ |
||||
@spotlight = |
||||
hide: -> |
||||
$('.spotlight').addClass('hidden') |
||||
|
||||
show: -> |
||||
$('.spotlight input').val('') |
||||
$('.spotlight').removeClass('hidden') |
||||
$('.spotlight input').focus() |
||||
|
||||
getFromServer = (filter, records, cb) => |
||||
Meteor.call 'spotlight', filter, Meteor.user().username, (err, results) -> |
||||
if err? |
||||
return console.log err |
||||
|
||||
server = [] |
||||
|
||||
if results?.users?.length > 0 |
||||
for user in results.users when not _.findWhere(records, {t: 'd', name: user.username})? |
||||
server.push({ |
||||
_id: user._id |
||||
t: 'd', |
||||
name: user.username |
||||
}) |
||||
|
||||
if results?.rooms?.length > 0 |
||||
for room in results.rooms |
||||
server.push({ |
||||
_id: room._id |
||||
t: room.t, |
||||
name: room.name |
||||
}) |
||||
|
||||
if server.length > 0 |
||||
cb(records.concat(server)) |
||||
|
||||
getFromServerDelayed = _.throttle getFromServer, 500 |
||||
|
||||
Template.spotlight.helpers |
||||
popupConfig: -> |
||||
config = |
||||
cls: 'popup-down' |
||||
collection: RocketChat.models.Subscriptions |
||||
template: 'spotlightTemplate' |
||||
input: '[name=spotlight]' |
||||
getFilter: (collection, filter, cb) -> |
||||
exp = new RegExp("#{RegExp.escape filter}", 'i') |
||||
|
||||
records = collection.find({name: exp, rid: {$ne: Session.get('openedRoom')}}, {limit: 10, sort: {unread: -1, ls: -1}}).fetch() |
||||
|
||||
cb(records) |
||||
|
||||
if filter?.trim().length < 1 or records.length >= 5 |
||||
return |
||||
|
||||
getFromServerDelayed(filter, records, cb) |
||||
|
||||
getValue: (_id, collection, records, firstPartValue) -> |
||||
doc = _.findWhere(records, {_id: _id}) |
||||
|
||||
RocketChat.roomTypes.openRouteLink(doc.t, doc, FlowRouter.current().queryParams) |
||||
|
||||
spotlight.hide() |
||||
|
||||
return config |
||||
@ -1,9 +0,0 @@ |
||||
<template name="spotlight"> |
||||
<div class="spotlight hidden background-transparent-darker"> |
||||
<div class="spotlight-input secondary-background-color secondary-font-color"> |
||||
<i class="icon-search secondary-font-color"></i> |
||||
<input type="text" name="spotlight"> |
||||
{{> messagePopup popupConfig}} |
||||
</div> |
||||
</div> |
||||
</template> |
||||
@ -1,7 +0,0 @@ |
||||
<template name="spotlightTemplate"> |
||||
<i class="{{icon}} {{userStatus}}"></i> |
||||
{{name}} |
||||
{{#if unread}} |
||||
<span>{{unread}}</span> |
||||
{{/if}} |
||||
</template> |
||||
@ -1,13 +0,0 @@ |
||||
Template.spotlightTemplate.helpers({ |
||||
icon() { |
||||
return RocketChat.roomTypes.getIcon(this.t); |
||||
}, |
||||
|
||||
userStatus() { |
||||
if (this.t === 'd') { |
||||
return 'status-' + (Session.get(`user_${this.name}_status`) || 'offline'); |
||||
} else { |
||||
return 'status-' + (RocketChat.roomTypes.getUserStatus(this.t, this.rid || this._id) || 'offline'); |
||||
} |
||||
} |
||||
}); |
||||
Loading…
Reference in new issue