Skip to content
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
12 changes: 12 additions & 0 deletions src/components/LeftSidebar/ConversationsList/Conversation.spec.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading