Refactor: Move data-access code to Typescript w/ shared interface
This commit is contained in:
		
					parent
					
						
							
								9ab54b9b83
							
						
					
				
			
			
				commit
				
					
						6b094e1514
					
				
			
		
					 35 changed files with 1695 additions and 598 deletions
				
			
		| 
						 | 
				
			
			@ -1996,10 +1996,7 @@
 | 
			
		|||
        conversation.set({ avatar: null });
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      window.Signal.Data.updateConversation(
 | 
			
		||||
        details.number || details.uuid,
 | 
			
		||||
        conversation.attributes
 | 
			
		||||
      );
 | 
			
		||||
      window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
 | 
			
		||||
      const { expireTimer } = details;
 | 
			
		||||
      const isValidExpireTimer = typeof expireTimer === 'number';
 | 
			
		||||
| 
						 | 
				
			
			@ -2108,7 +2105,7 @@
 | 
			
		|||
      conversation.set(newAttributes);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    window.Signal.Data.updateConversation(id, conversation.attributes);
 | 
			
		||||
    window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
 | 
			
		||||
    const { appView } = window.owsDesktopApp;
 | 
			
		||||
    if (appView && appView.installView && appView.installView.didLink) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2240,7 +2237,7 @@
 | 
			
		|||
    );
 | 
			
		||||
 | 
			
		||||
    conversation.set({ profileSharing: true });
 | 
			
		||||
    window.Signal.Data.updateConversation(id, conversation.attributes);
 | 
			
		||||
    window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
 | 
			
		||||
    // Then we update our own profileKey if it's different from what we have
 | 
			
		||||
    const ourNumber = textsecure.storage.user.getNumber();
 | 
			
		||||
| 
						 | 
				
			
			@ -2518,10 +2515,7 @@
 | 
			
		|||
          ev.confirm();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        window.Signal.Data.updateConversation(
 | 
			
		||||
          conversationId,
 | 
			
		||||
          conversation.attributes
 | 
			
		||||
        );
 | 
			
		||||
        window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -240,10 +240,7 @@
 | 
			
		|||
                this.model.set({
 | 
			
		||||
                  draft: draft.slice(0, MAX_MESSAGE_BODY_LENGTH),
 | 
			
		||||
                });
 | 
			
		||||
                window.Signal.Data.updateConversation(
 | 
			
		||||
                  conversation.id,
 | 
			
		||||
                  conversation.attributes
 | 
			
		||||
                );
 | 
			
		||||
                window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
              }
 | 
			
		||||
            })
 | 
			
		||||
          );
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -60,16 +60,15 @@
 | 
			
		|||
  let timeout;
 | 
			
		||||
  async function checkExpiringMessages() {
 | 
			
		||||
    // Look up the next expiring message and set a timer to destroy it
 | 
			
		||||
    const messages = await window.Signal.Data.getNextExpiringMessage({
 | 
			
		||||
      MessageCollection: Whisper.MessageCollection,
 | 
			
		||||
    const message = await window.Signal.Data.getNextExpiringMessage({
 | 
			
		||||
      Message: Whisper.Message,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const next = messages.at(0);
 | 
			
		||||
    if (!next) {
 | 
			
		||||
    if (!message) {
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const expiresAt = next.get('expires_at');
 | 
			
		||||
    const expiresAt = message.get('expires_at');
 | 
			
		||||
    Whisper.ExpiringMessagesListener.nextExpiration = expiresAt;
 | 
			
		||||
    window.log.info('next message expires', new Date(expiresAt).toISOString());
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -424,7 +424,7 @@
 | 
			
		|||
      const oldValue = this.get('e164');
 | 
			
		||||
      if (e164 !== oldValue) {
 | 
			
		||||
        this.set('e164', e164);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
        this.trigger('idUpdated', this, 'e164', oldValue);
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			@ -432,7 +432,7 @@
 | 
			
		|||
      const oldValue = this.get('uuid');
 | 
			
		||||
      if (uuid !== oldValue) {
 | 
			
		||||
        this.set('uuid', uuid);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
        this.trigger('idUpdated', this, 'uuid', oldValue);
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			@ -440,7 +440,7 @@
 | 
			
		|||
      const oldValue = this.get('groupId');
 | 
			
		||||
      if (groupId !== oldValue) {
 | 
			
		||||
        this.set('groupId', groupId);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
        this.trigger('idUpdated', this, 'groupId', oldValue);
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			@ -461,7 +461,7 @@
 | 
			
		|||
 | 
			
		||||
        if (this.get('verified') !== verified) {
 | 
			
		||||
          this.set({ verified });
 | 
			
		||||
          window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
          window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return;
 | 
			
		||||
| 
						 | 
				
			
			@ -525,7 +525,7 @@
 | 
			
		|||
      }
 | 
			
		||||
 | 
			
		||||
      this.set({ verified });
 | 
			
		||||
      window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
      window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
 | 
			
		||||
      // Three situations result in a verification notice in the conversation:
 | 
			
		||||
      //   1) The message came from an explicit verification in another client (not
 | 
			
		||||
| 
						 | 
				
			
			@ -1222,7 +1222,7 @@
 | 
			
		|||
          draft: null,
 | 
			
		||||
          draftTimestamp: null,
 | 
			
		||||
        });
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
 | 
			
		||||
        // We're offline!
 | 
			
		||||
        if (!textsecure.messaging) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1354,10 +1354,7 @@
 | 
			
		|||
            conversation.set({
 | 
			
		||||
              sealedSender: SEALED_SENDER.DISABLED,
 | 
			
		||||
            });
 | 
			
		||||
            window.Signal.Data.updateConversation(
 | 
			
		||||
              conversation.id,
 | 
			
		||||
              conversation.attributes
 | 
			
		||||
            );
 | 
			
		||||
            window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      );
 | 
			
		||||
| 
						 | 
				
			
			@ -1385,10 +1382,7 @@
 | 
			
		|||
                sealedSender: SEALED_SENDER.UNRESTRICTED,
 | 
			
		||||
              });
 | 
			
		||||
            }
 | 
			
		||||
            window.Signal.Data.updateConversation(
 | 
			
		||||
              conversation.id,
 | 
			
		||||
              conversation.attributes
 | 
			
		||||
            );
 | 
			
		||||
            window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      );
 | 
			
		||||
| 
						 | 
				
			
			@ -1530,7 +1524,7 @@
 | 
			
		|||
      this.set(lastMessageUpdate);
 | 
			
		||||
 | 
			
		||||
      if (this.hasChanged()) {
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes, {
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes, {
 | 
			
		||||
          Conversation: Whisper.Conversation,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -1538,7 +1532,7 @@
 | 
			
		|||
 | 
			
		||||
    async setArchived(isArchived) {
 | 
			
		||||
      this.set({ isArchived });
 | 
			
		||||
      window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
      window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    async updateExpirationTimer(
 | 
			
		||||
| 
						 | 
				
			
			@ -1581,7 +1575,7 @@
 | 
			
		|||
      const timestamp = (receivedAt || Date.now()) - 1;
 | 
			
		||||
 | 
			
		||||
      this.set({ expireTimer });
 | 
			
		||||
      window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
      window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
 | 
			
		||||
      const model = new Whisper.Message({
 | 
			
		||||
        // Even though this isn't reflected to the user, we want to place the last seen
 | 
			
		||||
| 
						 | 
				
			
			@ -1787,7 +1781,7 @@
 | 
			
		|||
      if (this.get('type') === 'group') {
 | 
			
		||||
        const groupNumbers = this.getRecipients();
 | 
			
		||||
        this.set({ left: true });
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
 | 
			
		||||
        const model = new Whisper.Message({
 | 
			
		||||
          group_update: { left: 'You' },
 | 
			
		||||
| 
						 | 
				
			
			@ -1852,7 +1846,7 @@
 | 
			
		|||
 | 
			
		||||
      const unreadCount = unreadMessages.length - read.length;
 | 
			
		||||
      this.set({ unreadCount });
 | 
			
		||||
      window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
      window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
 | 
			
		||||
      // If a message has errors, we don't want to send anything out about it.
 | 
			
		||||
      //   read syncs - let's wait for a client that really understands the message
 | 
			
		||||
| 
						 | 
				
			
			@ -2055,7 +2049,7 @@
 | 
			
		|||
      }
 | 
			
		||||
 | 
			
		||||
      if (c.hasChanged()) {
 | 
			
		||||
        window.Signal.Data.updateConversation(id, c.attributes);
 | 
			
		||||
        window.Signal.Data.updateConversation(c.attributes);
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    async setProfileName(encryptedName) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2135,7 +2129,7 @@
 | 
			
		|||
 | 
			
		||||
        await this.deriveAccessKeyIfNeeded();
 | 
			
		||||
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes, {
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes, {
 | 
			
		||||
          Conversation: Whisper.Conversation,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -2159,7 +2153,7 @@
 | 
			
		|||
          sealedSender: SEALED_SENDER.UNKNOWN,
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
        window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2219,7 +2213,7 @@
 | 
			
		|||
        timestamp: null,
 | 
			
		||||
        active_at: null,
 | 
			
		||||
      });
 | 
			
		||||
      window.Signal.Data.updateConversation(this.id, this.attributes);
 | 
			
		||||
      window.Signal.Data.updateConversation(this.attributes);
 | 
			
		||||
 | 
			
		||||
      await window.Signal.Data.removeAllMessagesInConversation(this.id, {
 | 
			
		||||
        MessageCollection: Whisper.MessageCollection,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2437,10 +2437,7 @@
 | 
			
		|||
          }
 | 
			
		||||
 | 
			
		||||
          MessageController.register(message.id, message);
 | 
			
		||||
          window.Signal.Data.updateConversation(
 | 
			
		||||
            conversationId,
 | 
			
		||||
            conversation.attributes
 | 
			
		||||
          );
 | 
			
		||||
          window.Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
 | 
			
		||||
          await message.queueAttachmentDownloads();
 | 
			
		||||
          await window.Signal.Data.saveMessage(message.attributes, {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ const {
 | 
			
		|||
  saveAttachmentDownloadJob,
 | 
			
		||||
  saveMessage,
 | 
			
		||||
  setAttachmentDownloadJobPending,
 | 
			
		||||
} = require('./data');
 | 
			
		||||
} = require('../../ts/sql/Client').default;
 | 
			
		||||
const { stringFromBytes } = require('../../ts/Crypto');
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
| 
						 | 
				
			
			@ -445,7 +445,7 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
 | 
			
		|||
        hash,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
    Signal.Data.updateConversation(conversationId, conversation.attributes);
 | 
			
		||||
    Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
 | 
			
		||||
    message.set({
 | 
			
		||||
      group_update: {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1192
									
								
								js/modules/data.js
									
										
									
									
									
								
							
							
						
						
									
										1192
									
								
								js/modules/data.js
									
										
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
				
			
			@ -50,7 +50,7 @@ exports.createConversation = async ({
 | 
			
		|||
    unread: numMessages,
 | 
			
		||||
  });
 | 
			
		||||
  const conversationId = conversation.get('id');
 | 
			
		||||
  Signal.Data.updateConversation(conversationId, conversation.attributes);
 | 
			
		||||
  Signal.Data.updateConversation(conversation.attributes);
 | 
			
		||||
 | 
			
		||||
  await Promise.all(
 | 
			
		||||
    range(0, numMessages).map(async index => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,5 @@
 | 
			
		|||
const { take } = require('lodash');
 | 
			
		||||
const { getRecentEmojis } = require('./data');
 | 
			
		||||
const { getRecentEmojis } = require('../../ts/sql/Client').default;
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
  getInitialState,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,7 @@ const {
 | 
			
		|||
 | 
			
		||||
  saveConversations,
 | 
			
		||||
  _removeConversations,
 | 
			
		||||
} = require('./data');
 | 
			
		||||
} = require('../../ts/sql/Client').default;
 | 
			
		||||
const {
 | 
			
		||||
  getMessageExportLastIndex,
 | 
			
		||||
  setMessageExportLastIndex,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								js/modules/privacy.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								js/modules/privacy.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
export function redactAll(log: string): string;
 | 
			
		||||
| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
const { bindActionCreators } = require('redux');
 | 
			
		||||
const Backbone = require('../../ts/backbone');
 | 
			
		||||
const Crypto = require('../../ts/Crypto');
 | 
			
		||||
const Data = require('./data');
 | 
			
		||||
const Data = require('../../ts/sql/Client').default;
 | 
			
		||||
const Database = require('./database');
 | 
			
		||||
const Emojis = require('./emojis');
 | 
			
		||||
const EmojiLib = require('../../ts/components/emoji/lib');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ const {
 | 
			
		|||
  getAllStickers,
 | 
			
		||||
  getRecentStickers,
 | 
			
		||||
  updateStickerPackStatus,
 | 
			
		||||
} = require('./data');
 | 
			
		||||
} = require('../../ts/sql/Client').default;
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
  BLESSED_PACKS,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								js/modules/types/message.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								js/modules/types/message.d.ts
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
export const CURRENT_SCHEMA_VERSION: number;
 | 
			
		||||
| 
						 | 
				
			
			@ -431,7 +431,7 @@
 | 
			
		|||
        }
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      await window.Signal.Data.removeSessionsById(identifier);
 | 
			
		||||
      await window.Signal.Data.removeSessionsByConversation(identifier);
 | 
			
		||||
    },
 | 
			
		||||
    async archiveSiblingSessions(identifier) {
 | 
			
		||||
      const address = libsignal.SignalProtocolAddress.fromString(identifier);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1123,13 +1123,7 @@
 | 
			
		|||
    },
 | 
			
		||||
 | 
			
		||||
    async saveModel() {
 | 
			
		||||
      window.Signal.Data.updateConversation(
 | 
			
		||||
        this.model.id,
 | 
			
		||||
        this.model.attributes,
 | 
			
		||||
        {
 | 
			
		||||
          Conversation: Whisper.Conversation,
 | 
			
		||||
        }
 | 
			
		||||
      );
 | 
			
		||||
      window.Signal.Data.updateConversation(this.model.attributes);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    async addAttachment(attachment) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue