mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-23 05:13:04 +03:00
Merge pull request #1061 from esteemapp/bugfix/logout-pincode
Fixed logout realm issue
This commit is contained in:
commit
0e26f12139
@ -114,11 +114,17 @@ if (Array.from(settings).length <= 0) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const convertToArray = realmObjectsArray => {
|
||||||
|
const copyOfJsonArray = Array.from(realmObjectsArray);
|
||||||
|
const jsonArray = JSON.parse(JSON.stringify(copyOfJsonArray));
|
||||||
|
return jsonArray;
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: This is getting ALL user data, we should change this method with getUserDataWithUsername
|
// TODO: This is getting ALL user data, we should change this method with getUserDataWithUsername
|
||||||
export const getUserData = () =>
|
export const getUserData = () =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const user = Array.from(realm.objects(USER_SCHEMA));
|
const user = convertToArray(realm.objects(USER_SCHEMA));
|
||||||
resolve(user);
|
resolve(user);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
@ -137,7 +143,7 @@ export const getSelectedUser = username =>
|
|||||||
|
|
||||||
export const getUserDataWithUsername = username => {
|
export const getUserDataWithUsername = username => {
|
||||||
try {
|
try {
|
||||||
const user = Array.from(realm.objects(USER_SCHEMA).filtered('username = $0', username));
|
const user = convertToArray(realm.objects(USER_SCHEMA).filtered('username = $0', username));
|
||||||
return user;
|
return user;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
@ -167,7 +173,7 @@ export const updateUserData = userData =>
|
|||||||
try {
|
try {
|
||||||
const account = realm.objects(USER_SCHEMA).filtered('username = $0', userData.username);
|
const account = realm.objects(USER_SCHEMA).filtered('username = $0', userData.username);
|
||||||
|
|
||||||
if (Array.from(account).length > 0) {
|
if (convertToArray(account).length > 0) {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
account[0].masterKey = userData.masterKey;
|
account[0].masterKey = userData.masterKey;
|
||||||
account[0].activeKey = userData.activeKey;
|
account[0].activeKey = userData.activeKey;
|
||||||
@ -187,11 +193,8 @@ export const updateUserData = userData =>
|
|||||||
export const removeUserData = username =>
|
export const removeUserData = username =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const account = Object.assign(
|
const account = Array.from(realm.objects(USER_SCHEMA).filtered('username = $0', username));
|
||||||
[],
|
if (convertToArray(account).length > 0) {
|
||||||
realm.objects(USER_SCHEMA).filtered('username = $0', username),
|
|
||||||
);
|
|
||||||
if (Array.from(account).length > 0) {
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
realm.delete(account);
|
realm.delete(account);
|
||||||
resolve();
|
resolve();
|
||||||
@ -242,7 +245,7 @@ export const setDraftPost = (fields, username) =>
|
|||||||
const draft = realm.objects(DRAFT_SCHEMA).filtered('username = $0', username);
|
const draft = realm.objects(DRAFT_SCHEMA).filtered('username = $0', username);
|
||||||
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
if (Array.from(draft).length > 0) {
|
if (convertToArray(draft).length > 0) {
|
||||||
draft[0].title = fields.title;
|
draft[0].title = fields.title;
|
||||||
draft[0].tags = fields.tags;
|
draft[0].tags = fields.tags;
|
||||||
draft[0].body = fields.body;
|
draft[0].body = fields.body;
|
||||||
@ -265,7 +268,7 @@ export const setDraftPost = (fields, username) =>
|
|||||||
export const getDraftPost = username =>
|
export const getDraftPost = username =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const draft = Array.from(realm.objects(DRAFT_SCHEMA).filtered('username = $0', username));
|
const draft = convertToArray(realm.objects(DRAFT_SCHEMA).filtered('username = $0', username));
|
||||||
resolve(draft[0]);
|
resolve(draft[0]);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
@ -291,7 +294,7 @@ export const setAuthStatus = authStatus =>
|
|||||||
try {
|
try {
|
||||||
const auth = realm.objects(AUTH_SCHEMA);
|
const auth = realm.objects(AUTH_SCHEMA);
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
if (Array.from(auth).length > 0) {
|
if (convertToArray(auth).length > 0) {
|
||||||
auth[0].isLoggedIn = authStatus.isLoggedIn;
|
auth[0].isLoggedIn = authStatus.isLoggedIn;
|
||||||
resolve(auth[0]);
|
resolve(auth[0]);
|
||||||
} else {
|
} else {
|
||||||
@ -309,7 +312,7 @@ export const updateCurrentUsername = username =>
|
|||||||
try {
|
try {
|
||||||
const auth = realm.objects(AUTH_SCHEMA);
|
const auth = realm.objects(AUTH_SCHEMA);
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
if (Array.from(auth).length > 0) {
|
if (convertToArray(auth).length > 0) {
|
||||||
auth[0].currentUsername = username;
|
auth[0].currentUsername = username;
|
||||||
resolve(auth[0]);
|
resolve(auth[0]);
|
||||||
} else {
|
} else {
|
||||||
@ -616,7 +619,7 @@ export const setPushTokenSaved = pushTokenSaved =>
|
|||||||
try {
|
try {
|
||||||
const application = realm.objects(APPLICATION_SCHEMA);
|
const application = realm.objects(APPLICATION_SCHEMA);
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
if (Array.from(application).length > 0) {
|
if (convertToArray(application).length > 0) {
|
||||||
application[0].isPushTokenSaved = pushTokenSaved;
|
application[0].isPushTokenSaved = pushTokenSaved;
|
||||||
resolve(application[0]);
|
resolve(application[0]);
|
||||||
} else {
|
} else {
|
||||||
@ -655,7 +658,7 @@ export const setExistUser = existUser =>
|
|||||||
try {
|
try {
|
||||||
const application = realm.objects(APPLICATION_SCHEMA);
|
const application = realm.objects(APPLICATION_SCHEMA);
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
if (Array.from(application).length > 0) {
|
if (convertToArray(application).length > 0) {
|
||||||
application[0].isExistUser = existUser;
|
application[0].isExistUser = existUser;
|
||||||
resolve(application[0]);
|
resolve(application[0]);
|
||||||
} else {
|
} else {
|
||||||
@ -678,7 +681,7 @@ export const setSCAccount = data =>
|
|||||||
const date = new Date();
|
const date = new Date();
|
||||||
date.setSeconds(date.getSeconds() + data.expires_in);
|
date.setSeconds(date.getSeconds() + data.expires_in);
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
if (Array.from(scAccount).length > 0) {
|
if (convertToArray(scAccount).length > 0) {
|
||||||
scAccount[0].refreshToken = data.refresh_token;
|
scAccount[0].refreshToken = data.refresh_token;
|
||||||
scAccount[0].expireDate = date.toString();
|
scAccount[0].expireDate = date.toString();
|
||||||
resolve();
|
resolve();
|
||||||
@ -702,7 +705,7 @@ export const getSCAccount = username =>
|
|||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const scAccount = realm.objects(SC_ACCOUNTS).filtered('username = $0', username);
|
const scAccount = realm.objects(SC_ACCOUNTS).filtered('username = $0', username);
|
||||||
if (Array.from(scAccount).length > 0) {
|
if (convertToArray(scAccount).length > 0) {
|
||||||
resolve(scAccount[0]);
|
resolve(scAccount[0]);
|
||||||
} else {
|
} else {
|
||||||
resolve(false);
|
resolve(false);
|
||||||
@ -717,7 +720,7 @@ export const removeSCAccount = username =>
|
|||||||
try {
|
try {
|
||||||
const scAccount = realm.objects(SC_ACCOUNTS).filtered('username = $0', username);
|
const scAccount = realm.objects(SC_ACCOUNTS).filtered('username = $0', username);
|
||||||
|
|
||||||
if (Array.from(scAccount).length > 0) {
|
if (convertToArray(scAccount).length > 0) {
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
realm.delete(scAccount);
|
realm.delete(scAccount);
|
||||||
resolve();
|
resolve();
|
||||||
|
Loading…
Reference in New Issue
Block a user