Skip to content

Commit

Permalink
Merge pull request #9366 from nextcloud/backport/9346/stable26
Browse files Browse the repository at this point in the history
[stable26] Allow to mark conversation as unread
  • Loading branch information
Antreesy committed Apr 24, 2023
2 parents 7948f0b + a3f9b7b commit 968cb58
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 60 deletions.
12 changes: 12 additions & 0 deletions src/components/LeftSidebar/ConversationsList/Conversation.spec.js
Expand Up @@ -530,10 +530,22 @@ describe('Conversation.vue', () => {

expect(toggleFavoriteAction).toHaveBeenCalledWith(expect.anything(), item)
})
test('marks conversation as unread', async () => {
const markConversationUnreadAction = jest.fn().mockResolvedValueOnce()
testStoreConfig.modules.conversationsStore.actions.markConversationUnread = markConversationUnreadAction

const action = shallowMountAndGetAction('Mark as unread')
expect(action.exists()).toBe(true)

await action.find('button').trigger('click')

expect(markConversationUnreadAction).toHaveBeenCalledWith(expect.anything(), { token: item.token })
})
test('marks conversation as read', async () => {
const clearLastReadMessageAction = jest.fn().mockResolvedValueOnce()
testStoreConfig.modules.conversationsStore.actions.clearLastReadMessage = clearLastReadMessageAction

item.unreadMessages = 1
const action = shallowMountAndGetAction('Mark as read')
expect(action.exists()).toBe(true)

Expand Down
24 changes: 20 additions & 4 deletions src/components/LeftSidebar/ConversationsList/Conversation.vue
Expand Up @@ -62,13 +62,22 @@
@click.stop.prevent="handleCopyLink">
{{ t('spreed', 'Copy link') }}
</NcActionButton>
<NcActionButton :close-after-click="true"
<NcActionButton v-if="item.unreadMessages"
:close-after-click="true"
@click.prevent.exact="markConversationAsRead">
<template #icon>
<EyeOutline :size="16" />
</template>
{{ t('spreed', 'Mark as read') }}
</NcActionButton>
<NcActionButton v-else
:close-after-click="true"
@click.prevent.exact="markConversationAsUnread">
<template #icon>
<EyeOffOutline :size="16" />
</template>
{{ t('spreed', 'Mark as unread') }}
</NcActionButton>
<NcActionButton :close-after-click="true"
@click.prevent.exact="showConversationSettings">
<Cog slot="icon"
Expand Down Expand Up @@ -116,6 +125,7 @@ import ArrowRight from 'vue-material-design-icons/ArrowRight.vue'
import Cog from 'vue-material-design-icons/Cog.vue'
import Delete from 'vue-material-design-icons/Delete.vue'
import ExitToApp from 'vue-material-design-icons/ExitToApp.vue'
import EyeOffOutline from 'vue-material-design-icons/EyeOffOutline.vue'
import EyeOutline from 'vue-material-design-icons/EyeOutline.vue'
import Star from 'vue-material-design-icons/Star.vue'
Expand All @@ -134,14 +144,16 @@ export default {
name: 'Conversation',
components: {
ConversationIcon,
NcActionButton,
NcListItem,
// Icons
ArrowRight,
Cog,
ConversationIcon,
Delete,
ExitToApp,
EyeOffOutline,
EyeOutline,
NcActionButton,
NcListItem,
Star,
},
Expand Down Expand Up @@ -350,6 +362,10 @@ export default {
this.$store.dispatch('clearLastReadMessage', { token: this.item.token })
},
markConversationAsUnread() {
this.$store.dispatch('markConversationUnread', { token: this.item.token })
},
showConversationSettings() {
emit('show-conversation-settings', { token: this.item.token })
},
Expand Down
15 changes: 15 additions & 0 deletions src/services/conversationsService.js
Expand Up @@ -206,6 +206,20 @@ const clearConversationHistory = async function(token) {
return response
}

/**
* Set conversation as unread
*
* @param {string} token The token of the conversation to be set as unread
*/
const setConversationUnread = async function(token) {
try {
const response = axios.delete(generateOcsUrl('apps/spreed/api/v1/chat/{token}/read', { token }))
return response
} catch (error) {
console.debug('Error while setting the conversation as unread: ', error)
}
}

/**
* Add a conversation to the favorites
*
Expand Down Expand Up @@ -433,6 +447,7 @@ export {
setConversationName,
setConversationDescription,
clearConversationHistory,
setConversationUnread,
setConversationPermissions,
setCallPermissions,
setMessageExpiration,
Expand Down

0 comments on commit 968cb58

Please sign in to comment.