Skip to content

Commit

Permalink
feat: add block msg requests from sogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Aug 15, 2023
1 parent c875bbe commit 8572957
Show file tree
Hide file tree
Showing 26 changed files with 333 additions and 39 deletions.
3 changes: 3 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@
"clearAll": "Clear All",
"clearDataSettingsTitle": "Clear Data",
"messageRequests": "Message Requests",
"blindedMsgReqsSettingTitle": "Community Message Requests",
"blindedMsgReqsSettingDesc": "Allow message requests from Community conversations.",
"requestsSubtitle": "Pending Requests",
"requestsPlaceholder": "No requests",
"hideRequestBannerDescription": "Hide the Message Request banner until you receive a new message request.",
Expand Down Expand Up @@ -489,6 +491,7 @@
"clearAllConfirmationTitle": "Clear All Message Requests",
"clearAllConfirmationBody": "Are you sure you want to clear all message requests?",
"noMessagesInReadOnly": "There are no messages in <b>$name$</b>.",
"noMessagesInBlindedDisabledMsgRequests": "<b>$name$</b> has message requests from Community conversations turned off, so you cannot send them a message.",
"noMessagesInNoteToSelf": "You have no messages in <b>$name$</b>.",
"noMessagesInEverythingElse": "You have no messages from <b>$name$</b>. Send a message to start the conversation!",
"hideBanner": "Hide",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"glob": "7.1.2",
"image-type": "^4.1.0",
"ip2country": "1.0.1",
"libsession_util_nodejs": "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.2.5/libsession_util_nodejs-v0.2.5.tar.gz",
"libsession_util_nodejs": "https://github.com/oxen-io/libsession-util-nodejs/releases/download/v0.2.6/libsession_util_nodejs-v0.2.6.tar.gz",
"libsodium-wrappers-sumo": "^0.7.9",
"linkify-it": "^4.0.1",
"lodash": "^4.17.21",
Expand Down
1 change: 1 addition & 0 deletions protos/SignalService.proto
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ message DataMessage {
optional OpenGroupInvitation openGroupInvitation = 102;
optional ClosedGroupControlMessage closedGroupControlMessage = 104;
optional string syncTarget = 105;
optional bool blocksCommunityMessageRequests = 106;
// optional GroupMessage groupMessage = 120;
}

Expand Down
8 changes: 7 additions & 1 deletion ts/components/conversation/SubtleNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
getSelectedCanWrite,
useSelectedConversationKey,
useSelectedHasDisabledBlindedMsgRequests,
useSelectedNicknameOrProfileNameOrShortenedPubkey,
useSelectedisNoteToSelf,
} from '../../state/selectors/selectedConversation';
Expand Down Expand Up @@ -61,6 +62,7 @@ export const NoMessageInConversation = () => {

const isMe = useSelectedisNoteToSelf();
const canWrite = useSelector(getSelectedCanWrite);
const privateBlindedAndBlockingMsgReqs = useSelectedHasDisabledBlindedMsgRequests();
// TODOLATER use this selector accross the whole application (left pane excluded)
const nameToRender = useSelectedNicknameOrProfileNameOrShortenedPubkey();

Expand All @@ -69,7 +71,11 @@ export const NoMessageInConversation = () => {
}
let localizedKey: LocalizerKeys = 'noMessagesInEverythingElse';
if (!canWrite) {
localizedKey = 'noMessagesInReadOnly';
if (privateBlindedAndBlockingMsgReqs) {
localizedKey = 'noMessagesInBlindedDisabledMsgRequests';
} else {
localizedKey = 'noMessagesInReadOnly';
}
} else if (isMe) {
localizedKey = 'noMessagesInNoteToSelf';
}
Expand Down
2 changes: 1 addition & 1 deletion ts/components/conversation/composition/CompositionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class CompositionBoxInner extends React.Component<Props, State> {
{typingEnabled && (
<ToggleEmojiButton ref={this.emojiPanelButton} onClick={this.toggleEmojiPanel} />
)}
<SendMessageButton onClick={this.onSendMessage} />
{typingEnabled && <SendMessageButton onClick={this.onSendMessage} />}
{typingEnabled && showEmojiPanel && (
<StyledEmojiPanelContainer role="button">
<SessionEmojiPanel
Expand Down
6 changes: 6 additions & 0 deletions ts/components/leftpane/ActionsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
import { isDarkTheme } from '../../state/selectors/theme';
import { ThemeStateType } from '../../themes/constants/colors';
import { switchThemeTo } from '../../themes/switchTheme';
import { ConfigurationSync } from '../../session/utils/job_runners/jobs/ConfigurationSyncJob';

const Section = (props: { type: SectionType }) => {
const ourNumber = useSelector(getOurNumber);
Expand Down Expand Up @@ -213,6 +214,11 @@ const doAppStartUp = async () => {
// this call does nothing except calling the constructor, which will continue sending message in the pipeline
void getMessageQueue().processAllPending();
}, 3000);

global.setTimeout(() => {
// Schedule a confSyncJob in some time to let anything incoming from the network be applied and see if there is a push needed
void ConfigurationSync.queueNewJobIfNeeded();
}, 20000);
};

async function fetchReleaseFromFSAndUpdateMain() {
Expand Down
25 changes: 23 additions & 2 deletions ts/components/settings/section/CategoryPrivacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ import { SessionButtonColor } from '../../basic/SessionButton';
import { SpacerLG } from '../../basic/Text';
import { TypingBubble } from '../../conversation/TypingBubble';

import { UserUtils } from '../../../session/utils';
import { ConfigurationSync } from '../../../session/utils/job_runners/jobs/ConfigurationSyncJob';
import { SessionUtilUserProfile } from '../../../session/utils/libsession/libsession_utils_user_profile';
import {
useHasBlindedMsgRequestsEnabled,
useHasLinkPreviewEnabled,
} from '../../../state/selectors/settings';
import { Storage } from '../../../util/storage';
import { SessionSettingButtonItem, SessionToggleWithDescription } from '../SessionSettingListItem';
import { displayPasswordModal } from '../SessionSettings';
import { Storage } from '../../../util/storage';
import { useHasLinkPreviewEnabled } from '../../../state/selectors/settings';

async function toggleLinkPreviews(isToggleOn: boolean, forceUpdate: () => void) {
if (!isToggleOn) {
Expand Down Expand Up @@ -50,6 +56,7 @@ export const SettingsCategoryPrivacy = (props: {
}) => {
const forceUpdate = useUpdate();
const isLinkPreviewsOn = useHasLinkPreviewEnabled();
const areBlindedRequestsEnabled = useHasBlindedMsgRequestsEnabled();

if (props.hasPassword !== null) {
return (
Expand Down Expand Up @@ -83,6 +90,20 @@ export const SettingsCategoryPrivacy = (props: {
description={window.i18n('linkPreviewDescription')}
active={isLinkPreviewsOn}
/>
<SessionToggleWithDescription
onClickToggle={async () => {
const toggledValue = !areBlindedRequestsEnabled;
await window.setSettingValue(SettingsKey.hasBlindedMsgRequestsSetting, toggledValue);
await SessionUtilUserProfile.insertUserProfileIntoWrapper(
UserUtils.getOurPubKeyStrFromCache()
);
await ConfigurationSync.queueNewJobIfNeeded();
forceUpdate();
}}
title={window.i18n('blindedMsgReqsSettingTitle')}
description={window.i18n('blindedMsgReqsSettingDesc')}
active={areBlindedRequestsEnabled}
/>

{!props.hasPassword && (
<SessionSettingButtonItem
Expand Down
2 changes: 2 additions & 0 deletions ts/data/settings-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const settingsAutoUpdate = 'auto-update';
const settingsMenuBar = 'hide-menu-bar';
const settingsSpellCheck = 'spell-check';
const settingsLinkPreview = 'link-preview-setting';
const hasBlindedMsgRequestsSetting = 'hasBlindedMsgRequestsSetting';
const settingsStartInTray = 'start-in-tray-setting';
const settingsOpengroupPruning = 'prune-setting';
const settingsNotification = 'notification-setting';
Expand All @@ -28,6 +29,7 @@ export const SettingsKey = {
settingsLinkPreview,
settingsStartInTray,
settingsOpengroupPruning,
hasBlindedMsgRequestsSetting,
settingsNotification,
settingsAudioNotification,
someDeviceOutdatedSyncing,
Expand Down
35 changes: 35 additions & 0 deletions ts/models/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isEmpty,
isEqual,
isFinite,
isNil,
isNumber,
isString,
sortBy,
Expand Down Expand Up @@ -291,6 +292,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
toRet.isMarkedUnread = !!this.get('markedAsUnread');
}

const blocksSogsMsgReqsTimestamp = this.get('blocksSogsMsgReqsTimestamp');
if (blocksSogsMsgReqsTimestamp) {
toRet.blocksSogsMsgReqsTimestamp = blocksSogsMsgReqsTimestamp;
}

if (isPrivate) {
toRet.isPrivate = true;
if (this.typingTimer) {
Expand Down Expand Up @@ -1243,6 +1249,35 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return !!this.get('markedAsUnread');
}

public async updateBlocksSogsMsgReqsTimestamp(
blocksSogsMsgReqsTimestamp: number,
shouldCommit: boolean = true
) {
if (!PubKey.isBlinded(this.id)) {
return; // that sogs thing only applies to blinded conversations
}

if (
(isNil(this.get('blocksSogsMsgReqsTimestamp')) && !isNil(blocksSogsMsgReqsTimestamp)) ||
(blocksSogsMsgReqsTimestamp === 0 && this.get('blocksSogsMsgReqsTimestamp') !== 0) ||
blocksSogsMsgReqsTimestamp > this.get('blocksSogsMsgReqsTimestamp')
) {
this.set({
blocksSogsMsgReqsTimestamp,
});
if (shouldCommit) {
await this.commit();
}
}
}

public blocksSogsMsgReqsTimestamp(): number {
if (!PubKey.isBlinded(this.id)) {
return 0; // that sogs thing only applies to blinded conversations
}
return this.get('blocksSogsMsgReqsTimestamp') || 0;
}

/**
* Mark a private conversation as approved to the specified value.
* Does not do anything on non private chats.
Expand Down
3 changes: 3 additions & 0 deletions ts/models/conversationAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export interface ConversationAttributes {
didApproveMe: boolean; // if our message request was approved already (or they've sent us a message request/message themselves). If isApproved & didApproveMe, a message request becomes a contact

markedAsUnread: boolean; // Force the conversation as unread even if all the messages are read. Used to highlight a conversation the user wants to check again later, synced.

blocksSogsMsgReqsTimestamp: number; // if that convo is a blinded one and that user denied be contacted through sogs, this field will be set to his latest message timestamp
}

/**
Expand Down Expand Up @@ -133,6 +135,7 @@ export const fillConvoAttributesWithDefaults = (
left: false,
priority: CONVERSATION_PRIORITIES.default,
markedAsUnread: false,
blocksSogsMsgReqsTimestamp: 0,
});
};

Expand Down
8 changes: 7 additions & 1 deletion ts/node/database_utility.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { difference, omit, pick } from 'lodash';
import { difference, isNumber, omit, pick } from 'lodash';
import * as BetterSqlite3 from '@signalapp/better-sqlite3';
import {
ConversationAttributes,
Expand Down Expand Up @@ -72,6 +72,7 @@ const allowedKeysFormatRowOfConversation = [
'displayNameInProfile',
'conversationIdOrigin',
'markedAsUnread',
'blocksSogsMsgReqsTimestamp',
'priority',
];

Expand Down Expand Up @@ -138,6 +139,10 @@ export function formatRowOfConversation(
convo.lastMessageStatus = undefined;
}

if (!isNumber(convo.blocksSogsMsgReqsTimestamp)) {
convo.blocksSogsMsgReqsTimestamp = 0;
}

if (!convo.triggerNotificationsFor) {
convo.triggerNotificationsFor = 'all';
}
Expand Down Expand Up @@ -189,6 +194,7 @@ const allowedKeysOfConversationAttributes = [
'displayNameInProfile',
'conversationIdOrigin',
'markedAsUnread',
'blocksSogsMsgReqsTimestamp',
'priority',
];

Expand Down
Loading

0 comments on commit 8572957

Please sign in to comment.