Skip to content

Commit

Permalink
refactor(matrix-client): remove sending join event and generating adm…
Browse files Browse the repository at this point in the history
…in message on account creation (#2415)
  • Loading branch information
domw30 authored Nov 8, 2024
1 parent 01dc40b commit 160c32a
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 27 deletions.
5 changes: 0 additions & 5 deletions src/lib/chat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export interface IChatClient {
mentionedUserIds: string[],
data?: Partial<EditMessageOptions>
): Promise<any>;
userJoinedInviterOnZero: (channelId: string, inviterId: string, inviteeId: string) => Promise<any>;
markRoomAsRead: (roomId: string, userId?: string) => Promise<void>;
getSecureBackup: () => Promise<any>;
generateSecureBackup: () => Promise<any>;
Expand Down Expand Up @@ -147,10 +146,6 @@ export class Chat {
return this.client.deleteMessageByRoomId(roomId, messageId);
}

async userJoinedInviterOnZero(channelId: string, inviterId: string, inviteeId: string) {
return this.client.userJoinedInviterOnZero(channelId, inviterId, inviteeId);
}

async editMessage(
roomId: string,
messageId: string,
Expand Down
8 changes: 0 additions & 8 deletions src/lib/chat/matrix-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ export class MatrixClient implements IChatClient {
case EventType.RoomMessage:
return mapMatrixMessage(event, this.matrix);

case CustomEventType.USER_JOINED_INVITER_ON_ZERO:
case EventType.RoomCreate:
return mapEventToAdminMessage(event);

Expand Down Expand Up @@ -714,13 +713,6 @@ export class MatrixClient implements IChatClient {
return await this.mapConversation(room);
}

async userJoinedInviterOnZero(channelId: string, inviterId: string, inviteeId: string) {
this.matrix.sendEvent(channelId, CustomEventType.USER_JOINED_INVITER_ON_ZERO as any, {
inviterId,
inviteeId,
});
}

mxcUrlToHttp(mxcUrl: string, isThumbnail: boolean = false): string {
const height = isThumbnail ? 96 : undefined;
const width = isThumbnail ? 96 : undefined;
Expand Down
2 changes: 0 additions & 2 deletions src/lib/chat/matrix/chat-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ export async function mapEventToPostMessage(matrixMessage, sdkMatrixClient: SDKM

function getAdminDataFromEventType(type, content, sender, targetUserId, previousContent) {
switch (type) {
case CustomEventType.USER_JOINED_INVITER_ON_ZERO:
return { type: AdminMessageType.JOINED_ZERO, inviterId: content.inviterId, inviteeId: content.inviteeId };
case EventType.RoomMember:
return getRoomMemberAdminData(content, targetUserId, previousContent);
case EventType.RoomCreate:
Expand Down
5 changes: 0 additions & 5 deletions src/store/registration/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { completeUserLogin } from '../authentication/saga';
import { createConversation } from '../channels-list/saga';
import { denormalize as denormalizeUser } from '../users';
import { StoreBuilder } from '../test/store';
import { chat } from '../../lib/chat';

describe('validate invite', () => {
it('validates invite code, returns true if VALID', async () => {
Expand Down Expand Up @@ -508,13 +507,10 @@ describe('authorizeAndCreateWeb3Account', () => {
});

describe(createWelcomeConversation, () => {
const chatClient = { userJoinedInviterOnZero: jest.fn() };

function subject(...args: Parameters<typeof expectSaga>) {
return expectSaga(...args).provide([
[matchers.call.fn(getZEROUsersAPI), [{ userId: 'stub-id' }]],
[matchers.call.fn(createConversation), { id: 'conversation-id' }],
[matchers.call.fn(chat.get), chatClient],
]);
}
it('creates the welcome conversation between the inviter and new user', async () => {
Expand All @@ -524,7 +520,6 @@ describe(createWelcomeConversation, () => {
.provide([[call(getZEROUsersAPI, ['inviter-matrix-id']), [{ userId: 'inviter-id', firstName: 'The inviter' }]]])
.withReducer(rootReducer, initialState.build())
.call(createConversation, ['inviter-id'], '', null)
.call([chatClient, chatClient.userJoinedInviterOnZero], 'conversation-id', 'inviter-id', 'new-user-id')
.run();
});

Expand Down
8 changes: 1 addition & 7 deletions src/store/registration/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { getHistory } from '../../lib/browser';
import { setIsComplete as setPageLoadComplete } from '../page-load';
import { createConversation } from '../channels-list/saga';
import { getZEROUsers as getZEROUsersAPI } from '../channels-list/api';
import { chat } from '../../lib/chat';
import { getProvider as getIndexedDbProvider } from '../../lib/storage/idb';
import { receive as receiveUser } from '../users';

Expand Down Expand Up @@ -251,12 +250,7 @@ export function* createWelcomeConversation(userId: string, inviter: { id: string
const inviterZeroUserData = yield call(getZEROUsersAPI, [inviter.matrixId]);
const inviterUser = inviterZeroUserData?.[0];
yield put(receiveUser(inviterUser));

const createdConversation = yield call(createConversation, [inviterUser.userId], '', null);
const createdConversationId = createdConversation.id;

const chatClient = yield call(chat.get);
yield call([chatClient, chatClient.userJoinedInviterOnZero], createdConversationId, inviterUser.userId, userId);
yield call(createConversation, [inviterUser.userId], '', null);
} catch (error) {}
}

Expand Down

0 comments on commit 160c32a

Please sign in to comment.