store roster groups in DB
This commit is contained in:
parent
405445afbe
commit
acb297ac96
|
@ -6,8 +6,10 @@ import androidx.room.Dao;
|
|||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import androidx.room.Transaction;
|
||||
import com.google.common.collect.Collections2;
|
||||
import eu.siacs.conversations.xmpp.Jid;
|
||||
import im.conversations.android.database.entity.RosterItemEntity;
|
||||
import im.conversations.android.database.entity.RosterItemGroupEntity;
|
||||
import im.conversations.android.database.model.Account;
|
||||
import im.conversations.android.xmpp.model.roster.Item;
|
||||
import java.util.Collection;
|
||||
|
@ -33,7 +35,9 @@ public abstract class RosterDao {
|
|||
clear(account.id);
|
||||
for (final Item item : rosterItems) {
|
||||
final long id = insert(RosterItemEntity.of(account.id, item));
|
||||
// TODO insert groups
|
||||
insertRosterGroups(
|
||||
Collections2.transform(
|
||||
item.getGroups(), name -> RosterItemGroupEntity.of(id, name)));
|
||||
}
|
||||
setRosterVersion(account.id, version);
|
||||
}
|
||||
|
@ -50,8 +54,13 @@ public abstract class RosterDao {
|
|||
}
|
||||
final RosterItemEntity entity = RosterItemEntity.of(account.id, item);
|
||||
final long id = insert(entity);
|
||||
// TODO groups
|
||||
insertRosterGroups(
|
||||
Collections2.transform(
|
||||
item.getGroups(), name -> RosterItemGroupEntity.of(id, name)));
|
||||
}
|
||||
setRosterVersion(account.id, version);
|
||||
}
|
||||
|
||||
@Insert
|
||||
protected abstract void insertRosterGroups(Collection<RosterItemGroupEntity> entities);
|
||||
}
|
||||
|
|
|
@ -23,4 +23,11 @@ public class RosterItemGroupEntity {
|
|||
@NonNull public Long rosterItemId;
|
||||
|
||||
public String name;
|
||||
|
||||
public static RosterItemGroupEntity of(long rosterItemId, final String name) {
|
||||
final var entity = new RosterItemGroupEntity();
|
||||
entity.rosterItemId = rosterItemId;
|
||||
entity.name = name;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package im.conversations.android.xmpp.model.roster;
|
||||
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
|
||||
public class Group extends Extension {
|
||||
|
||||
public Group() {
|
||||
super(Group.class);
|
||||
}
|
||||
}
|
|
@ -1,11 +1,15 @@
|
|||
package im.conversations.android.xmpp.model.roster;
|
||||
|
||||
import com.google.common.collect.Collections2;
|
||||
import eu.siacs.conversations.xml.Element;
|
||||
import eu.siacs.conversations.xmpp.Jid;
|
||||
import im.conversations.android.annotation.XmlElement;
|
||||
import im.conversations.android.xmpp.model.Extension;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
@XmlElement
|
||||
public class Item extends Extension {
|
||||
|
@ -38,6 +42,12 @@ public class Item extends Extension {
|
|||
}
|
||||
}
|
||||
|
||||
public Collection<String> getGroups() {
|
||||
return Collections2.filter(
|
||||
Collections2.transform(getExtensions(Group.class), Element::getContent),
|
||||
Objects::nonNull);
|
||||
}
|
||||
|
||||
public enum Subscription {
|
||||
NONE,
|
||||
TO,
|
||||
|
|
Loading…
Reference in a new issue