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

[stable24] Move message.reactions.self to message.reactionsSelf to not merge different data structures #7182

Merged
merged 4 commits into from Apr 20, 2022
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
2 changes: 1 addition & 1 deletion docs/chat.md
Expand Up @@ -51,7 +51,7 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1`
`messageParameters` | array | Message parameters for `message` (see [Rich Object String](https://github.com/nextcloud/server/issues/1706))
`parent` | array | **Optional:** See `Parent data` below
`reactions` | array | **Optional:** An array map with relation between reaction emoji and total count of reactions with this emoji
`reactions`.`self` | array | **Optional:** When the user reacted the reactions array will have an entry `self` with the list of emojis the user reacted with
`reactionsSelf` | array | **Optional:** When the user reacted this is the list of emojis the user reacted with

#### Parent data

Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/ChatController.php
Expand Up @@ -555,14 +555,14 @@ protected function loadSelfReactions(array $messages, array $commentIdToIndex):
// Inject the reactions self into the $messages array
foreach ($reactionsById as $messageId => $reactions) {
if (isset($messages[$commentIdToIndex[$messageId]])) {
$messages[$commentIdToIndex[$messageId]]['reactions']['self'] = $reactions;
$messages[$commentIdToIndex[$messageId]]['reactionsSelf'] = $reactions;
}

// Add the self part also to potential parent elements
if (isset($parentMap[$messageId])) {
foreach ($parentMap[$messageId] as $mid) {
if (isset($messages[$commentIdToIndex[$mid]])) {
$messages[$commentIdToIndex[$mid]]['parent']['reactions']['self'] = $reactions;
$messages[$commentIdToIndex[$mid]]['parent']['reactionsSelf'] = $reactions;
}
}
}
Expand Down
Expand Up @@ -817,10 +817,8 @@ describe('Message.vue', () => {
store = new Store(testStoreConfig)

const messagePropsWithReactions = Object.assign({}, messageProps)
messagePropsWithReactions.reactions = {
'👍': 1,
self: ['👍'],
}
messagePropsWithReactions.reactions = { '👍': 1 }
messagePropsWithReactions.reactionsSelf = ['👍']

const wrapper = shallowMount(Message, {
localVue,
Expand Down Expand Up @@ -855,10 +853,8 @@ describe('Message.vue', () => {
store = new Store(testStoreConfig)

const messagePropsWithReactions = Object.assign({}, messageProps)
messagePropsWithReactions.reactions = {
'❤️': 1,
self: ['❤️'],
}
messagePropsWithReactions.reactions = { '❤️': 1 }
messagePropsWithReactions.reactionsSelf = ['❤️']

const wrapper = shallowMount(Message, {
localVue,
Expand Down
14 changes: 7 additions & 7 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Expand Up @@ -350,6 +350,11 @@ export default {
type: [Array, Object],
default: () => { return {} },
},

reactionsSelf: {
type: Array,
default: () => { return [] },
},
},

data() {
Expand Down Expand Up @@ -567,12 +572,7 @@ export default {
},

simpleReactions() {
const reactions = Object.assign({}, this.messageObject.reactions)
if (reactions?.self) {
// Remove the self entry for the rendering
delete reactions.self
}
return reactions
return this.messageObject.reactions
},

detailedReactions() {
Expand Down Expand Up @@ -610,7 +610,7 @@ export default {

methods: {
userHasReacted(reaction) {
return this.reactions?.self && this.reactions.self.indexOf(reaction) !== -1
return this.reactionsSelf && this.reactionsSelf.indexOf(reaction) !== -1
},

lastReadMessageVisibilityChanged(isVisible) {
Expand Down
12 changes: 6 additions & 6 deletions src/store/messagesStore.js
Expand Up @@ -356,10 +356,10 @@ const mutations = {
const reactionCount = state.messages[token][messageId].reactions[reaction] + 1
Vue.set(state.messages[token][messageId].reactions, reaction, reactionCount)

if (!state.messages[token][messageId].reactions.self) {
Vue.set(state.messages[token][messageId].reactions, 'self', [reaction])
if (!state.messages[token][messageId].reactionsSelf) {
Vue.set(state.messages[token][messageId], 'reactionsSelf', [reaction])
} else {
state.messages[token][messageId].reactions.self.push(reaction)
state.messages[token][messageId].reactionsSelf.push(reaction)
}
},

Expand All @@ -371,10 +371,10 @@ const mutations = {
Vue.delete(state.messages[token][messageId].reactions, reaction)
}

if (state.messages[token][messageId].reactions.self) {
const i = state.messages[token][messageId].reactions.self.indexOf(reaction)
if (state.messages[token][messageId].reactionsSelf) {
const i = state.messages[token][messageId].reactionsSelf.indexOf(reaction)
if (i !== -1) {
Vue.delete(state.messages[token][messageId].reactions, 'self', i)
Vue.delete(state.messages[token][messageId], 'reactionsSelf', i)
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/features/bootstrap/FeatureContext.php
Expand Up @@ -1678,6 +1678,7 @@ protected function compareDataResponse(TableNode $formData = null) {
$includeParents = in_array('parentMessage', $formData->getRow(0), true);
$includeReferenceId = in_array('referenceId', $formData->getRow(0), true);
$includeReactions = in_array('reactions', $formData->getRow(0), true);
$includeReactionsSelf = in_array('reactionsSelf', $formData->getRow(0), true);

$count = count($formData->getHash());
Assert::assertCount($count, $messages, 'Message count does not match');
Expand All @@ -1686,7 +1687,7 @@ protected function compareDataResponse(TableNode $formData = null) {
$messages[$i]['messageParameters'] = 'IGNORE';
}
}
Assert::assertEquals($formData->getHash(), array_map(function ($message) use ($includeParents, $includeReferenceId, $includeReactions) {
Assert::assertEquals($formData->getHash(), array_map(function ($message) use ($includeParents, $includeReferenceId, $includeReactions, $includeReactionsSelf) {
$data = [
'room' => self::$tokenToIdentifier[$message['token']],
'actorType' => $message['actorType'],
Expand All @@ -1706,6 +1707,13 @@ protected function compareDataResponse(TableNode $formData = null) {
if ($includeReactions) {
$data['reactions'] = json_encode($message['reactions'], JSON_UNESCAPED_UNICODE);
}
if ($includeReactionsSelf) {
if (isset($message['reactionsSelf'])) {
$data['reactionsSelf'] = json_encode($message['reactionsSelf'], JSON_UNESCAPED_UNICODE);
} else {
$data['reactionsSelf'] = null;
}
}
return $data;
}, $messages));
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/features/reaction/react.feature
Expand Up @@ -18,16 +18,16 @@ Feature: reaction/react
| room | users | participant1 | participant1-displayname | user_added |
| room | users | participant1 | participant1-displayname | conversation_created |
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"👍":1} |
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions | reactionsSelf |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"👍":1} | |
And user "participant1" react with "👍" on message "Message 1" to room "room" with 201
| actorType | actorId | actorDisplayName | reaction |
| users | participant1 | participant1-displayname | 👍 |
| users | participant2 | participant2-displayname | 👍 |
And user "participant1" react with "🚀" on message "Message 1" to room "room" with 201
Then user "participant1" sees the following messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"👍":2,"🚀":1,"self":["👍","🚀"]} |
| room | actorType | actorId | actorDisplayName | message | messageParameters | reactions | reactionsSelf |
| room | users | participant1 | participant1-displayname | Message 1 | [] | {"👍":2,"🚀":1} | ["👍","🚀"] |
Then user "participant1" sees the following system messages in room "room" with 200
| room | actorType | actorId | actorDisplayName | systemMessage |
| room | users | participant1 | participant1-displayname | reaction |
Expand Down