mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-15 20:53:07 +01:00
Fix bug with unsubscribing from communities
This commit is contained in:
parent
6542859892
commit
70cf6f3340
@ -118,25 +118,20 @@ public class InsertSubscribedThings {
|
|||||||
(List<SubscribedSubredditData> newSubscribedSubreddits,
|
(List<SubscribedSubredditData> newSubscribedSubreddits,
|
||||||
List<SubscribedSubredditData> oldSubscribedSubreddits,
|
List<SubscribedSubredditData> oldSubscribedSubreddits,
|
||||||
List<String> unsubscribedSubredditNames) {
|
List<String> unsubscribedSubredditNames) {
|
||||||
int newIndex = 0;
|
List<String> oldSubredditNames = new ArrayList<>();
|
||||||
for (int oldIndex = 0; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
|
for (SubscribedSubredditData subredditData : oldSubscribedSubreddits) {
|
||||||
if (newIndex >= newSubscribedSubreddits.size()) {
|
oldSubredditNames.add(subredditData.getQualified_name());
|
||||||
for (; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
|
|
||||||
unsubscribedSubredditNames.add(oldSubscribedSubreddits.get(oldIndex).getQualified_name());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SubscribedSubredditData old = oldSubscribedSubreddits.get(oldIndex);
|
List<String> newSubredditNames = new ArrayList<>();
|
||||||
for (; newIndex < newSubscribedSubreddits.size(); newIndex++) {
|
for (SubscribedSubredditData subredditData : newSubscribedSubreddits) {
|
||||||
if (newSubscribedSubreddits.get(newIndex).getQualified_name().compareToIgnoreCase(old.getQualified_name()) == 0) {
|
newSubredditNames.add(subredditData.getQualified_name());
|
||||||
newIndex++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (newSubscribedSubreddits.get(newIndex).getQualified_name().compareToIgnoreCase(old.getQualified_name()) > 0) {
|
|
||||||
unsubscribedSubredditNames.add(old.getQualified_name());
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (String subredditName : oldSubredditNames) {
|
||||||
|
if (!newSubredditNames.contains(subredditName)) {
|
||||||
|
unsubscribedSubredditNames.add(subredditName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public interface SubscribedSubredditDao {
|
|||||||
@Query("SELECT * from subscribed_subreddits WHERE qualified_name = :qualified_name COLLATE NOCASE AND username = :accountName COLLATE NOCASE LIMIT 1")
|
@Query("SELECT * from subscribed_subreddits WHERE qualified_name = :qualified_name COLLATE NOCASE AND username = :accountName COLLATE NOCASE LIMIT 1")
|
||||||
SubscribedSubredditData getSubscribedSubredditByQualifiedName(String qualified_name, String accountName);
|
SubscribedSubredditData getSubscribedSubredditByQualifiedName(String qualified_name, String accountName);
|
||||||
|
|
||||||
@Query("DELETE FROM subscribed_subreddits WHERE name = :subredditName COLLATE NOCASE AND username = :accountName COLLATE NOCASE")
|
@Query("DELETE FROM subscribed_subreddits WHERE qualified_name = :subredditName COLLATE NOCASE AND username = :accountName COLLATE NOCASE")
|
||||||
void deleteSubscribedSubreddit(String subredditName, String accountName);
|
void deleteSubscribedSubreddit(String subredditName, String accountName);
|
||||||
|
|
||||||
@Query("SELECT * from subscribed_subreddits WHERE username = :qualified_name AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
|
@Query("SELECT * from subscribed_subreddits WHERE username = :qualified_name AND name LIKE '%' || :searchQuery || '%' COLLATE NOCASE AND is_favorite = 1 ORDER BY name COLLATE NOCASE ASC")
|
||||||
|
@ -129,13 +129,13 @@ public class SubscribedSubredditData implements Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return id;
|
return id + username.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (obj instanceof SubscribedSubredditData) {
|
if (obj instanceof SubscribedSubredditData) {
|
||||||
return id == ((SubscribedSubredditData) obj).getId();
|
return id == ((SubscribedSubredditData) obj).getId() && username.equalsIgnoreCase(((SubscribedSubredditData) obj).getUsername());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user