Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Envfile
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ variable :TWITCH_WEBHOOK_SECRET, :String, default: "Optional"
# (https://api.stackexchange.com/docs)
variable :STACK_EXCHANGE_APP_KEY, :String, default: ""

# For Heroku domain
# ("https://medium.com/")
variable :MEDIUM_DOMIAN, :String, default: "https://medium.com/"

# For setting the IDs of the staff and welcoming users
variable :STAFF_USER_ID, :Integer, default: 1
variable :WELCOMING_USER_ID, :Integer, default: 1
Expand All @@ -182,4 +186,5 @@ group :production do

# Heroku
variable :HEROKU_APP_URL, :String # practicaldev.herokuapp.com
variable :MEDIUM_DOMIAN, :String, default: "https://medium.com/"
end
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ gem "oj", "~> 3.10" # JSON parser and object serializer
gem "omniauth", "~> 1.9" # A generalized Rack framework for multiple-provider authentication
gem "omniauth-github", "~> 1.3" # OmniAuth strategy for GitHub
gem "omniauth-twitter", "~> 1.4" # OmniAuth strategy for Twitter
gem "opengraph_parser", "~> 0.2.3" # Open Graph Protocol information from a website
gem "pg", "~> 1.2" # Pg is the Ruby interface to the PostgreSQL RDBMS
gem "puma", "~> 4.3" # Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server
gem "pundit", "~> 2.1" # Object oriented authorization for Rails applications
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ GEM
omniauth-twitter (1.4.0)
omniauth-oauth (~> 1.1)
rack
opengraph_parser (0.2.3)
addressable
nokogiri
orm_adapter (0.5.0)
os (1.0.1)
parallel (1.19.1)
Expand Down Expand Up @@ -921,6 +924,7 @@ DEPENDENCIES
omniauth (~> 1.9)
omniauth-github (~> 1.3)
omniauth-twitter (~> 1.4)
opengraph_parser (~> 0.2.3)
parallel_tests (~> 2.31)
pg (~> 1.2)
pry (~> 0.12)
Expand Down
15 changes: 15 additions & 0 deletions app/models/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def append_rich_links(html)
#{user.name}
</h1>
</a>".html_safe
elsif (medium = rich_medium_link(anchor))
html += "<a href='#{medium.url}'
class='chatchannels__richlink'
target='_blank' data-content='sidecar-medium'>
#{"<div class='chatchannels__richlinkmainimage' style='background-image:url(" + medium.image_url + ")' data-content='sidecar-medium' ></div>" if medium.image_url.present?}
<h1 data-content='sidecar-medium'>#{medium.title}</h1>
<h4 data-content='sidecar-medium'>#{medium.description}</h4>".html_safe
end
end
html
Expand Down Expand Up @@ -163,6 +170,14 @@ def rich_user_link(link)
User.find_by(username: link["href"].split("/")[3].split("/")[0]) if link["href"].include?("//#{ApplicationConfig['APP_DOMAIN']}/")
end

def rich_medium_link(link)
# restricted to preview only medium urls. Not sure we need to suport others or not.
return unless link["href"].include?(ApplicationConfig["MEDIUM_DOMIAN"]) && link["href"].split("/")[4]

website = OpenGraph.new(link["href"])
OpenStruct.new(title: website.title, url: website.url, description: website.description.presence, image_url: website.images.present? ? website.images.first : nil) if website
end

def send_email_if_appropriate
recipient = direct_receiver
return if !chat_channel.direct? ||
Expand Down