-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathmessagePopupConfig.coffee
More file actions
123 lines (100 loc) · 2.79 KB
/
messagePopupConfig.coffee
File metadata and controls
123 lines (100 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@filteredUsers = new Mongo.Collection 'filtered-users'
Template.messagePopupConfig.helpers
popupUserConfig: ->
self = this
template = Template.instance()
config =
title: 'People'
collection: filteredUsers
template: 'messagePopupUser'
getInput: self.getInput
textFilterDelay: 200
getFilter: (collection, filter) ->
exp = new RegExp("^#{filter}", 'i')
Meteor.subscribe 'filteredUsers', filter
items = filteredUsers.find({$or: [{username: exp}, {name: exp}]}, {limit: 5}).fetch()
all =
_id: '@all'
username: '@all'
system: true
name: t 'Notify_all_in_this_room'
compatibility: 'channel group'
exp = new RegExp("(^|\\s)#{filter}", 'i')
if exp.test(all.username) or exp.test(all.compatibility)
items.unshift all
return items
getValue: (_id, collection, firstPartValue) ->
if _id is '@all'
if firstPartValue.indexOf(' ') > -1
return 'all'
return 'all:'
username = collection.findOne(_id)?.username
if firstPartValue.indexOf(' ') > -1
return username
return username + ':'
return config
popupChannelConfig: ->
self = this
template = Template.instance()
config =
title: 'Channels'
collection: ChatSubscription
trigger: '#'
template: 'messagePopupChannel'
getInput: self.getInput
getFilter: (collection, filter) ->
return collection.find({t: 'c', name: new RegExp(filter, 'i')}, {limit: 10})
getValue: (_id, collection) ->
return collection.findOne(_id)?.name
return config
popupSlashCommandsConfig: ->
self = this
template = Template.instance()
config =
title: 'Commands'
collection: RocketChat.slashCommands.commands
trigger: '/'
triggerAnywhere: false
template: 'messagePopupSlashCommand'
getInput: self.getInput
getFilter: (collection, filter) ->
commands = []
for command, item of collection
if command.indexOf(filter) > -1
commands.push
_id: command
params: item.params
description: item.description
if commands.length > 10
break
commands = commands.sort (a, b) ->
return a._id > b._id
return commands
return config
emojiEnabled: ->
return RocketChat.emoji?
popupEmojiConfig: ->
if RocketChat.emoji?
self = this
template = Template.instance()
config =
title: 'Emoji'
collection: RocketChat.emoji.list
template: 'messagePopupEmoji'
trigger: ':'
prefix: ''
getInput: self.getInput
getFilter: (collection, filter) ->
results = []
for shortname, data of collection
if shortname.indexOf(filter) > -1
results.push
_id: shortname
data: data
if results.length > 10
break
if filter.length >= 3
results.sort (a, b) ->
a.length > b.length
return results
return config