Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable31] fix(actorStore): fetch teams with membership #14455

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ export default {
if (getCurrentUser()) {
console.debug('Setting current user')
this.$store.dispatch('setCurrentUser', getCurrentUser())
this.$store.dispatch('getCurrentUserTeams')
} else {
console.debug('Can not set current user because it\'s a guest')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
</template>

<script>
import { loadState } from '@nextcloud/initial-state'

import NcUserBubble from '@nextcloud/vue/dist/Components/NcUserBubble.js'
import { useIsDarkTheme } from '@nextcloud/vue/dist/Composables/useIsDarkTheme.js'

Expand Down Expand Up @@ -105,12 +103,10 @@ export default {
&& this.id === this.$store.getters.getUserId()
},
isCurrentUserGroup() {
return this.isGroupMention
&& loadState('spreed', 'user_group_ids', []).includes(this.id)
return this.isGroupMention && this.$store.getters.isActorMemberOfGroup(this.id)
},
isCurrentUserTeam() {
// FIXME need backend support here
return this.isTeamMention && false
return this.isTeamMention && this.$store.getters.isActorMemberOfTeam(this.id)
},
primary() {
return this.isMentionToAll
Expand Down
20 changes: 20 additions & 0 deletions src/services/teamsService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'

import type { getTeamsProbeResponse } from '../types/index.ts'

/**
* Get teams (circles) for a current user
*/
const getTeams = async (): getTeamsProbeResponse => {
return axios.get(generateOcsUrl('/apps/circles/probecircles'))
}

export {
getTeams,
}
38 changes: 38 additions & 0 deletions src/store/actorStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
* If an as no userId, they are a guest and identified by actorType + sessionId.
*/

import { loadState } from '@nextcloud/initial-state'

import { ATTENDEE, PARTICIPANT } from '../constants.ts'
import { getTeams } from '../services/teamsService.ts'

const state = {
userId: null,
Expand All @@ -19,6 +22,8 @@ const state = {
actorId: null,
actorType: null,
displayName: '',
actorGroups: loadState('spreed', 'user_group_ids', []),
actorTeams: [],
}

const getters = {
Expand All @@ -43,6 +48,12 @@ const getters = {
isActorGuest: (state) => () => {
return state.actorType === ATTENDEE.ACTOR_TYPE.GUESTS
},
isActorMemberOfGroup: (state) => (groupId) => {
return state.actorGroups.includes(groupId)
},
isActorMemberOfTeam: (state) => (teamId) => {
return state.actorTeams.includes(teamId)
},
getDisplayName: (state) => () => {
return state.displayName
},
Expand Down Expand Up @@ -112,6 +123,15 @@ const mutations = {
setActorType(state, actorType) {
state.actorType = actorType
},
/**
* Set the user teams ids
*
* @param {object} state current store state;
* @param {Array} teams Teams ids of the current user
*/
setCurrentUserTeams(state, teams) {
state.actorTeams = teams
},
}

const actions = {
Expand Down Expand Up @@ -162,6 +182,24 @@ const actions = {
setDisplayName(context, displayName) {
context.commit('setDisplayName', displayName)
},
/**
* Sets current user teams, if circles app enabled
*
* @param {object} context default store context;
*/
async getCurrentUserTeams(context) {
if (!loadState('spreed', 'circles_enabled', false)) {
return
}

try {
const response = await getTeams()
const teams = response.data.ocs.data.map(team => team.id)
context.commit('setCurrentUserTeams', teams)
} catch (error) {
console.error(error)
}
},
}

export default { state, mutations, getters, actions }
16 changes: 16 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ export type TaskProcessingResponse = ApiResponseUnwrapped<{
}
}>

// Teams (circles)
export type TeamProbe = {
id: string,
name: string,
displayName: string,
sanitizedName: string,
source: number,
population: number,
config: number,
description: string,
url: string,
creation: number,
initiator: null
}
export type getTeamsProbeResponse = ApiResponseUnwrapped<TeamProbe[]>

// Groupware
export type DavPrincipal = {
calendarHomes: string[],
Expand Down
Loading