50 lines
1.7 KiB
Java
50 lines
1.7 KiB
Java
package org.mercury_im.messenger.persistence.room.dao;
|
|
|
|
import androidx.room.Dao;
|
|
import androidx.room.Insert;
|
|
import androidx.room.Query;
|
|
import androidx.room.TypeConverters;
|
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
|
import org.mercury_im.messenger.persistence.room.model.RoomContactAttributes;
|
|
import org.mercury_im.messenger.persistence.room.type_converter.EntityBareJidConverter;
|
|
|
|
import java.util.List;
|
|
|
|
import io.reactivex.Maybe;
|
|
import io.reactivex.Observable;
|
|
import io.reactivex.Single;
|
|
|
|
import static androidx.room.OnConflictStrategy.REPLACE;
|
|
|
|
@Dao
|
|
@TypeConverters(EntityBareJidConverter.class)
|
|
public interface ContactAttributesDao extends BaseDao<RoomContactAttributes> {
|
|
|
|
@Override
|
|
@Insert(onConflict = REPLACE)
|
|
Single<Long> insert(RoomContactAttributes entity);
|
|
|
|
@Query("SELECT * FROM contacts WHERE pk_contact_id = :id")
|
|
Maybe<RoomContactAttributes> getContact(long id);
|
|
|
|
@Query("SELECT * FROM contacts WHERE fk_entity_id = :entityId")
|
|
Maybe<RoomContactAttributes> getContactForEntityId(long entityId);
|
|
|
|
/**
|
|
* Return a {@link Observable} wrapping a {@link List} of all {@link RoomContactAttributes RosterEntries}
|
|
* which are currently found in the database.
|
|
*
|
|
* @return
|
|
*/
|
|
@Query("SELECT * FROM contacts")
|
|
Observable<List<RoomContactAttributes>> getAllContacts();
|
|
|
|
@Query("SELECT contacts.* FROM contacts JOIN entities " +
|
|
"WHERE contacts.fk_account_id = :accountId AND jid = :jid")
|
|
Maybe<RoomContactAttributes> getContactByJid(long accountId, EntityBareJid jid);
|
|
|
|
@Query("SELECT * FROM contacts WHERE fk_account_id = :accountId")
|
|
Observable<List<RoomContactAttributes>> getContactsForAccount(long accountId);
|
|
}
|