Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
Rocket.Chat
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
natalie
Rocket.Chat
Commits
1b13e1f7
Commit
1b13e1f7
authored
Dec 16, 2016
by
Bradley Hilton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When the @ sign is not present, only try to find a user by id
parent
51d3c6bd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
20 deletions
+21
-20
packages/rocketchat-integrations/server/processWebhookMessage.js
...s/rocketchat-integrations/server/processWebhookMessage.js
+21
-20
No files found.
packages/rocketchat-integrations/server/processWebhookMessage.js
View file @
1b13e1f7
function
retrieveRoomInfo
({
u
serId
,
channel
,
ignoreEmpty
=
false
})
{
function
retrieveRoomInfo
({
currentU
serId
,
channel
,
ignoreEmpty
=
false
})
{
const
room
=
RocketChat
.
models
.
Rooms
.
findOneByIdOrName
(
channel
);
if
(
!
_
.
isObject
(
room
)
&&
!
ignoreEmpty
)
{
throw
new
Meteor
.
Error
(
'
invalid-channel
'
);
}
if
(
room
&&
room
.
t
===
'
c
'
)
{
Meteor
.
runAsUser
(
u
serId
,
function
()
{
Meteor
.
runAsUser
(
currentU
serId
,
function
()
{
return
Meteor
.
call
(
'
joinRoom
'
,
room
.
_id
);
});
}
...
...
@@ -13,25 +13,26 @@ function retrieveRoomInfo({ userId, channel, ignoreEmpty=false }) {
return
room
;
}
function
retrieveDirectMessageInfo
({
userId
,
channel
})
{
const
roomUser
=
RocketChat
.
models
.
Users
.
findOne
({
$or
:
[
{
_id
:
channel
},
{
username
:
channel
}
]
})
||
{};
function
retrieveDirectMessageInfo
({
currentUserId
,
channel
,
findByUserIdOnly
=
false
})
{
let
roomUser
=
undefined
;
const
rid
=
[
userId
,
roomUser
.
_id
].
sort
().
join
(
''
);
let
room
=
RocketChat
.
models
.
Rooms
.
findOneById
({
$in
:
[
rid
,
channel
]});
if
(
!
_
.
isObject
(
roomUser
)
&&
!
_
.
isObject
(
room
))
{
if
(
findByUserIdOnly
)
{
roomUser
=
RocketChat
.
models
.
Users
.
findOneById
(
channel
);
}
else
{
roomUser
=
RocketChat
.
models
.
Users
.
findOne
({
$or
:
[{
_id
:
channel
},
{
username
:
channel
}]
});
}
if
(
!
_
.
isObject
(
roomUser
))
{
throw
new
Meteor
.
Error
(
'
invalid-channel
'
);
}
const
rid
=
[
currentUserId
,
roomUser
.
_id
].
sort
().
join
(
''
);
let
room
=
RocketChat
.
models
.
Rooms
.
findOneById
({
$in
:
[
rid
,
channel
]
});
if
(
!
room
)
{
Meteor
.
runAsUser
(
u
serId
,
function
()
{
Meteor
.
runAsUser
(
currentU
serId
,
function
()
{
Meteor
.
call
(
'
createDirectMessage
'
,
roomUser
.
username
);
room
=
RocketChat
.
models
.
Rooms
.
findOneById
(
rid
);
});
...
...
@@ -64,20 +65,20 @@ this.processWebhookMessage = function(messageObj, user, defaultValues) {
switch
(
channelType
)
{
case
'
#
'
:
room
=
retrieveRoomInfo
({
u
serId
:
user
.
_id
,
channel
});
room
=
retrieveRoomInfo
({
currentU
serId
:
user
.
_id
,
channel
});
break
;
case
'
@
'
:
room
=
retrieveDirectMessageInfo
({
u
serId
:
user
.
_id
,
channel
});
room
=
retrieveDirectMessageInfo
({
currentU
serId
:
user
.
_id
,
channel
});
break
;
default
:
//Try to find the room by id or name if they didn't include the prefix.
room
=
retrieveRoomInfo
({
u
serId
:
user
.
_id
,
channel
:
channelType
+
channel
,
ignoreEmpty
:
true
});
room
=
retrieveRoomInfo
({
currentU
serId
:
user
.
_id
,
channel
:
channelType
+
channel
,
ignoreEmpty
:
true
});
if
(
room
)
{
break
;
}
//We didn't get a room, let's try finding direct messages
room
=
retrieveDirectMessageInfo
({
userId
:
user
.
_id
,
channel
:
channelType
+
channel
});
room
=
retrieveDirectMessageInfo
({
currentUserId
:
user
.
_id
,
channel
:
channelType
+
channel
,
findByUserIdOnly
:
true
});
if
(
room
)
{
break
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment