Skip to content

Commit

Permalink
fix: redirect to last active conversation when social channel opened …
Browse files Browse the repository at this point in the history
…in messenger (#2689)
  • Loading branch information
domw30 authored Feb 21, 2025
1 parent 866c8c4 commit 63b4a2b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
53 changes: 53 additions & 0 deletions src/store/chat/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ describe(performValidateActiveConversation, () => {
[matchers.call.fn(getRoomIdForAlias), 'room-id'],
[matchers.call.fn(joinRoom), undefined],
[matchers.call.fn(openFirstConversation), null],
[
matchers.call.fn(getHistory),
{
location: { pathname: '/conversation/some-id' },
},
],
]);
}

Expand Down Expand Up @@ -122,6 +128,53 @@ describe(performValidateActiveConversation, () => {
.call(joinRoom, '#some-other-convo:matrix.org')
.run();
});

it('opens first conversation when social channel is accessed from messenger app', async () => {
const initialState = new StoreBuilder().withCurrentUser({ id: 'current-user' }).withConversationList({
id: 'social-channel',
name: 'Social Channel',
isSocialChannel: true,
});

await subject(performValidateActiveConversation, 'social-channel')
.withReducer(rootReducer, initialState.build())
.provide([
[matchers.call.fn(getRoomIdForAlias), 'social-channel'],
[
matchers.call.fn(getHistory),
{
location: { pathname: '/conversation/social-channel' },
},
],
])
.call(openFirstConversation)
.run();
});

it('does not redirect social channel when accessed from feed app', async () => {
const initialState = new StoreBuilder().withCurrentUser({ id: 'current-user' }).withConversationList({
id: 'social-channel',
name: 'Social Channel',
isSocialChannel: true,
});

await subject(performValidateActiveConversation, 'social-channel')
.withReducer(rootReducer, initialState.build())
.provide([
[matchers.call.fn(getRoomIdForAlias), 'social-channel'],
[
matchers.call.fn(getHistory),
{
location: { pathname: '/feed/social-channel' },
},
],
[matchers.call.fn(markConversationAsRead), undefined],
])
.put(rawSetActiveConversationId('social-channel'))
.call(markConversationAsRead, 'social-channel')
.not.call(openFirstConversation)
.run();
});
});

describe(isMemberOfActiveConversation, () => {
Expand Down
13 changes: 12 additions & 1 deletion src/store/chat/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { receive } from '../users';
import { chat, getRoomIdForAlias, isRoomMember } from '../../lib/chat';
import { ConversationEvents, getConversationsBus } from '../channels-list/channels';
import { getHistory } from '../../lib/browser';
import { markConversationAsRead, openFirstConversation } from '../channels/saga';
import { markConversationAsRead, openFirstConversation, rawChannelSelector } from '../channels/saga';
import { translateJoinRoomApiError, parseAlias, isAlias, extractDomainFromAlias } from './utils';
import { joinRoom as apiJoinRoom } from './api';
import { rawConversationsList } from '../channels-list/selectors';
Expand Down Expand Up @@ -182,6 +182,10 @@ export function* setWhenUserJoinedRoom(conversationId: string) {
}

export function* performValidateActiveConversation(activeConversationId: string) {
const history = yield call(getHistory);
const currentPath = history.location.pathname;
const isMessengerApp = currentPath.startsWith('/conversation');

if (!activeConversationId) {
yield put(clearJoinRoomErrorContent());
yield call(openFirstConversation);
Expand All @@ -194,6 +198,13 @@ export function* performValidateActiveConversation(activeConversationId: string)
conversationId = yield call(getRoomIdForAlias, activeConversationId);
}

const conversation = yield select(rawChannelSelector(conversationId));
if (conversation?.isSocialChannel && isMessengerApp) {
// If it's a social channel and accessed from messenger app, open the last active conversation instead
yield call(openFirstConversation);
return;
}

if (!conversationId || !(yield call(isMemberOfActiveConversation, conversationId))) {
yield call(joinRoom, activeConversationId);
return;
Expand Down

0 comments on commit 63b4a2b

Please sign in to comment.