Skip to content

Commit 1361a98

Browse files
Merge pull request #7142 from nextcloud/bugfix/7024/dont-update-last-message
Don't update last message of conversation with invisible message
2 parents 6ff57ea + 09731a4 commit 1361a98

File tree

6 files changed

+246
-113
lines changed

6 files changed

+246
-113
lines changed

lib/Chat/ChatManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ public function deleteMessage(Room $chat, IComment $comment, Participant $partic
363363
$this->timeFactory->getDateTime(),
364364
false,
365365
null,
366-
(int) $comment->getId()
366+
(int) $comment->getId(),
367+
true
367368
);
368369
}
369370

lib/Chat/ReactionManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ public function deleteReactionMessage(Room $chat, Participant $participant, int
141141
$this->timeFactory->getDateTime(),
142142
false,
143143
null,
144-
$messageId
144+
$messageId,
145+
true
145146
);
146147

147148
return $comment;

src/components/LeftSidebar/ConversationsList/Conversation.spec.js

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -130,42 +130,36 @@ describe('Conversation.vue', () => {
130130
describe('author name', () => {
131131
test('displays last chat message with shortened author name', () => {
132132
testConversationLabel(item, 'Alice: hello')
133-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
134133
})
135134

136135
test('displays last chat message with author name if no space in name', () => {
137136
item.lastMessage.actorDisplayName = 'Bob'
138137
testConversationLabel(item, 'Bob: hello')
139-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
140138
})
141139

142140
test('displays own last chat message with "You" as author', () => {
143141
item.lastMessage.actorId = 'user-id-self'
144142

145143
testConversationLabel(item, 'You: hello')
146-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
147144
})
148145

149146
test('displays last system message without author', () => {
150147
item.lastMessage.message = 'Alice has joined the call'
151148
item.lastMessage.systemMessage = 'call_joined'
152149

153150
testConversationLabel(item, 'Alice has joined the call')
154-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
155151
})
156152

157153
test('displays last message without author in one to one conversations', () => {
158154
item.type = CONVERSATION.TYPE.ONE_TO_ONE
159155
testConversationLabel(item, 'hello')
160-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
161156
})
162157

163158
test('displays own last message with "You" author in one to one conversations', () => {
164159
item.type = CONVERSATION.TYPE.ONE_TO_ONE
165160
item.lastMessage.actorId = 'user-id-self'
166161

167162
testConversationLabel(item, 'You: hello')
168-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
169163
})
170164

171165
test('displays last guest message with default author when none set', () => {
@@ -174,14 +168,12 @@ describe('Conversation.vue', () => {
174168
item.lastMessage.actorType = ATTENDEE.ACTOR_TYPE.GUESTS
175169

176170
testConversationLabel(item, 'Guest: hello')
177-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
178171
})
179172

180173
test('displays last message for search results', () => {
181174
// search results have no actor id
182175
item.actorId = null
183176
testConversationLabel(item, 'Alice: hello', true)
184-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
185177
})
186178
})
187179

@@ -194,80 +186,6 @@ describe('Conversation.vue', () => {
194186
}
195187

196188
testConversationLabel(item, 'Alice: filename.jpg')
197-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
198-
})
199-
200-
describe('last message from messages store', () => {
201-
// see Conversation.lastChatMessage() description for the reasoning
202-
let displayedLastStoreMessage
203-
let lastMessageFromConversation
204-
205-
beforeEach(() => {
206-
displayedLastStoreMessage = {
207-
id: 100,
208-
actorId: 'user-id-alice',
209-
actorDisplayName: 'Alice Wonderland',
210-
actorType: ATTENDEE.ACTOR_TYPE.USERS,
211-
message: 'hello from store',
212-
messageParameters: {},
213-
systemMessage: '',
214-
timestamp: 100,
215-
}
216-
217-
lastMessageFromConversation = {
218-
id: 110,
219-
actorId: 'user-id-alice',
220-
actorDisplayName: 'Alice Wonderland',
221-
actorType: ATTENDEE.ACTOR_TYPE.USERS,
222-
message: 'hello from conversation',
223-
messageParameters: {},
224-
systemMessage: '',
225-
timestamp: 100,
226-
}
227-
228-
item.lastMessage = lastMessageFromConversation
229-
230-
messagesMock.mockClear().mockReturnValue({
231-
100: displayedLastStoreMessage,
232-
})
233-
})
234-
235-
test('displays store message when more recent', () => {
236-
displayedLastStoreMessage.timestamp = 2000
237-
238-
testConversationLabel(item, 'Alice: hello from store')
239-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
240-
})
241-
242-
test('displays conversation message when last one is a temporary command message', () => {
243-
messagesMock.mockClear().mockReturnValue({
244-
'temp-100': displayedLastStoreMessage,
245-
})
246-
247-
displayedLastStoreMessage.timestamp = 2000
248-
displayedLastStoreMessage.id = 'temp-100'
249-
displayedLastStoreMessage.message = '/me doing things'
250-
251-
testConversationLabel(item, 'Alice: hello from conversation')
252-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
253-
})
254-
255-
test('displays conversation message when last one is a bot message', () => {
256-
displayedLastStoreMessage.timestamp = 2000
257-
displayedLastStoreMessage.actorType = ATTENDEE.ACTOR_TYPE.BOTS
258-
259-
testConversationLabel(item, 'Alice: hello from conversation')
260-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
261-
})
262-
263-
test('displays store message when last one is a changelog bot message', () => {
264-
displayedLastStoreMessage.timestamp = 2000
265-
displayedLastStoreMessage.actorType = ATTENDEE.ACTOR_TYPE.BOTS
266-
displayedLastStoreMessage.actorId = ATTENDEE.CHANGELOG_BOT_ID
267-
268-
testConversationLabel(item, 'Alice: hello from store')
269-
expect(messagesMock).toHaveBeenCalledWith(TOKEN)
270-
})
271189
})
272190
})
273191

src/components/LeftSidebar/ConversationsList/Conversation.vue

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -219,39 +219,12 @@ export default {
219219
})
220220
},
221221
222-
// The messages array for this conversation
223-
messages() {
224-
return this.$store.getters.messages(this.item.token)
225-
},
226-
227222
// Get the last message for this conversation from the message store instead
228223
// of the conversations store. The message store is updated immediately,
229224
// while the conversations store is refreshed every 30 seconds. This allows
230225
// to display message previews in this component as soon as new messages are
231226
// received by the server.
232227
lastChatMessage() {
233-
const lastMessageTimestamp = this.item.lastMessage ? this.item.lastMessage.timestamp : 0
234-
235-
if (Object.keys(this.messages).length > 0) {
236-
// FIXME: risky way to get last message that assumes that keys are always sorted
237-
// should use this.$store.getters.messagesList instead ?
238-
const messagesKeys = Object.keys(this.messages)
239-
const lastMessageId = messagesKeys[messagesKeys.length - 1]
240-
241-
/**
242-
* Only use the last message as lastmessage when:
243-
* 1. It's newer than the conversations last message
244-
* 2. It's not a command reply
245-
* 3. It's not a temporary message starting with "/" which is a user posting a command
246-
*/
247-
if (this.messages[lastMessageId].timestamp > lastMessageTimestamp
248-
&& (this.messages[lastMessageId].actorType !== ATTENDEE.ACTOR_TYPE.BOTS
249-
|| this.messages[lastMessageId].actorId === ATTENDEE.CHANGELOG_BOT_ID)
250-
&& (!lastMessageId.startsWith('temp-')
251-
|| !this.messages[lastMessageId].message.startsWith('/'))) {
252-
return this.messages[lastMessageId]
253-
}
254-
}
255228
return this.item.lastMessage
256229
},
257230

src/store/conversationsStore.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,18 @@ const actions = {
410410
* Only use the last message as lastmessage when:
411411
* 1. It's not a command reply
412412
* 2. It's not a temporary message starting with "/" which is a user posting a command
413+
* 3. It's not a reaction or deletion of a reaction
414+
* 3. It's not a deletion of a message
413415
*/
414416
if ((lastMessage.actorType !== 'bots'
415417
|| lastMessage.actorId === 'changelog')
416-
&& ((typeof lastMessage.id.startsWith === 'function' && !lastMessage.id.startsWith('temp-'))
417-
|| !lastMessage.message.startsWith('/'))) {
418+
&& lastMessage.systemMessage !== 'reaction'
419+
&& lastMessage.systemMessage !== 'reaction_deleted'
420+
&& lastMessage.systemMessage !== 'reaction_revoked'
421+
&& lastMessage.systemMessage !== 'message_deleted'
422+
&& !(typeof lastMessage.id.startsWith === 'function'
423+
&& lastMessage.id.startsWith('temp-')
424+
&& lastMessage.message.startsWith('/'))) {
418425
commit('updateConversationLastMessage', { token, lastMessage })
419426
}
420427
},

0 commit comments

Comments
 (0)