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

[IMPROVE] Team system messages feedback #24209

Merged
merged 17 commits into from
Feb 18, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ API.v1.addRoute(
{ authRequired: true },
{
post() {
const findResult = findChannelByIdOrName({
const room = findChannelByIdOrName({
params: this.requestParams(),
checkedArchived: false,
});

Meteor.runAsUser(this.userId, () => {
Meteor.call('eraseRoom', findResult._id);
Meteor.call('eraseRoom', room._id);
});

return API.v1.success();
Expand Down
14 changes: 9 additions & 5 deletions app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ API.v1.addRoute(
});
}

await Promise.all([Team.unsetTeamIdOfRooms(team._id), Team.removeAllMembersFromTeam(team._id), Team.deleteById(team._id)]);
await Promise.all([
Team.unsetTeamIdOfRooms(this.userId, team._id),
Team.removeAllMembersFromTeam(team._id),
Team.deleteById(team._id),
]);

return API.v1.success();
},
Expand Down Expand Up @@ -606,9 +610,6 @@ API.v1.addRoute(

const rooms: string[] = await Team.getMatchingTeamRooms(team._id, roomsToRemove);

// Remove the team's main room
Meteor.call('eraseRoom', team.roomId);

// If we got a list of rooms to delete along with the team, remove them first
if (rooms.length) {
rooms.forEach((room) => {
Expand All @@ -617,7 +618,10 @@ API.v1.addRoute(
}

// Move every other room back to the workspace
await Team.unsetTeamIdOfRooms(team._id);
await Team.unsetTeamIdOfRooms(this.userId, team._id);

// Remove the team's main room
Meteor.call('eraseRoom', team.roomId);

// Delete all team memberships
Team.removeAllMembersFromTeam(team._id);
Expand Down
106 changes: 106 additions & 0 deletions app/lib/lib/MessageTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ Meteor.startup(function () {
};
},
});
MessageTypes.registerType({
id: 'added-user-to-team',
system: true,
message: 'Added__username__to_team',
data(message) {
return {
user_added: message.msg,
};
},
});
MessageTypes.registerType({
id: 'ru',
system: true,
Expand All @@ -37,6 +47,16 @@ Meteor.startup(function () {
};
},
});
MessageTypes.registerType({
id: 'removed-user-from-team',
system: true,
message: 'Removed__username__from_team',
data(message) {
return {
user_removed: message.msg,
};
},
});
MessageTypes.registerType({
id: 'ul',
system: true,
Expand All @@ -57,6 +77,56 @@ Meteor.startup(function () {
};
},
});
MessageTypes.registerType({
id: 'user-converted-to-team',
system: true,
message: 'Converted__roomName__to_team',
data(message) {
return {
roomName: message.msg,
};
},
});
MessageTypes.registerType({
id: 'user-converted-to-channel',
system: true,
message: 'Converted__roomName__to_channel',
data(message) {
return {
roomName: message.msg,
};
},
});
MessageTypes.registerType({
id: 'user-removed-room-from-team',
system: true,
message: 'Removed__roomName__from_this_team',
data(message) {
return {
roomName: message.msg,
};
},
});
MessageTypes.registerType({
id: 'user-deleted-room-from-team',
system: true,
message: 'Deleted__roomName__',
data(message) {
return {
roomName: message.msg,
};
},
});
MessageTypes.registerType({
id: 'user-added-room-to-team',
system: true,
message: 'added__roomName__to_team',
data(message) {
return {
roomName: message.msg,
};
},
});
MessageTypes.registerType({
id: 'uj',
system: true,
Expand Down Expand Up @@ -246,18 +316,34 @@ export const MessageTypesValues = [
key: 'uj',
i18nLabel: 'Message_HideType_uj',
},
{
key: 'ujt',
i18nLabel: 'Message_HideType_ujt',
},
{
key: 'ul',
i18nLabel: 'Message_HideType_ul',
},
{
key: 'ult',
i18nLabel: 'Message_HideType_ult',
},
{
key: 'ru',
i18nLabel: 'Message_HideType_ru',
},
{
key: 'removed-user-from-team',
i18nLabel: 'Message_HideType_removed_user_from_team',
},
{
key: 'au',
i18nLabel: 'Message_HideType_au',
},
{
key: 'added-user-to-team',
i18nLabel: 'Message_HideType_added_user_to_team',
},
{
key: 'mute_unmute',
i18nLabel: 'Message_HideType_mute_unmute',
Expand Down Expand Up @@ -330,4 +416,24 @@ export const MessageTypesValues = [
key: 'room-allowed-reacting',
i18nLabel: 'Message_HideType_room_allowed_reacting',
},
{
key: 'user-added-room-to-team',
i18nLabel: 'Message_HideType_user_added_room_to_team',
},
{
key: 'user-converted-to-channel',
i18nLabel: 'Message_HideType_user_converted_to_channel',
},
{
key: 'user-converted-to-team',
i18nLabel: 'Message_HideType_user_converted_to_team',
},
{
key: 'user-deleted-room-from-team',
i18nLabel: 'Message_HideType_user_deleted_room_from_team',
},
{
key: 'user-removed-room-from-team',
i18nLabel: 'Message_HideType_user_removed_room_from_team',
},
];
9 changes: 7 additions & 2 deletions app/lib/server/functions/addUserToRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ export const addUserToRoom = function (rid, user, inviter, silenced) {

if (!silenced) {
if (inviter) {
Messages.createUserAddedWithRoomIdAndUser(rid, user, {
const extraData = {
ts: now,
u: {
_id: inviter._id,
username: inviter.username,
},
});
};
if (room.teamMain) {
Messages.createUserAddedToTeamWithRoomIdAndUser(rid, user, extraData);
} else {
Messages.createUserAddedWithRoomIdAndUser(rid, user, extraData);
}
} else if (room.prid) {
Messages.createUserJoinWithRoomIdAndUserDiscussion(rid, user, { ts: now });
} else if (room.teamMain) {
Expand Down
7 changes: 6 additions & 1 deletion app/lib/server/functions/createRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import s from 'underscore.string';
import { Apps } from '../../../apps/server';
import { addUserRoles } from '../../../authorization';
import { callbacks } from '../../../../lib/callbacks';
import { Rooms, Subscriptions, Users } from '../../../models';
import { Messages, Rooms, Subscriptions, Users } from '../../../models';
import { getValidRoomName } from '../../../utils';
import { createDirectRoom } from './createDirectRoom';
import { Team } from '../../../../server/sdk';
Expand Down Expand Up @@ -131,6 +131,11 @@ export const createRoom = function (type, name, owner, members = [], readOnly, {

addUserRoles(owner._id, ['owner'], room._id);

if (room.teamId) {
const team = Promise.await(Team.getOneById(room.teamId));
Messages.createUserAddRoomToTeamWithRoomIdAndUser(team.roomId, room.name, owner);
}

if (type === 'c') {
Meteor.defer(() => {
callbacks.run('afterCreateChannel', owner, room);
Expand Down
10 changes: 8 additions & 2 deletions app/lib/server/functions/removeUserFromRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ export const removeUserFromRoom = function (rid, user, options = {}) {
if (subscription) {
const removedUser = user;
if (options.byUser) {
Messages.createUserRemovedWithRoomIdAndUser(rid, user, {
const extraData = {
u: options.byUser,
});
};

if (room.teamMain) {
Messages.createUserRemovedFromTeamWithRoomIdAndUser(rid, user, extraData);
} else {
Messages.createUserRemovedWithRoomIdAndUser(rid, user, extraData);
}
} else if (room.teamMain) {
Messages.createUserLeaveTeamWithRoomIdAndUser(rid, removedUser);
} else {
Expand Down
30 changes: 30 additions & 0 deletions app/models/server/models/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,16 +923,46 @@ export class Messages extends Base {
return this.createWithTypeRoomIdMessageAndUser('ult', roomId, message, user, extraData);
}

createUserConvertChannelToTeamWithRoomIdAndUser(roomId, roomName, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('user-converted-to-team', roomId, roomName, user, extraData);
}

createUserConvertTeamToChannelWithRoomIdAndUser(roomId, roomName, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('user-converted-to-channel', roomId, roomName, user, extraData);
}

createUserRemoveRoomFromTeamWithRoomIdAndUser(roomId, roomName, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('user-removed-room-from-team', roomId, roomName, user, extraData);
}

createUserDeleteRoomFromTeamWithRoomIdAndUser(roomId, roomName, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('user-deleted-room-from-team', roomId, roomName, user, extraData);
}

createUserAddRoomToTeamWithRoomIdAndUser(roomId, roomName, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('user-added-room-to-team', roomId, roomName, user, extraData);
}

createUserRemovedWithRoomIdAndUser(roomId, user, extraData) {
const message = user.username;
return this.createWithTypeRoomIdMessageAndUser('ru', roomId, message, user, extraData);
}

createUserRemovedFromTeamWithRoomIdAndUser(roomId, user, extraData) {
const message = user.username;
return this.createWithTypeRoomIdMessageAndUser('removed-user-from-team', roomId, message, user, extraData);
}

createUserAddedWithRoomIdAndUser(roomId, user, extraData) {
const message = user.username;
return this.createWithTypeRoomIdMessageAndUser('au', roomId, message, user, extraData);
}

createUserAddedToTeamWithRoomIdAndUser(roomId, user, extraData) {
const message = user.username;
return this.createWithTypeRoomIdMessageAndUser('added-user-to-team', roomId, message, user, extraData);
}

createCommandWithRoomIdAndUser(command, roomId, user, extraData) {
return this.createWithTypeRoomIdMessageAndUser('command', roomId, command, user, extraData);
}
Expand Down
2 changes: 0 additions & 2 deletions app/theme/client/imports/general/base_old.css
Original file line number Diff line number Diff line change
Expand Up @@ -1880,8 +1880,6 @@
& .user {
display: inline-block;

margin-right: 5px;

font-family: inherit;
font-size: 0.875rem;

Expand Down
7 changes: 7 additions & 0 deletions app/ui-message/client/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
{{#if isBot}}
<span class="is-bot color-secondary-color border-component-color">{{_ "Bot"}}</span>
{{/if}}
{{#unless system}}
<time class="time" title='{{date}} {{time}}' datetime='{{date}} {{time}}'>{{time}}</time>
{{/unless}}
{{#if showTranslated}}
<span class="translated">
<i class="icon-language {{#if msg.autoTranslateFetching}}loading{{/if}}" title="{{_ "Translated"}}"></i>
Expand Down Expand Up @@ -111,6 +113,11 @@
{{> messageLocation location=msg.location}}
{{/if}}
</div>
{{#if system}}
<div class='title border-component-color color-info-font-color'>
<time class="time" title='{{date}} {{time}}' datetime='{{date}} {{time}}'>{{time}}</time>
</div>
{{/if}}
</div>

{{#if hasOembed}}
Expand Down
38 changes: 38 additions & 0 deletions app/user-data-download/server/cronProcessDownloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,45 @@ const getMessageData = function (msg, hideUsers, userData, usersMap) {
case 'ult':
messageObject.msg = TAPi18n.__('User_left_team');
break;
case 'user-added-room-to-team':
messageObject.msg = TAPi18n.__('added__roomName__to_team', {
roomName: msg.msg,
});
break;
case 'user-converted-to-team':
messageObject.msg = TAPi18n.__('Converted__roomName__to_team', {
roomName: msg.msg,
});
break;
case 'user-converted-to-channel':
messageObject.msg = TAPi18n.__('Converted__roomName__to_channel', {
roomName: msg.msg,
});
break;
case 'user-deleted-room-from-team':
messageObject.msg = TAPi18n.__('Deleted__roomName__', {
roomName: msg.msg,
});
break;
case 'user-removed-room-from-team':
messageObject.msg = TAPi18n.__('Removed__roomName__from_this_team', {
roomName: msg.msg,
});
break;
case 'ujt':
messageObject.msg = TAPi18n.__('User_joined_team');
break;
case 'au':
messageObject.msg = TAPi18n.__('User_added_by', {
user_added: hideUserName(msg.msg, userData, usersMap),
user_by: username,
});
break;
case 'added-user-to-team':
messageObject.msg = TAPi18n.__('Added__username__to_team', {
user_added: msg.msg,
});
break;
case 'r':
messageObject.msg = TAPi18n.__('Room_name_changed', {
room_name: msg.msg,
Expand All @@ -183,6 +216,11 @@ const getMessageData = function (msg, hideUsers, userData, usersMap) {
user_by: username,
});
break;
case 'removed-user-from-team':
messageObject.msg = TAPi18n.__('Removed__username__from_team', {
user_removed: hideUserName(msg.msg, userData, usersMap),
});
break;
case 'wm':
messageObject.msg = TAPi18n.__('Welcome', { user: username });
break;
Expand Down
Loading