Include course info in contact message session links

This commit is contained in:
Nick Winter 2015-12-28 08:15:48 -08:00
parent f369c73b2a
commit 187a6f87a9
3 changed files with 12 additions and 10 deletions

View file

@ -33,6 +33,7 @@ module.exports = class ContactModal extends ModalView
res = tv4.validateMultiple contactMessage, contactSchema
return forms.applyErrorsToForm @$el, res.errors unless res.valid
@populateBrowserData contactMessage
contactMessage = _.merge contactMessage, @options
contactMessage.country = me.get('country')
window.tracker?.trackEvent 'Sent Feedback', message: contactMessage
sendContactMessage contactMessage, @$el

View file

@ -570,7 +570,7 @@ module.exports = class PlayLevelView extends RootView
session.save {screenshot: screenshot}, {patch: true, type: 'PUT'}
onContactClicked: (e) ->
@openModalView contactModal = new ContactModal()
@openModalView contactModal = new ContactModal levelID: @level.get('slug') or @level.id, courseID: @courseID, courseInstanceID: @courseInstanceID
screenshot = @surface.screenshot(1, 'image/png', 1.0, 1)
body =
b64png: screenshot.replace 'data:image/png;base64,', ''

View file

@ -24,6 +24,7 @@ createMailContext = (req, done) ->
recipientID = req.body.recipientID
subject = req.body.subject
country = req.body.country
sentFromLevel = levelID: req.body.levelID, courseID: req.body.courseID, courseInstanceID: req.body.courseInstanceID
level = if user?.get('points') > 0 then Math.floor(5 * Math.log((1 / 100) * (user.get('points') + 100))) + 1 else 0
premium = user?.isPremium()
@ -58,7 +59,7 @@ createMailContext = (req, done) ->
done context
else
async.waterfall [
fetchRecentSessions.bind undefined, user, context
fetchRecentSessions.bind undefined, user, context, sentFromLevel
# Can add other data-grabbing stuff here if we want.
], (err, results) ->
console.error "Error getting contact message context for #{sender}: #{err}" if err
@ -66,13 +67,7 @@ createMailContext = (req, done) ->
context.email_data.content += "\n<img src='#{req.body.screenshotURL}' />"
done context
# I'll try having it just send the emails instead of spamming the chat.
#if /Level Load Error/.test context.email_data.subject
# message = "#{user.get('name') or user.get('email')} saw #{context.email_data.subject} <a href=\"http://direct.codecombat.com/editor/level/#{req.body.levelSlug}\">(level editor)</a>"
# hipchat.sendHipChatMessage message, ['tower'], color: 'red'
fetchRecentSessions = (user, context, callback) ->
fetchRecentSessions = (user, context, sentFromLevel, callback) ->
query = creator: user.get('_id') + ''
projection = levelID: 1, levelName: 1, changed: 1, team: 1, codeLanguage: 1, 'state.complete': 1, playtime: 1
sort = changed: -1
@ -83,5 +78,11 @@ fetchRecentSessions = (user, context, callback) ->
else if s.playtime < 7200 then playtime = "#{Math.round(s.playtime / 60)}m played"
else playtime = "#{Math.round(s.playtime / 3600)}h played"
ago = moment(s.changed).fromNow()
context.email_data.content += "\n<a href='http://codecombat.com/play/level/#{s.levelID}?session=#{s._id}&team=#{s.team or 'humans'}&dev=true'>#{s.levelName}#{if s.team is 'ogres' then ' ' + s.team else ''}</a>#{if s.state?.complete then ' complete ' else ''}- #{s.codeLanguage}, #{playtime}, #{ago}"
url = "http://codecombat.com/play/level/#{s.levelID}?session=#{s._id}&team=#{s.team or 'humans'}&dev=true"
urlName = "#{s.levelName}#{if s.team is 'ogres' then ' ' + s.team else ''}"
sessionStatus = "#{if s.state?.complete then ' complete ' else ''}- #{s.codeLanguage}, #{playtime}, #{ago}"
if sentFromLevel?.levelID is s.levelID and sentFromLevel?.courseID
url += "&course=#{sentFromLevel.courseID}&course-instance=#{sentFromLevel.courseInstanceID}"
urlName += ' (course)'
context.email_data.content += "\n<a href='#{url}'>#{urlName}</a>#{sessionStatus}"
callback null