From 273d866b98be07a5f47de0362c742649ae80559d Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 2 Dec 2021 16:22:14 +1100 Subject: [PATCH] Cleanup message request (#2063) * close incoming call dialog if endCall from seame sender * disable message request toggle if featureFlag is OFF * cleanup UI of message requests * mark all existing conversations as approved in a migration * fix regex with conversationID for opengroups --- app/sql.js | 19 ++++ stylesheets/_session_left_pane.scss | 8 -- ts/components/Avatar.tsx | 1 + ts/components/ConversationListItem.tsx | 107 +++++++++++------- .../session/SessionClosableOverlay.tsx | 11 +- ts/opengroup/utils/OpenGroupUtils.ts | 2 +- .../conversations/ConversationController.ts | 12 +- 7 files changed, 98 insertions(+), 62 deletions(-) diff --git a/app/sql.js b/app/sql.js index 5125442f3..0948d915b 100644 --- a/app/sql.js +++ b/app/sql.js @@ -834,6 +834,7 @@ const LOKI_SCHEMA_VERSIONS = [ updateToLokiSchemaVersion14, updateToLokiSchemaVersion15, updateToLokiSchemaVersion16, + updateToLokiSchemaVersion17, ]; function updateToLokiSchemaVersion1(currentVersion, db) { @@ -1227,6 +1228,24 @@ function updateToLokiSchemaVersion16(currentVersion, db) { console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); } +function updateToLokiSchemaVersion17(currentVersion, db) { + const targetVersion = 17; + if (currentVersion >= targetVersion) { + return; + } + console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`); + + db.transaction(() => { + db.exec(` + UPDATE ${CONVERSATIONS_TABLE} SET + json = json_set(json, '$.isApproved', 1) + `); + + writeLokiSchemaVersion(targetVersion, db); + })(); + console.log(`updateToLokiSchemaVersion${targetVersion}: success!`); +} + function writeLokiSchemaVersion(newVersion, db) { db.prepare( `INSERT INTO loki_schema( diff --git a/stylesheets/_session_left_pane.scss b/stylesheets/_session_left_pane.scss index f33fba1df..ade13d4d4 100644 --- a/stylesheets/_session_left_pane.scss +++ b/stylesheets/_session_left_pane.scss @@ -249,14 +249,6 @@ $session-compose-margin: 20px; margin-bottom: 3rem; flex-shrink: 0; } - - .message-request-list__container { - width: 100%; - - .session-button { - margin: $session-margin-xs $session-margin-xs $session-margin-xs 0; - } - } } } .module-search-results { diff --git a/ts/components/Avatar.tsx b/ts/components/Avatar.tsx index dc6d191df..4af7040f9 100644 --- a/ts/components/Avatar.tsx +++ b/ts/components/Avatar.tsx @@ -113,6 +113,7 @@ const AvatarInner = (props: Props) => { )} onClick={e => { e.stopPropagation(); + e.preventDefault(); props.onAvatarClick?.(); }} role="button" diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index f1c56e0a1..01dece988 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -25,7 +25,6 @@ import { useDispatch, useSelector } from 'react-redux'; import { SectionType } from '../state/ducks/section'; import { getFocusedSection } from '../state/selectors/section'; import { ConversationNotificationSettingType } from '../models/conversation'; -import { Flex } from './basic/Flex'; import { forceSyncConfigurationNowIfNeeded } from '../session/utils/syncUtils'; import { updateUserDetailsModal } from '../state/ducks/modalDialog'; import { approveConversation, blockConvoById } from '../interactions/conversationInteractions'; @@ -170,6 +169,8 @@ const MessageItem = (props: { lastMessage?: LastMessageType; isTyping: boolean; unreadCount: number; + isMessageRequest: boolean; + conversationId: string; }) => { const { lastMessage, isTyping, unreadCount } = props; @@ -196,7 +197,11 @@ const MessageItem = (props: { )} - {lastMessage && lastMessage.status ? ( + + {lastMessage && lastMessage.status && !props.isMessageRequest ? ( ) : null} @@ -230,6 +235,64 @@ const AvatarItem = (props: { conversationId: string; isPrivate: boolean }) => { ); }; +const RejectMessageRequestButton = ({ conversationId }: { conversationId: string }) => { + /** + * Removes conversation from requests list, + * adds ID to block list, syncs the block with linked devices. + */ + const handleConversationBlock = async () => { + await blockConvoById(conversationId); + await forceSyncConfigurationNowIfNeeded(); + }; + return ( + + ); +}; + +const ApproveMessageRequestButton = ({ conversationId }: { conversationId: string }) => { + return ( + { + await approveConversation(conversationId); + }} + backgroundColor="var(--color-accent)" + iconColor="var(--color-foreground-primary)" + iconPadding="var(--margins-xs)" + borderRadius="2px" + /> + ); +}; + +const MessageRequestButtons = ({ + conversationId, + isMessageRequest, +}: { + conversationId: string; + isMessageRequest: boolean; +}) => { + if (!isMessageRequest) { + return null; + } + + return ( + <> + + + + ); +}; + // tslint:disable: max-func-body-length const ConversationListItem = (props: Props) => { const { @@ -267,15 +330,6 @@ const ConversationListItem = (props: Props) => { [conversationId] ); - /** - * Removes conversation from requests list, - * adds ID to block list, syncs the block with linked devices. - */ - const handleConversationBlock = async () => { - await blockConvoById(conversationId); - await forceSyncConfigurationNowIfNeeded(); - }; - return (
{ isTyping={!!isTyping} unreadCount={unreadCount || 0} lastMessage={lastMessage} + isMessageRequest={Boolean(isMessageRequest)} + conversationId={conversationId} /> - {isMessageRequest ? ( - - - { - await approveConversation(conversationId); - }} - backgroundColor="var(--color-accent)" - iconColor="var(--color-foreground-primary)" - iconPadding="var(--margins-xs)" - borderRadius="2px" - /> - - ) : null}
diff --git a/ts/components/session/SessionClosableOverlay.tsx b/ts/components/session/SessionClosableOverlay.tsx index 1c280a2c9..897be4bb7 100644 --- a/ts/components/session/SessionClosableOverlay.tsx +++ b/ts/components/session/SessionClosableOverlay.tsx @@ -12,6 +12,7 @@ import { SpacerLG, SpacerMD } from '../basic/Text'; import { useSelector } from 'react-redux'; import { getConversationRequests } from '../../state/selectors/conversations'; import { MemoConversationListItemWithDetails } from '../ConversationListItem'; +import styled from 'styled-components'; export enum SessionClosableOverlayType { Message = 'message', @@ -287,6 +288,12 @@ export class SessionClosableOverlay extends React.Component { } } +const MessageRequestListContainer = styled.div` + width: 100%; + overflow-y: auto; + border: var(--border-session); +`; + /** * A request needs to be be unapproved and not blocked to be valid. * @returns List of message request items @@ -294,7 +301,7 @@ export class SessionClosableOverlay extends React.Component { const MessageRequestList = () => { const conversationRequests = useSelector(getConversationRequests); return ( -
+ {conversationRequests.map(conversation => { return ( { /> ); })} -
+ ); }; diff --git a/ts/opengroup/utils/OpenGroupUtils.ts b/ts/opengroup/utils/OpenGroupUtils.ts index d72048daf..648f6f79f 100644 --- a/ts/opengroup/utils/OpenGroupUtils.ts +++ b/ts/opengroup/utils/OpenGroupUtils.ts @@ -40,7 +40,7 @@ export const openGroupPrefix = 'publicChat:'; export const openGroupPrefixRegex = new RegExp(`^${openGroupPrefix}`); export const openGroupV2ConversationIdRegex = new RegExp( - `${openGroupPrefix}${roomIdV2Regex}@${protocolRegex.source}${hostnameRegex.source}${portRegex}` + `${openGroupPrefix}${roomIdV2Regex}@${openGroupV2ServerUrlRegex.source}` ); /** diff --git a/ts/session/conversations/ConversationController.ts b/ts/session/conversations/ConversationController.ts index 1de41ac0f..3775a17e4 100644 --- a/ts/session/conversations/ConversationController.ts +++ b/ts/session/conversations/ConversationController.ts @@ -1,9 +1,4 @@ -import { - getAllConversations, - getAllGroupsInvolvingId, - removeConversation, - saveConversation, -} from '../../data/data'; +import { getAllConversations, removeConversation, saveConversation } from '../../data/data'; import { ConversationAttributes, ConversationCollection, @@ -181,11 +176,6 @@ export class ConversationController { }); } - public async getAllGroupsInvolvingId(id: string) { - const groups = await getAllGroupsInvolvingId(id); - return groups.map((group: any) => this.conversations.add(group)); - } - public async deleteContact(id: string) { if (!this._initialFetchComplete) { throw new Error('getConversationController().get() needs complete initial fetch');