Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/store
diff options
context:
space:
mode:
authorMarco <marcoambrosini@pm.me>2022-04-14 10:32:23 +0300
committerGitHub <noreply@github.com>2022-04-14 10:32:23 +0300
commit1361a9838c8a07ae5464496d615e478b82c597b8 (patch)
tree2215cc597663826b5d35fb0042d4422537fdff58 /src/store
parent6ff57ea87eaf4114e211f1b1706d88b994954cf5 (diff)
parent09731a4ac649fe2504606289e5846657d7dcc71b (diff)
Merge pull request #7142 from nextcloud/bugfix/7024/dont-update-last-message
Don't update last message of conversation with invisible message
Diffstat (limited to 'src/store')
-rw-r--r--src/store/conversationsStore.js11
-rw-r--r--src/store/conversationsStore.spec.js233
2 files changed, 242 insertions, 2 deletions
diff --git a/src/store/conversationsStore.js b/src/store/conversationsStore.js
index 27dd0ecbd..d5daa289c 100644
--- a/src/store/conversationsStore.js
+++ b/src/store/conversationsStore.js
@@ -410,11 +410,18 @@ const actions = {
* Only use the last message as lastmessage when:
* 1. It's not a command reply
* 2. It's not a temporary message starting with "/" which is a user posting a command
+ * 3. It's not a reaction or deletion of a reaction
+ * 3. It's not a deletion of a message
*/
if ((lastMessage.actorType !== 'bots'
|| lastMessage.actorId === 'changelog')
- && ((typeof lastMessage.id.startsWith === 'function' && !lastMessage.id.startsWith('temp-'))
- || !lastMessage.message.startsWith('/'))) {
+ && lastMessage.systemMessage !== 'reaction'
+ && lastMessage.systemMessage !== 'reaction_deleted'
+ && lastMessage.systemMessage !== 'reaction_revoked'
+ && lastMessage.systemMessage !== 'message_deleted'
+ && !(typeof lastMessage.id.startsWith === 'function'
+ && lastMessage.id.startsWith('temp-')
+ && lastMessage.message.startsWith('/'))) {
commit('updateConversationLastMessage', { token, lastMessage })
}
},
diff --git a/src/store/conversationsStore.spec.js b/src/store/conversationsStore.spec.js
index 83f38785b..739df851e 100644
--- a/src/store/conversationsStore.spec.js
+++ b/src/store/conversationsStore.spec.js
@@ -50,6 +50,13 @@ jest.mock('../services/conversationsService', () => ({
describe('conversationsStore', () => {
const testToken = 'XXTOKENXX'
+ const previousLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: '',
+ id: 31,
+ message: 'Message 1',
+ }
let testStoreConfig = null
let testConversation
let localVue = null
@@ -592,6 +599,232 @@ describe('conversationsStore', () => {
})
})
+ describe('update last message', () => {
+ beforeEach(() => {
+ store = new Vuex.Store(testStoreConfig)
+ })
+
+ test('successful update from user', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: '',
+ id: 42,
+ message: 'Message 2',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(testLastMessage)
+ })
+
+ test('ignore update from bot', () => {
+ const testLastMessage = {
+ actorType: 'bots',
+ actorId: 'selfmade',
+ systemMessage: '',
+ id: 42,
+ message: 'Message 2',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(previousLastMessage)
+ })
+
+ test('ignore update from bot but not from changelog', () => {
+ const testLastMessage = {
+ actorType: 'bots',
+ actorId: 'changelog',
+ systemMessage: '',
+ id: 42,
+ message: 'Message 2',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(testLastMessage)
+ })
+
+ test('ignore update reactions', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: 'reaction',
+ id: 42,
+ message: '👍',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(previousLastMessage)
+ })
+
+ test('ignore update from the action of deleting reactions', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: 'reaction_revoked',
+ id: 42,
+ message: 'Admin deleted a reaction',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(previousLastMessage)
+ })
+
+ test('ignore update deleted reactions (only theory as the action of deleting would come after it anyway)', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: 'reaction_deleted',
+ id: 42,
+ message: 'Reaction deleted by author',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(previousLastMessage)
+ })
+
+ test('ignore update from deleting a message', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: 'message_deleted',
+ id: 42,
+ message: 'Admin deleted a message',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(previousLastMessage)
+ })
+
+ test('successfully update temporary messages', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: '',
+ id: 'temp-42',
+ message: 'quit',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(testLastMessage)
+ })
+
+ test('successfully update also posted messages which start with a slash', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: '',
+ id: 42,
+ message: '/quit',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(testLastMessage)
+ })
+
+ test('ignore update from temporary if posting a command', () => {
+ const testLastMessage = {
+ actorType: 'users',
+ actorId: 'admin',
+ systemMessage: '',
+ id: 'temp-42',
+ message: '/quit',
+ }
+
+ testConversation.lastMessage = previousLastMessage
+
+ store.dispatch('addConversation', testConversation)
+
+ store.dispatch('updateConversationLastMessage', {
+ token: testToken,
+ lastMessage: testLastMessage,
+ })
+
+ const changedConversation = store.getters.conversation(testToken)
+ expect(changedConversation.lastMessage).toBe(previousLastMessage)
+ })
+ })
+
describe('creating conversations', () => {
test('creates one to one conversation', async () => {
const newConversation = {