From 74cece57968f067edd7cd5b22c4c78d028b5df95 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 21 Apr 2022 10:21:05 +0200 Subject: [PATCH 1/5] Preload user.activity_settings to as it's being used after Signed-off-by: Thomas Citharel --- lib/service/workers/send_activity_recap_worker.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/service/workers/send_activity_recap_worker.ex b/lib/service/workers/send_activity_recap_worker.ex index 8b87cbb95..6d0d163f4 100644 --- a/lib/service/workers/send_activity_recap_worker.ex +++ b/lib/service/workers/send_activity_recap_worker.ex @@ -23,7 +23,7 @@ defmodule Mobilizon.Service.Workers.SendActivityRecapWorker do Repo.transaction(fn -> Users.stream_users_for_recap() |> Enum.to_list() - |> Repo.preload([:settings]) + |> Repo.preload([:settings, :activity_settings]) |> Enum.filter(&filter_elegible_users/1) |> Enum.map(fn %User{} = user -> %{ From 0c49ddc65b5e64cba1000eed0c41b02df0231253 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 21 Apr 2022 10:33:42 +0200 Subject: [PATCH 2/5] Add "Accept-Language" header to sentry request metadata Signed-off-by: Thomas Citharel --- lib/web/request_context.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/web/request_context.ex b/lib/web/request_context.ex index b41acb46e..68140cde4 100644 --- a/lib/web/request_context.ex +++ b/lib/web/request_context.ex @@ -11,7 +11,8 @@ defmodule Mobilizon.Web.RequestContext do method: conn.method, headers: %{ "User-Agent": conn |> Plug.Conn.get_req_header("user-agent") |> List.first(), - Referer: conn |> Plug.Conn.get_req_header("referer") |> List.first() + Referer: conn |> Plug.Conn.get_req_header("referer") |> List.first(), + "Accept-Language": conn |> Plug.Conn.get_req_header("accept-language") |> List.first() }, query_string: conn.query_string, env: %{ From dc75a9beb347cd3ee23930008ec63f141fbdf0df Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 21 Apr 2022 11:43:24 +0200 Subject: [PATCH 3/5] [Front-end] Address model refactoring Signed-off-by: Thomas Citharel --- js/src/types/address.model.ts | 151 ++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 69 deletions(-) diff --git a/js/src/types/address.model.ts b/js/src/types/address.model.ts index bfac5696e..e75d18f2f 100644 --- a/js/src/types/address.model.ts +++ b/js/src/types/address.model.ts @@ -65,80 +65,93 @@ export class Address implements IAddress { } get poiInfos(): IPoiInfo { - /* generate name corresponding to poi type */ - let name = ""; - let alternativeName = ""; - let poiIcon: IPOIIcon = poiIcons.default; - // Google Maps doesn't have a type - if (this.type == null && this.description === this.street) { - this.type = "house"; - } - switch (this.type) { - case "house": - name = this.description; - alternativeName = [this.postalCode, this.locality, this.country] - .filter((zone) => zone) - .join(", "); - poiIcon = poiIcons.defaultAddress; - break; - case "street": - case "secondary": - name = this.description; - alternativeName = [this.postalCode, this.locality, this.country] - .filter((zone) => zone) - .join(", "); - poiIcon = poiIcons.defaultStreet; - break; - case "zone": - case "city": - case "administrative": - name = this.postalCode - ? `${this.description} (${this.postalCode})` - : this.description; - alternativeName = [this.region, this.country] - .filter((zone) => zone) - .join(", "); - poiIcon = poiIcons.defaultAdministrative; - break; - default: - // POI - name = this.description; - alternativeName = ""; - if (this.street && this.street.trim()) { - alternativeName = `${this.street}`; - if (this.locality) { - alternativeName += ` (${this.locality})`; - } - } else if (this.locality && this.locality.trim()) { - alternativeName = `${this.locality}, ${this.region}, ${this.country}`; - } else if (this.region && this.region.trim()) { - alternativeName = `${this.region}, ${this.country}`; - } else if (this.country && this.country.trim()) { - alternativeName = this.country; - } - poiIcon = this.iconForPOI; - break; - } - return { name, alternativeName, poiIcon }; + return addressToPoiInfos(this); } get fullName(): string { - const { name, alternativeName } = this.poiInfos; - if (name && alternativeName) { - return `${name}, ${alternativeName}`; - } - if (name) { - return name; - } - return ""; + return addressFullName(this); } get iconForPOI(): IPOIIcon { - if (this.type == null) { - return poiIcons.default; - } - const type = this.type.split(":").pop() || ""; - if (poiIcons[type]) return poiIcons[type]; - return poiIcons.default; + return iconForAddress(this); } } + +export function addressToPoiInfos(address: IAddress): IPoiInfo { + /* generate name corresponding to poi type */ + let name = ""; + let alternativeName = ""; + let poiIcon: IPOIIcon = poiIcons.default; + let addressType = address.type; + // Google Maps doesn't have a type + if (address.type == null && address.description === address.street) { + addressType = "house"; + } + switch (addressType) { + case "house": + name = address.description; + alternativeName = [address.postalCode, address.locality, address.country] + .filter((zone) => zone) + .join(", "); + poiIcon = poiIcons.defaultAddress; + break; + case "street": + case "secondary": + name = address.description; + alternativeName = [address.postalCode, address.locality, address.country] + .filter((zone) => zone) + .join(", "); + poiIcon = poiIcons.defaultStreet; + break; + case "zone": + case "city": + case "administrative": + name = address.postalCode + ? `${address.description} (${address.postalCode})` + : address.description; + alternativeName = [address.region, address.country] + .filter((zone) => zone) + .join(", "); + poiIcon = poiIcons.defaultAdministrative; + break; + default: + // POI + name = address.description; + alternativeName = ""; + if (address.street && address.street.trim()) { + alternativeName = `${address.street}`; + if (address.locality) { + alternativeName += ` (${address.locality})`; + } + } else if (address.locality && address.locality.trim()) { + alternativeName = `${address.locality}, ${address.region}, ${address.country}`; + } else if (address.region && address.region.trim()) { + alternativeName = `${address.region}, ${address.country}`; + } else if (address.country && address.country.trim()) { + alternativeName = address.country; + } + poiIcon = iconForAddress(address); + break; + } + return { name, alternativeName, poiIcon }; +} + +export function iconForAddress(address: IAddress): IPOIIcon { + if (address.type == null) { + return poiIcons.default; + } + const type = address.type.split(":").pop() || ""; + if (poiIcons[type]) return poiIcons[type]; + return poiIcons.default; +} + +export function addressFullName(address: IAddress): string { + const { name, alternativeName } = addressToPoiInfos(address); + if (name && alternativeName) { + return `${name}, ${alternativeName}`; + } + if (name) { + return name; + } + return ""; +} From e36f8f53ab63ab3fee0f43f668e95bed81f1e591 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 21 Apr 2022 11:53:42 +0200 Subject: [PATCH 4/5] Hide address blocks when address has no real data Closes #1085 Signed-off-by: Thomas Citharel --- js/src/components/Group/GroupCard.vue | 5 ++++- js/src/views/Group/Group.vue | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/js/src/components/Group/GroupCard.vue b/js/src/components/Group/GroupCard.vue index 2ac23002d..f2a711b4a 100644 --- a/js/src/components/Group/GroupCard.vue +++ b/js/src/components/Group/GroupCard.vue @@ -39,7 +39,7 @@

@@ -65,6 +65,7 @@ import { displayName, IGroup, usernameWithDomain } from "@/types/actor"; import LazyImageWrapper from "@/components/Image/LazyImageWrapper.vue"; import RouteName from "../../router/name"; import InlineAddress from "@/components/Address/InlineAddress.vue"; +import { addressFullName } from "@/types/address.model"; @Component({ components: { @@ -80,6 +81,8 @@ export default class GroupCard extends Vue { usernameWithDomain = usernameWithDomain; displayName = displayName; + + addressFullName = addressFullName; }