Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
diasporg
diaspora
Commits
718c4fd3
Commit
718c4fd3
authored
Jan 26, 2012
by
Maxwell Salzberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor status_message_controller#create to suck less. it still sucks
parent
0da5f18a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
32 deletions
+47
-32
app/controllers/status_messages_controller.rb
app/controllers/status_messages_controller.rb
+26
-32
app/models/photo.rb
app/models/photo.rb
+2
-0
app/models/service.rb
app/models/service.rb
+5
-0
app/models/status_message.rb
app/models/status_message.rb
+10
-0
app/models/user.rb
app/models/user.rb
+4
-0
No files found.
app/controllers/status_messages_controller.rb
View file @
718c4fd3
...
...
@@ -43,32 +43,21 @@ class StatusMessagesController < ApplicationController
def
create
params
[
:status_message
][
:aspect_ids
]
=
[
*
params
[
:aspect_ids
]]
normalize_public_flag!
# ensure services is an array since .map doesn't work on a string for ruby 1.9
params
[
:services
]
=
[
params
[
:services
]]
if
params
[
:services
].
is_a?
(
String
)
services
=
[
*
params
[
:services
]].
compact
@status_message
=
current_user
.
build_post
(
:status_message
,
params
[
:status_message
])
@status_message
.
attach_photos_by_ids
(
params
[
:photos
])
photos
=
Photo
.
where
(
:id
=>
[
*
params
[
:photos
]],
:diaspora_handle
=>
current_user
.
person
.
diaspora_handle
)
unless
photos
.
empty?
@status_message
.
photos
<<
photos
end
if
@status_message
.
save
# always send to all aspects if public
if
params
[
:status_message
][
:public
]
||
params
[
:status_message
][
:aspect_ids
].
first
==
"all_aspects"
aspect_ids
=
current_user
.
aspects
.
map
{
|
a
|
a
.
id
}
else
aspect_ids
=
params
[
:aspect_ids
]
end
aspects
=
current_user
.
aspects_from_ids
(
aspect_ids
)
aspects
=
current_user
.
aspects_from_ids
(
destination_aspect_ids
)
current_user
.
add_to_streams
(
@status_message
,
aspects
)
receiving_services
=
current_user
.
services
.
where
(
:type
=>
params
[
:services
].
map
{
|
s
|
"Services::"
+
s
.
titleize
})
if
params
[
:services
]
receiving_services
=
current_user
.
services
.
where
(
:type
=>
Service
.
titles
(
services
))
current_user
.
dispatch_post
(
@status_message
,
:url
=>
short_post_url
(
@status_message
.
guid
),
:services
=>
receiving_services
)
if
request
.
env
[
'HTTP_REFERER'
].
include?
(
"people"
)
# if this is a post coming from a profile page
flash
[
:notice
]
=
t
(
'status_messages.create.success'
,
:names
=>
@status_message
.
mentions
.
includes
(
:person
=>
:profile
).
map
{
|
mention
|
mention
.
person
.
name
}.
join
(
', '
))
if
coming_from_profile_page?
# if this is a post coming from a profile page
flash
[
:notice
]
=
successful_mention_message
end
respond_to
do
|
format
|
...
...
@@ -77,10 +66,6 @@ class StatusMessagesController < ApplicationController
format
.
json
{
render
:json
=>
@status_message
.
as_api_response
(
:backbone
),
:status
=>
201
}
end
else
unless
photos
.
empty?
photos
.
update_all
(
:status_message_guid
=>
nil
)
end
respond_to
do
|
format
|
format
.
json
{
render
:nothing
,
:status
=>
403
}
format
.
html
{
redirect_to
:back
}
...
...
@@ -88,23 +73,32 @@ class StatusMessagesController < ApplicationController
end
end
def
destination_aspect_ids
if
params
[
:status_message
][
:public
]
||
params
[
:status_message
][
:aspect_ids
].
first
==
"all_aspects"
current_user
.
aspect_ids
else
params
[
:aspect_ids
]
end
end
def
successful_mention_message
t
(
'status_messages.create.success'
,
:names
=>
@status_message
.
mentioned_people_names
)
end
def
coming_from_profile_page?
request
.
env
[
'HTTP_REFERER'
].
include?
(
"people"
)
end
def
normalize_public_flag!
# mobile || desktop conditions
public_flag
=
(
params
[
:status_message
][
:aspect_ids
]
&&
params
[
:status_message
][
:aspect_ids
].
first
==
'public'
)
||
params
[
:status_message
][
:public
]
sm
=
params
[
:status_message
]
public_flag
=
(
sm
[
:aspect_ids
]
&&
sm
[
:aspect_ids
].
first
==
'public'
)
||
sm
[
:public
]
public_flag
.
to_s
.
match
(
/(true)|(on)/
)
?
public_flag
=
true
:
public_flag
=
false
params
[
:status_message
][
:public
]
=
public_flag
public_flag
end
helper_method
:comments_expanded
def
comments_expanded
true
end
def
remove_getting_started
if
current_user
.
getting_started
==
true
current_user
.
update_attributes
(
:getting_started
=>
false
)
end
true
current_user
.
disable_getting_started
end
end
app/models/photo.rb
View file @
718c4fd3
...
...
@@ -8,6 +8,7 @@ class Photo < ActiveRecord::Base
include
Diaspora
::
Commentable
include
Diaspora
::
Shareable
# NOTE API V1 to be extracted
acts_as_api
api_accessible
:backbone
do
|
t
|
...
...
@@ -32,6 +33,7 @@ class Photo < ActiveRecord::Base
xml_attr
:status_message_guid
belongs_to
:status_message
,
:foreign_key
=>
:status_message_guid
,
:primary_key
=>
:guid
validates_associated
:status_message
attr_accessible
:text
,
:pending
validate
:ownership_of_status_message
...
...
app/models/service.rb
View file @
718c4fd3
...
...
@@ -9,6 +9,10 @@ class Service < ActiveRecord::Base
validates_uniqueness_of
:uid
,
:scope
=>
:type
has_many
:service_users
,
:dependent
=>
:destroy
def
self
.
titles
(
service_strings
)
service_strings
.
map
{
|
s
|
"Services::
#{
s
.
titleize
}
"
}
end
def
public_message
(
post
,
length
,
url
=
""
)
url
=
""
if
post
.
respond_to?
(
:photos
)
&&
post
.
photos
.
count
==
0
space_for_url
=
url
.
blank?
?
0
:
(
url
.
length
+
1
)
...
...
@@ -17,6 +21,7 @@ class Service < ActiveRecord::Base
return
truncated
end
def
profile_photo_url
nil
end
...
...
app/models/status_message.rb
View file @
718c4fd3
...
...
@@ -66,6 +66,12 @@ class StatusMessage < Post
write_attribute
(
:text
,
text
)
end
def
attach_photos_by_ids
(
photo_ids
)
return
[]
unless
photo_ids
.
present?
self
.
photos
<<
Photo
.
where
(
:id
=>
photo_ids
,
:author_id
=>
self
.
author_id
).
all
end
def
nsfw?
self
.
raw_message
.
match
(
/#nsfw/i
)
end
...
...
@@ -104,6 +110,10 @@ class StatusMessage < Post
end
end
def
mentioned_people_names
self
.
mentioned_people
.
map
(
&
:name
).
join
(
', '
)
end
def
create_mentions
mentioned_people_from_string
.
each
do
|
person
|
self
.
mentions
.
create
(
:person
=>
person
)
...
...
app/models/user.rb
View file @
718c4fd3
...
...
@@ -191,6 +191,10 @@ class User < ActiveRecord::Base
end
end
def
disable_getting_started
self
.
update_attribute
(
:getting_started
,
false
)
if
self
.
getting_started?
end
def
set_current_language
self
.
language
=
I18n
.
locale
.
to_s
if
self
.
language
.
blank?
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment