mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-21 14:08:31 -04:00
* Shows notice when user or obs is opted out of Community Taxon on ObsDetails (closes #882) * Unifies mapApiToRealm methods around a single interface * Ensure that the remote obs used on ObsDetail is normalized to look like a local obs * Ensure some tests that use signIn() have isolated Realm instances * Update current user's obs from ObsDetails (closes #1045) * Fixed CC0 license display on ObsDetails (was not actually related to updating the local copy of the obs
77 lines
1.7 KiB
JavaScript
77 lines
1.7 KiB
JavaScript
import { Realm } from "@realm/react";
|
|
import rnUUID from "react-native-uuid";
|
|
|
|
import Flag from "./Flag";
|
|
import Taxon from "./Taxon";
|
|
import User from "./User";
|
|
|
|
class Identification extends Realm.Object {
|
|
static ID_FIELDS = {
|
|
body: true,
|
|
category: true,
|
|
created_at: true,
|
|
current: true,
|
|
disagreement: true,
|
|
id: true,
|
|
flags: Flag.FLAG_FIELDS,
|
|
taxon: Taxon.TAXON_FIELDS,
|
|
updated_at: true,
|
|
// $FlowFixMe
|
|
user: User && ( { ...User.FIELDS, id: true } ),
|
|
uuid: true,
|
|
vision: true
|
|
};
|
|
|
|
static mimicRealmMappedPropertiesSchema( id ) {
|
|
return {
|
|
...id,
|
|
createdAt: id.created_at,
|
|
flags: id.flags || [],
|
|
taxon: Taxon.mapApiToRealm( id.taxon )
|
|
};
|
|
}
|
|
|
|
static mapApiToRealm( id, realm = null ) {
|
|
const newId = {
|
|
...id,
|
|
taxon: Taxon.mapApiToRealm( id.taxon, realm )
|
|
};
|
|
return newId;
|
|
}
|
|
|
|
static new = attrs => {
|
|
const newIdent = {
|
|
...attrs,
|
|
uuid: rnUUID.v4( )
|
|
};
|
|
|
|
return newIdent;
|
|
};
|
|
|
|
static schema = {
|
|
name: "Identification",
|
|
embedded: true,
|
|
properties: {
|
|
uuid: "string",
|
|
body: "string?",
|
|
category: "string?",
|
|
current: "bool",
|
|
created_at: { type: "string", mapTo: "createdAt", optional: true },
|
|
flags: "Flag[]",
|
|
id: "int?",
|
|
taxon: "Taxon?",
|
|
user: "User?",
|
|
vision: "bool?",
|
|
// this creates an inverse relationship so identifications
|
|
// automatically keep track of which Observation they are assigned to
|
|
assignee: {
|
|
type: "linkingObjects",
|
|
objectType: "Observation",
|
|
property: "identifications"
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
export default Identification;
|