Update group name modal dialog fixes
This commit is contained in:
parent
9e5824cee1
commit
59b02a5ed4
|
@ -138,7 +138,7 @@
|
|||
|
||||
|
||||
<!-- DIALOGS-->
|
||||
<script type='text/javascript' src='js/views/update_group_dialog_view.js'></script>
|
||||
<!-- <script type='text/javascript' src='js/views/update_group_dialog_view.js'></script> -->
|
||||
<script type='text/javascript' src='js/views/invite_contacts_dialog_view.js'></script>
|
||||
<script type='text/javascript' src='js/views/admin_leave_closed_group_dialog_view.js'></script>
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import { ConversationController } from '../../session/conversations';
|
|||
|
||||
import _ from 'lodash';
|
||||
import { Text } from '../basic/Text';
|
||||
import { SessionWrapperModal } from '../session/SessionWrapperModal';
|
||||
|
||||
interface Props {
|
||||
titleText: string;
|
||||
|
@ -51,8 +52,8 @@ export class UpdateGroupMembersDialog extends React.Component<Props, State> {
|
|||
const name = nickname
|
||||
? nickname
|
||||
: lokiProfile
|
||||
? lokiProfile.displayName
|
||||
: window.i18n('anonymous');
|
||||
? lokiProfile.displayName
|
||||
: window.i18n('anonymous');
|
||||
|
||||
const existingMember = this.props.existingMembers.includes(d.id);
|
||||
|
||||
|
@ -125,7 +126,7 @@ export class UpdateGroupMembersDialog extends React.Component<Props, State> {
|
|||
const hasZombies = Boolean(existingZombies.length);
|
||||
|
||||
return (
|
||||
<SessionModal
|
||||
<SessionWrapperModal
|
||||
title={titleText}
|
||||
// tslint:disable-next-line: no-void-expression
|
||||
onClose={() => this.closeDialog()}
|
||||
|
@ -152,7 +153,7 @@ export class UpdateGroupMembersDialog extends React.Component<Props, State> {
|
|||
/>
|
||||
)}
|
||||
</div>
|
||||
</SessionModal>
|
||||
</SessionWrapperModal>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -230,56 +231,6 @@ export class UpdateGroupMembersDialog extends React.Component<Props, State> {
|
|||
}
|
||||
}
|
||||
|
||||
private async onSubmit(newMembers) {
|
||||
const _ = window.Lodash;
|
||||
const ourPK = window.libsession.Utils.UserUtils.getOurPubKeyStrFromCache();
|
||||
|
||||
const allMembersAfterUpdate = window.Lodash.concat(newMembers, [ourPK]);
|
||||
|
||||
if (!this.isAdmin) {
|
||||
window.log.warn('Skipping update of members, we are not the admin');
|
||||
return;
|
||||
}
|
||||
// new members won't include the zombies. We are the admin and we want to remove them not matter what
|
||||
|
||||
// We need to NOT trigger an group update if the list of member is the same.
|
||||
// we need to merge all members, including zombies for this call.
|
||||
|
||||
// we consider that the admin ALWAYS wants to remove zombies (actually they should be removed
|
||||
// automatically by him when the LEFT message is received)
|
||||
const allExistingMembersWithZombies = _.uniq(
|
||||
this.existingMembers.concat(this.existingZombies)
|
||||
);
|
||||
|
||||
const notPresentInOld = allMembersAfterUpdate.filter(
|
||||
m => !allExistingMembersWithZombies.includes(m)
|
||||
);
|
||||
|
||||
// be sure to include zombies in here
|
||||
const membersToRemove = allExistingMembersWithZombies.filter(
|
||||
m => !allMembersAfterUpdate.includes(m)
|
||||
);
|
||||
|
||||
const xor = _.xor(membersToRemove, notPresentInOld);
|
||||
if (xor.length === 0) {
|
||||
window.log.info('skipping group update: no detected changes in group member list');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If any extra devices of removed exist in newMembers, ensure that you filter them
|
||||
// Note: I think this is useless
|
||||
const filteredMembers = allMembersAfterUpdate.filter(
|
||||
member => !_.includes(membersToRemove, member)
|
||||
);
|
||||
|
||||
window.libsession.ClosedGroup.initiateGroupUpdate(
|
||||
this.groupId,
|
||||
this.groupName,
|
||||
filteredMembers,
|
||||
this.avatarPath
|
||||
);
|
||||
}
|
||||
|
||||
// Return members that would comprise the group given the
|
||||
// current state in `users`
|
||||
|
|
|
@ -6,7 +6,7 @@ import classNames from 'classnames';
|
|||
|
||||
import { SessionCompositionBox, StagedAttachmentType } from './SessionCompositionBox';
|
||||
|
||||
import { ClosedGroup, Constants } from '../../../session';
|
||||
import { ClosedGroup, Constants, Utils } from '../../../session';
|
||||
import _ from 'lodash';
|
||||
import { AttachmentUtil, GoogleChrome } from '../../../util';
|
||||
import { ConversationHeaderWithDetails } from '../../conversation/ConversationHeader';
|
||||
|
@ -35,6 +35,9 @@ import { SessionButtonColor } from '../SessionButton';
|
|||
import { AddModeratorsDialog } from '../../conversation/ModeratorsAddDialog';
|
||||
import { RemoveModeratorsDialog } from '../../conversation/ModeratorsRemoveDialog';
|
||||
import { UpdateGroupNameDialog } from '../../conversation/UpdateGroupNameDialog';
|
||||
import { UpdateGroupMembersDialog } from '../../conversation/UpdateGroupMembersDialog';
|
||||
import { getOurNumber } from '../../../state/selectors/user';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
|
||||
|
||||
|
@ -517,13 +520,15 @@ export class SessionConversation extends React.Component<Props, State> {
|
|||
this.setState({ ...this.state, modal: null })
|
||||
}
|
||||
|
||||
const onUpdateGroupNameSubmit = (groupName: string, avatar: string) => {
|
||||
ClosedGroup.initiateGroupUpdate(
|
||||
groupId,
|
||||
groupName,
|
||||
members,
|
||||
avatar
|
||||
)
|
||||
const onUpdateGroupNameSubmit = (newGroupName: string, newAvatarPath: string) => {
|
||||
if (newGroupName !== groupName || newAvatarPath !== avatarPath) {
|
||||
ClosedGroup.initiateGroupUpdate(
|
||||
groupId,
|
||||
newGroupName,
|
||||
members,
|
||||
newAvatarPath
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({
|
||||
|
@ -549,6 +554,9 @@ export class SessionConversation extends React.Component<Props, State> {
|
|||
|
||||
},
|
||||
onUpdateGroupMembers: async () => {
|
||||
// window.Whisper.events.trigger('updateGroupMembers', conversation);
|
||||
// return;
|
||||
|
||||
if (conversation.isMediumGroup()) {
|
||||
// make sure all the members' convo exists so we can add or remove them
|
||||
await Promise.all(
|
||||
|
@ -562,7 +570,126 @@ export class SessionConversation extends React.Component<Props, State> {
|
|||
)
|
||||
);
|
||||
}
|
||||
window.Whisper.events.trigger('updateGroupMembers', conversation);
|
||||
|
||||
|
||||
const groupName = conversation.getName();
|
||||
const isPublic = conversation.isPublic();
|
||||
const groupId = conversation.id;
|
||||
const members = conversation.get('members') || [];
|
||||
const avatarPath = conversation.getAvatarPath();
|
||||
const theme = this.props.theme;
|
||||
|
||||
const titleText = window.i18n('updateGroupDialogTitle', groupName);
|
||||
|
||||
const ourPK = Utils.UserUtils.getOurPubKeyStrFromCache();
|
||||
|
||||
let admins = conversation.get('groupAdmins');
|
||||
const isAdmin = conversation.get('groupAdmins')?.includes(ourPK) ? true : false;
|
||||
|
||||
|
||||
const convos = ConversationController.getInstance().getConversations()
|
||||
.filter(d => !!d);
|
||||
|
||||
let existingMembers = conversation.get('members') || [];
|
||||
let existingZombies = conversation.get('zombies') || [];
|
||||
|
||||
|
||||
let contactsAndMembers = convos.filter(
|
||||
d => existingMembers.includes(d.id) && d.isPrivate() && !d.isMe()
|
||||
);
|
||||
|
||||
|
||||
// contactsAndMembers = _.uniqBy(contactsAndMembers, true, d => d.id);
|
||||
contactsAndMembers = _.uniqBy(contactsAndMembers, 'id');
|
||||
|
||||
|
||||
// at least make sure it's an array
|
||||
if (!Array.isArray(existingMembers)) {
|
||||
existingMembers = [];
|
||||
}
|
||||
|
||||
|
||||
const onClose = () => {
|
||||
this.setState({
|
||||
...this.state,
|
||||
modal: null
|
||||
})
|
||||
}
|
||||
|
||||
const onSubmit = async (newMembers: string[]) => {
|
||||
const _ = window.Lodash;
|
||||
const ourPK = Utils.UserUtils.getOurPubKeyStrFromCache();
|
||||
|
||||
const allMembersAfterUpdate = window.Lodash.concat(newMembers, [ourPK]);
|
||||
|
||||
if (!isAdmin) {
|
||||
window.log.warn('Skipping update of members, we are not the admin');
|
||||
return;
|
||||
}
|
||||
// new members won't include the zombies. We are the admin and we want to remove them not matter what
|
||||
|
||||
// We need to NOT trigger an group update if the list of member is the same.
|
||||
// we need to merge all members, including zombies for this call.
|
||||
|
||||
// we consider that the admin ALWAYS wants to remove zombies (actually they should be removed
|
||||
// automatically by him when the LEFT message is received)
|
||||
const allExistingMembersWithZombies = _.uniq(
|
||||
existingMembers.concat(existingZombies)
|
||||
);
|
||||
|
||||
const notPresentInOld = allMembersAfterUpdate.filter(
|
||||
(m: string) => !allExistingMembersWithZombies.includes(m)
|
||||
);
|
||||
|
||||
// be sure to include zombies in here
|
||||
const membersToRemove = allExistingMembersWithZombies.filter(
|
||||
(m: string) => !allMembersAfterUpdate.includes(m)
|
||||
);
|
||||
|
||||
const xor = _.xor(membersToRemove, notPresentInOld);
|
||||
if (xor.length === 0) {
|
||||
window.log.info('skipping group update: no detected changes in group member list');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If any extra devices of removed exist in newMembers, ensure that you filter them
|
||||
// Note: I think this is useless
|
||||
const filteredMembers = allMembersAfterUpdate.filter(
|
||||
(member: string) => !_.includes(membersToRemove, member)
|
||||
);
|
||||
|
||||
ClosedGroup.initiateGroupUpdate(
|
||||
groupId,
|
||||
groupName,
|
||||
filteredMembers,
|
||||
avatarPath
|
||||
);
|
||||
}
|
||||
|
||||
this.setState({
|
||||
...this.state,
|
||||
modal: (<UpdateGroupMembersDialog
|
||||
titleText={titleText}
|
||||
isPublic={isPublic}
|
||||
admins={admins || []}
|
||||
onSubmit={onSubmit}
|
||||
onClose={onClose}
|
||||
okText={window.i18n('ok')}
|
||||
cancelText={window.i18n('cancel')}
|
||||
contactList={contactsAndMembers}
|
||||
|
||||
isAdmin={isAdmin}
|
||||
i18n={window.i18n}
|
||||
|
||||
existingMembers={existingMembers}
|
||||
existingZombies={existingZombies}
|
||||
|
||||
theme={this.props.theme}
|
||||
/>)
|
||||
})
|
||||
|
||||
// warrick: delete old code
|
||||
},
|
||||
onInviteContacts: () => {
|
||||
window.Whisper.events.trigger('inviteContacts', conversation);
|
||||
|
|
Loading…
Reference in New Issue