diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index c6097003c..0cfa6083f 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -494,9 +494,11 @@ const RocketChat = { } AsyncStorage.removeItem(TOKEN_KEY); AsyncStorage.removeItem(`${ TOKEN_KEY }-${ server }`); - setTimeout(() => { + try { database.deleteAll(); - }, 1500); + } catch (error) { + console.warn(error); + } }, disconnect() { try { diff --git a/app/presentation/RoomItem.js b/app/presentation/RoomItem.js index b525adb35..26f91e056 100644 --- a/app/presentation/RoomItem.js +++ b/app/presentation/RoomItem.js @@ -134,7 +134,7 @@ export default class RoomItem extends React.Component { name: PropTypes.string.isRequired, baseUrl: PropTypes.string.isRequired, StoreLastMessage: PropTypes.bool, - _updatedAt: PropTypes.instanceOf(Date), + _updatedAt: PropTypes.string, lastMessage: PropTypes.object, showLastMessage: PropTypes.bool, favorite: PropTypes.bool, @@ -159,10 +159,10 @@ export default class RoomItem extends React.Component { const oldlastMessage = lastMessage; const newLastmessage = nextProps.lastMessage; - if (oldlastMessage && newLastmessage && oldlastMessage.ts.toGMTString() !== newLastmessage.ts.toGMTString()) { + if (oldlastMessage && newLastmessage && oldlastMessage.ts !== newLastmessage.ts) { return true; } - if (_updatedAt && nextProps._updatedAt && nextProps._updatedAt.toGMTString() !== _updatedAt.toGMTString()) { + if (_updatedAt && nextProps._updatedAt && nextProps._updatedAt !== _updatedAt) { return true; } // eslint-disable-next-line react/destructuring-assignment diff --git a/app/sagas/login.js b/app/sagas/login.js index 61bb0fae2..2cda9fdb9 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -102,7 +102,6 @@ const handleLogout = function* handleLogout() { if (server) { try { yield put(appStart('outside')); - // yield delay(300); yield call(logoutCall, { server }); } catch (e) { log('handleLogout', e); diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index 491f1d8ae..48416fdab 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -225,9 +225,9 @@ export default class RoomsListView extends LoggedView { // unread if (showUnread) { this.unread = this.data.filtered('archived != true && open == true').filtered('(unread > 0 || alert == true)'); - unread = this.unread.slice(); + unread = this.removeRealmInstance(this.unread); setTimeout(() => { - this.unread.addListener(() => this.setState({ unread: this.unread.slice() })); + this.unread.addListener(() => this.setState({ unread: this.removeRealmInstance(this.unread) })); }); } else { this.removeListener(unread); @@ -235,9 +235,9 @@ export default class RoomsListView extends LoggedView { // favorites if (showFavorites) { this.favorites = this.data.filtered('f == true'); - favorites = this.favorites.slice(); + favorites = this.removeRealmInstance(this.favorites); setTimeout(() => { - this.favorites.addListener(() => this.setState({ favorites: this.favorites.slice() })); + this.favorites.addListener(() => this.setState({ favorites: this.removeRealmInstance(this.favorites) })); }); } else { this.removeListener(favorites); @@ -246,21 +246,25 @@ export default class RoomsListView extends LoggedView { if (groupByType) { // channels this.channels = this.data.filtered('t == $0', 'c'); - channels = this.channels.slice(); + channels = this.removeRealmInstance(this.channels); + // private this.privateGroup = this.data.filtered('t == $0', 'p'); - privateGroup = this.privateGroup.slice(); + privateGroup = this.removeRealmInstance(this.privateGroup); + // direct this.direct = this.data.filtered('t == $0', 'd'); - direct = this.direct.slice(); + direct = this.removeRealmInstance(this.direct); + // livechat this.livechat = this.data.filtered('t == $0', 'l'); - livechat = this.livechat.slice(); + livechat = this.removeRealmInstance(this.livechat); + setTimeout(() => { - this.channels.addListener(() => this.setState({ channels: this.channels.slice() })); - this.privateGroup.addListener(() => this.setState({ privateGroup: this.privateGroup.slice() })); - this.direct.addListener(() => this.setState({ direct: this.direct.slice() })); - this.livechat.addListener(() => this.setState({ livechat: this.livechat.slice() })); + this.channels.addListener(() => this.setState({ channels: this.removeRealmInstance(this.channels) })); + this.privateGroup.addListener(() => this.setState({ privateGroup: this.removeRealmInstance(this.privateGroup) })); + this.direct.addListener(() => this.setState({ direct: this.removeRealmInstance(this.direct) })); + this.livechat.addListener(() => this.setState({ livechat: this.removeRealmInstance(this.livechat) })); }); this.removeListener(this.chats); } else { @@ -270,9 +274,12 @@ export default class RoomsListView extends LoggedView { } else { this.chats = this.data; } - chats = this.chats.slice(); + chats = this.removeRealmInstance(this.chats); + setTimeout(() => { - this.chats.addListener(() => this.setState({ chats: this.chats.slice() })); + this.chats.addListener(() => { + this.setState({ chats: this.removeRealmInstance(this.chats) }); + }); }); this.removeListener(this.channels); this.removeListener(this.privateGroup); @@ -290,6 +297,11 @@ export default class RoomsListView extends LoggedView { }, 200); } + removeRealmInstance = (data) => { + const array = Array.from(data); + return JSON.parse(JSON.stringify(array)); + } + removeListener = (data) => { if (data && data.removeAllListeners) { data.removeAllListeners();