PC-1001 Do not show private messages between users unless reporter is

involved
This commit is contained in:
Keir Nellyer 2016-09-21 13:21:23 +01:00
parent 09287ddefc
commit c6eb23812f
4 changed files with 37 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package mineplex.core.chatsnap;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CompletableFuture;
@ -67,6 +68,29 @@ public class SnapshotManager
return messages;
}
/**
* Gets all messages an account is involved in.
* The user may be the sender or recipient of a message.
* Does not include PMs unless sender or receiver is in the exclusions collection.
*
* @param accountId the account to search for messages involved in
* @param pmIdWhitelist a list of account ids of which to include PMs of
* @return the messages that the account is involved in
*/
public Set<SnapshotMessage> getMessagesInvolving(int accountId, Collection<Integer> pmIdWhitelist)
{
return getMessagesInvolving(accountId).stream()
.filter(message -> includeMessage(message, pmIdWhitelist))
.collect(Collectors.toCollection(TreeSet::new));
}
private boolean includeMessage(SnapshotMessage message, Collection<Integer> pmExclusions)
{
return message.getType() != MessageType.PM ||
pmExclusions.contains(message.getSenderId()) ||
!Collections.disjoint(message.getRecipientIds(), pmExclusions);
}
/**
* Gets all messages an account is involved in.
* The user may be the sender or recipient of a message.

View File

@ -1,5 +1,7 @@
package mineplex.core.chatsnap.command;
import java.util.Set;
import mineplex.serverdata.commands.ServerCommand;
/**
@ -9,12 +11,14 @@ public class PushSnapshotsCommand extends ServerCommand
{
private final int _accountId;
private final long _reportId;
private final Set<Integer> _reporters;
public PushSnapshotsCommand(int accountId, long reportId)
public PushSnapshotsCommand(int accountId, long reportId, Set<Integer> reporters)
{
super();
_accountId = accountId;
_reportId = reportId;
_reporters = reporters;
}
public int getAccountId()
@ -27,6 +31,11 @@ public class PushSnapshotsCommand extends ServerCommand
return _reportId;
}
public Set<Integer> getReporters()
{
return _reporters;
}
@Override
public void run()
{

View File

@ -29,7 +29,8 @@ public class PushSnapshotsHandler implements CommandCallback
PushSnapshotsCommand pushCommand = (PushSnapshotsCommand) command;
int accountId = pushCommand.getAccountId();
long reportId = pushCommand.getReportId();
Set<SnapshotMessage> messages = _snapshotManager.getMessagesInvolving(accountId);
Set<Integer> reporters = pushCommand.getReporters();
Set<SnapshotMessage> messages = _snapshotManager.getMessagesInvolving(accountId, reporters);
if (messages.size() > 0)
{

View File

@ -387,7 +387,7 @@ public class ReportManager
{
future.thenAccept(reportId ->
{
PushSnapshotsCommand command = new PushSnapshotsCommand(report.getSuspectId(), reportId);
PushSnapshotsCommand command = new PushSnapshotsCommand(report.getSuspectId(), reportId, report.getReporterIds());
command.publish();
});
}