[FIX] Logout (#497)

* [FIX] Logout

* Removed realm instances on rooms list
This commit is contained in:
Diego Mello 2018-10-18 14:56:49 -03:00 committed by GitHub
parent abc61342b0
commit ed1988d64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 20 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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);

View File

@ -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();