Revert "Refactor outbound delivery state"

This reverts commit 9c48a95eb5.
This commit is contained in:
Fedor Indutny 2021-07-12 16:51:45 -07:00 committed by GitHub
parent 77668c3247
commit ad217c808d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 694 additions and 3197 deletions

View file

@ -48,6 +48,7 @@ import {
ItemKeyType,
ItemType,
MessageType,
MessageTypeUnhydrated,
PreKeyType,
SearchResultMessageType,
SenderKeyType,
@ -61,10 +62,8 @@ import {
UnprocessedUpdateType,
} from './Interface';
import Server from './Server';
import { MessageRowWithJoinedSends, rowToMessage } from './rowToMessage';
import { MessageModel } from '../models/messages';
import { ConversationModel } from '../models/conversations';
import { SendState } from '../messages/MessageSendState';
// We listen to a lot of events on ipcRenderer, often on the same channel. This prevents
// any warnings that might be sent to the console in that case.
@ -202,8 +201,6 @@ const dataInterface: ClientInterface = {
hasGroupCallHistoryMessage,
migrateConversationMessages,
updateMessageSendState,
getUnprocessedCount,
getAllUnprocessed,
getUnprocessedById,
@ -251,7 +248,6 @@ const dataInterface: ClientInterface = {
// Test-only
_getAllMessages,
_getSendStates,
// Client-side only
@ -945,17 +941,17 @@ async function searchConversations(query: string) {
return conversations;
}
function handleSearchMessageRows(
rows: ReadonlyArray<SearchResultMessageType>
function handleSearchMessageJSON(
messages: Array<SearchResultMessageType>
): Array<ClientSearchResultMessageType> {
return rows.map(row => ({
json: row.json,
return messages.map(message => ({
json: message.json,
// Empty array is a default value. `message.json` has the real field
bodyRanges: [],
...rowToMessage(row),
snippet: row.snippet,
...JSON.parse(message.json),
snippet: message.snippet,
}));
}
@ -965,7 +961,7 @@ async function searchMessages(
) {
const messages = await channels.searchMessages(query, { limit });
return handleSearchMessageRows(messages);
return handleSearchMessageJSON(messages);
}
async function searchMessagesInConversation(
@ -979,7 +975,7 @@ async function searchMessagesInConversation(
{ limit }
);
return handleSearchMessageRows(messages);
return handleSearchMessageJSON(messages);
}
// Message
@ -1057,16 +1053,6 @@ async function _getAllMessages({
return new MessageCollection(messages);
}
// For testing only
function _getSendStates(
options: Readonly<{
messageId: string;
destinationConversationId: string;
}>
) {
return channels._getSendStates(options);
}
async function getAllMessageIds() {
const ids = await channels.getAllMessageIds();
@ -1143,10 +1129,8 @@ async function addReaction(reactionObj: ReactionType) {
return channels.addReaction(reactionObj);
}
function handleMessageRows(
rows: ReadonlyArray<MessageRowWithJoinedSends>
): Array<MessageType> {
return rows.map(row => rowToMessage(row));
function handleMessageJSON(messages: Array<MessageTypeUnhydrated>) {
return messages.map(message => JSON.parse(message.json));
}
async function getOlderMessagesByConversation(
@ -1175,7 +1159,7 @@ async function getOlderMessagesByConversation(
}
);
return new MessageCollection(handleMessageRows(messages));
return new MessageCollection(handleMessageJSON(messages));
}
async function getNewerMessagesByConversation(
conversationId: string,
@ -1200,7 +1184,7 @@ async function getNewerMessagesByConversation(
}
);
return new MessageCollection(handleMessageRows(messages));
return new MessageCollection(handleMessageJSON(messages));
}
async function getLastConversationActivity({
conversationId,
@ -1258,17 +1242,6 @@ async function migrateConversationMessages(
await channels.migrateConversationMessages(obsoleteId, currentId);
}
async function updateMessageSendState(
params: Readonly<
{
messageId: string;
destinationConversationId: string;
} & SendState
>
): Promise<void> {
await channels.updateMessageSendState(params);
}
async function removeAllMessagesInConversation(
conversationId: string,
{