Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rocket.Chat
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RocketChat
Rocket.Chat
Commits
db82bfcb
Commit
db82bfcb
authored
9 years ago
by
Gabriel Engel
Browse files
Options
Downloads
Patches
Plain Diff
several performance improvements
parent
95c69b1d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/methods/canAccessRoom.coffee
+8
-9
8 additions, 9 deletions
server/methods/canAccessRoom.coffee
server/methods/sendMessage.coffee
+33
-10
33 additions, 10 deletions
server/methods/sendMessage.coffee
with
41 additions
and
19 deletions
server/methods/canAccessRoom.coffee
+
8
−
9
View file @
db82bfcb
Meteor
.
methods
canAccessRoom
:
(
r
oomI
d
,
userId
)
->
console
.
log
'[methods] canAccessRoom -> '
.
green
,
'userId:'
,
userId
,
'r
oomI
d:'
,
r
oomI
d
canAccessRoom
:
(
r
i
d
,
userId
)
->
console
.
log
'[methods] canAccessRoom -> '
.
green
,
'userId:'
,
userId
,
'r
i
d:'
,
r
i
d
user
=
Meteor
.
users
.
findOne
userId
,
fields
:
username
:
1
...
...
@@ -8,12 +8,10 @@ Meteor.methods
unless
user
?
.
username
throw
new
Meteor
.
Error
'not-logged-user'
,
"[methods] canAccessRoom -> User doesn't have enough permissions"
unless
r
oomI
d
unless
r
i
d
throw
new
Meteor
.
Error
'invalid-room'
,
'[methods] canAccessRoom -> Cannot access empty room'
room
=
ChatRoom
.
findOne
roomId
,
{
fields
:
{
usernames
:
1
,
t
:
1
}
}
canAccess
=
false
room
=
ChatRoom
.
findOne
rid
,
{
fields
:
{
usernames
:
1
,
t
:
1
}
}
if
room
.
t
is
'c'
canAccess
=
true
...
...
@@ -22,9 +20,12 @@ Meteor.methods
if
canAccess
isnt
true
throw
new
Meteor
.
Error
'without-permission'
,
"[methods] canAccessRoom -> User doesn't have enough permissions"
return
false
else
return
room
# # create room subscription
# ChatSubscription.upsert { rid: r
oomI
d, $and: [{'u._id': Meteor.userId()}] },
# ChatSubscription.upsert { rid: r
i
d, $and: [{'u._id': Meteor.userId()}] },
# $setOnInsert:
# 'u._id': Meteor.userId()
# name: room.name
...
...
@@ -33,5 +34,3 @@ Meteor.methods
# $set:
# ls: (new Date())
# ts: (new Date())
return
canAccess
This diff is collapsed.
Click to expand it.
server/methods/sendMessage.coffee
+
33
−
10
View file @
db82bfcb
...
...
@@ -3,7 +3,9 @@ Meteor.methods
if
not
Meteor
.
userId
()
throw
new
Meteor
.
Error
(
'invalid-user'
,
"[methods] sendMessage -> Invalid user"
)
if
not
Meteor
.
call
'canAccessRoom'
,
message
.
rid
,
Meteor
.
userId
()
room
=
Meteor
.
call
'canAccessRoom'
,
message
.
rid
,
Meteor
.
userId
()
if
not
room
return
false
console
.
log
'[methods] sendMessage -> '
.
green
,
'userId:'
,
Meteor
.
userId
(),
'arguments:'
,
arguments
...
...
@@ -12,7 +14,7 @@ Meteor.methods
message
.
ts
=
new
Date
()
message
=
RocketChat
.
callbacks
.
run
'beforeSaveMessage'
,
message
console
.
log
"message"
,
message
#
console.log "message", message
###
Defer other updated as their return is not interesting to the user
...
...
@@ -33,28 +35,49 @@ Meteor.methods
$inc
:
msgs
:
1
message
.
mentions
?
.
forEach
(
mention
)
->
# increment unread couter if direct messages
if
room
.
t
is
'd'
###
Update all other subscriptions of mentioned users to alert their owners and incrementing
the unread counter for mentions and direct messages
Update the other subscriptions
###
ChatSubscription
.
update
# only subscriptions to the same room
rid
:
message
.
rid
# not the msg owner
'u._id'
:
mention
.
_id
'u._id'
:
$ne
:
message
.
u
.
_id
,
$set
:
# alert de user
alert
:
true
# open the room for the user
open
:
true
# increment un
d
ea
r
couter
# increment un
r
ea
d
couter
$inc
:
unread
:
1
,
# make sure we alert all matching subscription
multi
:
true
else
message
.
mentions
?
.
forEach
(
mention
)
->
console
.
log
mention
###
Update all other subscriptions of mentioned users to alert their owners and incrementing
the unread counter for mentions and direct messages
###
ChatSubscription
.
update
# only subscriptions to the same room
rid
:
message
.
rid
# the mentioned user
'u._id'
:
mention
.
_id
,
$set
:
# alert de user
alert
:
true
# open the room for the user
open
:
true
# increment unread couter
$inc
:
unread
:
1
###
Update all other subscriptions to alert their owners but witout incrementing
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment