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

[stable26] Allow to mark conversation as unread #9366

Merged
merged 2 commits into from Apr 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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