fix open group invitation logic

pull/1707/head
Audric Ackermann 4 years ago
parent 9ed030fac6
commit a659d5b480
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1,12 +1,11 @@
import React from 'react';
import classNames from 'classnames';
import { SessionButton, SessionButtonType } from '../session/SessionButton';
import { SessionIconButton, SessionIconSize, SessionIconType } from '../session/icon';
import { useTheme } from 'styled-components';
type Props = {
serverName: string;
serverAddress: string;
name: string;
url: string;
direction: string;
onJoinClick: () => void;
};
@ -32,9 +31,9 @@ export const GroupInvitation = (props: Props) => {
onClick={props.onJoinClick}
/>
<span className="group-details">
<span className="group-name">{props.serverName}</span>
<span className="group-name">{props.name}</span>
<span className="group-type">{openGroupInvitation}</span>
<span className="group-address">{props.serverAddress}</span>
<span className="group-address">{props.url}</span>
</span>
</div>
</div>

@ -116,8 +116,8 @@ const InviteContactsDialogInner = (props: Props) => {
if (convo.isOpenGroupV2()) {
const completeUrl = await getCompleteUrlForV2ConvoId(convo.id);
const groupInvitation = {
serverAddress: completeUrl,
serverName: convo.getName(),
url: completeUrl,
name: convo.getName(),
};
pubkeys.forEach(async pubkeyStr => {
const privateConvo = await ConversationController.getInstance().getOrCreateAndWait(

@ -8,7 +8,6 @@ import { ConversationController } from '../session/conversations';
import { PubKey } from '../session/types';
import { ToastUtils } from '../session/utils';
import { useDispatch } from 'react-redux';
import { updateConfirmModal } from '../state/ducks/modalDialog';
export function banUser(userToBan: string, conversationId: string) {
@ -21,9 +20,8 @@ export function banUser(userToBan: string, conversationId: string) {
return;
}
const dispatch = useDispatch();
const onClickClose = () => {
dispatch(updateConfirmModal(null));
window.inboxStore?.dispatch(updateConfirmModal(null));
};
const confirmationModalProps = {
@ -55,7 +53,7 @@ export function banUser(userToBan: string, conversationId: string) {
},
};
dispatch(updateConfirmModal(confirmationModalProps));
window.inboxStore?.dispatch(updateConfirmModal(confirmationModalProps));
}
/**
@ -77,8 +75,7 @@ export function unbanUser(userToUnBan: string, conversationId: string) {
return;
}
const dispatch = useDispatch();
const onClickClose = () => dispatch(updateConfirmModal(null));
const onClickClose = () => window.inboxStore?.dispatch(updateConfirmModal(null));
const onClickOk = async () => {
const conversation = ConversationController.getInstance().get(conversationId);
@ -104,7 +101,7 @@ export function unbanUser(userToUnBan: string, conversationId: string) {
}
};
dispatch(
window.inboxStore?.dispatch(
updateConfirmModal({
title: window.i18n('unbanUser'),
message: window.i18n('unbanUserConfirm'),
@ -168,13 +165,11 @@ export async function addSenderAsModerator(sender: string, convoId: string) {
}
const acceptOpenGroupInvitationV2 = (completeUrl: string, roomName?: string) => {
const dispatch = useDispatch();
const onClickClose = () => {
dispatch(updateConfirmModal(null));
window.inboxStore?.dispatch(updateConfirmModal(null));
};
dispatch(
window.inboxStore?.dispatch(
updateConfirmModal({
title: window.i18n('joinOpenGroupAfterInvitationConfirmationTitle', roomName),
message: window.i18n('joinOpenGroupAfterInvitationConfirmationDesc', roomName),

@ -612,8 +612,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const groupInvitMessage = new GroupInvitationMessage({
identifier: id,
timestamp: sentAt,
serverName: groupInvitation.serverName,
serverAddress: groupInvitation.serverAddress,
name: groupInvitation.name,
url: groupInvitation.url,
expireTimer: this.get('expireTimer'),
});
// we need the return await so that errors are caught in the catch {}

@ -314,18 +314,18 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
let serverAddress = '';
try {
const url = new URL(invitation.serverAddress);
const url = new URL(invitation.url);
serverAddress = url.origin;
} catch (e) {
window?.log?.warn('failed to get hostname from opengroupv2 invitation', invitation);
}
return {
serverName: invitation.serverName,
serverAddress,
serverName: invitation.name,
url: serverAddress,
direction,
onJoinClick: () => {
acceptOpenGroupInvitation(invitation.serverAddress, invitation.serverName);
acceptOpenGroupInvitation(invitation.url, invitation.name);
},
};
}

@ -295,8 +295,8 @@ async function handleRegularMessage(
}
}
if (dataMessage.groupInvitation) {
message.set({ groupInvitation: dataMessage.groupInvitation });
if (dataMessage.openGroupInvitation) {
message.set({ groupInvitation: dataMessage.openGroupInvitation });
}
handleLinkPreviews(dataMessage.body, dataMessage.preview, message);

@ -4,29 +4,29 @@ import { SignalService } from '../../../../protobuf';
import { MessageParams } from '../Message';
interface GroupInvitationMessageParams extends MessageParams {
serverAddress: string;
serverName: string;
url: string;
name: string;
// if there is an expire timer set for the conversation, we need to set it.
// otherwise, it will disable the expire timer on the receiving side.
expireTimer?: number;
}
export class GroupInvitationMessage extends DataMessage {
private readonly serverAddress: string;
private readonly serverName: string;
private readonly url: string;
private readonly name: string;
private readonly expireTimer?: number;
constructor(params: GroupInvitationMessageParams) {
super({ timestamp: params.timestamp, identifier: params.identifier });
this.serverAddress = params.serverAddress;
this.serverName = params.serverName;
this.url = params.url;
this.name = params.name;
this.expireTimer = params.expireTimer;
}
public dataProto(): SignalService.DataMessage {
const openGroupInvitation = new SignalService.DataMessage.OpenGroupInvitation({
url: this.serverAddress,
name: this.serverName,
url: this.url,
name: this.name,
});
return new SignalService.DataMessage({

@ -8,23 +8,23 @@ import { GroupInvitationMessage } from '../../../../session/messages/outgoing/vi
describe('GroupInvitationMessage', () => {
let message: GroupInvitationMessage;
const timestamp = Date.now();
const serverAddress = 'http://localhost';
const serverName = 'test';
const url = 'http://localhost';
const name = 'test';
beforeEach(() => {
message = new GroupInvitationMessage({
timestamp,
serverAddress,
serverName,
url,
name,
});
});
it('dataMessage.groupInvitation has serverAddress, and serverName set', () => {
it('dataMessage.groupInvitation has url, and serverName set', () => {
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.decode(plainText);
expect(decoded.dataMessage?.openGroupInvitation).to.have.property('url', serverAddress);
expect(decoded.dataMessage?.openGroupInvitation).to.have.property('name', serverName);
expect(decoded.dataMessage?.openGroupInvitation).to.have.property('url', url);
expect(decoded.dataMessage?.openGroupInvitation).to.have.property('name', name);
});
it('correct ttl', () => {

Loading…
Cancel
Save