Organized code, added a safe string helper.

This commit is contained in:
perroned 2014-10-28 07:24:56 -07:00
parent c1fa10e3bf
commit 524918ffcc

View File

@ -4,6 +4,28 @@
hex = "0" + hex while hex.length < 6
"##{hex}"
@currentUserIsMuted = ->
return Meteor.Users.findOne({_id: getInSession "DBID"})?.user?.voiceUser?.muted
# color can be a number (a hex converted to int) or a string (e.g. "#ffff00")
@formatColor = (color) ->
color ?= "0" # default value
if !color.toString().match(/\#.*/)
color = colourToHex(color)
color
# thickness can be a number (e.g. "2") or a string (e.g. "2px")
@formatThickness = (thickness) ->
thickness ?= "1" # default value
if !thickness.toString().match(/.*px$/)
"#" + thickness + "px" # leading "#" - to be compatible with Firefox
thickness
@getCurrentSlideDoc = -> # returns only one document
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
# retrieve account for selected user
@getCurrentUserFromSession = ->
Meteor.Users.findOne("_id": getInSession("userId"))
@ -35,19 +57,19 @@
setInSession "userName", user.user.name # store in session for fast access next time
user.user.name
else null
@getPresentationFilename = ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
currentPresentation?.presentation?.name
Handlebars.registerHelper "colourToHex", (value) =>
@window.colourToHex(value)
@window.colourToHex(value)
Handlebars.registerHelper 'equals', (a, b) -> # equals operator was dropped in Meteor's migration from Handlebars to Spacebars
a is b
Handlebars.registerHelper "getCurrentMeeting", ->
Meteor.Meetings.findOne()
Meteor.Meetings.findOne()
Handlebars.registerHelper "getCurrentSlide", ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
@ -63,13 +85,10 @@ Handlebars.registerHelper "getInSession", (k) -> SessionAmplify.get k
Handlebars.registerHelper "getMeetingName", ->
window.getMeetingName()
Handlebars.registerHelper "getWhiteboardTitle", ->
"Whiteboard: " + getPresentationFilename()
Handlebars.registerHelper "getShapesForSlide", ->
currentSlide = getCurrentSlideDoc()
# try to reuse the lines above
Meteor.Shapes.find({whiteboardId: currentSlide?.slide?.id})
@ -77,12 +96,12 @@ Handlebars.registerHelper "getShapesForSlide", ->
Handlebars.registerHelper "getUsersInMeeting", ->
Meteor.Users.find({})
Handlebars.registerHelper "getWhiteboardTitle", ->
"Whiteboard: " + getPresentationFilename()
Handlebars.registerHelper "isCurrentUser", (_id) ->
_id is getInSession("DBID")
Handlebars.registerHelper "meetingIsRecording", ->
Meteor.Meetings.findOne()?.recorded # Should only ever have one meeting, so we dont need any filter and can trust result #1
Handlebars.registerHelper "isCurrentUserMuted", ->
return currentUserIsMuted()
@ -95,21 +114,25 @@ Handlebars.registerHelper "isCurrentUserSharingAudio", ->
return user?.user?.voiceUser?.joined
Handlebars.registerHelper "isCurrentUserSharingVideo", ->
user = Meteor.Users.findOne({_id:getInSession("DBID")})
user?.webcam_stream?.length isnt 0
user = Meteor.Users.findOne({_id:getInSession("DBID")})
user?.webcam_stream?.length isnt 0
Handlebars.registerHelper "isCurrentUserTalking", ->
user = Meteor.Users.findOne({_id:getInSession("DBID")})
return user?.user?.voiceUser?.talking
Handlebars.registerHelper "isUserSharingAudio", (_id) ->
user = Meteor.Users.findOne({_id:_id})
return user.user?.voiceUser?.joined
Handlebars.registerHelper "isUserListenOnly", (_id) ->
user = Meteor.Users.findOne({_id:_id})
return user?.user?.listenOnly
Handlebars.registerHelper "isUserMuted", (_id) ->
user = Meteor.Users.findOne({_id:_id})
return user?.user?.voiceUser?.muted
Handlebars.registerHelper "isUserSharingAudio", (_id) ->
user = Meteor.Users.findOne({_id:_id})
return user.user?.voiceUser?.joined
Handlebars.registerHelper "isUserSharingVideo", (_id) ->
user = Meteor.Users.findOne({_id:_id})
return user.user?.webcam_stream?.length isnt 0
@ -118,17 +141,19 @@ Handlebars.registerHelper "isUserTalking", (_id) ->
user = Meteor.Users.findOne({_id:_id})
return user?.user?.voiceUser?.talking
Handlebars.registerHelper "isUserMuted", (_id) ->
user = Meteor.Users.findOne({_id:_id})
return user?.user?.voiceUser?.muted
Handlebars.registerHelper "meetingIsRecording", ->
Meteor.Meetings.findOne()?.recorded # Should only ever have one meeting, so we dont need any filter and can trust result #1
Handlebars.registerHelper "messageFontSize", ->
style: "font-size: #{getInSession("messageFontSize")}px;"
style: "font-size: #{getInSession("messageFontSize")}px;"
Handlebars.registerHelper "pointerLocation", ->
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
currentPresentation?.pointer
Handlebars.registerHelper "safeName", (str) ->
safeString(str)
Handlebars.registerHelper "setInSession", (k, v) -> SessionAmplify.set k, v
Handlebars.registerHelper "visibility", (section) ->
@ -137,6 +162,9 @@ Handlebars.registerHelper "visibility", (section) ->
else
style: 'display:none'
@isSharingAudio = ->
return Meteor.Users.findOne({_id: getInSession "DBID"})?.user?.voiceUser?.joined
# transform plain text links into HTML tags compatible with Flash client
@linkify = (str) ->
www = /(^|[^\/])(www\.[\S]+($|\b))/img
@ -144,14 +172,6 @@ Handlebars.registerHelper "visibility", (section) ->
str = str.replace http, "<a href='event:$1'><u>$1</u></a>"
str = str.replace www, "$1<a href='event:http://$2'><u>$2</u></a>"
@setInSession = (k, v) -> SessionAmplify.set k, v
@currentUserIsMuted = ->
return Meteor.Users.findOne({_id: getInSession "DBID"})?.user?.voiceUser?.muted
@isSharingAudio = ->
return Meteor.Users.findOne({_id: getInSession "DBID"})?.user?.voiceUser?.joined
Meteor.methods
sendMeetingInfoToClient: (meetingId, userId) ->
setInSession("userId", userId)
@ -160,6 +180,36 @@ Meteor.methods
setInSession("meetingName", null)
setInSession("userName", null)
# check the chat history of the user and add tabs for the private chats
@populateChatTabs = ->
mydbid = getInSession "DBID"
users = Meteor.Users.find().fetch()
# assuming that I only have access only to private messages where I am the sender or the recipient
myPrivateChats = Meteor.Chat.find({'message.chat_type': 'PRIVATE_CHAT'}).fetch()
uniqueArray = []
for chat in myPrivateChats
if chat.message.to_userid is mydbid
uniqueArray.push({userId: chat.message.from_userid, username: chat.message.from_username})
if chat.message.from_userid is mydbid
uniqueArray.push({userId: chat.message.to_userid, username: chat.message.to_username})
#keep unique entries only
uniqueArray = uniqueArray.filter((itm, i, a) ->
i is a.indexOf(itm)
)
#insert the unique entries in the collection
for u in uniqueArray
unless chatTabs.findOne({userId: u.userId})?
chatTabs.insert({ userId: u.userId, name: u.username, gotMail: false, class: "privateChatTab"})
@setInSession = (k, v) -> SessionAmplify.set k, v
@safeString = (str) ->
if typeof str is 'string' and 1 is 1
str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
@toggleCam = (event) ->
# Meteor.Users.update {_id: context._id} , {$set:{"user.sharingVideo": !context.sharingVideo}}
# Meteor.call('userToggleCam', context._id, !context.sharingVideo)
@ -184,7 +234,7 @@ Meteor.methods
# hangup and inform bbb-apps
Meteor.call("userStopAudio", getInSession("meetingId"), getInSession("userId"), getInSession("DBID"), getInSession("userId"), getInSession("DBID"))
hangupCallback = ->
console.log "left voice conference"
console.log "left voice conference"
webrtc_hangup hangupCallback # sign out of call
else
# create voice call params
@ -216,60 +266,14 @@ Meteor.methods
Router.go('logout') # navigate to logout
# color can be a number (a hex converted to int) or a string (e.g. "#ffff00")
@formatColor = (color) ->
color ?= "0" # default value
if !color.toString().match(/\#.*/)
color = colourToHex(color)
color
# thickness can be a number (e.g. "2") or a string (e.g. "2px")
@formatThickness = (thickness) ->
thickness ?= "1" # default value
if !thickness.toString().match(/.*px$/)
"#" + thickness + "px" # leading "#" - to be compatible with Firefox
thickness
# applies zooming to the stroke thickness
@zoomStroke = (thickness) ->
currentSlide = @getCurrentSlideDoc()
ratio = (currentSlide?.slide.width_ratio + currentSlide?.slide.height_ratio) / 2
thickness * 100 / ratio
@getCurrentSlideDoc = -> # returns only one document
currentPresentation = Meteor.Presentations.findOne({"presentation.current": true})
presentationId = currentPresentation?.presentation?.id
currentSlide = Meteor.Slides.findOne({"presentationId": presentationId, "slide.current": true})
#start a clientside-only collection keeping track of the chat tabs
# start a clientside-only collection keeping track of the chat tabs
@chatTabs = new Meteor.Collection(null)
#insert the basic tabs
# insert the basic tabs
@chatTabs.insert({ userId: "PUBLIC_CHAT", name: "Public", gotMail: false, class: "publicChatTab"})
@chatTabs.insert({ userId: "OPTIONS", name: "Options", gotMail: false, class: "optionsChatTab"})
#check the chat history of the user and add tabs for the private chats
@populateChatTabs = ->
mydbid = getInSession "DBID"
users = Meteor.Users.find().fetch()
# assuming that I only have access only to private messages where I am the sender or the recipient
myPrivateChats = Meteor.Chat.find({'message.chat_type': 'PRIVATE_CHAT'}).fetch()
uniqueArray = []
for chat in myPrivateChats
if chat.message.to_userid is mydbid
uniqueArray.push({userId: chat.message.from_userid, username: chat.message.from_username})
if chat.message.from_userid is mydbid
uniqueArray.push({userId: chat.message.to_userid, username: chat.message.to_username})
#keep unique entries only
uniqueArray = uniqueArray.filter((itm, i, a) ->
i is a.indexOf(itm)
)
#insert the unique entries in the collection
for u in uniqueArray
unless chatTabs.findOne({userId: u.userId})?
chatTabs.insert({ userId: u.userId, name: u.username, gotMail: false, class: "privateChatTab"})
Handlebars.registerHelper "grabChatTabs", ->
chatTabs.find().fetch()