message request refactoring.

This commit is contained in:
warrickct 2021-11-22 12:08:48 +11:00
parent 40396224dc
commit 2e2941ba9b
4 changed files with 115 additions and 33 deletions

View file

@ -51,7 +51,7 @@ window.lokiFeatureFlags = {
padOutgoingAttachments: true,
enablePinConversations: true,
useUnsendRequests: false,
useMessageRequests: false,
useMessageRequests: true,
};
window.isBeforeVersion = (toCheck, baseVersion) => {

View file

@ -84,10 +84,6 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
throw new Error('renderRow: Tried to render without conversations');
}
const messageRequestsEnabled =
window.inboxStore?.getState().userConfig.messageRequests === true &&
window?.lokiFeatureFlags?.useMessageRequests;
let conversation;
if (conversations?.length) {
conversation = conversations[index];
@ -97,10 +93,6 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
return null;
}
// TODO: need to confirm what default setting is best here.
if (messageRequestsEnabled && !Boolean(conversation.isApproved)) {
return null;
}
return <MemoConversationListItemWithDetails key={key} style={style} {...conversation} />;
};

View file

@ -236,7 +236,11 @@ export class ConversationController {
if (conversation.isPrivate()) {
window.log.info(`deleteContact isPrivate, marking as inactive: ${id}`);
conversation.set('active_at', undefined);
// conversation.set('active_at', undefined);
conversation.set({
active_at: undefined,
isApproved: false,
});
await conversation.commit();
} else {
window.log.info(`deleteContact !isPrivate, removing convo from DB: ${id}`);

View file

@ -304,41 +304,49 @@ export const _getLeftPaneLists = (
};
}
if (!Boolean(conversation.isApproved) === true && window.lokiFeatureFlags.useMessageRequests) {
continue;
}
const messageRequestsEnabled =
window.inboxStore?.getState().userConfig.messageRequests === true &&
window?.lokiFeatureFlags?.useMessageRequests === true;
// if (!Boolean(conversation.isApproved) === true && window.lokiFeatureFlags.useMessageRequests) {
// continue;
// }
// Add Open Group to list as soon as the name has been set
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
continue;
// if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
// continue;
// }
// if (!conversation.isApproved && !conversation.isBlocked) {
// conversationRequests.push(conversation);
// }
if (shouldShowInRequestList(conversation, messageRequestsEnabled)) {
conversationRequests.push(conversation);
}
// Remove all invalid conversations and conversatons of devices associated
// with cancelled attempted links
if (!conversation.isPublic && !conversation.activeAt) {
continue;
}
// if (!conversation.isPublic && !conversation.activeAt) {
// continue;
// }
if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) {
// if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) {
// directConversations.push(conversation);
// }
if (shouldShowInContacts(conversation)) {
directConversations.push(conversation);
}
if (!conversation.isApproved && !conversation.isBlocked) {
conversationRequests.push(conversation);
}
if (
unreadCount < 9 &&
conversation.unreadCount &&
conversation.unreadCount > 0 &&
conversation.currentNotificationSetting !== 'disabled'
) {
unreadCount += conversation.unreadCount;
}
if (conversation.isApproved) {
if (shouldShowInConversationList(conversation, messageRequestsEnabled)) {
conversations.push(conversation);
unreadCount = calculateNewUnreadTotal(unreadCount, conversation);
}
// if (conversation.isApproved) {
// conversations.push(conversation);
// }
}
return {
@ -349,6 +357,84 @@ export const _getLeftPaneLists = (
};
};
const calculateNewUnreadTotal = (unreadCount: number, conversation: ReduxConversationType) => {
if (
unreadCount < 9 &&
conversation.unreadCount &&
conversation.unreadCount > 0 &&
conversation.currentNotificationSetting !== 'disabled'
) {
unreadCount += conversation.unreadCount;
}
return unreadCount;
};
const shouldShowInRequestList = (
conversation: ReduxConversationType,
messageRequestsEnabled: boolean
) => {
if (conversation.isPublic || conversation.isBlocked || Boolean(conversation.activeAt) === false) {
return false;
}
if (messageRequestsEnabled) {
if (Boolean(conversation.isApproved || !conversation.isBlocked)) {
return false;
}
}
return true;
};
const shouldShowInContacts = (conversation: ReduxConversationType) => {
// Add Open Group to list as soon as the name has been set
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
return false;
}
// if (shouldShowInRequestList(conversation)) {
// conversationRequests.push(conversation);
// }
// Remove all invalid conversations and conversatons of devices associated
// with cancelled attempted links
if (!conversation.isPublic && !conversation.activeAt) {
return false;
}
if (conversation.activeAt !== undefined && conversation.type === ConversationTypeEnum.PRIVATE) {
// directConversations.push(conversation);
return true;
} else {
return false;
}
};
const shouldShowInConversationList = (
conversation: ReduxConversationType,
messageRequestsEnabled: boolean
) => {
// // Add Open Group to list as soon as the name has been set
if (conversation.isPublic && (!conversation.name || conversation.name === 'Unknown group')) {
return false;
}
// Remove all invalid conversations and conversatons of devices associated
// with cancelled attempted links
if (!conversation.isPublic && !conversation.activeAt) {
return false;
}
// if (!conversation.activeAt) {
// return false;
// }
if (messageRequestsEnabled && !conversation.isApproved) {
return false;
}
return true;
};
export const getLeftPaneLists = createSelector(
getConversationLookup,
getConversationComparator,