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

[FIX] Archiving Direct Messages #6737

Merged
merged 2 commits into from
Apr 19, 2017
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: 4 additions & 0 deletions packages/rocketchat-lib/server/methods/archiveRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Meteor.methods({
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'archiveRoom' });
}

if (room.t === 'd') {
throw new Meteor.Error('error-direct-message-room', 'Direct Messages can not be archived', { method: 'archiveRoom' });
}

return RocketChat.archiveRoom(rid);
}
});
5 changes: 5 additions & 0 deletions packages/rocketchat-slashcommands-archiveroom/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ function Archive(command, params, item) {
room = RocketChat.models.Rooms.findOneByName(channel);
}

// You can not archive direct messages.
if (room.t === 'd') {
return;
}

const user = Meteor.users.findOne(Meteor.userId());

if (room.archived) {
Expand Down
9 changes: 9 additions & 0 deletions packages/rocketchat-slashcommands-unarchiveroom/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ function Unarchive(command, params, item) {
channel = channel.replace('#', '');
room = RocketChat.models.Rooms.findOneByName(channel);
}

// You can not archive direct messages.
if (room.t === 'd') {
return;
}

const user = Meteor.users.findOne(Meteor.userId());

if (!room.archived) {
Expand All @@ -27,7 +33,9 @@ function Unarchive(command, params, item) {
});
return;
}

Meteor.call('unarchiveRoom', room._id);

RocketChat.models.Messages.createRoomUnarchivedByRoomIdAndUser(room._id, Meteor.user());
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),
Expand All @@ -38,6 +46,7 @@ function Unarchive(command, params, item) {
sprintf: [channel]
}, user.language)
});

return Unarchive;
}

Expand Down