Skip to content

Commit 75e2f8c

Browse files
committed
Fixing conflict
2 parents 9d7cb8a + 30d3a56 commit 75e2f8c

40 files changed

+813
-65
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ group :development do
3434
end
3535

3636
gem 'webmock'
37-
gem 'pender_client', git: 'https://github.com/meedan/pender-client.git', ref: 'ad74fad'
37+
gem 'pender_client', git: 'https://github.com/meedan/pender-client.git', ref: 'a57737b'
3838
gem 'lograge'
3939
gem 'rails', '~> 6.1.7'
4040
gem 'pg', '~> 1.1'

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ GIT
4040

4141
GIT
4242
remote: https://github.com/meedan/pender-client.git
43-
revision: ad74fadd10af2fdd359ab1f5e7a71362a47f9eff
44-
ref: ad74fad
43+
revision: a57737be5a63bf1575ae33eba304300568ad86cf
44+
ref: a57737b
4545
specs:
4646
pender_client (0.0.4)
4747

app/controllers/test_controller.rb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,65 @@ def random
265265
render html: "<!doctype html><html><head><title>Test #{rand(100000).to_i}</title></head><body>Test</body></html>".html_safe
266266
end
267267

268+
def create_saved_search_list
269+
team = Team.current = Team.find(params[:team_id])
270+
saved_search = create_saved_search(team: team)
271+
272+
render_success 'saved_search', saved_search
273+
end
274+
275+
def create_feed_with_item
276+
team = Team.current = Team.find(params[:team_id])
277+
user = User.where(email: params[:email]).last
278+
saved_search = team.saved_searches.first || SavedSearch.create!(
279+
title: "#{user.name.capitalize}'s list",
280+
team: team,
281+
filters: { created_by: user }
282+
)
283+
284+
feed = create_feed(
285+
name: "Feed for #{team.name} ##{team.feeds.count + 1}",
286+
user: user,
287+
team: team,
288+
published: true,
289+
saved_search: saved_search,
290+
licenses: [1],
291+
last_clusterized_at: Time.now,
292+
data_points: [1, 2]
293+
)
294+
295+
pm = create_project_media(
296+
user: user,
297+
team: team,
298+
project: saved_search.team.projects.first,
299+
quote: 'Test',
300+
media_type: 'Claim',
301+
media: Blank.create!
302+
)
303+
304+
cluster = create_cluster( project_media: pm, feed: feed )
305+
306+
render_success 'feed', { feed: feed, cluster: cluster, project_media: pm }
307+
end
308+
309+
def create_feed_invitation
310+
team = Team.current = Team.find(params[:team_id])
311+
user = User.where(email: params[:email]).last
312+
user_inviter = User.where(email: params[:email2]).last
313+
feed = team.feeds.first || create_feed(team: team, user: user_inviter)
314+
315+
feed_invitation_params = {
316+
email: user.email,
317+
feed: feed,
318+
user: user_inviter,
319+
state: :invited
320+
}
321+
322+
feed_invitation = FeedInvitation.create!(feed_invitation_params)
323+
324+
render_success 'feed_invitation', { feed: feed, feed_invitation: feed_invitation, team: team }
325+
end
326+
268327
protected
269328

270329
def new_media(type)

app/graph/mutations/saved_search_mutations.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Create < Mutations::CreateMutation
1515

1616
argument :title, GraphQL::Types::String, required: true
1717
argument :team_id, GraphQL::Types::Int, required: true, camelize: false
18+
argument :list_type, GraphQL::Types::String, required: true, camelize: false
1819
end
1920

2021
class Update < Mutations::UpdateMutation

app/graph/types/saved_search_type.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SavedSearchType < DefaultObject
88
field :team_id, GraphQL::Types::Int, null: true
99
field :team, PublicTeamType, null: true
1010
field :items_count, GraphQL::Types::Int, null: true
11+
field :list_type, GraphQL::Types::String, null: true
1112
field :filters, GraphQL::Types::String, null: true
1213

1314
def filters

app/graph/types/team_type.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ def verification_statuses(items_count_for_status: nil, published_reports_count_f
163163
# We sometimes call this method and somehow object is nil despite self.object being available
164164
object ||= self.object
165165
object = object.reload if items_count_for_status || published_reports_count_for_status
166-
object.verification_statuses("media", nil, items_count_for_status, published_reports_count_for_status)
166+
statuses = object.verification_statuses("media", nil, items_count_for_status, published_reports_count_for_status)
167+
# Sort the statuses by the 'label' field
168+
statuses["statuses"] = statuses["statuses"].sort_by { |status| status["label"] }
169+
statuses
167170
end
168171

169172
field :team_bot_installation, TeamBotInstallationType, null: true do

app/lib/tipline_search_result.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def footer(language)
4848
def text(language = nil, hide_body = false)
4949
text = []
5050
text << "*#{self.title.strip}*" unless self.title.blank?
51-
text << self.body.to_s unless hide_body
51+
text << self.body.to_s.truncate(900 - self.title.to_s.size - self.url.to_s.size) unless hide_body
5252
text << self.url unless self.url.blank?
5353
unless language.nil?
5454
footer = self.footer(language)

app/models/bot/smooch.rb

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class CapiUnhandledMessageWarning < MessageDeliveryError; end
1313
SUPPORTED_INTEGRATION_NAMES = { 'whatsapp' => 'WhatsApp', 'messenger' => 'Facebook Messenger', 'twitter' => 'Twitter', 'telegram' => 'Telegram', 'viber' => 'Viber', 'line' => 'LINE', 'instagram' => 'Instagram' }
1414
SUPPORTED_INTEGRATIONS = SUPPORTED_INTEGRATION_NAMES.keys
1515
SUPPORTED_TRIGGER_MAPPING = { 'message:appUser' => :incoming, 'message:delivery:channel' => :outgoing }
16+
TIPLINE_CUSTOMIZABLE_MESSAGES = ['smooch_message_smooch_bot_greetings', 'submission_prompt', 'add_more_details_state', 'ask_if_ready_state',
17+
'search_state', 'search_no_results', 'search_result_state', 'search_result_is_relevant', 'search_submit',
18+
'newsletter_optin_optout', 'option_not_available', 'timeout', 'smooch_message_smooch_bot_disabled']
1619

1720
check_settings
1821

@@ -960,31 +963,33 @@ def self.send_correction_to_user(data, pm, tipline_request, last_published_at, a
960963
self.get_platform_from_message(data)
961964
uid = data['authorId']
962965
lang = data['language']
963-
field_name = ''
964966
# User received a report before
965967
if subscribed_at.to_i < last_published_at.to_i && published_count > 0
966968
if ['publish', 'republish_and_resend'].include?(action)
967-
field_name = 'smooch_report_correction_sent_at'
968-
self.send_report_to_user(uid, data, pm, lang, 'fact_check_report_updated', self.get_string(:report_updated, lang))
969+
self.send_report_to_user(uid, data, pm, lang, 'fact_check_report_updated', self.get_string(:report_updated, lang), tipline_request)
969970
end
970971
# First report
971972
else
972-
field_name = 'smooch_report_sent_at'
973-
self.send_report_to_user(uid, data, pm, lang, 'fact_check_report')
974-
end
975-
unless field_name.blank?
976-
tipline_request.skip_check_ability = true
977-
tipline_request.send("#{field_name}=", Time.now.to_i)
978-
tipline_request.save!
973+
self.send_report_to_user(uid, data, pm, lang, 'fact_check_report', nil, tipline_request)
979974
end
980975
end
981976

982-
def self.send_report_to_user(uid, data, pm, lang = 'en', fallback_template = nil, pre_message = nil)
977+
def self.send_report_to_user(uid, data, pm, lang = 'en', fallback_template = nil, pre_message = nil, tipline_request = nil)
983978
parent = Relationship.confirmed_parent(pm)
984979
return if parent.nil?
985980
report = parent.get_dynamic_annotation('report_design')
986-
Rails.logger.info "[Smooch Bot] Sending report to user #{uid} for item with ID #{pm.id}..."
987-
if report&.get_field_value('state') == 'published' && [CheckArchivedFlags::FlagCodes::NONE, CheckArchivedFlags::FlagCodes::UNCONFIRMED].include?(parent.archived) && report.should_send_report_in_this_language?(lang)
981+
Rails.logger.info "[Smooch Bot] Trying to send report to user #{uid} for item with ID #{pm.id}..."
982+
983+
# Only send a report if these conditions are met
984+
should_send_report_in_language = !!report&.should_send_report_in_this_language?(lang)
985+
if report&.get_field_value('state') == 'published' && [CheckArchivedFlags::FlagCodes::NONE, CheckArchivedFlags::FlagCodes::UNCONFIRMED].include?(parent.archived) && should_send_report_in_language
986+
987+
# Map the template name to a ticker field
988+
ticker_field_name = {
989+
fact_check_report_updated: 'smooch_report_correction_sent_at',
990+
fact_check_report: 'smooch_report_sent_at'
991+
}[fallback_template.to_s.to_sym]
992+
988993
unless pre_message.blank?
989994
self.send_message_to_user(uid, pre_message)
990995
sleep 1
@@ -1005,6 +1010,12 @@ def self.send_report_to_user(uid, data, pm, lang = 'en', fallback_template = nil
10051010
Rails.logger.info "[Smooch Bot] Sent report visual card to user #{uid} for item with ID #{pm.id}, response was: #{last_smooch_response&.body}"
10061011
end
10071012
self.save_smooch_response(last_smooch_response, parent, data['received'], fallback_template, lang)
1013+
1014+
if tipline_request.present? && ticker_field_name.present? && last_smooch_response.present?
1015+
tipline_request.update_column(ticker_field_name, Time.now.to_i)
1016+
end
1017+
else
1018+
Rails.logger.info "[Smooch Bot] Not sending report to user #{uid} for item with ID #{pm.id}. Report state: #{report&.get_field_value('state')} | Item archived flag: #{parent.archived} | Should send report in #{lang}? #{should_send_report_in_language}"
10081019
end
10091020
end
10101021

@@ -1035,7 +1046,7 @@ def self.send_report_from_parent_to_child(parent_id, target_id)
10351046
data = tr.smooch_data
10361047
self.get_platform_from_message(data)
10371048
self.get_installation(self.installation_setting_id_keys, data['app_id']) if self.config.blank?
1038-
self.send_report_to_user(tr.tipline_user_uid, data, parent, tr.language, 'fact_check_report')
1049+
self.send_report_to_user(tr.tipline_user_uid, data, parent, tr.language, 'fact_check_report', nil, tr)
10391050
end
10401051
end
10411052

@@ -1108,4 +1119,28 @@ def self.sanitize_installation(team_bot_installation, blast_secret_settings = fa
11081119
end
11091120
team_bot_installation
11101121
end
1122+
1123+
def self.default_settings
1124+
settings = [
1125+
{
1126+
'smooch_workflow_language' => 'en',
1127+
'smooch_state_main' => {
1128+
'smooch_menu_message' => '',
1129+
'smooch_menu_options' => []
1130+
},
1131+
'smooch_state_secondary' => {
1132+
'smooch_menu_message' => '',
1133+
'smooch_menu_options' => []
1134+
},
1135+
'smooch_state_query' => {
1136+
'smooch_menu_message' => '',
1137+
'smooch_menu_options' => []
1138+
},
1139+
}
1140+
]
1141+
::Bot::Smooch::TIPLINE_CUSTOMIZABLE_MESSAGES.each do |key|
1142+
settings[0][key] = ''
1143+
end
1144+
settings
1145+
end
11111146
end

app/models/concerns/project_association.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ def update_elasticsearch_data
9090
['team_id', 'user_id', 'read', 'source_id', 'project_id', 'unmatched'].each do |fname|
9191
data[fname] = self.send(fname).to_i if self.send("saved_change_to_#{fname}?")
9292
end
93-
['archived', 'sources_count'].each do |fname|
94-
data[fname] = { method: fname, klass: 'ProjectMedia', id: self.id, type: 'int' } if self.send("saved_change_to_#{fname}?")
95-
end
93+
data['archived'] = { method: 'archived', klass: 'ProjectMedia', id: self.id, type: 'int' } if self.send(:saved_change_to_archived?)
9694
data['channel'] = self.channel.values.flatten.map(&:to_i) if self.send(:saved_change_to_channel?)
9795
data['source_name'] = self.source&.name if self.send(:saved_change_to_source_id?)
9896
unless data.blank?
@@ -157,7 +155,7 @@ def is_unique
157155
protected
158156

159157
def set_media
160-
unless self.url.blank? && self.quote.blank? && self.file.blank? && self.media_type != 'Blank'
158+
unless self.url.blank? && self.quote.blank? && self.file.blank? && self.media_type != 'Blank' && self.set_original_claim.blank?
161159
self.create_media!
162160
self.media_id unless self.media_id.nil?
163161
end

app/models/concerns/project_media_creators.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@ def set_media_type
122122

123123
if original_claim && original_claim.match?(/\A#{URI::DEFAULT_PARSER.make_regexp(['http', 'https'])}\z/)
124124
uri = URI.parse(original_claim)
125-
content_type = Net::HTTP.get_response(uri)['content-type']
125+
content_type = nil
126+
begin
127+
content_type = Net::HTTP.start(uri.host, uri.port, open_timeout: 3, read_timeout: 3, use_ssl: uri.scheme == 'https') { |http| http.request_head(uri) }['content-type']
128+
rescue
129+
self.media_type = 'Claim'
130+
return
131+
end
126132

127133
case content_type
128134
when /^image\//

0 commit comments

Comments
 (0)