mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-13 05:40:30 +05:30
Add support for overriding subscriptions when importing.
This commit is contained in:
parent
86827d6a2c
commit
3e99d1d806
@ -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);
|
||||
}
|
||||
|
@ -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,9 +811,12 @@ public class ResponseHelper {
|
||||
if (user != null) {
|
||||
|
||||
Multithreading.runAsync(() -> {
|
||||
for (String channelId : channelIds)
|
||||
if (!user.getSubscribed().contains(channelId))
|
||||
user.getSubscribed().add(channelId);
|
||||
if (override)
|
||||
user.setSubscribed(Arrays.asList(channelIds));
|
||||
else
|
||||
for (String channelId : channelIds)
|
||||
if (!user.getSubscribed().contains(channelId))
|
||||
user.getSubscribed().add(channelId);
|
||||
|
||||
if (channelIds.length > 0) {
|
||||
s.update(user);
|
||||
|
Loading…
Reference in New Issue
Block a user