<commit_before>require! {
	'../../auth': authorize
	'../../../utils/get-express-params'
	'../../../utils/publish-redis-streaming'
	'../../../models/utils/filter-user-for-response'
	'../../../models/utils/serialize-status'
	'../../../models/status': Status
	'../../../models/utils/status-check-reposted'
	'../../../models/user': User
	'../../../models/user-following': UserFollowing
}

module.exports = (req, res) -> authorize req, res, (user, app) ->
	[status-id] = get-express-params req, <[ status-id ]>
	switch
	| empty status-id => res.api-error 400 'status-id parameter is required :('
	| _ => Status.find-by-id status-id, (, target-status) ->
		| !target-status? => res.api-error 404 'Post not found...'
		| target-status.user-id.to-string! == user.id => res.api-error 400 'This post is your post!!!'
		| target-status.repost-from-status-id? => # Repostなら対象をRepost元に差し替え
			Status.find-by-id target-status.repost-from-status-id, (, true-target-status) ->
				repost-step req, res, app, user, true-target-status
		| _ => repost-step req, res, app, user, target-status

repost-step = (req, res, app, user, target-status) -> status-check-reposted user.id, target-status.id .then (is-reposted) ->
	| is-reposted => res.api-error 400 'This post is already reposted :)'
	| _ => User.find-by-id target-status.user-id, (, target-status-user) ->
		status = new Status do
			app-id: app.id
			text: "RP @#{target-status-user.screen-name} #{target-status.text}"
			user-id: user.id
			repost-from-status-id: target-status.id
		status.save (, created-status) ->
			target-status
				..reposts-count++
				..save (err) ->
					serialize-status target-status, (target-status-obj) ->
						target-status-obj
							..is-repost-to-status = true
							..reposted-by-user = filter-user-for-response user
							.. |> res.api-render
						stream-obj = to-json do
							type: \repost
							value: {created-status.id}
						publish-redis-streaming "userStream:#{user.id}", stream-obj
						UserFollowing.find {followee-id: user.id} (, user-followings) ->
							| !empty user-followings => user-followings |> each (user-following) ->
								publish-redis-streaming "userStream:#{user-following.follower-id}", stream-obj<commit_msg>Improve readability<commit_after>require! {
	'../../auth': authorize
	'../../../utils/get-express-params'
	'../../../utils/publish-redis-streaming'
	'../../../models/utils/filter-user-for-response'
	'../../../models/utils/serialize-status'
	'../../../models/status': Status
	'../../../models/utils/status-check-reposted'
	'../../../models/user': User
	'../../../models/user-following': UserFollowing
}

module.exports = (req, res) -> authorize req, res, (user, app) ->
	[status-id] = get-express-params req, <[ status-id ]>
	switch
	| empty status-id => res.api-error 400 'status-id parameter is required :('
	| _ => Status.find-by-id status-id, (, target-status) ->
		| !target-status? => res.api-error 404 'Post not found...'
		| target-status.user-id.to-string! == user.id => res.api-error 400 'This post is your post!!!'
		| target-status.repost-from-status-id? => # Repostなら対象をRepost元に差し替え
			Status.find-by-id target-status.repost-from-status-id, (, true-target-status) ->
				repost-step req, res, app, user, true-target-status
		| _ => repost-step req, res, app, user, target-status

repost-step = (req, res, app, user, target-status) -> status-check-reposted user.id, target-status.id .then (is-reposted) ->
	| is-reposted => res.api-error 400 'This post is already reposted :)'
	| _ => User.find-by-id target-status.user-id, (, target-status-user) ->
		status = new Status do
			app-id: app.id
			text: "RP @#{target-status-user.screen-name} #{target-status.text}"
			user-id: user.id
			repost-from-status-id: target-status.id
		status.save (, created-status) ->
			target-status
				..reposts-count++
				..save (err) ->
					serialize-status target-status, (target-status-obj) ->
						target-status-obj
							..is-repost-to-status = true
							..reposted-by-user = filter-user-for-response user
							.. |> res.api-render
						stream-obj = to-json do
							type: \repost
							value: {created-status.id}
						publish-redis-streaming "userStream:#{user.id}" stream-obj
						UserFollowing.find {followee-id: user.id} (, user-followings) ->
							| !empty user-followings => user-followings |> each (user-following) ->
								publish-redis-streaming "userStream:#{user-following.follower-id}" stream-obj
{'fraction_non_alphanumeric': 0.19801980198019803, 'fraction_numerical': 0.0054005400540054005, 'mean_word_length': 2.799145299145299, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7124024', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1535, 'n_words': 288}