Merge branch 'bugs' into 'master'

Various bugs

See merge request framasoft/mobilizon!1097
This commit is contained in:
Thomas Citharel 2021-11-06 10:44:23 +00:00
commit 1cc776622a
35 changed files with 545 additions and 355 deletions

View File

@ -210,10 +210,11 @@ pages:
docker buildx build
--push
--platform linux/amd64,linux/arm64,linux/arm
-t framasoft/mobilizon:multiarch
-t $DOCKER_IMAGE_NAME
-f docker/production/Dockerfile .
tags:
- "privileged"
timeout: 3 hours
build-docker-master:
<<: *docker

View File

@ -1,5 +1,6 @@
<template>
<div
class="ellipsis"
:title="
isDescriptionDifferentFromLocality
? `${physicalAddress.description}, ${physicalAddress.locality}`
@ -22,7 +23,7 @@ import { PropType } from "vue";
import { Prop, Vue, Component } from "vue-property-decorator";
@Component
export default class EventAddress extends Vue {
export default class InlineAddress extends Vue {
@Prop({ required: true, type: Object as PropType<IAddress> })
physicalAddress!: IAddress;
@ -34,3 +35,11 @@ export default class EventAddress extends Vue {
}
}
</script>
<style lang="scss" scoped>
.ellipsis {
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
overflow: hidden;
}
</style>

View File

@ -1,7 +1,7 @@
<template>
<router-link
class="card"
:to="{ name: 'Event', params: { uuid: event.uuid } }"
:to="{ name: RouteName.EVENT, params: { uuid: event.uuid } }"
>
<div class="card-image">
<figure class="image is-16by9">
@ -56,7 +56,7 @@
{{ organizerDisplayName(event) }}
</span>
</div>
<event-address
<inline-address
v-if="event.physicalAddress"
class="event-subtitle"
:physical-address="event.physicalAddress"
@ -87,13 +87,13 @@ import LazyImageWrapper from "@/components/Image/LazyImageWrapper.vue";
import { Actor, Person } from "@/types/actor";
import { EventStatus, ParticipantRole } from "@/types/enums";
import RouteName from "../../router/name";
import EventAddress from "@/components/Event/EventAddress.vue";
import InlineAddress from "@/components/Address/InlineAddress.vue";
@Component({
components: {
DateCalendarIcon,
LazyImageWrapper,
EventAddress,
InlineAddress,
},
})
export default class EventCard extends Vue {

View File

@ -26,7 +26,7 @@
>
{{ event.title }}
</h3>
<event-address
<inline-address
v-if="event.physicalAddress"
class="event-subtitle"
:physical-address="event.physicalAddress"
@ -107,13 +107,13 @@ import DateCalendarIcon from "@/components/Event/DateCalendarIcon.vue";
import { ParticipantRole } from "@/types/enums";
import RouteName from "../../router/name";
import LazyImageWrapper from "@/components/Image/LazyImageWrapper.vue";
import EventAddress from "@/components/Event/EventAddress.vue";
import InlineAddress from "@/components/Address/InlineAddress.vue";
@Component({
components: {
DateCalendarIcon,
LazyImageWrapper,
EventAddress,
InlineAddress,
},
})
export default class EventMinimalistCard extends Vue {

View File

@ -54,7 +54,7 @@
<h3 class="title">{{ participation.event.title }}</h3>
</router-link>
</div>
<event-address
<inline-address
v-if="participation.event.physicalAddress"
class="event-subtitle"
:physical-address="participation.event.physicalAddress"
@ -270,7 +270,7 @@ import RouteName from "../../router/name";
import { changeIdentity } from "../../utils/auth";
import PopoverActorCard from "../Account/PopoverActorCard.vue";
import LazyImageWrapper from "@/components/Image/LazyImageWrapper.vue";
import EventAddress from "@/components/Event/EventAddress.vue";
import InlineAddress from "@/components/Address/InlineAddress.vue";
import { PropType } from "vue";
const defaultOptions: IEventCardOptions = {
@ -286,7 +286,7 @@ const defaultOptions: IEventCardOptions = {
DateCalendarIcon,
PopoverActorCard,
LazyImageWrapper,
EventAddress,
InlineAddress,
},
apollo: {
currentActor: {

View File

@ -42,7 +42,7 @@
><br />
<small>{{ option.poiInfos.alternativeName }}</small>
</template>
<template slot="empty">
<template #empty>
<span v-if="isFetching">{{ $t("Searching") }}</span>
<div v-else-if="queryText.length >= 3" class="is-enabled">
<span>{{
@ -83,7 +83,7 @@
</div>
<div
class="map column"
v-if="selected && selected.geom && selected.poiInfos"
v-if="!hideMap && selected && selected.geom && selected.poiInfos"
>
<map-leaflet
:coords="selected.geom"
@ -96,47 +96,6 @@
:readOnly="false"
/>
</div>
<!-- <b-modal v-if="selected" :active.sync="addressModalActive" :width="640" has-modal-card scroll="keep">-->
<!-- <div class="modal-card" style="width: auto">-->
<!-- <header class="modal-card-head">-->
<!-- <p class="modal-card-title">{{ $t('Add an address') }}</p>-->
<!-- </header>-->
<!-- <section class="modal-card-body">-->
<!-- <form>-->
<!-- <b-field :label="$t('Name')">-->
<!-- <b-input aria-required="true" required v-model="selected.description" />-->
<!-- </b-field>-->
<!-- <b-field :label="$t('Street')">-->
<!-- <b-input v-model="selected.street" />-->
<!-- </b-field>-->
<!-- <b-field grouped>-->
<!-- <b-field :label="$t('Postal Code')">-->
<!-- <b-input v-model="selected.postalCode" />-->
<!-- </b-field>-->
<!-- <b-field :label="$t('Locality')">-->
<!-- <b-input v-model="selected.locality" />-->
<!-- </b-field>-->
<!-- </b-field>-->
<!-- <b-field grouped>-->
<!-- <b-field :label="$t('Region')">-->
<!-- <b-input v-model="selected.region" />-->
<!-- </b-field>-->
<!-- <b-field :label="$t('Country')">-->
<!-- <b-input v-model="selected.country" />-->
<!-- </b-field>-->
<!-- </b-field>-->
<!-- </form>-->
<!-- </section>-->
<!-- <footer class="modal-card-foot">-->
<!-- <button class="button" type="button" @click="resetPopup()">{{ $t('Clear') }}</button>-->
<!-- </footer>-->
<!-- </div>-->
<!-- </b-modal>-->
</div>
</template>
<script lang="ts">
@ -158,6 +117,7 @@ export default class FullAddressAutoComplete extends Mixins(
@Prop({ required: false, default: "" }) label!: string;
@Prop({ required: false }) userTimezone!: string;
@Prop({ required: false, default: false, type: Boolean }) disabled!: boolean;
@Prop({ required: false, default: false, type: Boolean }) hideMap!: boolean;
addressModalActive = false;
@ -175,10 +135,6 @@ export default class FullAddressAutoComplete extends Mixins(
updateEditing(): void {
if (!(this.value && this.value.id)) return;
this.selected = this.value;
const address = new Address(this.selected);
if (address.poiInfos) {
this.queryText = `${address.poiInfos.name} ${address.poiInfos.alternativeName}`;
}
}
updateSelected(option: IAddress): void {
@ -212,20 +168,6 @@ export default class FullAddressAutoComplete extends Mixins(
get canShowLocateMeButton(): boolean {
return window.isSecureContext;
}
@Watch("queryText")
resetAddressOnEmptyField(queryText: string): void {
if (queryText === "" && this.selected?.id) {
console.log("doing reset");
this.resetAddress();
}
}
resetAddress(): void {
this.$emit("input", null);
this.queryText = "";
this.selected = new Address();
}
}
</script>
<style lang="scss">

View File

@ -29,14 +29,7 @@ export default class MultiCard extends Vue {
grid-auto-rows: 1fr;
grid-column-gap: 30px;
grid-row-gap: 30px;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
// @media (min-width: 400px) {
// grid-template-columns: repeat(2, 1fr);
// }
// @media (min-width: 800px) {
// grid-template-columns: repeat(4, 1fr);
// }
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
.event-card {
height: 100%;
display: flex;

View File

@ -1,7 +1,21 @@
<template>
<div class="card">
<router-link
:to="{
name: RouteName.GROUP,
params: { preferredUsername: usernameWithDomain(group) },
}"
class="card"
>
<div class="card-image">
<figure class="image is-16by9">
<lazy-image-wrapper
:picture="group.banner"
style="height: 100%; position: absolute; top: 0; left: 0; width: 100%"
/>
</figure>
</div>
<div class="card-content">
<div class="media">
<div class="media mb-3">
<div class="media-left">
<figure class="image is-48x48" v-if="group.avatar">
<img class="is-rounded" :src="group.avatar.url" alt="" />
@ -9,40 +23,108 @@
<b-icon v-else size="is-large" icon="account-group" />
</div>
<div class="media-content">
<router-link
:to="{
name: RouteName.GROUP,
params: { preferredUsername: usernameWithDomain(group) },
}"
>
<h3>{{ group.name }}</h3>
<p class="is-6 has-text-grey">
<span v-if="group.domain">{{
`@${group.preferredUsername}@${group.domain}`
}}</span>
<span v-else>{{ `@${group.preferredUsername}` }}</span>
</p>
</router-link>
<h3 class="is-size-5 group-title">{{ displayName(group) }}</h3>
<span class="is-6 has-text-grey-dark">
{{ `@${usernameWithDomain(group)}` }}
</span>
</div>
</div>
<div class="content">
<p>{{ group.summary }}</p>
<div class="content" v-html="group.summary" />
<div class="card-custom-footer">
<inline-address
class="has-text-grey-dark"
v-if="group.physicalAddress"
:physicalAddress="group.physicalAddress"
/>
<p class="has-text-grey-dark">
{{
$tc(
"{count} members or followers",
group.members.total + group.followers.total,
{
count: group.members.total + group.followers.total,
}
)
}}
</p>
</div>
</div>
</div>
</router-link>
</template>
<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";
import { IGroup, usernameWithDomain } from "@/types/actor";
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";
@Component
@Component({
components: {
LazyImageWrapper,
InlineAddress,
},
})
export default class GroupCard extends Vue {
@Prop({ required: true }) group!: IGroup;
RouteName = RouteName;
usernameWithDomain = usernameWithDomain;
displayName = displayName;
}
</script>
<style lang="scss" scoped>
.card {
.card-content {
padding: 0.75rem;
display: flex;
flex-direction: column;
height: 100%;
.content {
flex: 1;
}
::v-deep .content {
& > *:first-child {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
margin-bottom: 0;
* {
font-weight: normal;
text-transform: none;
font-style: normal;
text-decoration: none;
}
}
& > *:not(:first-child) {
display: none;
}
}
.media-left {
margin-right: inherit;
margin-inline-end: 0.5rem;
}
.media-content {
overflow: hidden;
text-overflow: ellipsis;
.group-title {
line-height: 1.75rem;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
font-weight: bold;
}
}
}
}
</style>

View File

@ -0,0 +1,39 @@
<template>
<div class="multi-card-group">
<group-card
class="group-card"
v-for="group in groups"
:group="group"
:key="group.id"
/>
</div>
</template>
<script lang="ts">
import { IGroup } from "@/types/actor";
import { PropType } from "vue";
import { Component, Prop, Vue } from "vue-property-decorator";
import GroupCard from "./GroupCard.vue";
@Component({
components: {
GroupCard,
},
})
export default class MultiGroupCard extends Vue {
@Prop({ type: Array as PropType<IGroup[]>, required: true })
groups!: IGroup[];
}
</script>
<style lang="scss" scoped>
.multi-card-group {
display: grid;
grid-auto-rows: 1fr;
grid-column-gap: 30px;
grid-row-gap: 30px;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
.group-card {
height: 100%;
display: flex;
flex-direction: column;
}
}
</style>

View File

@ -163,7 +163,7 @@ export default class Map extends Vue {
</script>
<style lang="scss" scoped>
div.map-container {
height: 100%;
height: 80vh;
width: 100%;
.leaflet-map {

View File

@ -9,7 +9,7 @@
style="height: 120px"
/>
<div class="title-info-wrapper has-text-grey-dark">
<p class="post-minimalist-title">{{ post.title }}</p>
<h3 class="post-minimalist-title">{{ post.title }}</h3>
<p class="post-publication-date">
<b-icon icon="clock" />
<span class="has-text-grey-dark" v-if="isBeforeLastWeek">{{

View File

@ -466,44 +466,6 @@ export const FETCH_GROUP_EVENTS = gql`
${ADDRESS_FRAGMENT}
`;
export const CLOSE_EVENTS = gql`
query CloseEvents($location: String, $radius: Float) {
searchEvents(location: $location, radius: $radius, page: 1, limit: 10) {
total
elements {
id
title
uuid
beginsOn
picture {
id
url
}
tags {
...TagFragment
}
options {
...EventOptions
}
physicalAddress {
...AdressFragment
}
attributedTo {
...ActorFragment
}
organizerActor {
...ActorFragment
}
__typename
}
}
}
${ADDRESS_FRAGMENT}
${TAG_FRAGMENT}
${EVENT_OPTIONS_FRAGMENT}
${ACTOR_FRAGMENT}
`;
export const EXPORT_EVENT_PARTICIPATIONS = gql`
mutation ExportEventParticipants(
$eventId: ID!

View File

@ -408,3 +408,19 @@ export const GROUP_TIMELINE = gql`
}
${ACTOR_FRAGMENT}
`;
export const CLOSE_GROUPS = gql`
query CloseGroups($location: String, $radius: Float) {
searchGroups(location: $location, radius: $radius, page: 1, limit: 10) {
total
elements {
...ActorFragment
physicalAddress {
...AdressFragment
}
}
}
}
${ACTOR_FRAGMENT}
${ADDRESS_FRAGMENT}
`;

View File

@ -105,3 +105,51 @@ export const HOME_USER_QUERIES = gql`
${EVENT_OPTIONS_FRAGMENT}
${ACTOR_FRAGMENT}
`;
export const CLOSE_CONTENT = gql`
query CloseContent(
$location: String!
$radius: Float
$page: Int
$limit: Int
) {
searchEvents(
location: $location
radius: $radius
page: $page
limit: $limit
) {
total
elements {
id
title
uuid
beginsOn
picture {
id
url
}
tags {
...TagFragment
}
options {
...EventOptions
}
physicalAddress {
...AdressFragment
}
attributedTo {
...ActorFragment
}
organizerActor {
...ActorFragment
}
__typename
}
}
}
${ADDRESS_FRAGMENT}
${TAG_FRAGMENT}
${EVENT_OPTIONS_FRAGMENT}
${ACTOR_FRAGMENT}
`;

View File

@ -1,8 +1,10 @@
import gql from "graphql-tag";
import { ACTOR_FRAGMENT } from "./actor";
import { ADDRESS_FRAGMENT } from "./address";
import { TAG_FRAGMENT } from "./tags";
export const SEARCH_EVENTS = gql`
query SearchEvents(
export const SEARCH_EVENTS_AND_GROUPS = gql`
query SearchEventsAndGroups(
$location: String
$radius: Float
$tags: String
@ -33,23 +35,20 @@ export const SEARCH_EVENTS = gql`
url
}
tags {
slug
title
...TagFragment
}
physicalAddress {
...AdressFragment
}
organizerActor {
...ActorFragment
}
attributedTo {
...ActorFragment
}
__typename
}
}
}
`;
export const SEARCH_GROUPS = gql`
query SearchGroups(
$term: String
$location: String
$radius: Float
$page: Int
$limit: Int
) {
searchGroups(
term: $term
location: $location
@ -60,9 +59,24 @@ export const SEARCH_GROUPS = gql`
total
elements {
...ActorFragment
banner {
id
url
}
members(roles: "member,moderator,administrator,creator") {
total
}
followers(approved: true) {
total
}
physicalAddress {
...AdressFragment
}
}
}
}
${TAG_FRAGMENT}
${ADDRESS_FRAGMENT}
${ACTOR_FRAGMENT}
`;

View File

@ -1226,5 +1226,9 @@
"Post {eventTitle} reported": "Post {eventTitle} reported",
"You have attended {count} events in the past.": "You have not attended any events in the past.|You have attended one event in the past.|You have attended {count} events in the past.",
"Showing events starting on": "Showing events starting on",
"Showing events before": "Showing events before"
"Showing events before": "Showing events before",
"Clear date filter field": "Clear date filter field",
"{count} members or followers": "No members or followers|One member or follower|{count} members or followers",
"This profile is from another instance, the informations shown here may be incomplete.": "This profile is from another instance, the informations shown here may be incomplete.",
"View full profile": "View full profile"
}

View File

@ -1330,5 +1330,9 @@
"Post {eventTitle} reported": "Billet {eventTitle} signalé",
"You have attended {count} events in the past.": "Vous n'avez participé à aucun événement par le passé.|Vous avez participé à un événement par le passé.|Vous avez participé à {count} événements par le passé.",
"Showing events starting on": "Afficher les événements à partir de",
"Showing events before": "Afficher les événements avant"
"Showing events before": "Afficher les événements avant",
"Clear date filter field": "Vider le champ de filtre de la date",
"{count} members or followers": "Aucun⋅e membre ou abonné⋅e|Un⋅e membre ou abonné⋅e|{count} membres ou abonné⋅es",
"This profile is from another instance, the informations shown here may be incomplete.": "Ce profil provient d'une autre instance, les informations montrées ici peuvent être incomplètes.",
"View full profile": "Voir le profil complet"
}

View File

@ -1,4 +1,3 @@
import { mixins } from "vue-class-component";
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { LatLng } from "leaflet";
import { Address, IAddress } from "../types/address.model";
@ -7,6 +6,7 @@ import { CONFIG } from "../graphql/config";
import { IConfig } from "../types/config.model";
import debounce from "lodash/debounce";
import { DebouncedFunc } from "lodash";
import { PropType } from "vue";
@Component({
components: {
@ -17,8 +17,9 @@ import { DebouncedFunc } from "lodash";
config: CONFIG,
},
})
export default class AddressAutoCompleteMixin extends mixins(Vue) {
@Prop({ required: true }) value!: IAddress;
export default class AddressAutoCompleteMixin extends Vue {
@Prop({ required: true, type: Object as PropType<IAddress> })
value!: IAddress;
gettingLocationError: string | null = null;
gettingLocation = false;
@ -29,8 +30,6 @@ export default class AddressAutoCompleteMixin extends mixins(Vue) {
selected: IAddress = new Address();
queryText: string = (this.value && new Address(this.value).fullName) || "";
config!: IConfig;
isFetching = false;
@ -85,6 +84,22 @@ export default class AddressAutoCompleteMixin extends mixins(Vue) {
this.isFetching = false;
}
get queryText(): string {
return (this.value && new Address(this.value).fullName) || "";
}
set queryText(text: string) {
if (text === "" && this.selected?.id) {
console.log("doing reset");
this.resetAddress();
}
}
resetAddress(): void {
this.$emit("input", null);
this.selected = new Address();
}
async locateMe(): Promise<void> {
this.gettingLocation = true;
this.gettingLocationError = null;
@ -124,7 +139,6 @@ export default class AddressAutoCompleteMixin extends mixins(Vue) {
const defaultAddress = new Address(this.addressData[0]);
this.selected = defaultAddress;
this.$emit("input", this.selected);
this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`;
}
}

View File

@ -473,6 +473,16 @@
<div v-else-if="group" class="public-container">
<aside class="group-metadata">
<div class="sticky">
<b-message v-if="group.domain && !isCurrentActorAGroupMember">
{{
$t(
"This profile is from another instance, the informations shown here may be incomplete."
)
}}
<a :href="group.url" rel="noopener noreferrer external">{{
$t("View full profile")
}}</a>
</b-message>
<event-metadata-block :title="$t('Members')" icon="account-group">
{{
$tc("{count} members", group.members.total, {
@ -505,13 +515,15 @@
</p>
</address>
</div>
<span
<b-button
class="map-show-button"
type="is-text"
@click="showMap = !showMap"
@keyup.enter="showMap = !showMap"
v-if="physicalAddress.geom"
>{{ $t("Show map") }}</span
>
{{ $t("Show map") }}
</b-button>
</div>
</div>
</event-metadata-block>

View File

@ -153,8 +153,8 @@
<full-address-auto-complete
:label="$t('Group address')"
v-model="editableGroup.physicalAddress"
:value="currentAddress"
v-model="currentAddress"
:hideMap="true"
/>
<div class="buttons">
@ -184,7 +184,7 @@ import { mixins } from "vue-class-component";
import GroupMixin from "@/mixins/group";
import { GroupVisibility, Openness } from "@/types/enums";
import { UPDATE_GROUP } from "../../graphql/group";
import { IGroup, usernameWithDomain } from "../../types/actor";
import { Group, IGroup, usernameWithDomain } from "../../types/actor";
import { Address, IAddress } from "../../types/address.model";
import { CONFIG } from "@/graphql/config";
import { IConfig } from "@/types/config.model";
@ -209,14 +209,10 @@ import { buildFileFromIMedia } from "@/utils/image";
},
})
export default class GroupSettings extends mixins(GroupMixin) {
loading = true;
RouteName = RouteName;
config!: IConfig;
newMemberUsername = "";
errors: string[] = [];
avatarFile: File | null = null;
@ -231,12 +227,11 @@ export default class GroupSettings extends mixins(GroupMixin) {
showCopiedTooltip = false;
editableGroup!: IGroup;
editableGroup: IGroup = new Group();
async updateGroup(): Promise<void> {
try {
const variables = this.buildVariables();
console.log(variables);
await this.$apollo.mutate<{ updateGroup: IGroup }>({
mutation: UPDATE_GROUP,
variables,
@ -275,14 +270,23 @@ export default class GroupSettings extends mixins(GroupMixin) {
let avatarObj = {};
let bannerObj = {};
const variables = { ...this.editableGroup };
const physicalAddress = {
...variables.physicalAddress,
};
let physicalAddress;
if (variables.physicalAddress) {
physicalAddress = { ...variables.physicalAddress };
} else {
physicalAddress = variables.physicalAddress;
}
// eslint-disable-next-line
// @ts-ignore
delete variables.__typename;
if (physicalAddress) {
if (variables.__typename) {
// eslint-disable-next-line
// @ts-ignore
delete variables.__typename;
}
// eslint-disable-next-line
// @ts-ignore
if (physicalAddress && physicalAddress.__typename) {
// eslint-disable-next-line
// @ts-ignore
delete physicalAddress.__typename;
@ -335,6 +339,10 @@ export default class GroupSettings extends mixins(GroupMixin) {
return new Address(this.editableGroup.physicalAddress);
}
set currentAddress(address: IAddress) {
this.editableGroup.physicalAddress = address;
}
get avatarMaxSize(): number | undefined {
return this?.config?.uploadLimits?.avatar;
}

View File

@ -328,7 +328,7 @@ import { EventSortField, ParticipantRole, SortDirection } from "@/types/enums";
import { Paginate } from "@/types/paginate";
import { supportsWebPFormat } from "@/utils/support";
import { IParticipant, Participant } from "../types/participant.model";
import { CLOSE_EVENTS, FETCH_EVENTS } from "../graphql/event";
import { FETCH_EVENTS } from "../graphql/event";
import EventParticipationCard from "../components/Event/EventParticipationCard.vue";
import MultiCard from "../components/Event/MultiCard.vue";
import { CURRENT_ACTOR_CLIENT } from "../graphql/actor";
@ -339,7 +339,7 @@ import {
IUserSettings,
} from "../types/current-user.model";
import { CURRENT_USER_CLIENT } from "../graphql/user";
import { HOME_USER_QUERIES } from "../graphql/home";
import { CLOSE_CONTENT, HOME_USER_QUERIES } from "../graphql/home";
import RouteName from "../router/name";
import { IEvent } from "../types/event.model";
import DateComponent from "../components/Event/DateCalendarIcon.vue";
@ -363,15 +363,17 @@ import Subtitle from "../components/Utils/Subtitle.vue";
},
currentUser: CURRENT_USER_CLIENT,
config: CONFIG,
closeEvents: {
query: CLOSE_EVENTS,
closeContent: {
query: CLOSE_CONTENT,
variables() {
return {
location: this.loggedUser?.settings?.location?.geohash,
radius: this.loggedUser?.settings?.location?.range,
};
},
update: (data) => data.searchEvents,
update(data) {
this.closeEvents = data.searchEvents;
},
skip() {
return (
!this.currentUser?.isLoggedIn ||

View File

@ -70,15 +70,7 @@
<b-loading :active.sync="$apollo.loading"></b-loading>
<h2 class="title">{{ $t("Featured events") }}</h2>
<div v-if="events.elements.length > 0">
<div class="columns is-multiline">
<div
class="column is-one-third-desktop"
v-for="event in events.elements"
:key="event.uuid"
>
<EventCard :event="event" />
</div>
</div>
<multi-card :events="events.elements" />
<div class="pagination" v-if="events.total > EVENT_PAGE_LIMIT">
<b-pagination
:total="events.total"
@ -98,7 +90,7 @@
>{{ $t("No events found") }}</b-message
>
</section>
<b-tabs v-else v-model="activeTab" type="is-boxed" class="searchTabs">
<b-tabs v-else v-model="activeTab" type="is-boxed" class="mt-3 searchTabs">
<b-loading :active.sync="$apollo.loading"></b-loading>
<b-tab-item>
<template slot="header">
@ -109,15 +101,7 @@
</span>
</template>
<div v-if="searchEvents.total > 0">
<div class="columns is-multiline">
<div
class="column is-one-third-desktop"
v-for="event in searchEvents.elements"
:key="event.uuid"
>
<EventCard :event="event" />
</div>
</div>
<multi-card class="my-4" :events="searchEvents.elements" />
<div class="pagination" v-if="searchEvents.total > EVENT_PAGE_LIMIT">
<b-pagination
:total="searchEvents.total"
@ -146,15 +130,7 @@
{{ $t("Groups are not enabled on this instance.") }}
</b-message>
<div v-else-if="searchGroups.total > 0">
<div class="columns is-multiline">
<div
class="column is-one-third-desktop"
v-for="group in searchGroups.elements"
:key="group.uuid"
>
<group-card :group="group" />
</div>
</div>
<multi-group-card class="my-4" :groups="searchGroups.elements" />
<div class="pagination">
<b-pagination
:total="searchGroups.total"
@ -193,16 +169,16 @@ import {
eachWeekendOfInterval,
} from "date-fns";
import { SearchTabs } from "@/types/enums";
import EventCard from "../components/Event/EventCard.vue";
import MultiCard from "../components/Event/MultiCard.vue";
import { FETCH_EVENTS } from "../graphql/event";
import { IEvent } from "../types/event.model";
import RouteName from "../router/name";
import { IAddress, Address } from "../types/address.model";
import AddressAutoComplete from "../components/Event/AddressAutoComplete.vue";
import { SEARCH_EVENTS, SEARCH_GROUPS } from "../graphql/search";
import { SEARCH_EVENTS_AND_GROUPS } from "../graphql/search";
import { Paginate } from "../types/paginate";
import { IGroup } from "../types/actor";
import GroupCard from "../components/Group/GroupCard.vue";
import MultiGroupCard from "../components/Group/MultiGroupCard.vue";
import { CONFIG } from "../graphql/config";
import { REVERSE_GEOCODE } from "../graphql/address";
@ -226,9 +202,9 @@ const THROTTLE = 2000; // minimum interval in ms between two requests
@Component({
components: {
EventCard,
MultiCard,
AddressAutoComplete,
GroupCard,
MultiGroupCard,
},
apollo: {
config: CONFIG,
@ -241,8 +217,8 @@ const THROTTLE = 2000; // minimum interval in ms between two requests
};
},
},
searchEvents: {
query: SEARCH_EVENTS,
search: {
query: SEARCH_EVENTS_AND_GROUPS,
fetchPolicy: "cache-and-network",
variables() {
return {
@ -256,27 +232,11 @@ const THROTTLE = 2000; // minimum interval in ms between two requests
limit: EVENT_PAGE_LIMIT,
};
},
throttle: THROTTLE,
skip() {
return !this.canSearchEvents;
},
},
searchGroups: {
query: SEARCH_GROUPS,
fetchPolicy: "cache-and-network",
variables() {
return {
term: this.search,
location: this.geohash,
radius: this.radius,
page: this.groupPage,
limit: GROUP_PAGE_LIMIT,
};
update(data) {
this.searchEvents = data.searchEvents;
this.searchGroups = data.searchGroups;
},
throttle: THROTTLE,
skip() {
return !this.canSearchGroups;
},
},
},
metaInfo() {

View File

@ -4,7 +4,7 @@ exports[`PostListItem renders post list item with basic informations 1`] = `
<a href="/p/my-blog-post-some-uuid" class="post-minimalist-card-wrapper">
<!---->
<div class="title-info-wrapper has-text-grey-dark">
<p class="post-minimalist-title">My Blog Post</p>
<h3 class="post-minimalist-title">My Blog Post</h3>
<p class="post-publication-date"><span class="icon"><i class="mdi mdi-clock mdi-24px"></i></span> <span class="has-text-grey-dark">Dec 2, 2020</span></p>
<!---->
<!---->
@ -16,7 +16,7 @@ exports[`PostListItem renders post list item with publisher name 1`] = `
<a href="/p/my-blog-post-some-uuid" class="post-minimalist-card-wrapper">
<!---->
<div class="title-info-wrapper has-text-grey-dark">
<p class="post-minimalist-title">My Blog Post</p>
<h3 class="post-minimalist-title">My Blog Post</h3>
<p class="post-publication-date"><span class="icon"><i class="mdi mdi-clock mdi-24px"></i></span> <span class="has-text-grey-dark">Dec 2, 2020</span></p>
<!---->
<p class="post-publisher has-text-grey-dark"><span class="icon"><i class="mdi mdi-account-edit mdi-24px"></i></span> <span>Published by <b class="has-text-weight-medium">An author</b></span></p>
@ -28,7 +28,7 @@ exports[`PostListItem renders post list item with tags 1`] = `
<a href="/p/my-blog-post-some-uuid" class="post-minimalist-card-wrapper">
<!---->
<div class="title-info-wrapper has-text-grey-dark">
<p class="post-minimalist-title">My Blog Post</p>
<h3 class="post-minimalist-title">My Blog Post</h3>
<p class="post-publication-date"><span class="icon"><i class="mdi mdi-clock mdi-24px"></i></span> <span class="has-text-grey-dark">Dec 2, 2020</span></p>
<div class="tags" style="display: inline;"><span class="icon"><i class="mdi mdi-tag mdi-24px"></i></span> <span class="tag"><!----><span class="">A tag</span>
<!----></span>

View File

@ -8,12 +8,15 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
alias Mobilizon.Actors.Actor, as: ActorModel
alias Mobilizon.Addresses.Address
alias Mobilizon.Federation.ActivityPub.Utils
alias Mobilizon.Federation.ActivityStream.{Converter, Convertible}
alias Mobilizon.Federation.ActivityStream.Converter.Address, as: AddressConverter
alias Mobilizon.Medias.File
alias Mobilizon.Service.HTTP.RemoteMediaDownloaderClient
alias Mobilizon.Service.RichMedia.Parser
alias Mobilizon.Web.Upload
import Mobilizon.Federation.ActivityStream.Converter.Utils, only: [get_address: 1]
@behaviour Converter
@ -37,6 +40,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
banner =
download_picture(get_in(data, ["image", "url"]), get_in(data, ["image", "name"]), "banner")
address = get_address(data["location"])
%{
url: data["id"],
avatar: avatar,
@ -60,7 +65,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
manually_approves_followers: data["manuallyApprovesFollowers"],
type: data["type"],
visibility: if(Map.get(data, "discoverable", false) == true, do: :public, else: :unlisted),
openness: data["openness"]
openness: data["openness"],
physical_address_id: if(address, do: address.id, else: nil)
}
end
@ -106,33 +112,11 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
}
}
actor_data =
if actor.type == :Group do
Map.put(actor_data, "members", actor.members_url)
else
actor_data
end
actor_data =
if is_nil(actor.avatar) do
actor_data
else
Map.put(actor_data, "icon", %{
"type" => "Image",
"mediaType" => actor.avatar.content_type,
"url" => actor.avatar.url
})
end
if is_nil(actor.banner) do
actor_data
else
Map.put(actor_data, "image", %{
"type" => "Image",
"mediaType" => actor.banner.content_type,
"url" => actor.banner.url
})
end
actor_data
|> maybe_add_members(actor)
|> maybe_add_avatar_picture(actor)
|> maybe_add_banner_picture(actor)
|> maybe_add_physical_address(actor)
end
@spec download_picture(String.t() | nil, String.t(), String.t()) :: map() | nil
@ -146,4 +130,41 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Actor do
Map.take(file, [:content_type, :name, :url, :size])
end
end
defp maybe_add_members(actor_data, %ActorModel{type: :Group, members_url: members_url}) do
Map.put(actor_data, "members", members_url)
end
defp maybe_add_members(actor_data, %ActorModel{}), do: actor_data
@spec maybe_add_avatar_picture(map(), ActorModel.t()) :: map()
defp maybe_add_avatar_picture(actor_data, %ActorModel{avatar: %File{} = avatar}) do
Map.put(actor_data, "image", %{
"type" => "Image",
"mediaType" => avatar.content_type,
"url" => avatar.url
})
end
defp maybe_add_avatar_picture(res, %ActorModel{avatar: _}), do: res
@spec maybe_add_banner_picture(map(), ActorModel.t()) :: map()
defp maybe_add_banner_picture(actor_data, %ActorModel{banner: %File{} = banner}) do
Map.put(actor_data, "image", %{
"type" => "Image",
"mediaType" => banner.content_type,
"url" => banner.url
})
end
defp maybe_add_banner_picture(res, %ActorModel{banner: _}), do: res
@spec maybe_add_physical_address(map(), ActorModel.t()) :: map()
defp maybe_add_physical_address(res, %ActorModel{
physical_address: %Address{} = physical_address
}) do
Map.put(res, "location", AddressConverter.model_to_as(physical_address))
end
defp maybe_add_physical_address(res, %ActorModel{physical_address: _}), do: res
end

View File

@ -7,7 +7,6 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
"""
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Event, as: EventModel
alias Mobilizon.Medias.Media
@ -25,7 +24,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
fetch_mentions: 1,
build_tags: 1,
maybe_fetch_actor_and_attributed_to_id: 1,
process_pictures: 2
process_pictures: 2,
get_address: 1
]
require Logger
@ -192,44 +192,6 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Event do
defp get_metdata(_), do: []
@spec get_address(map | binary | nil) :: Address.t() | nil
defp get_address(address_url) when is_binary(address_url) do
get_address(%{"id" => address_url})
end
defp get_address(%{"id" => url} = map) when is_map(map) and is_binary(url) do
Logger.debug("Address with an URL, let's check against our own database")
case Addresses.get_address_by_url(url) do
%Address{} = address ->
address
_ ->
Logger.debug("not in our database, let's try to create it")
map = Map.put(map, "url", map["id"])
do_get_address(map)
end
end
defp get_address(map) when is_map(map) do
do_get_address(map)
end
defp get_address(nil), do: nil
@spec do_get_address(map) :: Address.t() | nil
defp do_get_address(map) do
map = AddressConverter.as_to_model_data(map)
case Addresses.create_address(map) do
{:ok, %Address{} = address} ->
address
_ ->
nil
end
end
defp get_visibility(object), do: if(@ap_public in object["to"], do: :public, else: :unlisted)
@spec date_to_string(DateTime.t() | nil) :: String.t()

View File

@ -3,14 +3,16 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
Various utils for converters.
"""
alias Mobilizon.{Actors, Events}
alias Mobilizon.{Actors, Addresses, Events}
alias Mobilizon.Actors.Actor
alias Mobilizon.Addresses.Address
alias Mobilizon.Events.Tag
alias Mobilizon.Medias.Media
alias Mobilizon.Mention
alias Mobilizon.Storage.Repo
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
alias Mobilizon.Federation.ActivityStream.Converter.Address, as: AddressConverter
alias Mobilizon.Federation.ActivityStream.Converter.Media, as: MediaConverter
alias Mobilizon.Web.Endpoint
@ -252,4 +254,42 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Utils do
defp get_banner_picture(attachments) do
Enum.find(attachments, &(&1["type"] == "Document" && &1["name"] == @banner_picture_name))
end
@spec get_address(map | binary | nil) :: Address.t() | nil
def get_address(address_url) when is_binary(address_url) do
get_address(%{"id" => address_url})
end
def get_address(%{"id" => url} = map) when is_map(map) and is_binary(url) do
Logger.debug("Address with an URL, let's check against our own database")
case Addresses.get_address_by_url(url) do
%Address{} = address ->
address
_ ->
Logger.debug("not in our database, let's try to create it")
map = Map.put(map, "url", map["id"])
do_get_address(map)
end
end
def get_address(map) when is_map(map) do
do_get_address(map)
end
def get_address(nil), do: nil
@spec do_get_address(map) :: Address.t() | nil
defp do_get_address(map) do
map = AddressConverter.as_to_model_data(map)
case Addresses.create_address(map) do
{:ok, %Address{} = address} ->
address
_ ->
nil
end
end
end

View File

@ -40,13 +40,15 @@ defmodule Mobilizon.GraphQL.API.Search do
true ->
page =
Actors.build_actors_by_username_or_name_page(
Actors.search_actors(
term,
[
actor_type: [result_type],
actor_type: result_type,
radius: Map.get(args, :radius),
location: Map.get(args, :location),
minimum_visibility: Map.get(args, :minimum_visibility, :public)
minimum_visibility: Map.get(args, :minimum_visibility, :public),
current_actor_id: Map.get(args, :current_actor_id),
exclude_my_groups: Map.get(args, :exclude_my_groups, false)
],
page,
limit

View File

@ -13,7 +13,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Followers do
@spec find_followers_for_group(Actor.t(), map(), map()) :: {:ok, Page.t()}
def find_followers_for_group(
%Actor{id: group_id} = group,
%{page: page, limit: limit} = args,
args,
%{
context: %{
current_user: %User{role: user_role},
@ -21,15 +21,23 @@ defmodule Mobilizon.GraphQL.Resolvers.Followers do
}
}
) do
followers = group_followers(group, args)
if Actors.is_moderator?(actor_id, group_id) or is_moderator(user_role) do
{:ok,
Actors.list_paginated_followers_for_actor(group, Map.get(args, :approved), page, limit)}
{:ok, followers}
else
{:error, :unauthorized}
{:ok, %Page{followers | elements: []}}
end
end
def find_followers_for_group(_, _, _), do: {:error, :unauthenticated}
def find_followers_for_group(%Actor{} = group, args, _) do
followers = group_followers(group, args)
{:ok, %Page{followers | elements: []}}
end
defp group_followers(group, %{page: page, limit: limit} = args) do
Actors.list_paginated_followers_for_actor(group, Map.get(args, :approved), page, limit)
end
@spec update_follower(any(), map(), map()) :: {:ok, Follower.t()} | {:error, any()}
def update_follower(_, %{id: follower_id, approved: approved}, %{

View File

@ -21,7 +21,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Search do
"""
@spec search_groups(any(), map(), Absinthe.Resolution.t()) ::
{:ok, Page.t(Actor.t())} | {:error, String.t()}
def search_groups(_parent, %{page: page, limit: limit} = args, _resolution) do
def search_groups(
_parent,
%{page: page, limit: limit} = args,
%{context: context} = _resolution
) do
current_actor = Map.get(context, :current_actor, nil)
current_actor_id = if current_actor, do: current_actor.id, else: nil
args = Map.put(args, :current_actor_id, current_actor_id)
Search.search_actors(args, page, limit, :Group)
end

View File

@ -59,6 +59,14 @@ defmodule Mobilizon.GraphQL.Schema.SearchType do
arg(:term, :string, default_value: "", description: "Search term")
arg(:location, :string, description: "A geohash for coordinates")
arg(:exclude_my_groups, :boolean,
description: "Whether to include the groups the current actor is member or follower"
)
arg(:minimum_visibility, :group_visibility,
description: "The minimum visibility the group must have"
)
arg(:radius, :float,
default_value: 50,
description: "Radius around the location to search in"

View File

@ -124,7 +124,8 @@ defmodule Mobilizon.Actors.Actor do
:summary,
:manually_approves_followers,
:visibility,
:openness
:openness,
:physical_address_id
]
@remote_actor_creation_attrs @remote_actor_creation_required_attrs ++
@remote_actor_creation_optional_attrs

View File

@ -450,29 +450,55 @@ defmodule Mobilizon.Actors do
@doc """
Builds a page struct for actors by their name or displayed name.
"""
@spec build_actors_by_username_or_name_page(
@spec search_actors(
String.t(),
Keyword.t(),
integer | nil,
integer | nil
) :: Page.t()
def build_actors_by_username_or_name_page(
def search_actors(
term,
options \\ [],
page \\ nil,
limit \\ nil
) do
term
|> build_actors_by_username_or_name_page_query(options)
|> maybe_exclude_my_groups(
Keyword.get(options, :exclude_my_groups, false),
Keyword.get(options, :current_actor_id)
)
|> Page.build_page(page, limit)
end
defp maybe_exclude_my_groups(query, true, current_actor_id) when current_actor_id != nil do
query
|> join(:left, [a], m in Member, on: a.id == m.parent_id)
|> join(:left, [a], f in Follower, on: a.id == f.target_actor_id)
|> where([_a, ..., m, f], m.actor_id != ^current_actor_id and f.actor_id != ^current_actor_id)
end
defp maybe_exclude_my_groups(query, _, _), do: query
@spec build_actors_by_username_or_name_page_query(
String.t(),
Keyword.t()
) :: Ecto.Query.t()
defp build_actors_by_username_or_name_page_query(
term,
options
) do
anonymous_actor_id = Mobilizon.Config.anonymous_actor_id()
query = from(a in Actor)
query
|> distinct([q], q.id)
|> actor_by_username_or_name_query(term)
|> actors_for_location(Keyword.get(options, :location), Keyword.get(options, :radius))
|> filter_by_types(Keyword.get(options, :actor_type, :Group))
|> filter_by_type(Keyword.get(options, :actor_type, :Group))
|> filter_by_minimum_visibility(Keyword.get(options, :minimum_visibility, :public))
|> filter_suspended(false)
|> filter_out_anonymous_actor_id(anonymous_actor_id)
|> Page.build_page(page, limit)
end
@doc """
@ -1313,17 +1339,15 @@ defmodule Mobilizon.Actors do
@spec actors_for_location(Ecto.Queryable.t(), String.t(), integer()) :: Ecto.Query.t()
defp actors_for_location(query, location, radius)
when is_valid_string(location) and not is_nil(radius) do
with {lon, lat} <- Geohax.decode(location),
point <- Geo.WKT.decode!("SRID=4326;POINT(#{lon} #{lat})") do
query
|> join(:inner, [q], a in Address, on: a.id == q.physical_address_id, as: :address)
|> where(
[q],
st_dwithin_in_meters(^point, as(:address).geom, ^(radius * 1000))
)
else
_ -> query
end
{lon, lat} = Geohax.decode(location)
point = Geo.WKT.decode!("SRID=4326;POINT(#{lon} #{lat})")
query
|> join(:inner, [q], a in Address, on: a.id == q.physical_address_id, as: :address)
|> where(
[q],
st_dwithin_in_meters(^point, as(:address).geom, ^(radius * 1000))
)
end
defp actors_for_location(query, _location, _radius), do: query
@ -1564,11 +1588,6 @@ defmodule Mobilizon.Actors do
defp filter_by_type(query, _type), do: query
@spec filter_by_types(Ecto.Queryable.t(), [ActorType.t()]) :: Ecto.Query.t()
defp filter_by_types(query, types) do
from(a in query, where: a.type in ^types)
end
@spec filter_by_minimum_visibility(Ecto.Queryable.t(), atom()) :: Ecto.Query.t()
defp filter_by_minimum_visibility(query, :private), do: query

View File

@ -38,16 +38,23 @@ defmodule Mobilizon.GraphQL.API.SearchTest do
test "search actors" do
with_mock Actors,
build_actors_by_username_or_name_page: fn "toto", _options, 1, 10 ->
search_actors: fn "toto", _options, 1, 10 ->
%Page{total: 1, elements: [%Actor{id: 42}]}
end do
assert {:ok, %{total: 1, elements: [%Actor{id: 42}]}} =
Search.search_actors(%{term: "toto"}, 1, 10, :Person)
assert_called(
Actors.build_actors_by_username_or_name_page(
Actors.search_actors(
"toto",
[actor_type: [:Person], radius: nil, location: nil, minimum_visibility: :public],
[
actor_type: :Person,
radius: nil,
location: nil,
minimum_visibility: :public,
current_actor_id: nil,
exclude_my_groups: false
],
1,
10
)

View File

@ -70,7 +70,9 @@ defmodule Mobilizon.Web.Resolvers.FollowerTest do
variables: %{name: preferred_username}
)
assert hd(res["errors"])["message"] == "unauthenticated"
assert res["errors"] == nil
assert res["data"]["group"]["followers"]["total"] == 1
assert res["data"]["group"]["followers"]["elements"] == []
end
test "without being a member", %{
@ -88,7 +90,9 @@ defmodule Mobilizon.Web.Resolvers.FollowerTest do
variables: %{name: preferred_username}
)
assert hd(res["errors"])["message"] == "unauthorized"
assert res["errors"] == nil
assert res["data"]["group"]["followers"]["total"] == 1
assert res["data"]["group"]["followers"]["elements"] == []
end
test "without being a moderator", %{
@ -107,7 +111,9 @@ defmodule Mobilizon.Web.Resolvers.FollowerTest do
variables: %{name: preferred_username}
)
assert hd(res["errors"])["message"] == "unauthorized"
assert res["errors"] == nil
assert res["data"]["group"]["followers"]["total"] == 1
assert res["data"]["group"]["followers"]["elements"] == []
end
test "while being a moderator", %{

View File

@ -183,14 +183,14 @@ defmodule Mobilizon.ActorsTest do
assert MapSet.new([actor_found_id, actor2_found_id]) == MapSet.new([actor.id, actor2.id])
end
test "test build_actors_by_username_or_name_page/4 returns actors with similar usernames",
test "test search_actors/4 returns actors with similar usernames",
%{actor: %Actor{id: actor_id}} do
use_cassette "actors/remote_actor_mastodon_tcit" do
with {:ok, %Actor{id: actor2_id}} <-
ActivityPubActor.get_or_fetch_actor_by_url(@remote_account_url) do
%Page{total: 2, elements: actors} =
Actors.build_actors_by_username_or_name_page("tcit",
actor_type: [:Person],
Actors.search_actors("tcit",
actor_type: :Person,
minimum_visibility: :private
)
@ -201,9 +201,8 @@ defmodule Mobilizon.ActorsTest do
end
end
test "test build_actors_by_username_or_name_page/4 returns actors with similar names" do
%{total: 0, elements: actors} =
Actors.build_actors_by_username_or_name_page("ohno", actor_type: [:Person])
test "test search_actors/4 returns actors with similar names" do
%{total: 0, elements: actors} = Actors.search_actors("ohno", actor_type: :Person)
assert actors == []
end