Skip to content

Commit

Permalink
Fix discussions issues after room deletion and translation actions no…
Browse files Browse the repository at this point in the history
…t being shown (#14018)

* fix deleted discussion closes #13689

* update topic discussion if the parent room name change

* fix translation to non subscribed channels closes #13965
  • Loading branch information
ggazzo authored and sampaiodiego committed Apr 8, 2019
1 parent 2143056 commit 7fc7856
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 13 deletions.
6 changes: 2 additions & 4 deletions app/autotranslate/client/lib/actionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ Meteor.startup(function() {
AutoTranslate.messageIdsToWait[message._id] = true;
Messages.update({ _id: message._id }, { $set: { autoTranslateFetching: true } });
Meteor.call('autoTranslate.translateMessage', message, language);
} else if (message.autoTranslateShowInverse) {
Messages.update({ _id: message._id }, { $unset: { autoTranslateShowInverse: true } });
} else {
Messages.update({ _id: message._id }, { $set: { autoTranslateShowInverse: true } });
}
const action = message.autoTranslateShowInverse ? '$unset' : '$set';
Messages.update({ _id: message._id }, { [action]: { autoTranslateShowInverse: true } });
},
condition(message) {
return message && message.u && message.u._id !== Meteor.userId();
Expand Down
2 changes: 1 addition & 1 deletion app/autotranslate/client/lib/autotranslate.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const AutoTranslate = {
if (!message.translations) {
message.translations = {};
}
if (subscription && subscription.autoTranslate !== message.autoTranslateShowInverse) {
if (!!(subscription && subscription.autoTranslate) !== !!message.autoTranslateShowInverse) {
message.translations.original = message.html;
if (message.translations[autoTranslateLanguage]) {
message.html = message.translations[autoTranslateLanguage];
Expand Down
5 changes: 2 additions & 3 deletions app/autotranslate/client/lib/tabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import { TabBar } from '../../../ui-utils';
Meteor.startup(function() {
Tracker.autorun(function() {
if (settings.get('AutoTranslate_Enabled') && hasAtLeastOnePermission(['auto-translate'])) {
TabBar.addButton({
return TabBar.addButton({
groups: ['channel', 'group', 'direct'],
id: 'autotranslate',
i18nTitle: 'Auto_Translate',
icon: 'language',
template: 'autoTranslateFlexTab',
order: 20,
});
} else {
TabBar.removeButton('autotranslate');
}
TabBar.removeButton('autotranslate');
});
});
2 changes: 2 additions & 0 deletions app/channel-settings/server/functions/saveRoomName.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { Rooms, Messages, Subscriptions, Integrations } from '../../../models';
import { roomTypes, getValidRoomName } from '../../../utils';
import { callbacks } from '../../../callbacks';

export const saveRoomName = function(rid, displayName, user, sendMessage = true) {
const room = Rooms.findOneById(rid);
Expand All @@ -26,5 +27,6 @@ export const saveRoomName = function(rid, displayName, user, sendMessage = true)
if (sendMessage) {
Messages.createRoomRenamedWithRoomIdRoomNameAndUser(rid, displayName, user);
}
callbacks.run('afterRoomNameChange', { rid, name: displayName });
return displayName;
};
15 changes: 12 additions & 3 deletions app/discussion/server/hooks/propagateDiscussionMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ callbacks.add('afterDeleteMessage', function(message, { _id, prid } = {}) {
return message;
}, callbacks.priority.LOW, 'PropagateDiscussionMetadata');

callbacks.add('afterDeleteRoom', function(rid) {
Rooms.find({ prid: rid }, { fields: { _id: 1 } }).forEach(({ _id }) => deleteRoom(_id));
}, 'DeleteDiscussionChain');
callbacks.add('afterDeleteRoom', (rid) => Rooms.find({ prid: rid }, { fields: { _id: 1 } }).forEach(({ _id }) => deleteRoom(_id)), 'DeleteDiscussionChain');

// TODO discussions define new fields
callbacks.add('afterRoomNameChange', ({ rid, name }) => Rooms.update({ prid: rid }, { $set: { topic: name } }, { multi: true }));

callbacks.add('afterDeleteRoom', (drid) => Messages.update({ drid }, {
$unset: {
dcount: 1,
dlm: 1,
drid: 1,
},
}), 'CleanDiscussionMessage');
2 changes: 1 addition & 1 deletion app/theme/client/imports/forms/input.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
textarea.rc-input__element {
height: auto;
padding: 0.5rem 1rem;

font-family: inherit;
line-height: 0.5rem 1rem;
}

.rc-input {
Expand Down
3 changes: 2 additions & 1 deletion app/ui-message/client/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ Template.message.helpers({
const { msg, subscription, settings } = this;
if (settings.AutoTranslate_Enabled && msg.u && msg.u._id !== Meteor.userId() && !MessageTypes.isSystemMessage(msg)) {
const language = AutoTranslate.getLanguage(msg.rid);
return msg.autoTranslateFetching || (subscription && subscription.autoTranslate !== msg.autoTranslateShowInverse && msg.translations && msg.translations[language]);
const autoTranslate = subscription && subscription.autoTranslate;
return msg.autoTranslateFetching || (!!autoTranslate !== !!msg.autoTranslateShowInverse && msg.translations && msg.translations[language]);
}
},
edited() {
Expand Down
1 change: 1 addition & 0 deletions server/startup/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@ import './v136';
import './v137';
import './v138';
import './v139';
import './v140';
import './xrun';
17 changes: 17 additions & 0 deletions server/startup/migrations/v140.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Migrations } from '../../../app/migrations/server';

import { Messages, Rooms } from '../../../app/models/server';

Migrations.add({
version: 140,
up() {
Messages.find({ drid: { $exists: 1 } }, { fields: { drid: 1 } }).forEach(({ _id, drid }) => Rooms.findOne({ _id: drid }) || Messages.update({ _id }, {
$unset: {
drid: 1,
dcount: 1,
dlm: 1,
t: 1,
},
}));
},
});

0 comments on commit 7fc7856

Please sign in to comment.