2013-02-22 15:41:12 -05:00
/ * *
A data model representing a user on Discourse
2013-02-20 13:15:50 -05:00
2013-02-22 15:41:12 -05:00
@ class User
@ extends Discourse . Model
@ namespace Discourse
@ module Discourse
* * /
Discourse . User = Discourse . Model . extend ( {
2014-05-03 00:40:57 +02:00
hasPMs : Em . computed . gt ( "private_messages_stats.all" , 0 ) ,
hasStartedPMs : Em . computed . gt ( "private_messages_stats.mine" , 0 ) ,
hasUnreadPMs : Em . computed . gt ( "private_messages_stats.unread" , 0 ) ,
2013-07-26 17:09:54 -04:00
/ * *
The user ' s stream
@ property stream
@ type { Discourse . UserStream }
* * /
stream : function ( ) {
return Discourse . UserStream . create ( { user : this } ) ;
} . property ( ) ,
2013-07-11 19:35:52 -04:00
/ * *
Is this user a member of staff ?
@ property staff
@ type { Boolean }
* * /
staff : Em . computed . or ( 'admin' , 'moderator' ) ,
2013-05-24 12:21:53 -04:00
searchContext : function ( ) {
2013-08-27 23:01:35 +02:00
return {
type : 'user' ,
id : this . get ( 'username_lower' ) ,
user : this
} ;
2013-05-24 12:21:53 -04:00
} . property ( 'username_lower' ) ,
2013-12-08 19:31:25 +05:30
/ * *
This user ' s display name . Returns the name if possible , otherwise returns the
username .
@ property displayName
@ type { String }
* * /
displayName : function ( ) {
if ( Discourse . SiteSettings . enable _names && ! this . blank ( 'name' ) ) {
return this . get ( 'name' ) ;
}
return this . get ( 'username' ) ;
} . property ( 'username' , 'name' ) ,
2013-03-13 16:43:16 -04:00
/ * *
This user ' s website .
@ property websiteName
@ type { String }
* * /
2013-04-18 17:22:59 +10:00
websiteName : function ( ) {
2013-07-11 19:35:52 -04:00
var website = this . get ( 'website' ) ;
if ( Em . isEmpty ( website ) ) { return ; }
2013-04-18 17:22:59 +10:00
2013-07-11 19:35:52 -04:00
return this . get ( 'website' ) . split ( "/" ) [ 2 ] ;
2013-04-18 17:22:59 +10:00
} . property ( 'website' ) ,
2014-03-05 22:11:01 +01:00
2014-02-28 21:12:51 +01:00
/ * *
This user ' s profile background ( in CSS ) .
2013-02-22 15:41:12 -05:00
2014-02-28 21:12:51 +01:00
@ property websiteName
@ type { String }
* * /
profileBackground : function ( ) {
var background = this . get ( 'profile_background' ) ;
if ( Em . isEmpty ( background ) || ! Discourse . SiteSettings . allow _profile _backgrounds ) { return ; }
2014-03-05 22:11:01 +01:00
2014-02-28 21:12:51 +01:00
return 'background-image: url(' + background + ')' ;
} . property ( 'profile_background' ) ,
2014-03-05 22:11:01 +01:00
2013-05-02 17:40:44 +10:00
statusIcon : function ( ) {
2014-04-03 11:54:51 -04:00
var name = Handlebars . Utils . escapeExpression ( this . get ( 'name' ) ) ,
desc ;
2013-05-02 17:40:44 +10:00
if ( this . get ( 'admin' ) ) {
2014-04-03 11:54:51 -04:00
desc = I18n . t ( 'user.admin' , { user : name } ) ;
2013-12-09 16:27:49 -05:00
return '<i class="fa fa-trophy" title="' + desc + '" alt="' + desc + '"></i>' ;
2013-05-02 17:40:44 +10:00
}
if ( this . get ( 'moderator' ) ) {
2014-04-03 11:54:51 -04:00
desc = I18n . t ( 'user.moderator' , { user : name } ) ;
2013-12-09 16:27:49 -05:00
return '<i class="fa fa-magic" title="' + desc + '" alt="' + desc + '"></i>' ;
2013-05-02 17:40:44 +10:00
}
return null ;
} . property ( 'admin' , 'moderator' ) ,
2013-03-13 16:43:16 -04:00
/ * *
Path to this user .
@ property path
@ type { String }
* * /
2013-07-11 19:35:52 -04:00
path : Discourse . computed . url ( 'username_lower' , "/users/%@" ) ,
2013-03-14 13:01:52 +01:00
/ * *
Path to this user ' s administration
@ property adminPath
@ type { String }
* * /
2013-07-11 19:35:52 -04:00
adminPath : Discourse . computed . url ( 'username_lower' , "/admin/users/%@" ) ,
2013-02-22 15:41:12 -05:00
2013-03-13 16:43:16 -04:00
/ * *
This user ' s username in lowercase .
@ property username _lower
@ type { String }
* * /
2013-05-07 13:30:12 -04:00
username _lower : function ( ) {
2013-02-22 15:41:12 -05:00
return this . get ( 'username' ) . toLowerCase ( ) ;
2013-05-07 13:30:12 -04:00
} . property ( 'username' ) ,
2013-02-22 15:41:12 -05:00
2013-03-13 16:43:16 -04:00
/ * *
This user ' s trust level .
@ property trustLevel
@ type { Integer }
* * /
2013-05-07 13:30:12 -04:00
trustLevel : function ( ) {
2013-08-08 12:49:58 -04:00
return Discourse . Site . currentProp ( 'trustLevels' ) . findProperty ( 'id' , parseInt ( this . get ( 'trust_level' ) , 10 ) ) ;
2013-05-07 13:30:12 -04:00
} . property ( 'trust_level' ) ,
2013-02-22 15:41:12 -05:00
2014-03-17 14:50:28 -04:00
isElder : Em . computed . equal ( 'trust_level' , 4 ) ,
canManageTopic : Em . computed . or ( 'staff' , 'isElder' ) ,
2013-11-07 16:34:18 -05:00
isSuspended : Em . computed . equal ( 'suspended' , true ) ,
2013-12-03 15:53:30 -05:00
suspended : function ( ) {
return this . get ( 'suspended_till' ) && moment ( this . get ( 'suspended_till' ) ) . isAfter ( ) ;
} . property ( 'suspended_till' ) ,
2013-11-07 16:34:18 -05:00
suspendedTillDate : function ( ) {
return Discourse . Formatter . longDate ( this . get ( 'suspended_till' ) ) ;
} . property ( 'suspended_till' ) ,
2013-03-14 14:45:29 -04:00
/ * *
2013-03-13 16:43:16 -04:00
Changes this user ' s username .
@ method changeUsername
@ param { String } newUsername The user ' s new username
@ returns Result of ajax call
* * /
2013-02-22 15:41:12 -05:00
changeUsername : function ( newUsername ) {
2013-08-27 23:01:35 +02:00
return Discourse . ajax ( "/users/" + this . get ( 'username_lower' ) + "/preferences/username" , {
2013-02-22 15:41:12 -05:00
type : 'PUT' ,
2013-05-07 13:30:12 -04:00
data : { new _username : newUsername }
2013-02-22 15:41:12 -05:00
} ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
Changes this user ' s email address .
@ method changeEmail
@ param { String } email The user ' s new email address \
@ returns Result of ajax call
* * /
2013-02-22 15:41:12 -05:00
changeEmail : function ( email ) {
2013-08-27 23:01:35 +02:00
return Discourse . ajax ( "/users/" + this . get ( 'username_lower' ) + "/preferences/email" , {
2013-02-22 15:41:12 -05:00
type : 'PUT' ,
2013-05-07 13:30:12 -04:00
data : { email : email }
2013-02-22 15:41:12 -05:00
} ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
Returns a copy of this user .
@ method copy
@ returns { User }
* * /
copy : function ( ) {
2013-02-22 15:41:12 -05:00
return Discourse . User . create ( this . getProperties ( Ember . keys ( this ) ) ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
Save 's this user' s properties over AJAX via a PUT request .
@ method save
2013-04-08 15:04:40 -04:00
@ returns { Promise } the result of the operation
2013-03-13 16:43:16 -04:00
* * /
2013-04-08 15:04:40 -04:00
save : function ( ) {
var user = this ;
2014-01-02 17:58:49 +11:00
var data = this . getProperties ( 'auto_track_topics_after_msecs' ,
2013-02-22 15:41:12 -05:00
'bio_raw' ,
'website' ,
2014-05-27 13:54:04 -04:00
'location' ,
2013-02-22 15:41:12 -05:00
'name' ,
2014-02-07 22:24:10 -05:00
'locale' ,
2013-02-22 15:41:12 -05:00
'email_digests' ,
'email_direct' ,
2013-10-01 17:04:02 +10:00
'email_always' ,
2013-02-22 15:41:12 -05:00
'email_private_messages' ,
2013-06-14 23:58:24 -07:00
'dynamic_favicon' ,
2013-02-22 15:41:12 -05:00
'digest_after_days' ,
2013-03-13 16:43:16 -04:00
'new_topic_duration_minutes' ,
2013-03-12 20:06:58 -07:00
'external_links_in_new_tab' ,
2014-02-07 11:06:35 +11:00
'mailing_list_mode' ,
2014-05-26 16:39:03 -04:00
'enable_quoting' ,
2014-06-11 15:50:37 +10:00
'disable_jump_reply' ,
'custom_fields' ) ;
2014-01-08 17:10:16 +11:00
2014-01-06 11:57:17 +11:00
_ . each ( [ 'muted' , 'watched' , 'tracked' ] , function ( s ) {
2014-01-08 17:10:16 +11:00
var cats = user . get ( s + 'Categories' ) . map ( function ( c ) { return c . get ( 'id' ) } ) ;
// HACK: denote lack of categories
if ( cats . length === 0 ) { cats = [ - 1 ] ; }
data [ s + '_category_ids' ] = cats ;
2014-01-06 11:57:17 +11:00
} ) ;
2014-01-02 17:58:49 +11:00
return Discourse . ajax ( "/users/" + this . get ( 'username_lower' ) , {
data : data ,
2013-05-07 10:58:41 -04:00
type : 'PUT'
} ) . then ( function ( data ) {
user . set ( 'bio_excerpt' , data . user . bio _excerpt ) ;
2013-06-15 00:05:55 -07:00
_ . each ( [
'enable_quoting' , 'external_links_in_new_tab' , 'dynamic_favicon'
] , function ( preference ) {
Discourse . User . current ( ) . set ( preference , user . get ( preference ) ) ;
} ) ;
2013-02-22 15:41:12 -05:00
} ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
Changes the password and calls the callback function on AJAX . complete .
@ method changePassword
2013-04-08 15:04:40 -04:00
@ returns { Promise } the result of the change password operation
2013-03-13 16:43:16 -04:00
* * /
2013-04-08 15:04:40 -04:00
changePassword : function ( ) {
2013-05-07 13:30:12 -04:00
return Discourse . ajax ( "/session/forgot_password" , {
2013-02-22 15:41:12 -05:00
dataType : 'json' ,
2013-08-27 23:01:35 +02:00
data : { login : this . get ( 'username' ) } ,
2013-04-08 15:04:40 -04:00
type : 'POST'
2013-02-22 15:41:12 -05:00
} ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
Loads a single user action by id .
@ method loadUserAction
@ param { Integer } id The id of the user action being loaded
@ returns A stream of the user ' s actions containing the action of id
* * /
2013-02-22 15:41:12 -05:00
loadUserAction : function ( id ) {
2013-04-08 15:04:40 -04:00
var user = this ;
var stream = this . get ( 'stream' ) ;
2013-05-07 13:30:12 -04:00
return Discourse . ajax ( "/user_actions/" + id + ".json" , { cache : 'false' } ) . then ( function ( result ) {
2013-04-08 15:04:40 -04:00
if ( result ) {
if ( ( user . get ( 'streamFilter' ) || result . action _type ) !== result . action _type ) return ;
2013-05-22 11:20:16 -04:00
var action = Discourse . UserAction . collapseStream ( [ Discourse . UserAction . create ( result ) ] ) ;
2014-06-16 14:49:39 -04:00
stream . set ( 'itemsLoaded' , stream . get ( 'itemsLoaded' ) + 1 ) ;
stream . get ( 'content' ) . insertAt ( 0 , action [ 0 ] ) ;
2013-02-20 13:15:50 -05:00
}
2013-02-22 15:41:12 -05:00
} ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
The user ' s stat count , excluding PMs .
@ property statsCountNonPM
@ type { Integer }
* * /
2013-05-20 16:52:37 -04:00
statsCountNonPM : function ( ) {
if ( this . blank ( 'statsExcludingPms' ) ) return 0 ;
2013-06-11 06:48:50 +10:00
var count = 0 ;
_ . each ( this . get ( 'statsExcludingPms' ) , function ( val ) {
count += val . count ;
2013-02-22 15:41:12 -05:00
} ) ;
2013-06-11 06:48:50 +10:00
return count ;
2013-05-20 16:52:37 -04:00
} . property ( 'statsExcludingPms.@each.count' ) ,
2013-02-22 15:41:12 -05:00
2013-03-13 16:43:16 -04:00
/ * *
The user ' s stats , excluding PMs .
@ property statsExcludingPms
@ type { Array }
* * /
2013-05-20 16:52:37 -04:00
statsExcludingPms : function ( ) {
if ( this . blank ( 'stats' ) ) return [ ] ;
return this . get ( 'stats' ) . rejectProperty ( 'isPM' ) ;
} . property ( 'stats.@each.isPM' ) ,
2013-02-22 15:41:12 -05:00
2013-05-22 11:20:16 -04:00
findDetails : function ( ) {
2013-04-04 12:59:44 -04:00
var user = this ;
2013-07-26 15:56:29 -04:00
2013-05-22 11:20:16 -04:00
return PreloadStore . getAndRemove ( "user_" + user . get ( 'username' ) , function ( ) {
return Discourse . ajax ( "/users/" + user . get ( 'username' ) + '.json' ) ;
2013-04-04 12:59:44 -04:00
} ) . then ( function ( json ) {
2013-07-12 15:59:35 -04:00
if ( ! Em . isEmpty ( json . user . stats ) ) {
json . user . stats = Discourse . User . groupStats ( _ . map ( json . user . stats , function ( s ) {
if ( s . count ) s . count = parseInt ( s . count , 10 ) ;
return Discourse . UserActionStat . create ( s ) ;
} ) ) ;
}
2013-04-04 12:59:44 -04:00
2014-02-06 17:34:48 -05:00
if ( ! Em . isEmpty ( json . user . custom _groups ) ) {
json . user . custom _groups = json . user . custom _groups . map ( function ( g ) {
return Discourse . Group . create ( g ) ;
} ) ;
}
2014-03-28 14:19:30 +05:30
2013-05-27 11:05:41 -04:00
if ( json . user . invited _by ) {
json . user . invited _by = Discourse . User . create ( json . user . invited _by ) ;
}
2014-03-28 14:19:30 +05:30
if ( ! Em . isEmpty ( json . user . featured _user _badge _ids ) ) {
var userBadgesMap = { } ;
Discourse . UserBadge . createFromJson ( json ) . forEach ( function ( userBadge ) {
userBadgesMap [ userBadge . get ( 'id' ) ] = userBadge ;
} ) ;
json . user . featured _user _badges = json . user . featured _user _badge _ids . map ( function ( id ) {
return userBadgesMap [ id ] ;
} ) ;
}
2013-04-04 12:59:44 -04:00
user . setProperties ( json . user ) ;
2013-05-20 16:52:37 -04:00
return user ;
2013-04-04 12:59:44 -04:00
} ) ;
2013-08-25 17:26:44 +02:00
} ,
2014-06-04 18:35:14 +02:00
avatarTemplate : function ( ) {
return Discourse . User . avatarTemplate ( this . get ( 'username' ) , this . get ( 'uploaded_avatar_id' ) ) ;
2014-05-22 17:37:02 +10:00
} . property ( 'uploaded_avatar_id' , 'username' ) ,
2013-08-25 17:26:44 +02:00
/ *
Change avatar selection
* /
2014-05-26 19:46:43 +10:00
pickAvatar : function ( uploadId ) {
this . set ( "uploaded_avatar_id" , uploadId ) ;
return Discourse . ajax ( "/users/" + this . get ( "username_lower" ) + "/preferences/avatar/pick" , {
2013-08-27 23:01:35 +02:00
type : 'PUT' ,
2014-05-26 19:46:43 +10:00
data : { upload _id : uploadId }
2013-08-27 23:01:35 +02:00
} ) ;
2013-09-07 10:49:11 +02:00
} ,
2014-03-05 22:11:01 +01:00
2014-02-28 21:12:51 +01:00
/ *
Clear profile background
2014-03-05 22:11:01 +01:00
2014-02-28 21:12:51 +01:00
@ method clearProfileBackground
@ returns { Promise } the result of the clear profile background request
* /
clearProfileBackground : function ( ) {
var user = this ;
return Discourse . ajax ( "/users/" + this . get ( "username_lower" ) + "/preferences/profile_background/clear" , {
type : 'PUT' ,
data : { }
} ) . then ( function ( ) {
user . set ( 'profile_background' , null ) ;
} ) ;
} ,
2013-09-07 10:49:11 +02:00
/ * *
Determines whether the current user is allowed to upload a file .
@ method isAllowedToUploadAFile
2013-11-06 12:56:26 -05:00
@ param { String } type The type of the upload ( image , attachment )
2013-09-07 10:49:11 +02:00
@ returns true if the current user is allowed to upload a file
* * /
isAllowedToUploadAFile : function ( type ) {
return this . get ( 'staff' ) ||
this . get ( 'trust_level' ) > 0 ||
Discourse . SiteSettings [ 'newuser_max_' + type + 's' ] > 0 ;
2013-11-06 12:56:26 -05:00
} ,
/ * *
Invite a user to the site
@ method createInvite
@ param { String } email The email address of the user to invite to the site
@ returns { Promise } the result of the server call
* * /
2014-05-09 18:22:15 +10:00
createInvite : function ( email , groupNames ) {
2013-11-06 12:56:26 -05:00
return Discourse . ajax ( '/invites' , {
type : 'POST' ,
2014-05-09 18:22:15 +10:00
data : { email : email , group _names : groupNames }
2013-11-06 12:56:26 -05:00
} ) ;
2013-12-30 18:46:18 +01:00
} ,
2014-01-02 17:58:49 +11:00
updateMutedCategories : function ( ) {
2014-01-08 17:10:16 +11:00
this . set ( "mutedCategories" , Discourse . Category . findByIds ( this . muted _category _ids ) ) ;
2014-01-02 17:58:49 +11:00
} . observes ( "muted_category_ids" ) ,
2014-01-06 11:57:17 +11:00
updateTrackedCategories : function ( ) {
2014-01-08 17:10:16 +11:00
this . set ( "trackedCategories" , Discourse . Category . findByIds ( this . tracked _category _ids ) ) ;
2014-01-06 11:57:17 +11:00
} . observes ( "tracked_category_ids" ) ,
2014-01-02 17:58:49 +11:00
updateWatchedCategories : function ( ) {
2014-01-08 17:10:16 +11:00
this . set ( "watchedCategories" , Discourse . Category . findByIds ( this . watched _category _ids ) ) ;
2014-02-13 11:42:35 -05:00
} . observes ( "watched_category_ids" ) ,
canDeleteAccount : function ( ) {
return this . get ( 'can_delete_account' ) && ( ( this . get ( 'reply_count' ) || 0 ) + ( this . get ( 'topic_count' ) || 0 ) ) <= 1 ;
} . property ( 'can_delete_account' , 'reply_count' , 'topic_count' ) ,
2014-05-26 19:46:43 +10:00
"delete" : function ( ) {
2014-02-13 11:42:35 -05:00
if ( this . get ( 'can_delete_account' ) ) {
return Discourse . ajax ( "/users/" + this . get ( 'username' ) , {
type : 'DELETE' ,
data : { context : window . location . pathname }
} ) ;
} else {
return Ember . RSVP . reject ( I18n . t ( 'user.delete_yourself_not_allowed' ) ) ;
}
2014-06-18 20:04:10 +02:00
} ,
dismissBanner : function ( bannerKey ) {
this . set ( "dismissed_banner_key" , bannerKey ) ;
Discourse . ajax ( "/users/" + this . get ( 'username' ) , {
type : 'PUT' ,
data : { dismissed _banner _key : bannerKey }
} ) ;
2014-02-13 11:42:35 -05:00
}
2014-01-08 17:10:16 +11:00
2013-02-22 15:41:12 -05:00
} ) ;
2013-02-20 13:15:50 -05:00
2013-08-08 12:42:08 -04:00
Discourse . User . reopenClass ( Discourse . Singleton , {
2014-05-22 17:37:02 +10:00
2014-06-04 18:35:14 +02:00
avatarTemplate : function ( username , uploadedAvatarId ) {
2014-05-30 14:17:35 +10:00
var url ;
2014-06-04 18:35:14 +02:00
if ( uploadedAvatarId ) {
2014-05-30 14:17:35 +10:00
url = "/user_avatar/" +
Discourse . BaseUrl +
"/" +
username . toLowerCase ( ) +
"/{size}/" +
uploadedAvatarId + ".png" ;
} else {
url = "/letter_avatar/" +
username . toLowerCase ( ) +
"/{size}/" +
Discourse . LetterAvatarVersion + ".png" ;
}
url = Discourse . getURL ( url ) ;
2014-06-04 18:35:14 +02:00
if ( Discourse . CDN ) {
2014-05-27 14:40:46 +10:00
url = Discourse . CDN + url ;
}
2014-05-27 22:29:27 +10:00
return url ;
2014-05-22 17:37:02 +10:00
} ,
2013-10-03 12:51:30 -04:00
/ * *
Find a ` Discourse.User ` for a given username .
@ method findByUsername
@ returns { Promise } a promise that resolves to a ` Discourse.User `
* * /
findByUsername : function ( username ) {
var user = Discourse . User . create ( { username : username } ) ;
return user . findDetails ( ) ;
} ,
2013-05-28 11:08:32 -04:00
/ * *
2013-08-08 12:42:08 -04:00
The current singleton will retrieve its attributes from the ` PreloadStore `
if it exists . Otherwise , no instance is created .
2013-05-28 11:08:32 -04:00
2013-08-08 12:42:08 -04:00
@ method createCurrent
@ returns { Discourse . User } the user , if logged in .
2013-05-28 11:08:32 -04:00
* * /
2013-08-08 12:42:08 -04:00
createCurrent : function ( ) {
var userJson = PreloadStore . get ( 'currentUser' ) ;
if ( userJson ) { return Discourse . User . create ( userJson ) ; }
return null ;
2013-05-28 11:08:32 -04:00
} ,
/ * *
Logs out the currently logged in user
@ method logout
@ returns { Promise } resolved when the logout finishes
* * /
logout : function ( ) {
var discourseUserClass = this ;
2013-08-08 12:42:08 -04:00
return Discourse . ajax ( "/session/" + Discourse . User . currentProp ( 'username' ) , {
2013-05-28 11:08:32 -04:00
type : 'DELETE'
} ) . then ( function ( ) {
discourseUserClass . currentUser = null ;
} ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
Checks if given username is valid for this email address
2013-02-22 15:41:12 -05:00
2013-03-13 16:43:16 -04:00
@ method checkUsername
@ param { String } username A username to check
@ param { String } email An email address to check
2014-03-18 18:19:20 -07:00
@ param { Number } forUserId user id - provide when changing username
2013-03-13 16:43:16 -04:00
* * /
2013-07-30 14:13:56 -04:00
checkUsername : function ( username , email , forUserId ) {
2013-05-07 13:30:12 -04:00
return Discourse . ajax ( '/users/check_username' , {
2013-07-30 14:13:56 -04:00
data : { username : username , email : email , for _user _id : forUserId }
2013-02-22 15:41:12 -05:00
} ) ;
} ,
2013-03-13 16:43:16 -04:00
/ * *
Groups the user ' s statistics
@ method groupStats
2014-03-18 18:19:20 -07:00
@ param { Array } stats Given stats
2013-03-13 16:43:16 -04:00
@ returns { Object }
* * /
2013-02-22 15:41:12 -05:00
groupStats : function ( stats ) {
2013-05-20 16:52:37 -04:00
var responses = Discourse . UserActionStat . create ( {
count : 0 ,
2013-07-16 16:16:37 -04:00
action _type : Discourse . UserAction . TYPES . replies
2013-02-22 15:41:12 -05:00
} ) ;
2013-05-20 16:52:37 -04:00
stats . filterProperty ( 'isResponse' ) . forEach ( function ( stat ) {
responses . set ( 'count' , responses . get ( 'count' ) + stat . get ( 'count' ) ) ;
2013-02-22 15:41:12 -05:00
} ) ;
2013-05-20 16:52:37 -04:00
var result = Em . A ( ) ;
result . pushObjects ( stats . rejectProperty ( 'isResponse' ) ) ;
2013-07-08 12:12:06 +10:00
2013-08-30 00:43:54 -04:00
var insertAt = 0 ;
2013-07-08 12:12:06 +10:00
result . forEach ( function ( item , index ) {
2013-07-16 16:16:37 -04:00
if ( item . action _type === Discourse . UserAction . TYPES . topics || item . action _type === Discourse . UserAction . TYPES . posts ) {
2013-07-08 12:12:06 +10:00
insertAt = index + 1 ;
}
} ) ;
2013-07-19 17:21:51 +10:00
if ( responses . count > 0 ) {
result . insertAt ( insertAt , responses ) ;
}
2013-05-20 16:52:37 -04:00
return ( result ) ;
2013-02-22 15:41:12 -05:00
} ,
2013-02-20 13:15:50 -05:00
2013-03-13 16:43:16 -04:00
/ * *
Creates a new account over POST
@ method createAccount
@ param { String } name This user ' s name
@ param { String } email This user ' s email
@ param { String } password This user ' s password
2014-03-18 18:19:20 -07:00
@ param { String } username This user ' s username
2013-03-13 16:43:16 -04:00
@ param { String } passwordConfirm This user ' s confirmed password
@ param { String } challenge
@ returns Result of ajax call
* * /
2013-02-22 15:41:12 -05:00
createAccount : function ( name , email , password , username , passwordConfirm , challenge ) {
2013-05-07 13:30:12 -04:00
return Discourse . ajax ( "/users" , {
2013-02-22 15:41:12 -05:00
data : {
name : name ,
email : email ,
password : password ,
username : username ,
password _confirmation : passwordConfirm ,
challenge : challenge
} ,
type : 'POST'
} ) ;
}
} ) ;