Merge branch 'hashtag-fixes' into 'main'

Exclude tags with more than 40 characters from being extracted.

Closes #939 et #562

See merge request framasoft/mobilizon!1214
This commit is contained in:
Thomas Citharel 2022-04-21 16:07:54 +00:00
commit e26364f973
4 changed files with 90 additions and 8 deletions

View File

@ -1,18 +1,22 @@
<template> <template>
<label for="navSearchField"> <b-field label-for="navSearchField" class="-mt-2">
<span class="visually-hidden">{{ defaultPlaceHolder }}</span>
<b-input <b-input
custom-class="searchField" :placeholder="defaultPlaceHolder"
type="search"
id="navSearchField" id="navSearchField"
icon="magnify" icon="magnify"
type="search" icon-clickable
rounded rounded
custom-class="searchField"
dir="auto" dir="auto"
:placeholder="defaultPlaceHolder"
v-model="search" v-model="search"
@keyup.native.enter="enter" @keyup.native.enter="enter"
/> >
</label> </b-input>
<template #label>
<span class="sr-only">{{ defaultPlaceHolder }}</span>
</template>
</b-field>
</template> </template>
<script lang="ts"> <script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator"; import { Component, Prop, Vue } from "vue-property-decorator";
@ -47,6 +51,7 @@ label span.visually-hidden {
input.searchField { input.searchField {
box-shadow: none; box-shadow: none;
border-color: #b5b5b5; border-color: #b5b5b5;
border-radius: 9999px !important;
&::placeholder { &::placeholder {
color: gray; color: gray;

View File

@ -6,6 +6,14 @@ module.exports = {
// remove the prefetch plugin // remove the prefetch plugin
config.plugins.delete("prefetch"); config.plugins.delete("prefetch");
}, },
configureWebpack: (config) => {
const miniCssExtractPlugin = config.plugins.find(
(plugin) => plugin.constructor.name === "MiniCssExtractPlugin"
);
if (miniCssExtractPlugin) {
miniCssExtractPlugin.options.linkType = false;
}
},
pwa: { pwa: {
themeColor: "#ffd599", //not required for service worker, but place theme color here if manifest.json doesn't change the color themeColor: "#ffd599", //not required for service worker, but place theme color here if manifest.json doesn't change the color
workboxPluginMode: "InjectManifest", workboxPluginMode: "InjectManifest",

View File

@ -267,12 +267,22 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
Map.merge(args, %{ Map.merge(args, %{
description: description, description: description,
mentions: mentions, mentions: mentions,
tags: tags # Exclude tags with length > 40
tags: Enum.filter(tags, &exclude_too_long_tags/1)
}) })
else else
args args
end end
# Make sure we don't have duplicate (with different casing) tags
args =
Map.update(
args,
:tags,
[],
&Enum.uniq_by(&1, fn tag -> tag |> tag_to_string() |> String.downcase() end)
)
# Check that we can only allow anonymous participation if our instance allows it # Check that we can only allow anonymous participation if our instance allows it
{_, options} = {_, options} =
Map.get_and_update( Map.get_and_update(
@ -292,4 +302,16 @@ defmodule Mobilizon.Federation.ActivityPub.Types.Events do
|> Map.update(:tags, [], &ConverterUtils.fetch_tags/1) |> Map.update(:tags, [], &ConverterUtils.fetch_tags/1)
|> Map.update(:contacts, [], &ConverterUtils.fetch_actors/1) |> Map.update(:contacts, [], &ConverterUtils.fetch_actors/1)
end end
@spec exclude_too_long_tags(%{title: String.t()} | String.t()) :: boolean()
defp exclude_too_long_tags(tag) do
tag
|> tag_to_string()
|> String.length()
|> Kernel.<(40)
end
@spec tag_to_string(%{title: String.t()} | String.t()) :: String.t()
defp tag_to_string(%{title: tag}), do: tag
defp tag_to_string(tag), do: tag
end end

View File

@ -808,6 +808,53 @@ defmodule Mobilizon.Web.Resolvers.EventTest do
end end
end end
describe "create_event/3 with special tags" do
test "same tags with different casing", %{conn: conn, actor: actor, user: user} do
begins_on = DateTime.utc_now()
res =
conn
|> auth_conn(user)
|> AbsintheHelpers.graphql_query(
query: @create_event_mutation,
variables: %{
title: "come to my event",
description: "it will be fine",
begins_on: "#{DateTime.add(begins_on, 3600 * 24)}",
organizer_actor_id: "#{actor.id}",
tags: ["Hello", "hello"]
}
)
assert res["error"] == nil
assert res["data"]["createEvent"]["tags"] == [%{"slug" => "hello", "title" => "Hello"}]
end
test "too long tags", %{conn: conn, actor: actor, user: user} do
begins_on = DateTime.utc_now()
res =
conn
|> auth_conn(user)
|> AbsintheHelpers.graphql_query(
query: @create_event_mutation,
variables: %{
title: "come to my event",
description:
"<p>it will be fine, what do you think? <br>#Detected <br>#ThisIsAVeryLongHashTagThatWillNotBeDetectedByTheParser</p>",
begins_on: "#{DateTime.add(begins_on, 3600 * 24)}",
organizer_actor_id: "#{actor.id}"
}
)
assert res["error"] == nil
assert res["data"]["createEvent"]["tags"] == [
%{"slug" => "detected", "title" => "detected"}
]
end
end
@update_event_mutation """ @update_event_mutation """
mutation updateEvent( mutation updateEvent(
$eventId: ID! $eventId: ID!