From 02fe7ad753d7fb88e7b362958c8dba9f8e919343 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 19 Mar 2021 15:31:13 +1100 Subject: [PATCH 1/3] add a way to copy an open group url --- _locales/en/messages.json | 4 ++++ _locales/fr/messages.json | 8 ++++++++ ts/components/session/menu/Menu.tsx | 7 +++++-- ts/models/conversation.ts | 7 +++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a871d300f..4fb53c2c7 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1062,6 +1062,10 @@ "description": "Copy to clipboard session ID", "androidKey": "activity_conversation_menu_copy_session_id" }, + "copyOpenGroupURL": { + "message": "Copy Group's URL", + "description": "Copy to clipboard Open Group URL" + }, "save": { "message": "Save", "description": "Used as a 'commit changes' button in the Caption Editor for outgoing image attachments", diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index 211b2b7df..ce2ede2c3 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -1221,6 +1221,14 @@ "copy": { "message": "Copier" }, + "copySessionID": { + "message": "Copier le Session ID", + "description": "Copy to clipboard session ID" + }, + "copyOpenGroupURL": { + "message": "Copier l'URL de Group", + "description": "Copy to clipboard Open Group URL" + }, "linkPreviewsTitle": { "message": "Envoyer des aperçus de liens" }, diff --git a/ts/components/session/menu/Menu.tsx b/ts/components/session/menu/Menu.tsx index ff9a0725a..30eb5e38f 100644 --- a/ts/components/session/menu/Menu.tsx +++ b/ts/components/session/menu/Menu.tsx @@ -32,8 +32,9 @@ function showDeleteMessages(isPublic: boolean): boolean { return !isPublic; } +// we want to show the copyId for open groups and private chats only function showCopyId(isPublic: boolean, isGroup: boolean): boolean { - return !isGroup; // || isPublic; + return !isGroup || isPublic; } function showDeleteContact( @@ -196,7 +197,9 @@ export function getCopyMenuItem( i18n: LocalizerType ): JSX.Element | null { if (showCopyId(Boolean(isPublic), Boolean(isGroup))) { - const copyIdLabel = i18n('copySessionID'); + const copyIdLabel = isPublic + ? i18n('copyOpenGroupURL') + : i18n('copySessionID'); return {copyIdLabel}; } return null; diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index a5f73b657..1c93332ba 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1351,6 +1351,13 @@ export class ConversationModel extends Backbone.Model { } public copyPublicKey() { + if (this.isPublic()) { + const openGroupUrl = this.id.substr(this.id.indexOf('@') + 1); + window.clipboard.writeText(openGroupUrl); + + ToastUtils.pushCopiedToClipBoard(); + return; + } window.clipboard.writeText(this.id); ToastUtils.pushCopiedToClipBoard(); From 1f509e003d707d59c9219edf208bb05b97421cda Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 19 Mar 2021 15:50:46 +1100 Subject: [PATCH 2/3] add a markAllAsRead option on menus --- _locales/en/messages.json | 4 ++++ _locales/fr/messages.json | 4 ++++ ts/components/ConversationListItem.tsx | 2 +- .../conversation/ConversationHeader.tsx | 2 ++ .../conversation/SessionConversation.tsx | 4 ++++ .../session/menu/ConversationHeaderMenu.tsx | 4 ++++ .../menu/ConversationListItemContextMenu.tsx | 5 +++++ ts/components/session/menu/Menu.tsx | 7 +++++++ ts/models/conversation.ts | 4 +++- ts/state/ducks/conversations.ts | 19 ++++++++++--------- 10 files changed, 44 insertions(+), 11 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 4fb53c2c7..93139c59f 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -453,6 +453,10 @@ "unverify": { "message": "Mark As Not Verified" }, + "markAllAsRead": { + "message": "Mark All as Read", + "description": "Shown on a menu to mark the whole convo as read." + }, "isNotVerified": { "message": "You have not verified your safety number with $name$.", "description": "Summary state shown at top of the safety number screen if user has not verified contact.", diff --git a/_locales/fr/messages.json b/_locales/fr/messages.json index ce2ede2c3..cd4d099bc 100644 --- a/_locales/fr/messages.json +++ b/_locales/fr/messages.json @@ -363,6 +363,10 @@ } } }, + "markAllAsRead": { + "message": "Tout Marquer Comme Lu", + "description": "Shown on a menu to mark the whole convo as read." + }, "isNotVerified": { "message": "Vous n’avez pas vérifié votre numéro de sécurité avec $name$", "description": "Summary state shown at top of the safety number screen if user has not verified contact.", diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index c436a7992..643b5fa46 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -42,6 +42,7 @@ type PropsHousekeeping = { onUnblockContact?: () => void; onInviteContacts?: () => void; onClearNickname?: () => void; + onMarkAllRead: () => void; theme: DefaultTheme; }; @@ -62,7 +63,6 @@ class ConversationListItem extends React.PureComponent { public renderAvatar() { const { avatarPath, - i18n, name, phoneNumber, profileName, diff --git a/ts/components/conversation/ConversationHeader.tsx b/ts/components/conversation/ConversationHeader.tsx index f291de213..c6a28b013 100644 --- a/ts/components/conversation/ConversationHeader.tsx +++ b/ts/components/conversation/ConversationHeader.tsx @@ -83,6 +83,8 @@ interface Props { onAvatarClick?: (userPubKey: string) => void; onUpdateGroupName: () => void; + onMarkAllRead: () => void; + memberAvatars?: Array; // this is added by usingClosedConversationDetails theme: DefaultTheme; } diff --git a/ts/components/session/conversation/SessionConversation.tsx b/ts/components/session/conversation/SessionConversation.tsx index 6becc6e27..57073b6e8 100644 --- a/ts/components/session/conversation/SessionConversation.tsx +++ b/ts/components/session/conversation/SessionConversation.tsx @@ -434,6 +434,10 @@ export class SessionConversation extends React.Component { window.Whisper.events.trigger('inviteContacts', conversation); }, + onMarkAllRead: () => { + void conversation.markReadBouncy(Date.now()); + }, + onAddModerators: () => { window.Whisper.events.trigger('addModerators', conversation); }, diff --git a/ts/components/session/menu/ConversationHeaderMenu.tsx b/ts/components/session/menu/ConversationHeaderMenu.tsx index 9dcd0a37e..967e7e2ad 100644 --- a/ts/components/session/menu/ConversationHeaderMenu.tsx +++ b/ts/components/session/menu/ConversationHeaderMenu.tsx @@ -4,6 +4,7 @@ import { getAddModeratorsMenuItem, getBlockMenuItem, getCopyMenuItem, + getMarkAllReadMenuItem, getDeleteContactMenuItem, getDeleteMessagesMenuItem, getDisappearingMenuItem, @@ -31,6 +32,7 @@ export type PropsConversationHeaderMenu = { onInviteContacts?: () => void; onLeaveGroup: () => void; + onMarkAllRead: () => void; onAddModerators: () => void; onRemoveModerators: () => void; onUpdateGroupName: () => void; @@ -55,6 +57,7 @@ export const ConversationHeaderMenu = (props: PropsConversationHeaderMenu) => { onDeleteMessages, onDeleteContact, onCopyPublicKey, + onMarkAllRead, onLeaveGroup, onAddModerators, onRemoveModerators, @@ -86,6 +89,7 @@ export const ConversationHeaderMenu = (props: PropsConversationHeaderMenu) => { )} {getCopyMenuItem(isPublic, isGroup, onCopyPublicKey, window.i18n)} + {getMarkAllReadMenuItem(onMarkAllRead, window.i18n)} {getDeleteMessagesMenuItem(isPublic, onDeleteMessages, window.i18n)} {getAddModeratorsMenuItem( isAdmin, diff --git a/ts/components/session/menu/ConversationListItemContextMenu.tsx b/ts/components/session/menu/ConversationListItemContextMenu.tsx index 7c3eadfb5..883a1a62d 100644 --- a/ts/components/session/menu/ConversationListItemContextMenu.tsx +++ b/ts/components/session/menu/ConversationListItemContextMenu.tsx @@ -5,6 +5,7 @@ import { getBlockMenuItem, getClearNicknameMenuItem, getCopyMenuItem, + getMarkAllReadMenuItem, getDeleteContactMenuItem, getDeleteMessagesMenuItem, getInviteContactMenuItem, @@ -25,6 +26,7 @@ export type PropsContextConversationItem = { onDeleteContact?: () => void; onLeaveGroup?: () => void; onBlockContact?: () => void; + onMarkAllRead: () => void; onCopyPublicKey?: () => void; onUnblockContact?: () => void; onInviteContacts?: () => void; @@ -48,6 +50,7 @@ export const ConversationListItemContextMenu = ( onBlockContact, onClearNickname, onCopyPublicKey, + onMarkAllRead, onUnblockContact, onInviteContacts, onLeaveGroup, @@ -81,6 +84,8 @@ export const ConversationListItemContextMenu = ( onCopyPublicKey, window.i18n )} + {getMarkAllReadMenuItem(onMarkAllRead, window.i18n)} + {getDeleteMessagesMenuItem(isPublic, onDeleteMessages, window.i18n)} {getInviteContactMenuItem( type === 'group', diff --git a/ts/components/session/menu/Menu.tsx b/ts/components/session/menu/Menu.tsx index 30eb5e38f..11ce15e1e 100644 --- a/ts/components/session/menu/Menu.tsx +++ b/ts/components/session/menu/Menu.tsx @@ -205,6 +205,13 @@ export function getCopyMenuItem( return null; } +export function getMarkAllReadMenuItem( + action: any, + i18n: LocalizerType +): JSX.Element | null { + return {i18n('markAllAsRead')}; +} + export function getDisappearingMenuItem( isPublic: boolean | undefined, isKickedFromGroup: boolean | undefined, diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 1c93332ba..240974cd5 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -423,6 +423,9 @@ export class ConversationModel extends Backbone.Model { onInviteContacts: () => { window.Whisper.events.trigger('inviteContacts', this); }, + onMarkAllRead: () => { + void this.markReadBouncy(Date.now()); + }, onClearNickname: () => { void this.setLokiProfile({ displayName: null }); }, @@ -468,7 +471,6 @@ export class ConversationModel extends Backbone.Model { } public async getUnreadCount() { - window.log.warn('getUnreadCount is slow'); const unreadCount = await getUnreadCountByConversation(this.id); return unreadCount; diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index f06f85492..aadf704eb 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -87,15 +87,16 @@ export interface ConversationType { groupAdmins?: Array; // admins for closed groups and moderators for open groups members?: Array; // members for closed groups only - onClick?: () => any; - onBlockContact?: () => any; - onUnblockContact?: () => any; - onCopyPublicKey?: () => any; - onDeleteContact?: () => any; - onLeaveGroup?: () => any; - onDeleteMessages?: () => any; - onInviteContacts?: () => any; - onClearNickname?: () => any; + onClick?: () => void; + onBlockContact?: () => void; + onUnblockContact?: () => void; + onCopyPublicKey?: () => void; + onDeleteContact?: () => void; + onLeaveGroup?: () => void; + onDeleteMessages?: () => void; + onInviteContacts?: () => void; + onMarkAllRead?: () => void; + onClearNickname?: () => void; } export type ConversationLookupType = { From c7d140f4d4bc99275a0a7927381b2059dfbb8cc8 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 22 Mar 2021 09:55:49 +1100 Subject: [PATCH 3/3] lint --- ts/components/session/menu/ConversationHeaderMenu.tsx | 2 +- ts/components/session/menu/ConversationListItemContextMenu.tsx | 2 +- ts/models/conversation.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ts/components/session/menu/ConversationHeaderMenu.tsx b/ts/components/session/menu/ConversationHeaderMenu.tsx index 967e7e2ad..84cc3e950 100644 --- a/ts/components/session/menu/ConversationHeaderMenu.tsx +++ b/ts/components/session/menu/ConversationHeaderMenu.tsx @@ -4,12 +4,12 @@ import { getAddModeratorsMenuItem, getBlockMenuItem, getCopyMenuItem, - getMarkAllReadMenuItem, getDeleteContactMenuItem, getDeleteMessagesMenuItem, getDisappearingMenuItem, getInviteContactMenuItem, getLeaveGroupMenuItem, + getMarkAllReadMenuItem, getRemoveModeratorsMenuItem, getUpdateGroupNameMenuItem, } from './Menu'; diff --git a/ts/components/session/menu/ConversationListItemContextMenu.tsx b/ts/components/session/menu/ConversationListItemContextMenu.tsx index 883a1a62d..a8db5274b 100644 --- a/ts/components/session/menu/ConversationListItemContextMenu.tsx +++ b/ts/components/session/menu/ConversationListItemContextMenu.tsx @@ -5,11 +5,11 @@ import { getBlockMenuItem, getClearNicknameMenuItem, getCopyMenuItem, - getMarkAllReadMenuItem, getDeleteContactMenuItem, getDeleteMessagesMenuItem, getInviteContactMenuItem, getLeaveGroupMenuItem, + getMarkAllReadMenuItem, } from './Menu'; export type PropsContextConversationItem = { diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 240974cd5..dec179e1e 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1354,7 +1354,8 @@ export class ConversationModel extends Backbone.Model { public copyPublicKey() { if (this.isPublic()) { - const openGroupUrl = this.id.substr(this.id.indexOf('@') + 1); + const atIndex = this.id.indexOf('@') as number; + const openGroupUrl = this.id.substr(atIndex + 1); window.clipboard.writeText(openGroupUrl); ToastUtils.pushCopiedToClipBoard();