Add support for overriding subscriptions when importing.

This commit is contained in:
FireMasterK 2021-08-28 13:26:50 +05:30
parent 86827d6a2c
commit 3e99d1d806
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD
2 changed files with 9 additions and 7 deletions

View file

@ -254,9 +254,8 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
try {
String[] subscriptions = Constants.mapper.readValue(request.loadBody().getResult().asArray(),
String[].class);
return getJsonResponse(
ResponseHelper.importResponse(request.getHeader(AUTHORIZATION), subscriptions),
"private");
return getJsonResponse(ResponseHelper.importResponse(request.getHeader(AUTHORIZATION),
subscriptions, Boolean.parseBoolean(request.getQueryParameter("override"))), "private");
} catch (Exception e) {
return getErrorResponse(e);
}

View file

@ -801,7 +801,7 @@ public class ResponseHelper {
}
public static final byte[] importResponse(String session, String[] channelIds)
public static final byte[] importResponse(String session, String[] channelIds, boolean override)
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
Session s = DatabaseSessionFactory.createSession();
@ -811,6 +811,9 @@ public class ResponseHelper {
if (user != null) {
Multithreading.runAsync(() -> {
if (override)
user.setSubscribed(Arrays.asList(channelIds));
else
for (String channelId : channelIds)
if (!user.getSubscribed().contains(channelId))
user.getSubscribed().add(channelId);