Correcting merge errors.

pull/2170/head
warrickct 3 years ago
parent ee9156d4f8
commit 6a02846829

@ -59,6 +59,7 @@ module.exports = {
removeMessage, removeMessage,
getUnreadByConversation, getUnreadByConversation,
getUnreadCountByConversation, getUnreadCountByConversation,
getIncomingMessagesCountByConversation,
getMessageBySenderAndSentAt, getMessageBySenderAndSentAt,
getMessageBySenderAndServerTimestamp, getMessageBySenderAndServerTimestamp,
getMessageBySenderAndTimestamp, getMessageBySenderAndTimestamp,
@ -2312,6 +2313,27 @@ function getUnreadCountByConversation(conversationId) {
return row['count(*)']; return row['count(*)'];
} }
function getIncomingMessagesCountByConversation(conversationId, type = '%') {
const row = globalInstance
.prepare(
`SELECT count(*) from ${MESSAGES_TABLE}
WHERE conversationId = $conversationId
AND type = $type;`
)
.get({
conversationId,
type,
});
if (!row) {
throw new Error(
`getIncomingMessagesCountByConversation: Unable to get incoming messages count of ${conversationId}`
);
}
return row['count(*)'];
}
// Note: Sorting here is necessary for getting the last message (with limit 1) // Note: Sorting here is necessary for getting the last message (with limit 1)
// be sure to update the sorting order to sort messages on redux too (sortMessages) // be sure to update the sorting order to sort messages on redux too (sortMessages)
const orderByClause = 'ORDER BY COALESCE(serverTimestamp, sent_at, received_at) DESC'; const orderByClause = 'ORDER BY COALESCE(serverTimestamp, sent_at, received_at) DESC';
@ -2333,7 +2355,6 @@ function getMessagesByConversation(conversationId, { messageId = null, type = '%
`WITH cte AS ( `WITH cte AS (
SELECT id, conversationId, json, row_number() OVER (${orderByClause}) as row_number SELECT id, conversationId, json, row_number() OVER (${orderByClause}) as row_number
FROM ${MESSAGES_TABLE} WHERE conversationId = $conversationId FROM ${MESSAGES_TABLE} WHERE conversationId = $conversationId
AND type LIKE $type
), current AS ( ), current AS (
SELECT row_number SELECT row_number
FROM cte FROM cte

@ -113,6 +113,7 @@ const channelsToMake = {
_removeMessages, _removeMessages,
getUnreadByConversation, getUnreadByConversation,
getUnreadCountByConversation, getUnreadCountByConversation,
getIncomingMessagesCountByConversation,
removeAllMessagesInConversation, removeAllMessagesInConversation,
@ -761,17 +762,19 @@ export async function getUnreadCountByConversation(conversationId: string): Prom
return channels.getUnreadCountByConversation(conversationId); return channels.getUnreadCountByConversation(conversationId);
} }
export async function getIncomingMessagesCountByConversation(
conversationId: string,
type: string = '%'
): Promise<number> {
return channels.getIncomingMessagesCountByConversation(conversationId, type);
}
export async function getMessagesByConversation( export async function getMessagesByConversation(
conversationId: string, conversationId: string,
{ { skipTimerInit = false, messageId = null }: { skipTimerInit?: false; messageId: string | null }
type = '%',
skipTimerInit = false,
messageId = null,
}: { type?: string; skipTimerInit?: false; messageId: string | null }
): Promise<MessageCollection> { ): Promise<MessageCollection> {
const messages = await channels.getMessagesByConversation(conversationId, { const messages = await channels.getMessagesByConversation(conversationId, {
messageId, messageId,
type,
}); });
if (skipTimerInit) { if (skipTimerInit) {
for (const message of messages) { for (const message of messages) {

@ -12,8 +12,8 @@ import { MessageModel } from './message';
import { MessageAttributesOptionals, MessageDirection } from './messageType'; import { MessageAttributesOptionals, MessageDirection } from './messageType';
import autoBind from 'auto-bind'; import autoBind from 'auto-bind';
import { import {
getIncomingMessagesCountByConversation,
getLastMessagesByConversation, getLastMessagesByConversation,
getMessagesByConversation,
getUnreadByConversation, getUnreadByConversation,
getUnreadCountByConversation, getUnreadCountByConversation,
removeMessage as dataRemoveMessage, removeMessage as dataRemoveMessage,
@ -626,16 +626,14 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}; };
const shouldApprove = !this.isApproved() && this.isPrivate(); const shouldApprove = !this.isApproved() && this.isPrivate();
const hasMsgsFromOther = const incomingMessages = await getIncomingMessagesCountByConversation(
( this.id,
await getMessagesByConversation(this.id, { MessageDirection.incoming
messageId: null, );
type: MessageDirection.incoming, const hasIncomingMessages = incomingMessages > 0;
})
).length > 0;
if (shouldApprove) { if (shouldApprove) {
await this.setIsApproved(true); await this.setIsApproved(true);
if (!this.didApproveMe() && hasMsgsFromOther) { if (!this.didApproveMe() && hasIncomingMessages) {
await this.setDidApproveMe(true); await this.setDidApproveMe(true);
await this.sendMessageRequestResponse(true); await this.sendMessageRequestResponse(true);
void forceSyncConfigurationNowIfNeeded(); void forceSyncConfigurationNowIfNeeded();
@ -1163,12 +1161,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
isApproved: value, isApproved: value,
}); });
if (!this.isApproved() && value) {
// if convo hasn't been approved until now, send approval msg
this.sendMessageRequestResponse(true);
void forceSyncConfigurationNowIfNeeded();
}
if (shouldCommit) { if (shouldCommit) {
await this.commit(); await this.commit();
} }
@ -1509,7 +1501,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
} }
private async addSingleMessage(messageAttributes: MessageAttributesOptionals) { public async addSingleMessage(messageAttributes: MessageAttributesOptionals) {
const model = new MessageModel(messageAttributes); const model = new MessageModel(messageAttributes);
// no need to trigger a UI update now, we trigger a messagesAdded just below // no need to trigger a UI update now, we trigger a messagesAdded just below

@ -19,6 +19,7 @@ import { getAllCachedECKeyPair } from './closedGroups';
import { handleCallMessage } from './callMessage'; import { handleCallMessage } from './callMessage';
import { SettingsKey } from '../data/settings-key'; import { SettingsKey } from '../data/settings-key';
import { ConversationTypeEnum } from '../models/conversation'; import { ConversationTypeEnum } from '../models/conversation';
import { showMessageRequestBanner } from '../state/ducks/userConfig';
export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) { export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) {
try { try {
@ -370,6 +371,19 @@ export async function innerHandleSwarmContentMessage(
); );
} }
const newConvo = await getConversationController().getOrCreateAndWait(
envelope.source,
ConversationTypeEnum.PRIVATE
);
if (
newConvo.isPrivate() &&
!newConvo.isApproved() &&
window.inboxStore?.getState().userConfig.hideMessageRequests
) {
window.inboxStore?.dispatch(showMessageRequestBanner());
}
if (content.dataMessage) { if (content.dataMessage) {
if (content.dataMessage.profileKey && content.dataMessage.profileKey.length === 0) { if (content.dataMessage.profileKey && content.dataMessage.profileKey.length === 0) {
content.dataMessage.profileKey = null; content.dataMessage.profileKey = null;

@ -256,19 +256,6 @@ async function handleRegularMessage(
await handleSyncedReceipts(message, conversation); await handleSyncedReceipts(message, conversation);
} }
if (
conversation.isPrivate() &&
!conversation.isApproved() &&
window.inboxStore?.getState().userConfig.hideMessageRequests
) {
window.inboxStore?.dispatch(showMessageRequestBanner());
}
if (!conversation.didApproveMe()) {
conversation.setDidApproveMe(true);
await forceSyncConfigurationNowIfNeeded();
}
const conversationActiveAt = conversation.get('active_at'); const conversationActiveAt = conversation.get('active_at');
if (!conversationActiveAt || (message.get('sent_at') || 0) > conversationActiveAt) { if (!conversationActiveAt || (message.get('sent_at') || 0) > conversationActiveAt) {
conversation.set({ conversation.set({

Loading…
Cancel
Save