Revert unsubscribe logic.

This commit is contained in:
Kavin 2022-05-05 19:40:38 +01:00
parent 05ac4dc3ce
commit 91372d7427
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -771,18 +771,14 @@ public class ResponseHelper {
public static byte[] unsubscribeResponse(String session, String channelId) public static byte[] unsubscribeResponse(String session, String channelId)
throws IOException { throws IOException {
User user = DatabaseHelper.getUserFromSessionWithSubscribed(session); User user = DatabaseHelper.getUserFromSession(session);
if (user != null) { if (user != null) {
try (Session s = DatabaseSessionFactory.createSession()) { try (Session s = DatabaseSessionFactory.createSession()) {
if (user.getSubscribed().contains(channelId)) {
user.getSubscribed().remove(channelId);
s.update(user);
s.getTransaction().begin(); s.getTransaction().begin();
s.createNativeQuery("delete from users_subscribed where subscriber = :id and channel = :channel")
.setParameter("id", user.getId()).setParameter("channel", channelId).executeUpdate();
s.getTransaction().commit(); s.getTransaction().commit();
}
return Constants.mapper.writeValueAsBytes(new AcceptedResponse()); return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
} }