Fix issue where auto closed DMs would not show again (#1689)

* Fix issue where auto closed DMs would not show again

* Fix lint error

* Review feedback
This commit is contained in:
Chris Duarte 2018-05-22 09:26:09 -07:00 committed by Elias Nahum
parent 8e0d167f95
commit 4cebfdfd5d
2 changed files with 14 additions and 9 deletions

View file

@ -332,7 +332,7 @@ export function insertToDraft(value) {
};
}
export function toggleDMChannel(otherUserId, visible) {
export function toggleDMChannel(otherUserId, visible, channelId) {
return async (dispatch, getState) => {
const state = getState();
const {currentUserId} = state.entities.users;
@ -342,6 +342,11 @@ export function toggleDMChannel(otherUserId, visible) {
category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
name: otherUserId,
value: visible,
}, {
user_id: currentUserId,
category: Preferences.CATEGORY_CHANNEL_OPEN_TIME,
name: channelId,
value: Date.now().toString(),
}];
savePreferences(currentUserId, dm)(dispatch, getState);

View file

@ -13,22 +13,22 @@ export function makeDirectChannel(otherUserId) {
const channelName = getDirectChannelName(currentUserId, otherUserId);
const {channels, myMembers} = state.entities.channels;
getProfilesByIds([otherUserId])(dispatch, getState);
getStatusesByIds([otherUserId])(dispatch, getState);
dispatch(getProfilesByIds([otherUserId]));
dispatch(getStatusesByIds([otherUserId]));
let result;
let channel = Object.values(channels).find((c) => c.name === channelName);
if (channel && myMembers[channel.id]) {
result = {data: channel};
toggleDMChannel(otherUserId, 'true')(dispatch, getState);
dispatch(toggleDMChannel(otherUserId, 'true', channel.id));
} else {
result = await createDirectChannel(currentUserId, otherUserId)(dispatch, getState);
channel = result.data;
}
if (channel) {
handleSelectChannel(channel.id)(dispatch, getState);
dispatch(handleSelectChannel(channel.id));
}
return result;
@ -40,15 +40,15 @@ export function makeGroupChannel(otherUserIds) {
const state = getState();
const {currentUserId} = state.entities.users;
getProfilesByIds(otherUserIds)(dispatch, getState);
getStatusesByIds(otherUserIds)(dispatch, getState);
dispatch(getProfilesByIds(otherUserIds));
dispatch(getStatusesByIds(otherUserIds));
const result = await createGroupChannel([currentUserId, ...otherUserIds])(dispatch, getState);
const channel = result.data;
if (channel) {
toggleGMChannel(channel.id, 'true')(dispatch, getState);
handleSelectChannel(channel.id)(dispatch, getState);
dispatch(toggleGMChannel(channel.id, 'true'));
dispatch(handleSelectChannel(channel.id));
}
return result;