mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
add comment elasticsearch and activity page strips
This commit is contained in:
parent
5f56710459
commit
509d53dbee
5 changed files with 95 additions and 3 deletions
|
@ -2,6 +2,11 @@ defmodule Philomena.Comments.Comment do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
use Philomena.Elasticsearch,
|
||||||
|
definition: Philomena.Comments.Elasticsearch,
|
||||||
|
index_name: "comments",
|
||||||
|
doc_type: "comment"
|
||||||
|
|
||||||
schema "comments" do
|
schema "comments" do
|
||||||
belongs_to :user, Philomena.Users.User
|
belongs_to :user, Philomena.Users.User
|
||||||
belongs_to :image, Philomena.Images.Image
|
belongs_to :image, Philomena.Images.Image
|
||||||
|
|
50
lib/philomena/comments/elasticsearch.ex
Normal file
50
lib/philomena/comments/elasticsearch.ex
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
defmodule Philomena.Comments.Elasticsearch do
|
||||||
|
def mapping do
|
||||||
|
%{
|
||||||
|
settings: %{
|
||||||
|
index: %{
|
||||||
|
number_of_shards: 5,
|
||||||
|
max_result_window: 10_000_000
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mappings: %{
|
||||||
|
comment: %{
|
||||||
|
_all: %{enabled: false},
|
||||||
|
dynamic: false,
|
||||||
|
properties: %{
|
||||||
|
id: %{type: "integer"},
|
||||||
|
posted_at: %{type: "date"},
|
||||||
|
ip: %{type: "ip"},
|
||||||
|
fingerprint: %{type: "keyword"},
|
||||||
|
image_id: %{type: "keyword"},
|
||||||
|
user_id: %{type: "keyword"},
|
||||||
|
author: %{type: "keyword"},
|
||||||
|
image_tag_ids: %{type: "keyword"},
|
||||||
|
anonymous: %{type: "keyword"}, # boolean
|
||||||
|
hidden_from_users: %{type: "keyword"}, # boolean
|
||||||
|
body: %{type: "text", analyzer: "snowball"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
# preload([
|
||||||
|
# :user, image: :tags
|
||||||
|
# ])
|
||||||
|
def as_json(comment) do
|
||||||
|
%{
|
||||||
|
id: comment.id,
|
||||||
|
posted_at: comment.created_at,
|
||||||
|
ip: comment.ip |> to_string,
|
||||||
|
fingerprint: comment.fingerprint,
|
||||||
|
image_id: comment.image_id,
|
||||||
|
user_id: comment.user_id,
|
||||||
|
author: if(!!comment.user and !comment.anonymous, do: comment.user.name),
|
||||||
|
image_tag_ids: comment.image.tags |> Enum.map(& &1.id),
|
||||||
|
anonymous: comment.anonymous,
|
||||||
|
hidden_from_users: comment.hidden_from_users,
|
||||||
|
body: comment.body
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
defmodule PhilomenaWeb.ActivityController do
|
defmodule PhilomenaWeb.ActivityController do
|
||||||
use PhilomenaWeb, :controller
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
alias Philomena.{Images, Images.Image, Images.Feature, Channels.Channel, Topics.Topic, Forums.Forum}
|
alias Philomena.{Images, Images.Image, Images.Feature, Comments.Comment, Channels.Channel, Topics.Topic, Forums.Forum}
|
||||||
alias Philomena.Repo
|
alias Philomena.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
@ -43,6 +43,26 @@ defmodule PhilomenaWeb.ActivityController do
|
||||||
Image |> preload([:tags])
|
Image |> preload([:tags])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
comments =
|
||||||
|
Comment.search_records(
|
||||||
|
%{
|
||||||
|
query: %{
|
||||||
|
bool: %{
|
||||||
|
must: %{
|
||||||
|
range: %{posted_at: %{gt: "now-1w"}}
|
||||||
|
},
|
||||||
|
must_not: [
|
||||||
|
%{terms: %{image_tag_ids: conn.assigns.current_filter.hidden_tag_ids}},
|
||||||
|
%{term: %{hidden_from_users: true}}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
size: 6,
|
||||||
|
sort: %{posted_at: :desc}
|
||||||
|
},
|
||||||
|
Comment |> preload([:user, :image])
|
||||||
|
)
|
||||||
|
|
||||||
watched = if !!user do
|
watched = if !!user do
|
||||||
{:ok, watched_query} = Images.Query.compile(user, "my:watched")
|
{:ok, watched_query} = Images.Query.compile(user, "my:watched")
|
||||||
|
|
||||||
|
@ -91,6 +111,7 @@ defmodule PhilomenaWeb.ActivityController do
|
||||||
conn,
|
conn,
|
||||||
"index.html",
|
"index.html",
|
||||||
images: images,
|
images: images,
|
||||||
|
comments: comments,
|
||||||
top_scoring: top_scoring,
|
top_scoring: top_scoring,
|
||||||
watched: watched,
|
watched: watched,
|
||||||
featured_image: featured_image,
|
featured_image: featured_image,
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
.block__content.flex.alternating-color
|
||||||
|
.flex__shrink.spacing-right
|
||||||
|
= render PhilomenaWeb.ImageView, "_image_container.html", image: @comment.image, size: :thumb_tiny
|
||||||
|
.flex__grow
|
||||||
|
a href="/#{@comment.image.id}#comment_#{@comment.id}"
|
||||||
|
| #
|
||||||
|
=> @comment.image.id
|
||||||
|
' by
|
||||||
|
span.hyphenate-breaks
|
||||||
|
= render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment
|
||||||
|
br
|
||||||
|
= pretty_time(@comment.created_at)
|
|
@ -12,6 +12,8 @@
|
||||||
| Issues? Want to chat?
|
| Issues? Want to chat?
|
||||||
a< href="/pages/contact" Contact us!
|
a< href="/pages/contact" Contact us!
|
||||||
.block.hide-mobile
|
.block.hide-mobile
|
||||||
|
a.block__header--single-item.center href="/search?q=first_seen_at.gt:3 days ago&sf=score&sd=desc"
|
||||||
|
' Trending Images
|
||||||
.block__content.flex.flex--centered.flex--wrap.image-flex-grid
|
.block__content.flex.flex--centered.flex--wrap.image-flex-grid
|
||||||
= for image <- @top_scoring do
|
= for image <- @top_scoring do
|
||||||
= render PhilomenaWeb.ImageView, "_image_box.html", image: image, size: :thumb_small
|
= render PhilomenaWeb.ImageView, "_image_box.html", image: image, size: :thumb_small
|
||||||
|
@ -30,8 +32,10 @@
|
||||||
.block.hide-mobile
|
.block.hide-mobile
|
||||||
a.block__header--single-item.center href="/lists/recent_comments"
|
a.block__header--single-item.center href="/lists/recent_comments"
|
||||||
' Recent Comments
|
' Recent Comments
|
||||||
/= render partial: 'comments/comment_activitypage', collection: @comments
|
= for comment <- @comments do
|
||||||
/a.block__header--single-item.center href=search_path(q: 'first_seen_at.gt:3 days ago', sf: 'comments', sd: 'desc') Most Commented-on Images
|
= render PhilomenaWeb.ActivityView, "_comment_strip.html", comment: comment
|
||||||
|
a.block__header--single-item.center href="/search?q=first_seen_at.gt:3 days ago&sf=comments&sd=desc"
|
||||||
|
' Most Commented-on Images
|
||||||
|
|
||||||
.column-layout__main
|
.column-layout__main
|
||||||
= render PhilomenaWeb.ImageView, "index.html", images: @images, size: :thumb
|
= render PhilomenaWeb.ImageView, "index.html", images: @images, size: :thumb
|
||||||
|
|
Loading…
Reference in a new issue