From e91d5a23f4173fa087cf90210b9329294f970b52 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Thu, 24 Oct 2019 23:28:59 +0300 Subject: [PATCH 1/4] pleroma_ctl: fix crashes due to different shift(1) behavior on dash --- rel/files/bin/pleroma_ctl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rel/files/bin/pleroma_ctl b/rel/files/bin/pleroma_ctl index 9fc5b0bad..87c486514 100755 --- a/rel/files/bin/pleroma_ctl +++ b/rel/files/bin/pleroma_ctl @@ -140,11 +140,15 @@ else FULL_ARGS="$*" ACTION="$1" - shift - echo "$1" | grep "^-" >/dev/null + if [ $# -gt 0 ]; then + shift + fi + echo "$1" | grep "^-" >/dev/null if [ $? -eq 1 ]; then SUBACTION="$1" - shift + if [ $# -gt 0 ]; then + shift + fi fi if [ "$ACTION" = "update" ]; then From ca1871fbb40e78cc0b56efd4b3ff56474c222d7d Mon Sep 17 00:00:00 2001 From: rinpatch Date: Mon, 21 Oct 2019 12:38:35 +0300 Subject: [PATCH 2/4] Do not include notifications from blocked users when with_muted is set This is not what with_muted is for per documentation and it was agreed on irc that this behavior doesn't make sense. --- lib/pleroma/notification.ex | 72 ++++++++++++++++++++----------------- test/notification_test.exs | 12 +++---- 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index d94ae5971..ed39958a8 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -34,41 +34,49 @@ defmodule Pleroma.Notification do end def for_user_query(user, opts \\ []) do - query = - Notification - |> where(user_id: ^user.id) - |> where( - [n, a], + Notification + |> where(user_id: ^user.id) + |> where( + [n, a], + fragment( + "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')", + a.actor + ) + ) + |> join(:inner, [n], activity in assoc(n, :activity)) + |> join(:left, [n, a], object in Object, + on: fragment( - "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')", - a.actor + "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)", + object.data, + a.data ) - ) - |> join(:inner, [n], activity in assoc(n, :activity)) - |> join(:left, [n, a], object in Object, - on: - fragment( - "(?->>'id') = COALESCE((? -> 'object'::text) ->> 'id'::text)", - object.data, - a.data - ) - ) - |> preload([n, a, o], activity: {a, object: o}) + ) + |> preload([n, a, o], activity: {a, object: o}) + |> exclude_muted(user, opts) + |> exclude_blocked(user) + end - if opts[:with_muted] do - query - else - where(query, [n, a], a.actor not in ^user.info.muted_notifications) - |> where([n, a], a.actor not in ^user.info.blocks) - |> where( - [n, a], - fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.info.domain_blocks - ) - |> join(:left, [n, a], tm in Pleroma.ThreadMute, - on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data) - ) - |> where([n, a, o, tm], is_nil(tm.user_id)) - end + defp exclude_blocked(query, user) do + query + |> where([n, a], a.actor not in ^user.info.blocks) + |> where( + [n, a], + fragment("substring(? from '.*://([^/]*)')", a.actor) not in ^user.info.domain_blocks + ) + end + + defp exclude_muted(query, _, %{with_muted: true}) do + query + end + + defp exclude_muted(query, user, _opts) do + query + |> where([n, a], a.actor not in ^user.info.muted_notifications) + |> join(:left, [n, a], tm in Pleroma.ThreadMute, + on: tm.user_id == ^user.id and tm.context == fragment("?->>'context'", a.data) + ) + |> where([n, a, o, tm], is_nil(tm.user_id)) end def for_user(user, opts \\ %{}) do diff --git a/test/notification_test.exs b/test/notification_test.exs index d68d4485f..2480d9b20 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -680,7 +680,7 @@ defmodule Pleroma.NotificationTest do assert Notification.for_user(user) == [] end - test "it returns notifications for muted user with notifications and with_muted parameter" do + test "it returns notifications from a muted user when with_muted is set" do user = insert(:user) muted = insert(:user) {:ok, user} = User.mute(user, muted) @@ -690,27 +690,27 @@ defmodule Pleroma.NotificationTest do assert length(Notification.for_user(user, %{with_muted: true})) == 1 end - test "it returns notifications for blocked user and with_muted parameter" do + test "it doesn't return notifications from a blocked user when with_muted is set" do user = insert(:user) blocked = insert(:user) {:ok, user} = User.block(user, blocked) {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"}) - assert length(Notification.for_user(user, %{with_muted: true})) == 1 + assert length(Notification.for_user(user, %{with_muted: true})) == 0 end - test "it returns notificatitons for blocked domain and with_muted parameter" do + test "it doesn't return notifications from a domain-blocked user when with_muted is set" do user = insert(:user) blocked = insert(:user, ap_id: "http://some-domain.com") {:ok, user} = User.block_domain(user, "some-domain.com") {:ok, _activity} = CommonAPI.post(blocked, %{"status" => "hey @#{user.nickname}"}) - assert length(Notification.for_user(user, %{with_muted: true})) == 1 + assert length(Notification.for_user(user, %{with_muted: true})) == 0 end - test "it returns notifications for muted thread with_muted parameter" do + test "it returns notifications from muted threads when with_muted is set" do user = insert(:user) another_user = insert(:user) From 3627ffc8b7da8b65a9cfcbef1f79f0ce4a1cb471 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 25 Oct 2019 18:46:28 +0300 Subject: [PATCH 3/4] Changelog: Add 1.1.3 entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index afbe7f91b..8e078d422 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [1.1.3] - 2019-10-25 +### Fixed +- Blocked users showing up in notifications collapsed as if they were muted +- `pleroma_ctl` not working on Debian's default shell + ## [1.1.2] - 2019-10-18 ### Fixed - `pleroma_ctl` trying to connect to a running instance when generating the config, which of course doesn't exist. From 948d0d3b0b2a2eb72a0db41abebd9ad976dfdbf7 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Fri, 25 Oct 2019 18:49:21 +0300 Subject: [PATCH 4/4] mixfile: bump version to 1.1.3 --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index fb72a22ed..fde6216d2 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Pleroma.Mixfile do def project do [ app: :pleroma, - version: version("1.1.2"), + version: version("1.1.3"), elixir: "~> 1.7", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix, :gettext] ++ Mix.compilers(),