mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-27 11:28:22 +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> oldSubscribedSubreddits,
|
||||
List<String> unsubscribedSubredditNames) {
|
||||
int newIndex = 0;
|
||||
for (int oldIndex = 0; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
|
||||
if (newIndex >= newSubscribedSubreddits.size()) {
|
||||
for (; oldIndex < oldSubscribedSubreddits.size(); oldIndex++) {
|
||||
unsubscribedSubredditNames.add(oldSubscribedSubreddits.get(oldIndex).getQualified_name());
|
||||
}
|
||||
return;
|
||||
}
|
||||
List<String> oldSubredditNames = new ArrayList<>();
|
||||
for (SubscribedSubredditData subredditData : oldSubscribedSubreddits) {
|
||||
oldSubredditNames.add(subredditData.getQualified_name());
|
||||
}
|
||||
|
||||
SubscribedSubredditData old = oldSubscribedSubreddits.get(oldIndex);
|
||||
for (; newIndex < newSubscribedSubreddits.size(); newIndex++) {
|
||||
if (newSubscribedSubreddits.get(newIndex).getQualified_name().compareToIgnoreCase(old.getQualified_name()) == 0) {
|
||||
newIndex++;
|
||||
break;
|
||||
}
|
||||
if (newSubscribedSubreddits.get(newIndex).getQualified_name().compareToIgnoreCase(old.getQualified_name()) > 0) {
|
||||
unsubscribedSubredditNames.add(old.getQualified_name());
|
||||
break;
|
||||
}
|
||||
List<String> newSubredditNames = new ArrayList<>();
|
||||
for (SubscribedSubredditData subredditData : newSubscribedSubreddits) {
|
||||
newSubredditNames.add(subredditData.getQualified_name());
|
||||
}
|
||||
|
||||
|
||||
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")
|
||||
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);
|
||||
|
||||
@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
|
||||
public int hashCode() {
|
||||
return id;
|
||||
return id + username.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof SubscribedSubredditData) {
|
||||
return id == ((SubscribedSubredditData) obj).getId();
|
||||
return id == ((SubscribedSubredditData) obj).getId() && username.equalsIgnoreCase(((SubscribedSubredditData) obj).getUsername());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user