Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
diaspora
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gigadoc 2
diaspora
Commits
33ad411b
Unverified
Commit
33ad411b
authored
Aug 22, 2016
by
cmrd Senya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mentions in comments backend changes
parent
ef5751b8
Changes
61
Hide whitespace changes
Inline
Side-by-side
Showing
61 changed files
with
1190 additions
and
449 deletions
+1190
-449
app/controllers/notifications_controller.rb
app/controllers/notifications_controller.rb
+17
-4
app/controllers/status_messages_controller.rb
app/controllers/status_messages_controller.rb
+4
-1
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+1
-10
app/helpers/notifications_helper.rb
app/helpers/notifications_helper.rb
+30
-26
app/mailers/notification_mailers/mentioned.rb
app/mailers/notification_mailers/mentioned.rb
+1
-1
app/mailers/notification_mailers/mentioned_in_comment.rb
app/mailers/notification_mailers/mentioned_in_comment.rb
+11
-0
app/models/comment.rb
app/models/comment.rb
+14
-5
app/models/mention.rb
app/models/mention.rb
+6
-2
app/models/notification.rb
app/models/notification.rb
+0
-11
app/models/notifications/also_commented.rb
app/models/notifications/also_commented.rb
+3
-5
app/models/notifications/comment_on_post.rb
app/models/notifications/comment_on_post.rb
+3
-4
app/models/notifications/commented.rb
app/models/notifications/commented.rb
+15
-0
app/models/notifications/mentioned.rb
app/models/notifications/mentioned.rb
+14
-21
app/models/notifications/mentioned_in_comment.rb
app/models/notifications/mentioned_in_comment.rb
+38
-0
app/models/notifications/mentioned_in_post.rb
app/models/notifications/mentioned_in_post.rb
+22
-0
app/models/post.rb
app/models/post.rb
+2
-4
app/models/status_message.rb
app/models/status_message.rb
+17
-32
app/models/user.rb
app/models/user.rb
+1
-0
app/models/user_preference.rb
app/models/user_preference.rb
+8
-7
app/presenters/person_presenter.rb
app/presenters/person_presenter.rb
+4
-0
app/services/notification_service.rb
app/services/notification_service.rb
+2
-2
app/services/post_service.rb
app/services/post_service.rb
+15
-3
app/services/status_message_creation_service.rb
app/services/status_message_creation_service.rb
+1
-11
app/views/notifications/_notification.haml
app/views/notifications/_notification.haml
+2
-2
app/views/notifications/_notification.mobile.haml
app/views/notifications/_notification.mobile.haml
+2
-1
app/views/notifications/index.html.haml
app/views/notifications/index.html.haml
+1
-1
app/views/notifier/mentioned.markerb
app/views/notifier/mentioned.markerb
+1
-1
app/views/notifier/mentioned_in_comment.markerb
app/views/notifier/mentioned_in_comment.markerb
+9
-0
app/views/users/_edit.haml
app/views/users/_edit.haml
+5
-0
app/workers/mail/mentioned_in_comment.rb
app/workers/mail/mentioned_in_comment.rb
+6
-0
config/locales/diaspora/en.yml
config/locales/diaspora/en.yml
+12
-3
db/migrate/20161107100840_polymorphic_mentions.rb
db/migrate/20161107100840_polymorphic_mentions.rb
+38
-0
db/schema.rb
db/schema.rb
+6
-5
features/desktop/change_settings.feature
features/desktop/change_settings.feature
+4
-0
features/desktop/notifications.feature
features/desktop/notifications.feature
+20
-0
features/step_definitions/comment_steps.rb
features/step_definitions/comment_steps.rb
+6
-0
features/step_definitions/custom_web_steps.rb
features/step_definitions/custom_web_steps.rb
+1
-1
features/step_definitions/notifications_steps.rb
features/step_definitions/notifications_steps.rb
+1
-1
lib/diaspora/mentionable.rb
lib/diaspora/mentionable.rb
+4
-30
lib/diaspora/mentions_container.rb
lib/diaspora/mentions_container.rb
+38
-0
lib/diaspora/message_renderer.rb
lib/diaspora/message_renderer.rb
+1
-1
spec/controllers/notifications_controller_spec.rb
spec/controllers/notifications_controller_spec.rb
+7
-6
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+17
-13
spec/factories.rb
spec/factories.rb
+31
-7
spec/helper_methods.rb
spec/helper_methods.rb
+18
-2
spec/helpers/notifications_helper_spec.rb
spec/helpers/notifications_helper_spec.rb
+31
-0
spec/integration/mentioning_spec.rb
spec/integration/mentioning_spec.rb
+327
-39
spec/lib/diaspora/federation/receive_spec.rb
spec/lib/diaspora/federation/receive_spec.rb
+9
-11
spec/lib/diaspora/mentionable_spec.rb
spec/lib/diaspora/mentionable_spec.rb
+9
-12
spec/mailers/notifier_spec.rb
spec/mailers/notifier_spec.rb
+32
-4
spec/models/comment_spec.rb
spec/models/comment_spec.rb
+51
-0
spec/models/mention_spec.rb
spec/models/mention_spec.rb
+2
-2
spec/models/notifications/mentioned_in_post_spec.rb
spec/models/notifications/mentioned_in_post_spec.rb
+72
-0
spec/models/notifications/mentioned_spec.rb
spec/models/notifications/mentioned_spec.rb
+39
-56
spec/models/status_message_spec.rb
spec/models/status_message_spec.rb
+14
-58
spec/presenters/post_presenter_spec.rb
spec/presenters/post_presenter_spec.rb
+2
-2
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+74
-0
spec/services/post_service_spec.rb
spec/services/post_service_spec.rb
+12
-2
spec/services/status_message_creation_service_spec.rb
spec/services/status_message_creation_service_spec.rb
+10
-38
spec/shared_behaviors/mentions_container.rb
spec/shared_behaviors/mentions_container.rb
+44
-0
spec/workers/mail/mentioned_spec.rb
spec/workers/mail/mentioned_spec.rb
+3
-2
No files found.
app/controllers/notifications_controller.rb
View file @
33ad411b
...
...
@@ -23,8 +23,8 @@ class NotificationsController < ApplicationController
def
index
conditions
=
{
:recipient_id
=>
current_user
.
id
}
if
params
[
:type
]
&&
Notification
.
types
.
has_key?
(
params
[
:type
])
conditions
[
:type
]
=
Notification
.
types
[
params
[
:type
]]
if
params
[
:type
]
&&
types
.
has_key?
(
params
[
:type
])
conditions
[
:type
]
=
types
[
params
[
:type
]]
end
if
params
[
:show
]
==
"unread"
then
conditions
[
:unread
]
=
true
end
page
=
params
[
:page
]
||
1
...
...
@@ -44,7 +44,7 @@ class NotificationsController < ApplicationController
@grouped_unread_notification_counts
=
{}
Notification
.
types
.
each_with_object
(
current_user
.
unread_notifications
.
group_by
(
&
:type
))
{
|
(
name
,
type
),
notifications
|
types
.
each_with_object
(
current_user
.
unread_notifications
.
group_by
(
&
:type
))
{
|
(
name
,
type
),
notifications
|
@grouped_unread_notification_counts
[
name
]
=
notifications
.
has_key?
(
type
)
?
notifications
[
type
].
count
:
0
}
...
...
@@ -65,7 +65,7 @@ class NotificationsController < ApplicationController
end
def
read_all
current_type
=
Notification
.
types
[
params
[
:type
]]
current_type
=
types
[
params
[
:type
]]
notifications
=
Notification
.
where
(
recipient_id:
current_user
.
id
,
unread:
true
)
notifications
=
notifications
.
where
(
type:
current_type
)
if
params
[
:type
]
notifications
.
update_all
(
unread:
false
)
...
...
@@ -93,4 +93,17 @@ class NotificationsController < ApplicationController
}
}.
as_json
end
def
types
{
"also_commented"
=>
"Notifications::AlsoCommented"
,
"comment_on_post"
=>
"Notifications::CommentOnPost"
,
"liked"
=>
"Notifications::Liked"
,
"mentioned"
=>
"Notifications::MentionedInPost"
,
"mentioned_in_comment"
=>
"Notifications::MentionedInComment"
,
"reshared"
=>
"Notifications::Reshared"
,
"started_sharing"
=>
"Notifications::StartedSharing"
}
end
helper_method
:types
end
app/controllers/status_messages_controller.rb
View file @
33ad411b
...
...
@@ -80,7 +80,10 @@ class StatusMessagesController < ApplicationController
def
handle_mention_feedback
(
status_message
)
return
unless
comes_from_others_profile_page?
flash
[
:notice
]
=
t
(
"status_messages.create.success"
,
names:
status_message
.
mentioned_people_names
)
flash
[
:notice
]
=
t
(
"status_messages.create.success"
,
names:
PersonPresenter
.
people_names
(
status_message
.
mentioned_people
)
)
end
def
comes_from_others_profile_page?
...
...
app/controllers/users_controller.rb
View file @
33ad411b
...
...
@@ -150,16 +150,7 @@ class UsersController < ApplicationController
:auto_follow_back_aspect_id
,
:getting_started
,
:post_default_public
,
email_preferences:
%i(
someone_reported
also_commented
mentioned
comment_on_post
private_message
started_sharing
liked
reshared
)
email_preferences:
UserPreference
::
VALID_EMAIL_TYPES
.
map
(
&
:to_sym
)
)
end
# rubocop:enable Metrics/MethodLength
...
...
app/helpers/notifications_helper.rb
View file @
33ad411b
...
...
@@ -2,42 +2,46 @@ module NotificationsHelper
include
PeopleHelper
include
PostsHelper
def
object_link
(
note
,
actors
)
def
object_link
(
note
,
actors
_html
)
target_type
=
note
.
popup_translation_key
actors_count
=
note
.
actors
.
size
opts
=
{
actors:
actors_html
,
count:
note
.
actors
.
size
}
if
note
.
instance_of?
(
Notifications
::
Mentioned
)
if
post
=
note
.
linked_object
t
ranslation
(
target_type
,
actors:
actors
,
count:
actors_count
,
post_link:
link_to
(
post_page_title
(
post
),
post_path
(
post
)).
html_safe
)
else
t
(
note
.
deleted_translation_key
,
:actors
=>
actors
,
:count
=>
actors_count
).
html_safe
if
note
.
respond_to?
(
:linked_object
)
if
note
.
linked_object
.
nil?
&&
note
.
respond_to?
(
:deleted_translation_key
)
t
arget_type
=
note
.
deleted_translation_key
elsif
note
.
is_a?
(
Notifications
::
Mentioned
)
opts
.
merge!
(
opts_for_mentioned
(
note
.
linked_object
))
elsif
%w(Notifications::CommentOnPost Notifications::AlsoCommented Notifications::Reshared Notifications::Liked
)
.
include?
(
note
.
type
)
opts
.
merge!
(
opts_for_post
(
note
.
linked_object
))
end
elsif
note
.
instance_of?
(
Notifications
::
CommentOnPost
)
||
note
.
instance_of?
(
Notifications
::
AlsoCommented
)
||
note
.
instance_of?
(
Notifications
::
Reshared
)
||
note
.
instance_of?
(
Notifications
::
Liked
)
if
post
=
note
.
linked_object
translation
(
target_type
,
actors:
actors
,
count:
actors_count
,
post_author:
h
(
post
.
author_name
),
post_link:
link_to
(
post_page_title
(
post
),
post_path
(
post
),
data:
{
ref:
post
.
id
},
class:
"hard_object_link"
).
html_safe
)
else
t
(
note
.
deleted_translation_key
,
:actors
=>
actors
,
:count
=>
actors_count
).
html_safe
end
else
#Notifications:StartedSharing, etc.
translation
(
target_type
,
:actors
=>
actors
,
:count
=>
actors_count
)
end
translation
(
target_type
,
opts
)
end
def
translation
(
target_type
,
opts
=
{})
{
:post_author
=>
nil
}.
merge!
(
opts
)
t
(
"
#{
target_type
}
"
,
opts
).
html_safe
end
def
opts_for_post
(
post
)
{
post_author:
html_escape
(
post
.
author_name
),
post_link:
link_to
(
post_page_title
(
post
),
post_path
(
post
),
data:
{
ref:
post
.
id
},
class:
"hard_object_link"
).
html_safe
}
end
def
opts_for_mentioned
(
mentioned
)
post
=
mentioned
.
instance_of?
(
Comment
)
?
mentioned
.
parent
:
mentioned
{
post_link:
link_to
(
post_page_title
(
post
),
post_path
(
post
)).
html_safe
}.
tap
{
|
opts
|
opts
[
:comment_path
]
=
post_path
(
post
,
anchor:
mentioned
.
guid
).
html_safe
if
mentioned
.
instance_of?
(
Comment
)
}
end
def
notification_people_link
(
note
,
people
=
nil
)
actors
=
people
||
note
.
actors
number_of_actors
=
actors
.
size
...
...
app/mailers/notification_mailers/mentioned.rb
View file @
33ad411b
...
...
@@ -4,7 +4,7 @@ module NotificationMailers
delegate
:author_name
,
to: :post
,
prefix:
true
def
set_headers
(
target_id
)
@post
=
Mention
.
find_by_id
(
target_id
).
post
@post
=
Mention
.
find_by_id
(
target_id
).
mentions_container
@headers
[
:subject
]
=
I18n
.
t
(
'notifier.mentioned.subject'
,
:name
=>
@sender
.
name
)
@headers
[
:in_reply_to
]
=
@headers
[
:references
]
=
"<
#{
@post
.
guid
}
@
#{
AppConfig
.
pod_uri
.
host
}
>"
...
...
app/mailers/notification_mailers/mentioned_in_comment.rb
0 → 100644
View file @
33ad411b
module
NotificationMailers
class
MentionedInComment
<
NotificationMailers
::
Base
attr_reader
:comment
def
set_headers
(
target_id
)
# rubocop:disable Style/AccessorMethodName
@comment
=
Mention
.
find_by_id
(
target_id
).
mentions_container
@headers
[
:subject
]
=
I18n
.
t
(
"notifier.mentioned.subject"
,
name:
@sender
.
name
)
end
end
end
app/models/comment.rb
View file @
33ad411b
...
...
@@ -11,6 +11,7 @@ class Comment < ActiveRecord::Base
include
Diaspora
::
Taggable
include
Diaspora
::
Likeable
include
Diaspora
::
MentionsContainer
acts_as_taggable_on
:tags
extract_tags_from
:text
...
...
@@ -49,14 +50,22 @@ class Comment < ActiveRecord::Base
participation
.
unparticipate!
if
participation
.
present?
end
def
message
@message
||=
Diaspora
::
MessageRenderer
.
new
text
end
def
text
=
text
self
[
:text
]
=
text
.
to_s
.
strip
#to_s if for nil, for whatever reason
end
def
people_allowed_to_be_mentioned
if
parent
.
public?
:all
else
[
*
parent
.
comments
.
pluck
(
:author_id
),
*
parent
.
likes
.
pluck
(
:author_id
),
parent
.
author_id
].
uniq
end
end
def
add_mention_subscribers?
super
&&
parent
.
author
.
local?
end
class
Generator
<
Diaspora
::
Federated
::
Generator
def
self
.
federated_class
Comment
...
...
@@ -68,7 +77,7 @@ class Comment < ActiveRecord::Base
end
def
relayable_options
{
:post
=>
@target
,
:text
=>
@text
}
{
post:
@target
,
text:
@text
}
end
end
end
app/models/mention.rb
View file @
33ad411b
...
...
@@ -3,11 +3,15 @@
# the COPYRIGHT file.
class
Mention
<
ActiveRecord
::
Base
belongs_to
:
post
belongs_to
:
mentions_container
,
polymorphic:
true
belongs_to
:person
validates
:
post
,
presence:
true
validates
:
mentions_container
,
presence:
true
validates
:person
,
presence:
true
scope
:local
,
->
{
joins
(
:person
).
where
.
not
(
people:
{
owner_id:
nil
})
}
after_destroy
:delete_notification
def
delete_notification
...
...
app/models/notification.rb
View file @
33ad411b
...
...
@@ -51,15 +51,4 @@ class Notification < ActiveRecord::Base
private_class_method
def
self
.
suppress_notification?
(
recipient
,
actor
)
recipient
.
blocks
.
where
(
person:
actor
).
exists?
end
def
self
.
types
{
"also_commented"
=>
"Notifications::AlsoCommented"
,
"comment_on_post"
=>
"Notifications::CommentOnPost"
,
"liked"
=>
"Notifications::Liked"
,
"mentioned"
=>
"Notifications::Mentioned"
,
"reshared"
=>
"Notifications::Reshared"
,
"started_sharing"
=>
"Notifications::StartedSharing"
}
end
end
app/models/notifications/also_commented.rb
View file @
33ad411b
module
Notifications
class
AlsoCommented
<
Notification
include
Notifications
::
Commented
def
mail_job
Workers
::
Mail
::
AlsoCommented
end
...
...
@@ -8,17 +10,13 @@ module Notifications
"notifications.also_commented"
end
def
deleted_translation_key
"notifications.also_commented_deleted"
end
def
self
.
notify
(
comment
,
_recipient_user_ids
)
actor
=
comment
.
author
commentable
=
comment
.
commentable
recipient_ids
=
commentable
.
participants
.
local
.
where
.
not
(
id:
[
commentable
.
author_id
,
actor
.
id
]).
pluck
(
:owner_id
)
User
.
where
(
id:
recipient_ids
).
find_each
do
|
recipient
|
next
if
recipient
.
is_shareable_hidden?
(
commentable
)
next
if
recipient
.
is_shareable_hidden?
(
commentable
)
||
mention_notification_exists?
(
comment
,
recipient
.
person
)
concatenate_or_create
(
recipient
,
commentable
,
actor
).
try
(
:email_the_user
,
comment
,
actor
)
end
...
...
app/models/notifications/comment_on_post.rb
View file @
33ad411b
module
Notifications
class
CommentOnPost
<
Notification
include
Notifications
::
Commented
def
mail_job
Workers
::
Mail
::
CommentOnPost
end
...
...
@@ -8,15 +10,12 @@ module Notifications
"notifications.comment_on_post"
end
def
deleted_translation_key
"notifications.also_commented_deleted"
end
def
self
.
notify
(
comment
,
_recipient_user_ids
)
actor
=
comment
.
author
commentable_author
=
comment
.
commentable
.
author
return
unless
commentable_author
.
local?
&&
actor
!=
commentable_author
return
if
mention_notification_exists?
(
comment
,
commentable_author
)
concatenate_or_create
(
commentable_author
.
owner
,
comment
.
commentable
,
actor
).
email_the_user
(
comment
,
actor
)
end
...
...
app/models/notifications/commented.rb
0 → 100644
View file @
33ad411b
module
Notifications
module
Commented
extend
ActiveSupport
::
Concern
def
deleted_translation_key
"notifications.also_commented_deleted"
end
module
ClassMethods
def
mention_notification_exists?
(
comment
,
recipient_person
)
Notifications
::
MentionedInComment
.
exists?
(
target:
comment
.
mentions
.
where
(
person:
recipient_person
))
end
end
end
end
app/models/notifications/mentioned.rb
View file @
33ad411b
module
Notifications
class
Mentioned
<
Notification
def
mail_job
Workers
::
Mail
::
Mentioned
end
def
popup_translation_key
"notifications.mentioned"
end
def
deleted_translation_key
"notifications.mentioned_deleted"
end
module
Mentioned
extend
ActiveSupport
::
Concern
def
linked_object
target
.
post
target
.
mentions_container
end
def
self
.
notify
(
mentionable
,
recipient_user_ids
)
actor
=
mentionable
.
author
mentionable
.
mentions
.
select
{
|
mention
|
mention
.
person
.
local?
}.
each
do
|
mention
|
recipient
=
mention
.
person
next
if
recipient
==
actor
||
!
(
mentionable
.
public
||
recipient_user_ids
.
include?
(
recipient
.
owner_id
))
module
ClassMethods
def
notify
(
mentionable
,
recipient_user_ids
)
actor
=
mentionable
.
author
relevant_mentions
=
filter_mentions
(
mentionable
.
mentions
.
local
.
where
.
not
(
person:
actor
),
mentionable
,
recipient_user_ids
)
create_notification
(
recipient
.
owner
,
mention
,
actor
).
try
(
:email_the_user
,
mention
,
actor
)
relevant_mentions
.
each
do
|
mention
|
create_notification
(
mention
.
person
.
owner
,
mention
,
actor
).
try
(
:email_the_user
,
mention
,
actor
)
end
end
end
end
...
...
app/models/notifications/mentioned_in_comment.rb
0 → 100644
View file @
33ad411b
module
Notifications
class
MentionedInComment
<
Notification
include
Notifications
::
Mentioned
def
popup_translation_key
"notifications.mentioned_in_comment"
end
def
deleted_translation_key
"notifications.mentioned_in_comment_deleted"
end
def
self
.
filter_mentions
(
mentions
,
mentionable
,
_recipient_user_ids
)
people
=
mentionable
.
people_allowed_to_be_mentioned
if
people
==
:all
mentions
else
mentions
.
where
(
person_id:
people
)
end
end
def
mail_job
if
!
recipient
.
user_preferences
.
exists?
(
email_type:
"mentioned_in_comment"
)
Workers
::
Mail
::
MentionedInComment
elsif
shareable
.
author
.
owner_id
==
recipient_id
Workers
::
Mail
::
CommentOnPost
elsif
shareable
.
participants
.
local
.
where
(
owner_id:
recipient_id
)
Workers
::
Mail
::
AlsoCommented
end
end
private
def
shareable
linked_object
.
parent
end
end
end
app/models/notifications/mentioned_in_post.rb
0 → 100644
View file @
33ad411b
module
Notifications
class
MentionedInPost
<
Notification
include
Notifications
::
Mentioned
def
mail_job
Workers
::
Mail
::
Mentioned
end
def
popup_translation_key
"notifications.mentioned"
end
def
deleted_translation_key
"notifications.mentioned_deleted"
end
def
self
.
filter_mentions
(
mentions
,
mentionable
,
recipient_user_ids
)
return
mentions
if
mentionable
.
public
mentions
.
where
(
person:
Person
.
where
(
owner_id:
recipient_user_ids
).
ids
)
end
end
end
app/models/post.rb
View file @
33ad411b
...
...
@@ -12,16 +12,15 @@ class Post < ActiveRecord::Base
include
Diaspora
::
Likeable
include
Diaspora
::
Commentable
include
Diaspora
::
Shareable
include
Diaspora
::
MentionsContainer
has_many
:participations
,
dependent: :delete_all
,
as: :target
,
inverse_of: :target
has_many
:participants
,
class_name:
"Person"
,
through: :participations
,
source: :author
has_many
:participants
,
through: :participations
,
source: :author
attr_accessor
:user_like
has_many
:reports
,
as: :item
has_many
:mentions
,
dependent: :destroy
has_many
:reshares
,
class_name:
"Reshare"
,
foreign_key: :root_guid
,
primary_key: :guid
has_many
:resharers
,
class_name:
"Person"
,
through: :reshares
,
source: :author
...
...
@@ -60,7 +59,6 @@ class Post < ActiveRecord::Base
end
def
root
;
end
def
mentioned_people
;
[];
end
def
photos
;
[];
end
#prevents error when trying to access @post.address in a post different than Reshare and StatusMessage types;
...
...
app/models/status_message.rb
View file @
33ad411b
...
...
@@ -23,13 +23,12 @@ class StatusMessage < Post
attr_accessor
:oembed_url
attr_accessor
:open_graph_url
after_create
:create_mentions
after_commit
:queue_gather_oembed_data
,
:on
=>
:create
,
:if
=>
:contains_oembed_url_in_text?
after_commit
:queue_gather_open_graph_data
,
:on
=>
:create
,
:if
=>
:contains_open_graph_url_in_text?
#scopes
scope
:where_person_is_mentioned
,
->
(
person
)
{
joins
(
:mentions
).
where
(
:mentions
=>
{
:person_id
=>
person
.
id
})
owned_or_visible_by_user
(
person
.
owner
).
joins
(
:mentions
).
where
(
mentions:
{
person_id:
person
.
id
})
}
def
self
.
guids_for_author
(
person
)
...
...
@@ -52,36 +51,6 @@ class StatusMessage < Post
text
.
try
(
:match
,
/#nsfw/i
)
||
super
end
def
message
@message
||=
Diaspora
::
MessageRenderer
.
new
(
text
,
mentioned_people:
mentioned_people
)
end
def
mentioned_people
if
self
.
persisted?
self
.
mentions
.
includes
(
:person
=>
:profile
).
map
{
|
mention
|
mention
.
person
}
else
Diaspora
::
Mentionable
.
people_from_string
(
text
)
end
end
## TODO ----
# don't put presentation logic in the model!
def
mentioned_people_names
self
.
mentioned_people
.
map
(
&
:name
).
join
(
', '
)
end
## ---- ----
def
create_mentions
ppl
=
Diaspora
::
Mentionable
.
people_from_string
(
text
)
ppl
.
each
do
|
person
|
self
.
mentions
.
find_or_create_by
(
person_id:
person
.
id
)
end
end
def
mentions?
(
person
)
mentioned_people
.
include?
person
end
def
comment_email_subject
message
.
title
end
...
...
@@ -126,6 +95,22 @@ class StatusMessage < Post
photos
.
each
{
|
photo
|
photo
.
receive
(
recipient_user_ids
)
}
end
# Only includes those people, to whom we're going to send a federation entity
# (and doesn't define exhaustive list of people who can receive it)
def
people_allowed_to_be_mentioned
@aspects_ppl
||=
if
public
?
:
all
else
Contact
.
joins
(
:aspect_memberships
).
where
(
aspect_memberships:
{
aspect:
aspects
}).
distinct
.
pluck
(
:person_id
)
end
end
def
filter_mentions
return
if
people_allowed_to_be_mentioned
==
:all
update
(
text:
Diaspora
::
Mentionable
.
filter_people
(
text
,
people_allowed_to_be_mentioned
))
end
private
def
presence_of_content
...
...
app/models/user.rb
View file @
33ad411b
...
...
@@ -333,6 +333,7 @@ class User < ActiveRecord::Base
######### Mailer #######################
def
mail
(
job
,
*
args
)
return
unless
job
.
present?
pref
=
job
.
to_s
.
gsub
(
'Workers::Mail::'
,
''
).
underscore
if
(
self
.
disable_mail
==
false
&&
!
self
.
user_preferences
.
exists?
(
:email_type
=>
pref
))
job
.
perform_async
(
*
args
)
...
...
app/models/user_preference.rb
View file @
33ad411b
...
...
@@ -5,13 +5,14 @@ class UserPreference < ActiveRecord::Base
VALID_EMAIL_TYPES
=
[
"someone_reported"
,
"mentioned"
,
"comment_on_post"
,
"private_message"
,
"started_sharing"
,
"also_commented"
,
"liked"
,
"reshared"
]
"mentioned"
,
"mentioned_in_comment"
,
"comment_on_post"
,
"private_message"
,
"started_sharing"
,
"also_commented"
,
"liked"
,
"reshared"
]
def
must_be_valid_email_type
unless
VALID_EMAIL_TYPES
.
include?
(
self
.
email_type
)
...
...
app/presenters/person_presenter.rb
View file @
33ad411b
...
...
@@ -40,6 +40,10 @@ class PersonPresenter < BasePresenter
}
end
def
self
.
people_names
(
people
)
people
.
map
(
&
:name
).
join
(
", "
)
end
protected
def
own_profile?
...
...
app/services/notification_service.rb
View file @
33ad411b
class
NotificationService
NOTIFICATION_TYPES
=
{
Comment
=>
[
Notifications
::
CommentOnPost
,
Notifications
::
AlsoCommented
],
Comment
=>
[
Notifications
::
MentionedInComment
,
Notifications
::
CommentOnPost
,
Notifications
::
AlsoCommented
],
Like
=>
[
Notifications
::
Liked
],
StatusMessage
=>
[
Notifications
::
Mentioned
],
StatusMessage
=>
[
Notifications
::
Mentioned
InPost
],
Conversation
=>
[
Notifications
::
PrivateMessage
],
Message
=>
[
Notifications
::
PrivateMessage
],
Reshare
=>
[
Notifications
::
Reshared
],
...
...
app/services/post_service.rb
View file @
33ad411b
...
...
@@ -59,8 +59,20 @@ class PostService
end
def
mark_mention_notifications_read
(
post_id
)
mention_id
=
Mention
.
where
(
post_id:
post_id
,
person_id:
user
.
person_id
).
pluck
(
:id
)
Notification
.
where
(
recipient_id:
user
.
id
,
target_type:
"Mention"
,
target_id:
mention_id
,
unread:
true
)
.
update_all
(
unread:
false
)
if
mention_id
mention_ids
=
Mention
.
where
(
mentions_container_id:
post_id
,
mentions_container_type:
"Post"
,
person_id:
user
.
person_id
).
ids
mention_ids
.
concat
(
mentions_in_comments_for_post
(
post_id
).
pluck
(
:id
))
Notification
.
where
(
recipient_id:
user
.
id
,
target_type:
"Mention"
,
target_id:
mention_ids
,
unread:
true
)
.
update_all
(
unread:
false
)
if
mention_ids
.
any?
end
def
mentions_in_comments_for_post
(
post_id
)
Mention
.
joins
(
"INNER JOIN comments ON mentions_container_id = comments.id AND mentions_container_type = 'Comment'"
)
.
where
(
comments:
{
commentable_id:
post_id
,
commentable_type:
"Post"
})
end
end
app/services/status_message_creation_service.rb
View file @
33ad411b
...
...
@@ -19,20 +19,9 @@ class StatusMessageCreationService
def
build_status_message
(
params
)
public
=
params
[
:public
]
||
false
filter_mentions
params