Skip to content

Commit

Permalink
feat: add handling of archived conversations
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Sep 20, 2024
1 parent 271e520 commit 843b38f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/__mocks__/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const mockedCapabilities: Capabilities = {
'chat-reference-id',
'mention-permissions',
'edit-messages-note-to-self',
'archived-conversations',
],
'features-local': [
'favorites',
Expand All @@ -95,6 +96,7 @@ export const mockedCapabilities: Capabilities = {
'avatar',
'remind-me-later',
'note-to-self',
'archived-conversations',
],
config: {
attachments: {
Expand Down
30 changes: 29 additions & 1 deletion src/components/LeftSidebar/ConversationsList/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
{{ t('spreed', 'Conversation settings') }}
</NcActionButton>

<NcActionButton v-if="supportsArchive"
key="toggle-archive"
close-after-click
@click="toggleArchiveConversation">
<template #icon>
<IconArchive v-if="!item.isArchived" :size="16" />
<IconArchiveOff v-else :size="16" />
</template>
{{ labelArchive }}
</NcActionButton>

<NcActionButton v-if="item.canLeaveConversation"
key="leave-conversation"
close-after-click
Expand Down Expand Up @@ -118,6 +129,8 @@
import { toRefs } from 'vue'
import { isNavigationFailure, NavigationFailureType } from 'vue-router'
import IconArchive from 'vue-material-design-icons/Archive.vue'
import IconArchiveOff from 'vue-material-design-icons/ArchiveOff.vue'
import IconArrowRight from 'vue-material-design-icons/ArrowRight.vue'
import IconCog from 'vue-material-design-icons/Cog.vue'
import IconContentCopy from 'vue-material-design-icons/ContentCopy.vue'
Expand All @@ -140,8 +153,11 @@ import ConversationIcon from './../../ConversationIcon.vue'
import { useConversationInfo } from '../../../composables/useConversationInfo.js'
import { PARTICIPANT } from '../../../constants.js'
import { hasTalkFeature } from '../../../services/CapabilitiesManager.ts'
import { copyConversationLinkToClipboard } from '../../../utils/handleUrl.ts'
const supportsArchive = hasTalkFeature('local', 'archived-conversations')
export default {
name: 'Conversation',
Expand All @@ -151,6 +167,8 @@ export default {
NcActionButton,
NcDialog,
NcListItem,
IconArchive,
IconArchiveOff,
IconArrowRight,
IconCog,
IconContentCopy,
Expand All @@ -159,7 +177,6 @@ export default {
IconEyeOff,
IconEye,
IconStar,
},
props: {
Expand Down Expand Up @@ -196,6 +213,7 @@ export default {
const { counterType, conversationInformation } = useConversationInfo({ item, isSearchResult })
return {
supportsArchive,
counterType,
conversationInformation,
}
Expand All @@ -220,6 +238,12 @@ export default {
return this.item.isFavorite ? t('spreed', 'Remove from favorites') : t('spreed', 'Add to favorites')
},
labelArchive() {
return this.item.isArchived
? t('spreed', 'Unarchive conversation')
: t('spreed', 'Archive conversation')
},
dialogMessage() {
return t('spreed', 'Do you really want to delete "{displayName}"?', this.item, undefined, {
escape: false,
Expand Down Expand Up @@ -298,6 +322,10 @@ export default {
this.$store.dispatch('toggleFavorite', this.item)
},
async toggleArchiveConversation() {
this.$store.dispatch('toggleArchive', this.item)
},
/**
* Set the notification level for the conversation
*
Expand Down
20 changes: 20 additions & 0 deletions src/services/conversationsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,24 @@ const removeFromFavorites = async function(token) {
return axios.delete(generateOcsUrl('apps/spreed/api/v4/room/{token}/favorite', { token }))
}

/**
* Add a conversation to the archive
*
* @param {string} token The token of the conversation to be archived
*/
const archiveConversation = async function(token) {
return axios.post(generateOcsUrl('apps/spreed/api/v4/room/{token}/archive', { token }))
}

/**
* Restore a conversation from the archive
*
* @param {string} token The token of the conversation to be removed from archive
*/
const unarchiveConversation = async function(token) {
return axios.delete(generateOcsUrl('apps/spreed/api/v4/room/{token}/archive', { token }))
}

/**
* Set notification level
*
Expand Down Expand Up @@ -380,6 +398,8 @@ export {
deleteConversation,
addToFavorites,
removeFromFavorites,
archiveConversation,
unarchiveConversation,
setNotificationLevel,
setNotificationCalls,
makeConversationPublic,
Expand Down
25 changes: 24 additions & 1 deletion src/store/conversationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
createOneToOneConversation,
addToFavorites,
removeFromFavorites,
archiveConversation,
unarchiveConversation,
fetchConversations,
fetchConversation,
setConversationName,
Expand Down Expand Up @@ -67,6 +69,7 @@ const DUMMY_CONVERSATION = {
token: '',
displayName: '',
isFavorite: false,
isArchived: false,
hasPassword: false,
breakoutRoomMode: CONVERSATION.BREAKOUT_ROOM_MODE.NOT_CONFIGURED,
breakoutRoomStatus: CONVERSATION.BREAKOUT_ROOM_STATUS.STOPPED,
Expand Down Expand Up @@ -525,6 +528,26 @@ const actions = {
}
},

async toggleArchive({ commit, getters }, { token, isArchived }) {
if (!getters.conversations[token]) {
return
}

try {
if (isArchived) {
await unarchiveConversation(token)
} else {
await archiveConversation(token)
}

const conversation = Object.assign({}, getters.conversations[token], { isArchived: !isArchived })

commit('addConversation', conversation)
} catch (error) {
console.error('Error while changing the conversation archived status: ', error)
}
},

async toggleLobby({ commit, getters }, { token, enableLobby }) {
if (!getters.conversations[token]) {
return
Expand Down Expand Up @@ -904,7 +927,7 @@ const actions = {
async setNotificationLevel({ commit }, { token, notificationLevel }) {
try {
await setNotificationLevel(token, notificationLevel)
commit('setNotificationLevel', { token, notificationLevel })
commit('setNotificationLevel', { token, notificationLevel: +notificationLevel })
} catch (error) {
console.error('Error while setting the notification level: ', error)
}
Expand Down

0 comments on commit 843b38f

Please sign in to comment.