QA fix - msg request accept buttons showing at wrong stage.

pull/2222/head
warrickct 3 years ago
parent e049934510
commit dcd78e85f6

@ -59,7 +59,7 @@ module.exports = {
removeMessage,
getUnreadByConversation,
getUnreadCountByConversation,
getIncomingMessagesCountByConversation,
getMessageCountByType,
getMessageBySenderAndSentAt,
getMessageBySenderAndServerTimestamp,
getMessageBySenderAndTimestamp,
@ -2311,15 +2311,16 @@ function getUnreadCountByConversation(conversationId) {
return row['count(*)'];
}
function getIncomingMessagesCountByConversation(conversationId) {
function getMessageCountByType(conversationId, type = '%') {
const row = globalInstance
.prepare(
`SELECT count(*) from ${MESSAGES_TABLE}
WHERE conversationId = $conversationId
AND type = "incoming";`
AND type = $type;`
)
.get({
conversationId,
type,
});
if (!row) {

@ -1,11 +1,13 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components';
import { getMessageCountByType } from '../../data/data';
import {
acceptConversation,
blockConvoById,
declineConversation,
} from '../../interactions/conversationInteractions';
import { MessageDirection } from '../../models/messageType';
import { forceSyncConfigurationNowIfNeeded } from '../../session/utils/syncUtils';
import { updateConfirmModal } from '../../state/ducks/modalDialog';
import { getSelectedConversation } from '../../state/selectors/conversations';
@ -14,12 +16,32 @@ import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/S
export const ConversationMessageRequestButtons = () => {
const selectedConversation = useSelector(getSelectedConversation);
if (!selectedConversation) {
const [hasIncoming, setHasIncomingMsg] = useState(false);
useEffect(() => {
async function getIncomingMessages() {
const id = selectedConversation?.id;
if (id) {
const msgCount = await getMessageCountByType(
selectedConversation?.id,
MessageDirection.incoming
);
if (msgCount > 0) {
setHasIncomingMsg(true);
}
}
}
getIncomingMessages();
});
if (!selectedConversation || !hasIncoming) {
return null;
}
const showMsgRequestUI =
!selectedConversation.isApproved && selectedConversation.type === 'private';
!selectedConversation.isApproved &&
!selectedConversation.isApproved &&
selectedConversation.type === 'private';
const dispatch = useDispatch();
const handleDeclineConversationRequest = () => {

@ -1,6 +1,8 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components';
import { getMessageCountByType } from '../../data/data';
import { MessageDirection } from '../../models/messageType';
import { getSelectedConversation } from '../../state/selectors/conversations';
export const ConversationRequestinfo = () => {
@ -8,7 +10,25 @@ export const ConversationRequestinfo = () => {
const showMsgRequestUI =
!selectedConversation?.isApproved && selectedConversation?.type === 'private';
if (!showMsgRequestUI) {
const [hasIncomingMessages, setHasIncomingMessages] = useState(false);
useEffect(() => {
async function getIncomingMessages() {
const id = selectedConversation?.id;
if (id) {
const msgCount = await getMessageCountByType(
selectedConversation?.id,
MessageDirection.incoming
);
if (msgCount > 0) {
setHasIncomingMessages(true);
}
}
}
getIncomingMessages();
});
if (!showMsgRequestUI || !hasIncomingMessages) {
return null;
}

@ -11,7 +11,7 @@ import {
ConversationTypeEnum,
} from '../models/conversation';
import { MessageCollection, MessageModel } from '../models/message';
import { MessageAttributes } from '../models/messageType';
import { MessageAttributes, MessageDirection } from '../models/messageType';
import { HexKeyPair } from '../receiver/keypairs';
import { getConversationController } from '../session/conversations';
import { getSodium } from '../session/crypto';
@ -113,7 +113,7 @@ const channelsToMake = {
_removeMessages,
getUnreadByConversation,
getUnreadCountByConversation,
getIncomingMessagesCountByConversation,
getMessageCountByType,
removeAllMessagesInConversation,
@ -762,11 +762,17 @@ export async function getUnreadCountByConversation(conversationId: string): Prom
return channels.getUnreadCountByConversation(conversationId);
}
export async function getIncomingMessagesCountByConversation(
/**
* Gets the count of messages for a direction
* @param conversationId Conversation for messages to retrieve from
* @param type outgoing/incoming
* @returns
*/
export async function getMessageCountByType(
conversationId: string,
type: string = '%'
type?: MessageDirection
): Promise<number> {
return channels.getIncomingMessagesCountByConversation(conversationId, type);
return channels.getMessageCountByType(conversationId, type);
}
export async function getMessagesByConversation(

@ -12,7 +12,7 @@ import { MessageModel } from './message';
import { MessageAttributesOptionals, MessageDirection } from './messageType';
import autoBind from 'auto-bind';
import {
getIncomingMessagesCountByConversation,
getMessageCountByType,
getLastMessagesByConversation,
getUnreadByConversation,
getUnreadCountByConversation,
@ -626,10 +626,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
};
const shouldApprove = !this.isApproved() && this.isPrivate();
const incomingMessageCount = await getIncomingMessagesCountByConversation(
this.id,
MessageDirection.incoming
);
const incomingMessageCount = await getMessageCountByType(this.id, MessageDirection.incoming);
const hasIncomingMessages = incomingMessageCount > 0;
if (shouldApprove) {
await this.setIsApproved(true);
@ -640,6 +637,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}
}
if (uploads.body?.includes('unapprove')) {
this.setIsApproved(false);
this.setDidApproveMe(false);
}
if (this.isOpenGroupV2()) {
const chatMessageOpenGroupV2 = new OpenGroupVisibleMessage(chatMessageParams);
const roomInfos = this.toOpenGroupV2();
@ -925,11 +927,15 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
) {
// for handling edge case for syncing/linking devices.
// if convo has a message by us, we have replied - which is considered as approved
// if (!this.isMe()) {
if (!this.isMe()) {
if (!this.isApproved() && this.isPrivate()) {
this.setIsApproved(true);
}
}
// this.setIsApproved(true);
// }
// }
return this.addSingleMessage({
...messageAttributes,

@ -122,6 +122,7 @@ export interface MessageRequestResponseMsg {
export enum MessageDirection {
outgoing = 'outgoing',
incoming = 'incoming',
any = '%',
}
export type PropsForDataExtractionNotification = DataExtractionNotificationMsg & {

@ -35,7 +35,7 @@ export const persistConfig = {
const persistedReducer = persistReducer(persistConfig, rootReducer);
// Exclude logger if we're in production mode
const disableLogging = false; //; env === 'production' || true; // ALWAYS TURNED OFF
const disableLogging = true; //; env === 'production' || true; // ALWAYS TURNED OFF
const middlewareList = disableLogging ? [promiseMiddleware] : [logger, promiseMiddleware];
export const createStore = (initialState: any) =>

Loading…
Cancel
Save