Merge pull request #1130 from metamaps/feature/release.notifs

make notifs and follows work for all users
This commit is contained in:
Connor Turland 2017-09-03 18:44:33 -04:00 committed by GitHub
commit 8af66b1b2c
10 changed files with 42 additions and 31 deletions

View file

@ -23,15 +23,15 @@ class UsersController < ApplicationController
if user_params[:password] == '' && user_params[:password_confirmation] == '' if user_params[:password] == '' && user_params[:password_confirmation] == ''
# not trying to change the password # not trying to change the password
if @user.update_attributes(user_params.except(:password, :password_confirmation)) if @user.update_attributes(user_params.except(:password, :password_confirmation))
update_follow_settings(@user, params[:settings]) if is_tester(@user) update_follow_settings(@user, params[:settings])
@user.image = nil if params[:remove_image] == '1' @user.image = nil if params[:remove_image] == '1'
@user.save @user.save
sign_in(@user, bypass: true) bypass_sign_in(@user)
respond_to do |format| respond_to do |format|
format.html { redirect_to root_url, notice: 'Settings updated' } format.html { redirect_to root_url, notice: 'Settings updated' }
end end
else else
sign_in(@user, bypass: true) bypass_sign_in(@user)
respond_to do |format| respond_to do |format|
format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] } format.html { redirect_to edit_user_path(@user), notice: @user.errors.to_a[0] }
end end

View file

@ -58,8 +58,8 @@ class User < ApplicationRecord
admin: admin } admin: admin }
if (_options[:follows]) if (_options[:follows])
json['follows'] = { json['follows'] = {
topics: following.where(followed_type: 'Topic').to_a.map(&:followed_id), topics: following.where(muted: false, followed_type: 'Topic').to_a.map(&:followed_id),
maps: following.where(followed_type: 'Map').to_a.map(&:followed_id) maps: following.where(muted: false, followed_type: 'Map').to_a.map(&:followed_id)
} }
end end
if (_options[:follow_settings]) if (_options[:follow_settings])

View file

@ -3,18 +3,20 @@ class FollowService
class << self class << self
def follow(entity, user, reason) def follow(entity, user, reason)
return unless user && is_tester(user) return unless user
return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason) return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason)
follow = Follow.where(followed: entity, user: user).first_or_create follow = Follow.where(followed: entity, user: user).first_or_create
follow.update_attribute('muted', false)
if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason) if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason)
follow.follow_reason.update_attribute(reason, true) follow.follow_reason.update_attribute(reason, true)
end end
end end
def unfollow(entity, user) def unfollow(entity, user)
Follow.where(followed: entity, user: user).destroy_all follow = Follow.where(followed: entity, user: user).first
follow.update_attribute('muted', true)
end end
def remove_reason(entity, user, reason) def remove_reason(entity, user, reason)
@ -31,6 +33,8 @@ class FollowService
protected protected
def should_auto_follow(entity, user, reason) def should_auto_follow(entity, user, reason)
follow = Follow.where(followed: entity, user: user).first
return false if follow && follow.muted
if entity.class == Topic if entity.class == Topic
if reason == 'created' if reason == 'created'
return user.settings.follow_topic_on_created == '1' return user.settings.follow_topic_on_created == '1'

View file

@ -54,7 +54,8 @@ class NotificationService
def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil) def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil)
follows = entity.follows.where.not(user_id: event.user.id) follows = entity.follows.where.not(user_id: event.user.id)
follows = follows.where(muted: false)
if !exclude_follows.nil? if !exclude_follows.nil?
follows = follows.where.not(id: exclude_follows) follows = follows.where.not(id: exclude_follows)
end end

View file

@ -45,24 +45,22 @@
<%= form.check_box :emails_allowed, class: 'inline' %> <%= form.check_box :emails_allowed, class: 'inline' %>
Send Metamaps notifications to my email. Send Metamaps notifications to my email.
<% end %> <% end %>
<% if is_tester(@user) %> <%= fields_for :settings, @user.settings do |settings| %>
<%= fields_for :settings, @user.settings do |settings| %> <%= settings.label :follow_topic_on_created, class: 'firstFieldText' do %>
<%= settings.label :follow_topic_on_created, class: 'firstFieldText' do %> <%= settings.check_box :follow_topic_on_created, class: 'inline' %>
<%= settings.check_box :follow_topic_on_created, class: 'inline' %> Auto-follow topics you create.
Auto-follow topics you create. <% end %>
<% end %> <%= settings.label :follow_topic_on_contributed, class: 'firstFieldText' do %>
<%= settings.label :follow_topic_on_contributed, class: 'firstFieldText' do %> <%= settings.check_box :follow_topic_on_contributed, class: 'inline' %>
<%= settings.check_box :follow_topic_on_contributed, class: 'inline' %> Auto-follow topics you edit
Auto-follow topics you edit. <% end %>
<% end %> <%= settings.label :follow_map_on_created, class: 'firstFieldText' do %>
<%= settings.label :follow_map_on_created, class: 'firstFieldText' do %> <%= settings.check_box :follow_map_on_created, class: 'inline' %>
<%= settings.check_box :follow_map_on_created, class: 'inline' %> Auto-follow maps you create.
Auto-follow maps you create. <% end %>
<% end %> <%= settings.label :follow_map_on_contributed, class: 'firstFieldText' do %>
<%= settings.label :follow_map_on_contributed, class: 'firstFieldText' do %> <%= settings.check_box :follow_map_on_contributed, class: 'inline' %>
<%= settings.check_box :follow_map_on_contributed, class: 'inline' %> Auto-follow maps you edit.
Auto-follow maps you edit.
<% end %>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>

View file

@ -0,0 +1,5 @@
class AddMutedToFollows < ActiveRecord::Migration[5.0]
def change
add_column :follows, :muted, :boolean
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170209215911) do ActiveRecord::Schema.define(version: 20170903180840) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -86,6 +86,7 @@ ActiveRecord::Schema.define(version: 20170209215911) do
t.integer "followed_id" t.integer "followed_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.boolean "muted"
t.index ["followed_type", "followed_id"], name: "index_follows_on_followed_type_and_followed_id", using: :btree t.index ["followed_type", "followed_id"], name: "index_follows_on_followed_type_and_followed_id", using: :btree
t.index ["user_id"], name: "index_follows_on_user_id", using: :btree t.index ["user_id"], name: "index_follows_on_user_id", using: :btree
end end

View file

@ -105,6 +105,10 @@ const Topic = Backbone.Model.extend({
var onPageWithTopicCard = Active.Map || Active.Topic var onPageWithTopicCard = Active.Map || Active.Topic
var node = this.get('node') var node = this.get('node')
if (Active.Mapper.get('follow_topic_on_contributed')) {
Active.Mapper.followTopic(this.id)
}
// update the node on the map // update the node on the map
if (onPageWithTopicCard && node) { if (onPageWithTopicCard && node) {
node.name = this.get('name') node.name = this.get('name')

View file

@ -1,7 +1,6 @@
import React, { Component, PropTypes } from 'react' import React, { Component, PropTypes } from 'react'
import { Link } from 'react-router' import { Link } from 'react-router'
import { find, values } from 'lodash' import { find, values } from 'lodash'
import Util from '../../Metamaps/Util'
const IN_CONVERSATION = 1 // shared with /realtime/reducer.js const IN_CONVERSATION = 1 // shared with /realtime/reducer.js
@ -38,7 +37,7 @@ class Menu extends Component {
<ul className='menuItems' style={ style }> <ul className='menuItems' style={ style }>
<li className='star' onClick={ () => { this.toggle() && onStar(map) }}>Star Map</li> <li className='star' onClick={ () => { this.toggle() && onStar(map) }}>Star Map</li>
{ !map.authorizeToEdit(currentUser) && <li className='request' onClick={ () => { this.toggle() && onRequest(map) }}>Request Access</li> } { !map.authorizeToEdit(currentUser) && <li className='request' onClick={ () => { this.toggle() && onRequest(map) }}>Request Access</li> }
{ Util.isTester(currentUser) && <li className='follow' onClick={ () => { this.toggle() && onMapFollow(map) }}>{isFollowing ? 'Unfollow' : 'Follow'}</li> } <li className='follow' onClick={ () => { this.toggle() && onMapFollow(map) }}>{isFollowing ? 'Unfollow' : 'Follow'}</li>
</ul> </ul>
</div> </div>
} }

View file

@ -6,7 +6,6 @@ import Links from './Links'
import Desc from './Desc' import Desc from './Desc'
import Attachments from './Attachments' import Attachments from './Attachments'
import Follow from './Follow' import Follow from './Follow'
import Util from '../../Metamaps/Util'
class ReactTopicCard extends Component { class ReactTopicCard extends Component {
render = () => { render = () => {
@ -53,7 +52,7 @@ class ReactTopicCard extends Component {
authorizedToEdit={authorizedToEdit} authorizedToEdit={authorizedToEdit}
updateTopic={wrappedUpdateTopic} updateTopic={wrappedUpdateTopic}
/> />
{Util.isTester(currentUser) && <Follow isFollowing={isFollowing} onTopicFollow={wrappedTopicFollow} />} <Follow isFollowing={isFollowing} onTopicFollow={wrappedTopicFollow} />
<div className="clearfloat"></div> <div className="clearfloat"></div>
</div> </div>
</div> </div>