remove schemaVersion field and logic from message object
This commit is contained in:
parent
3f4db67c1b
commit
4349b699cb
33
app/sql.js
33
app/sql.js
|
@ -839,6 +839,7 @@ const LOKI_SCHEMA_VERSIONS = [
|
|||
updateToLokiSchemaVersion16,
|
||||
updateToLokiSchemaVersion17,
|
||||
updateToLokiSchemaVersion18,
|
||||
updateToLokiSchemaVersion19,
|
||||
];
|
||||
|
||||
function updateToLokiSchemaVersion1(currentVersion, db) {
|
||||
|
@ -1311,6 +1312,29 @@ function updateToLokiSchemaVersion18(currentVersion, db) {
|
|||
console.log(`updateToLokiSchemaVersion${targetVersion}: success!`);
|
||||
}
|
||||
|
||||
function updateToLokiSchemaVersion19(currentVersion, db) {
|
||||
const targetVersion = 19;
|
||||
if (currentVersion >= targetVersion) {
|
||||
return;
|
||||
}
|
||||
console.log(`updateToLokiSchemaVersion${targetVersion}: starting...`);
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
DROP INDEX messages_schemaVersion;
|
||||
ALTER TABLE ${MESSAGES_TABLE} DROP COLUMN schemaVersion;
|
||||
`);
|
||||
// this is way to slow for now...
|
||||
// db.exec(`
|
||||
// UPDATE ${MESSAGES_TABLE} SET
|
||||
// json = json_remove(json, '$.schemaVersion')
|
||||
// `);
|
||||
writeLokiSchemaVersion(targetVersion, db);
|
||||
})();
|
||||
|
||||
console.log(`updateToLokiSchemaVersion${targetVersion}: success!`);
|
||||
}
|
||||
|
||||
function writeLokiSchemaVersion(newVersion, db) {
|
||||
db.prepare(
|
||||
`INSERT INTO loki_schema(
|
||||
|
@ -1901,7 +1925,6 @@ function saveMessage(data) {
|
|||
serverTimestamp,
|
||||
// eslint-disable-next-line camelcase
|
||||
received_at,
|
||||
schemaVersion,
|
||||
sent,
|
||||
// eslint-disable-next-line camelcase
|
||||
sent_at,
|
||||
|
@ -1936,7 +1959,6 @@ function saveMessage(data) {
|
|||
hasFileAttachments,
|
||||
hasVisualMediaAttachments,
|
||||
received_at,
|
||||
schemaVersion,
|
||||
sent,
|
||||
sent_at,
|
||||
source,
|
||||
|
@ -1961,7 +1983,6 @@ function saveMessage(data) {
|
|||
hasFileAttachments,
|
||||
hasVisualMediaAttachments,
|
||||
received_at,
|
||||
schemaVersion,
|
||||
sent,
|
||||
sent_at,
|
||||
source,
|
||||
|
@ -1982,7 +2003,6 @@ function saveMessage(data) {
|
|||
$hasFileAttachments,
|
||||
$hasVisualMediaAttachments,
|
||||
$received_at,
|
||||
$schemaVersion,
|
||||
$sent,
|
||||
$sent_at,
|
||||
$source,
|
||||
|
@ -3034,11 +3054,11 @@ function fillWithTestData(numConvosToAdd, numMsgsToAdd) {
|
|||
vehicula ante efficitur sed. Curabitur in sapien eros. Morbi tempor ante ut
|
||||
metus scelerisque condimentum. Integer sit amet tempus nulla. Vivamus
|
||||
imperdiet dui ac luctus vulputate. Sed a accumsan risus. Nulla facilisi.
|
||||
Nulla mauris dui, luctus in sagittis at, sodales id mauris. Integer efficitur
|
||||
Nulla mauris dui, luctus in sagittis at, sodales id mauris. Integer efficitur
|
||||
viverra ex, ut dignissim eros tincidunt placerat. Sed facilisis gravida
|
||||
mauris in luctus . Fusce dapibus, est vitae tincidunt eleifend, justo
|
||||
odio porta dui, sed ultrices mi arcu vitae ante. Mauris ut libero
|
||||
erat. Nam ut mi quis ante tincidunt facilisis sit amet id enim.
|
||||
erat. Nam ut mi quis ante tincidunt facilisis sit amet id enim.
|
||||
Vestibulum in molestie mi. In ac felis est. Vestibulum vel blandit ex. Morbi vitae
|
||||
viverra augue . Ut turpis quam, cursus quis ex a, convallis
|
||||
ullamcorper purus. Nam eget libero arcu. Integer fermentum enim nunc, non consequat urna
|
||||
|
@ -3111,7 +3131,6 @@ function fillWithTestData(numConvosToAdd, numMsgsToAdd) {
|
|||
serverTimestamp: 0,
|
||||
// eslint-disable-next-line camelcase
|
||||
received_at: Date.now(),
|
||||
schemaVersion: 5,
|
||||
sent: 0,
|
||||
// eslint-disable-next-line camelcase
|
||||
sent_at: Date.now(),
|
||||
|
|
|
@ -96,6 +96,8 @@ export const MessageSearchResult = (props: Props) => {
|
|||
direction,
|
||||
} = props;
|
||||
|
||||
console.info('rendering search result message ', id);
|
||||
|
||||
const sourceOrDestinationDerivable =
|
||||
(destination && direction === MessageDirection.outgoing) ||
|
||||
!destination ||
|
||||
|
@ -115,6 +117,7 @@ export const MessageSearchResult = (props: Props) => {
|
|||
|
||||
return (
|
||||
<div
|
||||
key={`div-msg-searchresult-${id}`}
|
||||
role="button"
|
||||
onClick={async () => {
|
||||
await openConversationWithMessages({
|
||||
|
|
|
@ -32,6 +32,7 @@ export const SearchResults = (props: SearchResultsProps) => {
|
|||
const haveContacts = contacts && contacts.length;
|
||||
const haveMessages = messages && messages.length;
|
||||
const noResults = !haveConversations && !haveContacts && !haveMessages;
|
||||
console.info('SearchResults ', messages?.length);
|
||||
|
||||
return (
|
||||
<div className="module-search-results">
|
||||
|
@ -62,7 +63,7 @@ export const SearchResults = (props: SearchResultsProps) => {
|
|||
</div>
|
||||
)}
|
||||
{messages.map(message => (
|
||||
<MessageSearchResult key={message.id} {...message} />
|
||||
<MessageSearchResult key={`search-result-${message.id}`} {...message} />
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
|
|
|
@ -588,6 +588,7 @@ export async function searchConversations(query: string): Promise<Array<any>> {
|
|||
|
||||
export async function searchMessages(query: string, { limit }: any = {}): Promise<Array<any>> {
|
||||
const messages = await channels.searchMessages(query, { limit });
|
||||
console.warn('searched message', messages);
|
||||
return messages;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import { toHex } from '../session/utils/String';
|
|||
import {
|
||||
actions as conversationActions,
|
||||
conversationChanged,
|
||||
conversationsChanged,
|
||||
LastMessageStatusType,
|
||||
MessageModelPropsWithoutConvoProps,
|
||||
ReduxConversationType,
|
||||
|
@ -204,10 +205,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
trailing: true,
|
||||
leading: true,
|
||||
});
|
||||
this.triggerUIRefresh = _.throttle(this.triggerUIRefresh, 1000, {
|
||||
trailing: true,
|
||||
leading: true,
|
||||
});
|
||||
|
||||
this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 5000, trailing: true });
|
||||
//start right away the function is called, and wait 1sec before calling it again
|
||||
const markReadDebounced = _.debounce(this.markReadBouncy, 1000, {
|
||||
|
@ -915,14 +913,8 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
}
|
||||
|
||||
public triggerUIRefresh() {
|
||||
window.inboxStore?.dispatch(
|
||||
conversationChanged({
|
||||
id: this.id,
|
||||
data: {
|
||||
...this.getConversationModelProps(),
|
||||
},
|
||||
})
|
||||
);
|
||||
updatesToDispatch.set(this.id, this.getConversationModelProps());
|
||||
trotthledAllConversationsDispatch();
|
||||
}
|
||||
|
||||
public async commit() {
|
||||
|
@ -1253,26 +1245,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
}
|
||||
}
|
||||
|
||||
public async upgradeMessages(messages: any) {
|
||||
// tslint:disable-next-line: one-variable-per-declaration
|
||||
for (let max = messages.length, i = 0; i < max; i += 1) {
|
||||
const message = messages.at(i);
|
||||
const { attributes } = message;
|
||||
const { schemaVersion } = attributes;
|
||||
|
||||
if (schemaVersion < window.Signal.Types.Message.VERSION_NEEDED_FOR_DISPLAY) {
|
||||
// Yep, we really do want to wait for each of these
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
const { upgradeMessageSchema } = window.Signal.Migrations;
|
||||
|
||||
const upgradedMessage = await upgradeMessageSchema(attributes);
|
||||
message.set(upgradedMessage);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await upgradedMessage.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public hasMember(pubkey: string) {
|
||||
return _.includes(this.get('members'), pubkey);
|
||||
}
|
||||
|
@ -1665,6 +1637,18 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
|
|||
}
|
||||
}
|
||||
|
||||
const trotthledAllConversationsDispatch = _.throttle(() => {
|
||||
if (updatesToDispatch.size === 0) {
|
||||
return;
|
||||
}
|
||||
console.warn('updatesToDispatch.size ', updatesToDispatch.size);
|
||||
window.inboxStore?.dispatch(conversationsChanged([...updatesToDispatch.values()]));
|
||||
|
||||
updatesToDispatch.clear();
|
||||
}, 500);
|
||||
|
||||
const updatesToDispatch: Map<string, ReduxConversationType> = new Map();
|
||||
|
||||
export class ConversationCollection extends Backbone.Collection<ConversationModel> {
|
||||
constructor(models?: Array<ConversationModel>) {
|
||||
super(models);
|
||||
|
|
|
@ -75,13 +75,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
|||
const filledAttrs = fillMessageAttributesWithDefaults(attributes);
|
||||
super(filledAttrs);
|
||||
|
||||
this.set(
|
||||
window.Signal.Types.Message.initializeSchemaVersion({
|
||||
message: filledAttrs,
|
||||
logger: window.log,
|
||||
})
|
||||
);
|
||||
|
||||
if (!this.attributes.id) {
|
||||
throw new Error('A message always needs to have an id.');
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ export interface MessageAttributes {
|
|||
hasAttachments: boolean;
|
||||
hasFileAttachments: boolean;
|
||||
hasVisualMediaAttachments: boolean;
|
||||
schemaVersion: number;
|
||||
expirationTimerUpdate?: {
|
||||
expireTimer: number;
|
||||
source: string;
|
||||
|
@ -163,7 +162,6 @@ export interface MessageAttributesOptionals {
|
|||
hasAttachments?: boolean;
|
||||
hasFileAttachments?: boolean;
|
||||
hasVisualMediaAttachments?: boolean;
|
||||
schemaVersion?: number;
|
||||
expirationTimerUpdate?: {
|
||||
expireTimer: number;
|
||||
source: string;
|
||||
|
@ -204,7 +202,6 @@ export const fillMessageAttributesWithDefaults = (
|
|||
const defaulted = _.defaults(optAttributes, {
|
||||
expireTimer: 0, // disabled
|
||||
id: uuidv4(),
|
||||
schemaVersion: window.Signal.Types.Message.CURRENT_SCHEMA_VERSION,
|
||||
unread: 0, // if nothing is set, this message is considered read
|
||||
});
|
||||
// this is just to cleanup a bit the db. delivered and delivered_to were removed, so everytime we load a message
|
||||
|
|
|
@ -18,9 +18,6 @@ function contentTypeSupported(type: string): boolean {
|
|||
|
||||
// tslint:disable-next-line: cyclomatic-complexity
|
||||
async function copyFromQuotedMessage(msg: MessageModel, quote?: Quote): Promise<void> {
|
||||
const { upgradeMessageSchema } = window.Signal.Migrations;
|
||||
const { Message: TypedMessage, Errors } = window.Signal.Types;
|
||||
|
||||
if (!quote) {
|
||||
return;
|
||||
}
|
||||
|
@ -217,7 +214,6 @@ async function handleRegularMessage(
|
|||
hasFileAttachments: dataMessage.hasFileAttachments,
|
||||
hasVisualMediaAttachments: dataMessage.hasVisualMediaAttachments,
|
||||
quote: dataMessage.quote,
|
||||
schemaVersion: dataMessage.schemaVersion,
|
||||
attachments: dataMessage.attachments,
|
||||
body: dataMessage.body,
|
||||
conversationId: conversation.id,
|
||||
|
|
|
@ -567,23 +567,25 @@ const conversationsSlice = createSlice({
|
|||
}>
|
||||
) {
|
||||
const { payload } = action;
|
||||
const { id, data } = payload;
|
||||
const { conversationLookup, selectedConversation } = state;
|
||||
return applyConversationChanged(state, payload);
|
||||
},
|
||||
conversationsChanged(
|
||||
state: ConversationsStateType,
|
||||
action: PayloadAction<Array<ReduxConversationType>>
|
||||
) {
|
||||
const { payload } = action;
|
||||
|
||||
const existing = conversationLookup[id];
|
||||
// In the change case we only modify the lookup if we already had that conversation
|
||||
if (!existing) {
|
||||
return state;
|
||||
let updatedState = state;
|
||||
if (payload.length) {
|
||||
payload.forEach(convoProps => {
|
||||
updatedState = applyConversationChanged(updatedState, {
|
||||
id: convoProps.id,
|
||||
data: convoProps,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
selectedConversation,
|
||||
conversationLookup: {
|
||||
...conversationLookup,
|
||||
[id]: data,
|
||||
},
|
||||
};
|
||||
return updatedState;
|
||||
},
|
||||
|
||||
conversationRemoved(state: ConversationsStateType, action: PayloadAction<string>) {
|
||||
|
@ -784,12 +786,36 @@ const conversationsSlice = createSlice({
|
|||
},
|
||||
});
|
||||
|
||||
function applyConversationChanged(
|
||||
state: ConversationsStateType,
|
||||
payload: { id: string; data: ReduxConversationType }
|
||||
) {
|
||||
const { id, data } = payload;
|
||||
const { conversationLookup, selectedConversation } = state;
|
||||
|
||||
const existing = conversationLookup[id];
|
||||
// In the change case we only modify the lookup if we already had that conversation
|
||||
if (!existing) {
|
||||
return state;
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
selectedConversation,
|
||||
conversationLookup: {
|
||||
...conversationLookup,
|
||||
[id]: data,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// destructures
|
||||
export const { actions, reducer } = conversationsSlice;
|
||||
export const {
|
||||
// conversation and messages list
|
||||
conversationAdded,
|
||||
conversationChanged,
|
||||
conversationsChanged,
|
||||
conversationRemoved,
|
||||
removeAllConversations,
|
||||
messageExpired,
|
||||
|
|
|
@ -5,6 +5,7 @@ import { searchConversations, searchMessages } from '../../../ts/data/data';
|
|||
import { ReduxConversationType } from './conversations';
|
||||
import { PubKey } from '../../session/types';
|
||||
import { ConversationTypeEnum } from '../../models/conversation';
|
||||
import _ from 'lodash';
|
||||
|
||||
// State
|
||||
|
||||
|
@ -82,8 +83,8 @@ async function doSearch(query: string, options: SearchOptions): Promise<SearchRe
|
|||
queryMessages(processedQuery),
|
||||
]);
|
||||
const { conversations, contacts } = discussions;
|
||||
let filteredMessages = messages.filter(message => message !== undefined);
|
||||
|
||||
let filteredMessages = _.compact(messages);
|
||||
console.warn('before filteredMessages ', filteredMessages);
|
||||
if (isAdvancedQuery) {
|
||||
let senderFilter: Array<string> = [];
|
||||
if (advancedSearchOptions.from && advancedSearchOptions.from.length > 0) {
|
||||
|
@ -95,7 +96,7 @@ async function doSearch(query: string, options: SearchOptions): Promise<SearchRe
|
|||
}
|
||||
filteredMessages = filterMessages(filteredMessages, advancedSearchOptions, senderFilter);
|
||||
}
|
||||
|
||||
console.warn('aftert filteredMessages ', filteredMessages);
|
||||
return {
|
||||
query,
|
||||
normalizedPhoneNumber: PubKey.normalize(query),
|
||||
|
@ -202,7 +203,7 @@ function getAdvancedSearchOptionsFromQuery(query: string): AdvancedSearchOptions
|
|||
async function queryMessages(query: string) {
|
||||
try {
|
||||
const normalized = cleanSearchTerm(query);
|
||||
|
||||
console.warn('normalized', normalized);
|
||||
return searchMessages(normalized);
|
||||
} catch (e) {
|
||||
return [];
|
||||
|
|
|
@ -268,15 +268,6 @@ export type Attachment = {
|
|||
contentType?: MIME.MIMEType;
|
||||
size?: number;
|
||||
data: ArrayBuffer;
|
||||
|
||||
// // Omit unused / deprecated keys:
|
||||
// schemaVersion?: number;
|
||||
// id?: string;
|
||||
// width?: number;
|
||||
// height?: number;
|
||||
// thumbnail?: ArrayBuffer;
|
||||
// key?: ArrayBuffer;
|
||||
// digest?: ArrayBuffer;
|
||||
} & Partial<AttachmentSchemaVersion3>;
|
||||
|
||||
interface AttachmentSchemaVersion3 {
|
||||
|
|
Loading…
Reference in New Issue