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

Typing streams #307

Merged
merged 6 commits into from
Jul 16, 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
44 changes: 5 additions & 39 deletions client/lib/chatMessages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,18 @@
wrapper = {}
input = {}
editing = {}
selfTyping = new ReactiveVar false
typingTimeout = {}


init = ->
wrapper = $(".messages-container").find(".wrapper")
input = $(".input-message").get(0)
# self.scrollable = false
# wrapper.bind "scroll", ->
# scrollable()
bindEvents()
return

# isScrollable = ->
# self.scrollable

resize = ->
dif = 60 + $(".messages-container").find("footer").outerHeight()
$(".messages-box").css
height: "calc(100% - #{dif}px)"

# scrollable = ->
# wrapper = $(".messages-container").find(".wrapper")
# top = wrapper.scrollTop() + wrapper.outerHeight()
# if top == wrapper.get(0).scrollHeight
# self.scrollable = true
# else
# self.scrollable = false

toPrevMessage = ->
msgs = wrapper.get(0).querySelectorAll(".own:not(.system)")
if msgs.length
Expand Down Expand Up @@ -83,9 +67,6 @@
else
editing.saved = input.value

# toBottom = ->
# ScrollListener.toBottom()

send = (rid, input) ->
if _.trim(input.value) isnt ''
KonchatNotification.removeRoomNotification(rid)
Expand All @@ -109,30 +90,18 @@

startTyping = (rid, input) ->
if _.trim(input.value) isnt ''
unless typingTimeout?[rid]
if Meteor.userId()?
selfTyping.set true
Meteor.call 'typingStatus', rid, true
typingTimeout[rid] = Meteor.setTimeout ->
stopTyping(rid)
, 10000
MsgTyping.start(rid)
else
stopTyping(rid)
MsgTyping.stop(rid)

stopTyping = (rid) ->
selfTyping.set false
if typingTimeout?[rid]?
clearTimeout(typingTimeout[rid])
typingTimeout[rid] = null

Meteor.call 'typingStatus', rid, false
MsgTyping.stop(rid)

bindEvents = ->
if wrapper?.length
$(".input-message").autogrow
postGrowCallback: ->
resize()
# toBottom() if self.scrollable

keyup = (rid, event) ->
input = event.currentTarget
Expand Down Expand Up @@ -194,13 +163,10 @@
RoomHistoryManager.clear rid


# isScrollable: isScrollable
# toBottom: toBottom
keydown: keydown
keyup: keyup
deleteMsg: deleteMsg
send: send
init: init
edit: edit
selfTyping: selfTyping
)()
)()
1 change: 0 additions & 1 deletion client/lib/collections.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
@ChatRoom = new Meteor.Collection 'data.ChatRoom'
@ChatSubscription = new Meteor.Collection 'data.ChatSubscription'
@ChatMessage = new Meteor.Collection 'data.ChatMessage'
@ChatTyping = new Meteor.Collection 'data.ChatTyping'

Meteor.startup ->
ChatMessage.find().observe
Expand Down
63 changes: 63 additions & 0 deletions client/lib/msgTyping.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@MsgTyping = do ->
stream = new Meteor.Stream 'typing'
timeout = 15000
timeouts = {}
renew = true
renewTimeout = 10000
selfTyping = new ReactiveVar false
usersTyping = {}

addStream = (room) ->
unless usersTyping[room]?
usersTyping[room] = { users: new ReactiveVar {} }
stream.on room, (typing) ->
unless typing.username is Meteor.user()?.username
if typing.start
console.log 'start', typing
users = usersTyping[room].users.get()
users[typing.username] = Meteor.setTimeout ->
delete users[typing.username]
, timeout
usersTyping[room].users.set users
else if typing.stop
console.log 'stop', typing
users = usersTyping[room].users.get()
delete users[typing.username]
usersTyping[room].users.set users

Tracker.autorun ->
addStream Session.get 'openedRoom'

start = (room) ->
return unless renew

setTimeout ->
renew = true
, renewTimeout

renew = false
selfTyping.set true
stream.emit 'typing', { room: room, username: Meteor.user().username, start: true }
clearTimeout timeouts[room]
timeouts[room] = Meteor.setTimeout ->
stop(room)
, timeout

stop = (room) ->
renew = true
selfTyping.set false
if timeouts?[room]?
clearTimeout(timeouts[room])
timeouts[room] = null
stream.emit 'typing', { room: room, username: Meteor.user().username, stop: true }

get = (room) ->
users = usersTyping[room].users.get()
return _.keys(users) or []

return {
start: start
stop: stop
get: get
selfTyping: selfTyping
}
3 changes: 0 additions & 3 deletions client/startup/startup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ Meteor.startup ->
UserPresence.start()
Meteor.subscribe("activeUsers")

Tracker.autorun ->
Meteor.subscribe 'typing', Session.get 'openedRoom'

Session.setDefault('flexOpened', false)
Session.setDefault('AvatarRandom', 0)

Expand Down
98 changes: 15 additions & 83 deletions client/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,29 @@ Template.room.helpers
console.log 'room.helpers roomContainerId' if window.rocketDebug
return "room-container-#{this._id}"

showTyping: ->
console.log 'room.helpers showTyping' if window.rocketDebug
return this.t is 't'

typing: ->
console.log 'room.helpers typing' if window.rocketDebug
return this.u._id isnt Meteor.userId()

usersTyping: ->
console.log 'room.helpers usersTyping' if window.rocketDebug
messages = ChatTyping.find({ rid: this._id, 'u._id': { $ne: Meteor.userId() } }).fetch()
if messages.length is 0
users = MsgTyping.get @_id
if users.length is 0
return
if messages.length is 1
if users.length is 1
return {
multi: false
selfTyping: ChatMessages.selfTyping.get()
users: messages[0].u.username
selfTyping: MsgTyping.selfTyping.get()
users: users[0]
}

usernames = _.map messages, (message) -> return message.u.username
# usernames = _.map messages, (message) -> return message.u.username

last = usernames.pop()
if messages.length > 4
last = users.pop()
if users.length > 4
last = t('others')
usernames = usernames.join(', ')
# else
usernames = users.join(', ')
usernames = [usernames, last]
return {
multi: true
selfTyping: ChatMessages.selfTyping.get()
selfTyping: MsgTyping.selfTyping.get()
users: usernames.join " #{t 'and'} "
}

Expand Down Expand Up @@ -189,15 +182,6 @@ Template.room.helpers
console.log 'room.helpers flexOpened' if window.rocketDebug
return 'opened' if Session.equals('flexOpened', true)

flexOpenedRTC1: ->
console.log 'room.helpers flexOpenedRTC1' if window.rocketDebug
return 'layout1' if Session.equals('flexOpenedRTC1', true)

flexOpenedRTC2: ->
console.log 'room.helpers flexOpenedRTC2' if window.rocketDebug
return 'layout2' if Session.equals('flexOpenedRTC2', true)


arrowPosition: ->
console.log 'room.helpers arrowPosition' if window.rocketDebug
return 'left' unless Session.equals('flexOpened', true)
Expand Down Expand Up @@ -267,33 +251,14 @@ Template.room.helpers
return Session.get('remoteVideoUrl')

selfVideoUrl: ->
Meteor.defer ->
$('video.video-self')[0]?.muted = true;
return Session.get('selfVideoUrl')

rtcLayout1: ->
return (Session.get('rtcLayoutmode') == 1 ? true: false);

rtcLayout2: ->
return (Session.get('rtcLayoutmode') == 2 ? true: false);

rtcLayout3: ->
return (Session.get('rtcLayoutmode') == 3 ? true: false);

noRtcLayout: ->
return (!Session.get('rtcLayoutmode') || (Session.get('rtcLayoutmode') == 0) ? true: false);


Template.room.events

"click .flex-tab .more": (event) ->
console.log 'room click .flex-tab .more' if window.rocketDebug
if (Session.get('flexOpened'))
Session.set('rtcLayoutmode', 0)
Session.set('flexOpened',false)
else
Session.set('flexOpened', true)

Session.set('flexOpened', !Session.get('flexOpened'))

'click .chat-new-messages': (event) ->
console.log 'room click .chat-new-messages' if window.rocketDebug
Expand All @@ -313,7 +278,7 @@ Template.room.events
event.preventDefault()
Meteor.call 'joinRoom', this._id

"click .burger": ->
"click .burger": ->
console.log 'room click .burger' if window.rocketDebug
chatContainer = $("#rocket-chat")
if chatContainer.hasClass("menu-closed")
Expand Down Expand Up @@ -383,36 +348,6 @@ Template.room.events
Session.set('flexOpened', true)
Session.set('showUserInfo', $(e.currentTarget).data('username'))

"click .flex-tab .video-remote" : (e) ->
console.log 'room click .flex-tab .video-remote' if window.rocketDebug
if (Session.get('flexOpened'))
if (!Session.get('rtcLayoutmode'))
Session.set('rtcLayoutmode', 1)
else
t = Session.get('rtcLayoutmode')
t = (t + 1) % 4
console.log 'setting rtcLayoutmode to ' + t if window.rocketDebug
Session.set('rtcLayoutmode', t)

"click .flex-tab .video-self" : (e) ->
console.log 'room click .flex-tab .video-self' if window.rocketDebug
if (Session.get('rtcLayoutmode') == 3)
console.log 'video-self clicked in layout3' if window.rocketDebug
i = document.getElementById("fullscreendiv")
if i.requestFullscreen
i.requestFullscreen()
else
if i.webkitRequestFullscreen
i.webkitRequestFullscreen()
else
if i.mozRequestFullScreen
i.mozRequestFullScreen()
else
if i.msRequestFullscreen
i.msRequestFullscreen()



'click .user-card-message': (e) ->
console.log 'room click .user-card-message' if window.rocketDebug
roomData = Session.get('roomData' + this._arguments[1].rid)
Expand Down Expand Up @@ -520,7 +455,6 @@ Template.room.events
ChatMessages.deleteMsg(msg)

'click .start-video': (event) ->
webrtc.to = Router.current().params._id.replace(Meteor.userId(), '')
webrtc.start(true)

'click .stop-video': (event) ->
Expand All @@ -529,6 +463,7 @@ Template.room.events
Template.room.onCreated ->
console.log 'room.onCreated' if window.rocketDebug
# this.scrollOnBottom = true
# this.typing = new msgTyping this.data._id
this.showUsersOffline = new ReactiveVar false
this.atBottom = true

Expand All @@ -551,10 +486,6 @@ Template.room.onRendered ->
newMessage.className = "new-message not"
, 100

wrapper.addEventListener 'touchmove', ->
template.atBottom = false
onscroll()

wrapper.addEventListener 'mousewheel', ->
template.atBottom = false
onscroll()
Expand All @@ -567,6 +498,7 @@ Template.room.onRendered ->
# salva a data da renderização para exibir alertas de novas mensagens
$.data(this.firstNode, 'renderedAt', new Date)

webrtc.to = this.data._id.replace(Meteor.userId(), '')
webrtc.onRemoteUrl = (url) ->
Session.set('flexOpened', true)
Session.set('remoteVideoUrl', url)
Expand Down
9 changes: 0 additions & 9 deletions packages/rocketchat-lib/server/sendMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ RocketChat.sendMessage = (user, message, room) ->

RocketChat.callbacks.run 'afterSaveMessage', message

###
Remove the typing record
###
Meteor.defer ->

ChatTyping.remove
rid: message.rid
'u._id': message.u._id

###
Update all the room activity tracker fields
###
Expand Down
1 change: 0 additions & 1 deletion server/lib/collections.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@ChatMessage = new Meteor.Collection 'data.ChatMessage'
@ChatRoom = new Meteor.Collection 'data.ChatRoom'
@ChatSubscription = new Meteor.Collection 'data.ChatSubscription'
@ChatTyping = new Meteor.Collection 'data.ChatTyping'
2 changes: 1 addition & 1 deletion server/methods/getAvatarSuggestion.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
Meteor.methods
getAvatarSuggestion: ->
if not Meteor.userId()
throw new Meteor.Error 203, '[methods] typingStatus -> Usuário não logado'
throw new Meteor.Error 203, '[methods] getAvatarSuggestion -> Usuário não logado'

user = Meteor.user()

Expand Down
2 changes: 1 addition & 1 deletion server/methods/getUsernameSuggestion.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ usernameIsAvaliable = (username) ->
Meteor.methods
getUsernameSuggestion: ->
if not Meteor.userId()
throw new Meteor.Error 203, '[methods] typingStatus -> Usuário não logado'
throw new Meteor.Error 203, '[methods] getUsernameSuggestion -> Usuário não logado'

user = Meteor.user()
return generateSuggestion(user)
Loading