mirror of
https://github.com/etesync/android
synced 2025-07-06 14:52:35 +00:00
Local resources: fix the mess of find by username/uid being all mixed up.
We were searching by filename but the function was called uid and other such mixups. This change should now fix all of them by having a function for each that actually does the right thing.
This commit is contained in:
parent
97d1a40e49
commit
bc44062e93
@ -346,7 +346,7 @@ class LocalAddressBook(
|
|||||||
return reallyDirty
|
return reallyDirty
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun findByFilename(uid: String): LocalAddress? {
|
override fun findByUid(uid: String): LocalAddress? {
|
||||||
val found = findContactByUID(uid)
|
val found = findContactByUID(uid)
|
||||||
if (found != null) {
|
if (found != null) {
|
||||||
return found
|
return found
|
||||||
@ -355,6 +355,16 @@ class LocalAddressBook(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun findByFilename(filename: String): LocalAddress? {
|
||||||
|
val found = queryContacts("${AndroidContact.COLUMN_FILENAME}=?", arrayOf(filename)).firstOrNull()
|
||||||
|
|
||||||
|
if (found != null) {
|
||||||
|
return found
|
||||||
|
} else {
|
||||||
|
return queryGroups("${AndroidGroup.COLUMN_FILENAME}=?", arrayOf(filename)).firstOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun findGroupById(id: Long): LocalGroup =
|
fun findGroupById(id: Long): LocalGroup =
|
||||||
queryGroups("${Groups._ID}=?", arrayOf(id.toString())).firstOrNull()
|
queryGroups("${Groups._ID}=?", arrayOf(id.toString())).firstOrNull()
|
||||||
?: throw FileNotFoundException()
|
?: throw FileNotFoundException()
|
||||||
|
@ -21,7 +21,9 @@ import at.bitfire.ical4android.*
|
|||||||
import com.etesync.syncadapter.CachedCollection
|
import com.etesync.syncadapter.CachedCollection
|
||||||
import com.etesync.syncadapter.log.Logger
|
import com.etesync.syncadapter.log.Logger
|
||||||
import com.etesync.syncadapter.model.JournalEntity
|
import com.etesync.syncadapter.model.JournalEntity
|
||||||
|
import com.etesync.syncadapter.resource.LocalEvent.Companion.COLUMN_UID
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
|
import org.dmfs.tasks.contract.TaskContract
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
@ -178,8 +180,11 @@ class LocalCalendar private constructor(
|
|||||||
override fun findAll(): List<LocalEvent>
|
override fun findAll(): List<LocalEvent>
|
||||||
= queryEvents(null, null)
|
= queryEvents(null, null)
|
||||||
|
|
||||||
override fun findByFilename(uid: String): LocalEvent?
|
override fun findByUid(uid: String): LocalEvent?
|
||||||
= queryEvents(Events._SYNC_ID + " =? ", arrayOf(uid)).firstOrNull()
|
= queryEvents(COLUMN_UID + " =? ", arrayOf(uid)).firstOrNull()
|
||||||
|
|
||||||
|
override fun findByFilename(filename: String): LocalEvent?
|
||||||
|
= queryEvents(Events._SYNC_ID + " =? ", arrayOf(filename)).firstOrNull()
|
||||||
|
|
||||||
fun processDirtyExceptions() {
|
fun processDirtyExceptions() {
|
||||||
// process deleted exceptions
|
// process deleted exceptions
|
||||||
|
@ -16,7 +16,8 @@ interface LocalCollection<out T: LocalResource<*>> {
|
|||||||
fun findWithoutFileName(): List<T>
|
fun findWithoutFileName(): List<T>
|
||||||
fun findAll(): List<T>
|
fun findAll(): List<T>
|
||||||
|
|
||||||
fun findByFilename(uid: String): T?
|
fun findByUid(uid: String): T?
|
||||||
|
fun findByFilename(filename: String): T?
|
||||||
|
|
||||||
|
|
||||||
fun count(): Long
|
fun count(): Long
|
||||||
|
@ -63,7 +63,7 @@ class LocalGroup : AndroidGroup, LocalAddress {
|
|||||||
// insert memberships
|
// insert memberships
|
||||||
val membersIds = members.map {uid ->
|
val membersIds = members.map {uid ->
|
||||||
Constants.log.fine("Assigning member: $uid")
|
Constants.log.fine("Assigning member: $uid")
|
||||||
val contact = addressBook.findByFilename(uid) as LocalContact?
|
val contact = addressBook.findByUid(uid) as LocalContact?
|
||||||
if (contact != null) contact.id else null
|
if (contact != null) contact.id else null
|
||||||
}.filterNotNull()
|
}.filterNotNull()
|
||||||
|
|
||||||
|
@ -124,8 +124,11 @@ class LocalTaskList private constructor(
|
|||||||
override fun findWithoutFileName(): List<LocalTask>
|
override fun findWithoutFileName(): List<LocalTask>
|
||||||
= queryTasks(Tasks._SYNC_ID + " IS NULL", null)
|
= queryTasks(Tasks._SYNC_ID + " IS NULL", null)
|
||||||
|
|
||||||
override fun findByFilename(uid: String): LocalTask?
|
override fun findByUid(uid: String): LocalTask?
|
||||||
= queryTasks(Tasks._SYNC_ID + " =? ", arrayOf(uid)).firstOrNull()
|
= queryTasks(LocalTask.COLUMN_UID + " =? ", arrayOf(uid)).firstOrNull()
|
||||||
|
|
||||||
|
override fun findByFilename(filename: String): LocalTask?
|
||||||
|
= queryTasks(Tasks._SYNC_ID + " =? ", arrayOf(filename)).firstOrNull()
|
||||||
|
|
||||||
override fun count(): Long {
|
override fun count(): Long {
|
||||||
try {
|
try {
|
||||||
|
@ -119,7 +119,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
}
|
}
|
||||||
|
|
||||||
val event = events[0]
|
val event = events[0]
|
||||||
val local = localCollection!!.findByFilename(event.uid!!)
|
val local = localCollection!!.findByUid(event.uid!!)
|
||||||
|
|
||||||
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
||||||
legacyProcessEvent(event, local)
|
legacyProcessEvent(event, local)
|
||||||
|
@ -13,7 +13,6 @@ import android.content.*
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import at.bitfire.ical4android.CalendarStorageException
|
import at.bitfire.ical4android.CalendarStorageException
|
||||||
import at.bitfire.ical4android.Event
|
|
||||||
import at.bitfire.vcard4android.BatchOperation
|
import at.bitfire.vcard4android.BatchOperation
|
||||||
import at.bitfire.vcard4android.Contact
|
import at.bitfire.vcard4android.Contact
|
||||||
import at.bitfire.vcard4android.ContactsStorageException
|
import at.bitfire.vcard4android.ContactsStorageException
|
||||||
@ -132,9 +131,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun processItem(item: Item) {
|
override fun processItem(item: Item) {
|
||||||
val uid = item.meta.name!!
|
val local = localCollection!!.findByFilename(item.uid)
|
||||||
|
|
||||||
val local = localCollection!!.findByFilename(uid)
|
|
||||||
|
|
||||||
if (!item.isDeleted) {
|
if (!item.isDeleted) {
|
||||||
val inputReader = StringReader(String(item.content))
|
val inputReader = StringReader(String(item.content))
|
||||||
@ -154,7 +151,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
Logger.log.info("Removing local record which has been deleted on the server")
|
Logger.log.info("Removing local record which has been deleted on the server")
|
||||||
local.delete()
|
local.delete()
|
||||||
} else {
|
} else {
|
||||||
Logger.log.warning("Tried deleting a non-existent record: " + uid)
|
Logger.log.warning("Tried deleting a non-existent record: " + item.uid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +168,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
Logger.log.warning("Received multiple VCards, using first one")
|
Logger.log.warning("Received multiple VCards, using first one")
|
||||||
|
|
||||||
val contact = contacts[0]
|
val contact = contacts[0]
|
||||||
val local = localCollection!!.findByFilename(contact.uid!!)
|
val local = localCollection!!.findByUid(contact.uid!!)
|
||||||
|
|
||||||
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
||||||
legacyProcessContact(contact, local)
|
legacyProcessContact(contact, local)
|
||||||
|
@ -109,7 +109,7 @@ class TasksSyncManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val event = tasks[0]
|
val event = tasks[0]
|
||||||
val local = localCollection!!.findByFilename(event.uid!!)
|
val local = localCollection!!.findByUid(event.uid!!)
|
||||||
|
|
||||||
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
||||||
legacyProcessTask(event, local)
|
legacyProcessTask(event, local)
|
||||||
|
@ -108,7 +108,7 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
|||||||
val provider = contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!!
|
val provider = contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!!
|
||||||
val localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info.uid!!)!!
|
val localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info.uid!!)!!
|
||||||
val event = Event.eventsFromReader(StringReader(syncEntry.content))[0]
|
val event = Event.eventsFromReader(StringReader(syncEntry.content))[0]
|
||||||
var localEvent = localCalendar.findByFilename(event.uid!!)
|
var localEvent = localCalendar.findByUid(event.uid!!)
|
||||||
if (localEvent != null) {
|
if (localEvent != null) {
|
||||||
localEvent.updateAsDirty(event)
|
localEvent.updateAsDirty(event)
|
||||||
} else {
|
} else {
|
||||||
@ -121,7 +121,7 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
|||||||
val provider = TaskProvider.acquire(this, it)!!
|
val provider = TaskProvider.acquire(this, it)!!
|
||||||
val localTaskList = LocalTaskList.findByName(account, provider, LocalTaskList.Factory, info.uid!!)!!
|
val localTaskList = LocalTaskList.findByName(account, provider, LocalTaskList.Factory, info.uid!!)!!
|
||||||
val task = Task.tasksFromReader(StringReader(syncEntry.content))[0]
|
val task = Task.tasksFromReader(StringReader(syncEntry.content))[0]
|
||||||
var localTask = localTaskList.findByFilename(task.uid!!)
|
var localTask = localTaskList.findByUid(task.uid!!)
|
||||||
if (localTask != null) {
|
if (localTask != null) {
|
||||||
localTask.updateAsDirty(task)
|
localTask.updateAsDirty(task)
|
||||||
} else {
|
} else {
|
||||||
@ -137,7 +137,7 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
|||||||
if (contact.group) {
|
if (contact.group) {
|
||||||
// FIXME: not currently supported
|
// FIXME: not currently supported
|
||||||
} else {
|
} else {
|
||||||
var localContact = localAddressBook.findByFilename(contact.uid!!) as LocalContact?
|
var localContact = localAddressBook.findByUid(contact.uid!!) as LocalContact?
|
||||||
if (localContact != null) {
|
if (localContact != null) {
|
||||||
localContact.updateAsDirty(contact)
|
localContact.updateAsDirty(contact)
|
||||||
} else {
|
} else {
|
||||||
|
@ -250,7 +250,7 @@ class ImportFragment(private val account: Account, private val uid: String, priv
|
|||||||
|
|
||||||
for (event in events) {
|
for (event in events) {
|
||||||
try {
|
try {
|
||||||
var localEvent = localCalendar.findByFilename(event.uid!!)
|
var localEvent = localCalendar.findByUid(event.uid!!)
|
||||||
if (localEvent != null) {
|
if (localEvent != null) {
|
||||||
localEvent.updateAsDirty(event)
|
localEvent.updateAsDirty(event)
|
||||||
result.updated++
|
result.updated++
|
||||||
@ -304,7 +304,7 @@ class ImportFragment(private val account: Account, private val uid: String, priv
|
|||||||
|
|
||||||
for (task in tasks) {
|
for (task in tasks) {
|
||||||
try {
|
try {
|
||||||
var localTask = localTaskList.findByFilename(task.uid!!)
|
var localTask = localTaskList.findByUid(task.uid!!)
|
||||||
if (localTask != null) {
|
if (localTask != null) {
|
||||||
localTask.updateAsDirty(task)
|
localTask.updateAsDirty(task)
|
||||||
result.updated++
|
result.updated++
|
||||||
@ -348,7 +348,7 @@ class ImportFragment(private val account: Account, private val uid: String, priv
|
|||||||
|
|
||||||
for (contact in contacts.filter { contact -> !contact.group }) {
|
for (contact in contacts.filter { contact -> !contact.group }) {
|
||||||
try {
|
try {
|
||||||
var localContact = localAddressBook.findByFilename(contact.uid!!) as LocalContact?
|
var localContact = localAddressBook.findByUid(contact.uid!!) as LocalContact?
|
||||||
|
|
||||||
if (localContact != null) {
|
if (localContact != null) {
|
||||||
localContact.updateAsDirty(contact)
|
localContact.updateAsDirty(contact)
|
||||||
@ -381,7 +381,7 @@ class ImportFragment(private val account: Account, private val uid: String, priv
|
|||||||
}
|
}
|
||||||
|
|
||||||
val group = contact
|
val group = contact
|
||||||
var localGroup: LocalGroup? = localAddressBook.findByFilename(group.uid!!) as LocalGroup?
|
var localGroup: LocalGroup? = localAddressBook.findByUid(group.uid!!) as LocalGroup?
|
||||||
|
|
||||||
if (localGroup != null) {
|
if (localGroup != null) {
|
||||||
localGroup.updateAsDirty(group, memberIds)
|
localGroup.updateAsDirty(group, memberIds)
|
||||||
|
@ -214,7 +214,7 @@ class LocalCalendarImportFragment(private val account: Account, private val uid:
|
|||||||
var localEvent = if (event == null || event.uid == null)
|
var localEvent = if (event == null || event.uid == null)
|
||||||
null
|
null
|
||||||
else
|
else
|
||||||
localCalendar.findByFilename(event.uid!!)
|
localCalendar.findByUid(event.uid!!)
|
||||||
|
|
||||||
if (localEvent != null) {
|
if (localEvent != null) {
|
||||||
localEvent.updateAsDirty(event!!)
|
localEvent.updateAsDirty(event!!)
|
||||||
|
@ -152,7 +152,7 @@ class LocalContactImportFragment(private val account: Account, private val uid:
|
|||||||
var localContact: LocalContact? = if (contact.uid == null)
|
var localContact: LocalContact? = if (contact.uid == null)
|
||||||
null
|
null
|
||||||
else
|
else
|
||||||
addressBook.findByFilename(contact.uid!!) as LocalContact?
|
addressBook.findByUid(contact.uid!!) as LocalContact?
|
||||||
|
|
||||||
if (localContact != null) {
|
if (localContact != null) {
|
||||||
localContact.updateAsDirty(contact)
|
localContact.updateAsDirty(contact)
|
||||||
@ -183,7 +183,7 @@ class LocalContactImportFragment(private val account: Account, private val uid:
|
|||||||
var localGroup: LocalGroup? = if (group.uid == null)
|
var localGroup: LocalGroup? = if (group.uid == null)
|
||||||
null
|
null
|
||||||
else
|
else
|
||||||
addressBook.findByFilename(group.uid!!) as LocalGroup?
|
addressBook.findByUid(group.uid!!) as LocalGroup?
|
||||||
|
|
||||||
if (localGroup != null) {
|
if (localGroup != null) {
|
||||||
localGroup.updateAsDirty(group, members)
|
localGroup.updateAsDirty(group, members)
|
||||||
|
Loading…
Reference in New Issue
Block a user