Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor bugs in irc plugin. #302

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions packages/rocketchat-irc/irc.server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async = (f, args...) ->
class IrcClient
constructor: (@loginReq) ->
@user = @loginReq.user
@user.username = @user.name
ircClientMap[@user._id] = this
@ircPort = IRC_PORT
@ircHost = IRC_HOST
Expand Down Expand Up @@ -157,8 +158,7 @@ class IrcClient
ircSendMessageCache.set cacheKey, timestamp

console.log '[irc] onReceiveMessage -> '.yellow, 'source:', source, 'target:', target, 'content:', content
@createUserWhenNotExist source
source = Meteor.users.findOne {name: source}
source = @createUserWhenNotExist source
if target[0] == '#'
room = ChatRoom.findOne {name: target.substring 1}
else
Expand Down Expand Up @@ -188,9 +188,6 @@ class IrcClient

for member in appendMembers
@createUserWhenNotExist member
Meteor.users.update {name: member},
$set:
status: 'online'

update =
$pull:
Expand Down Expand Up @@ -248,7 +245,7 @@ class IrcClient
@joinRoom(room)

joinRoom: (room) ->
if room.t isnt 'c'
if room.t isnt 'c' or room.name == 'general'
return

if @isJoiningRoom
Expand Down Expand Up @@ -304,15 +301,23 @@ class IrcClient
status: 'offline'

createUserWhenNotExist: (name) ->
user = Meteor.users.findOne {name: name}, fields: name: 1
user = Meteor.users.findOne {name: name}
unless user
console.log '[irc] createNotExistUser ->'.yellow, 'userName:', name
Meteor.call 'registerUser',
email: "#{name}@rocketchat.org",
pass: 'rocketchat',
email: "#{name}@rocketchat.org"
pass: 'rocketchat'
name: name
Meteor.users.update {name: name},
$set:
status: 'online'
username: name
user = Meteor.users.findOne {name: name}
return user


createDirectRoomWhenNotExist: (source, target) ->
console.log '[irc] createDirectRoomWhenNotExist -> '.yellow, 'source:', source, 'target:', target
rid = [source._id, target._id].sort().join('')
now = new Date()
ChatRoom.upsert
Expand Down Expand Up @@ -346,9 +351,12 @@ IrcClient.getByUid = (uid) ->
return ircClientMap[uid]

IrcClient.create = (login) ->
unless login.user?
return login
unless login.user._id of ircClientMap
ircClient = new IrcClient login
return async ircClient.connect

return login


Expand Down
11 changes: 6 additions & 5 deletions server/methods/createChannel.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Meteor.methods
console.log '[methods] createChannel -> '.green, 'userId:', Meteor.userId(), 'arguments:', arguments

now = new Date()
user = Meteor.user()

members.push Meteor.user().username
members.push user.username

# name = s.slugify name

Expand All @@ -22,9 +23,9 @@ Meteor.methods
msgs: 0
u:
_id: Meteor.userId()
username: Meteor.user().username
username: user.username

RocketChat.callbacks.run 'beforeCreateChannel', Meteor.user(), room
RocketChat.callbacks.run 'beforeCreateChannel', user, room

# create new room
rid = ChatRoom.insert room
Expand All @@ -44,14 +45,14 @@ Meteor.methods
_id: member._id
username: username

if username is Meteor.user().username
if username is user.username
sub.ls = now

ChatSubscription.insert sub

Meteor.defer ->

RocketChat.callbacks.run 'afterCreateChannel', Meteor.user(), room
RocketChat.callbacks.run 'afterCreateChannel', user, room

return {
rid: rid
Expand Down
4 changes: 3 additions & 1 deletion server/methods/joinRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Meteor.methods
_id: user._id
username: user.username

RocketChat.callbacks.run 'afterJoinRoom', user, room
Meteor.defer ->

RocketChat.callbacks.run 'afterJoinRoom', user, room

return true
15 changes: 9 additions & 6 deletions server/methods/leaveRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@ Meteor.methods
throw new Meteor.Error 300, 'Usuário não logado'

room = ChatRoom.findOne rid
user = Meteor.user()

RocketChat.callbacks.run 'beforeLeaveRoom', Meteor.user(), room
RocketChat.callbacks.run 'beforeLeaveRoom', user, room

update =
$pull:
usernames: Meteor.user().username
usernames: user.username

ChatSubscription.update { rid: rid },
$set:
name: room.name
,
multi: true

if room.t isnt 'c' and room.usernames.indexOf(Meteor.user().username) isnt -1
removedUser = Meteor.user()
if room.t isnt 'c' and room.usernames.indexOf(user.username) isnt -1
removedUser = user

ChatMessage.insert
rid: rid
Expand All @@ -33,7 +34,7 @@ Meteor.methods
username: removedUser.username

if room.u? and room.u._id is Meteor.userId()
newOwner = _.without(room.usernames, Meteor.user().username)[0]
newOwner = _.without(room.usernames, user.username)[0]
if newOwner?
newOwner = Meteor.users.findOne username: newOwner

Expand All @@ -48,4 +49,6 @@ Meteor.methods

ChatRoom.update rid, update

RocketChat.callbacks.run 'afterLeaveRoom', Meteor.user(), room
Meteor.defer ->

RocketChat.callbacks.run 'afterLeaveRoom', user, room
124 changes: 0 additions & 124 deletions server/methods/receiveMessage.coffee

This file was deleted.