make unread attrs as before a number, and remove calculatingPow

calculating pow is just the same as sending state
pull/1530/head
Audric Ackermann 4 years ago
parent 5f862e4c08
commit 553f264d12
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -740,15 +740,6 @@
} }
}); });
Whisper.events.on('calculatingPoW', ({ pubKey, timestamp }) => {
try {
const conversation = window.getConversationController().get(pubKey);
conversation.onCalculatingPoW(pubKey, timestamp);
} catch (e) {
window.log.error('Error showing PoW cog');
}
});
Whisper.events.on('password-updated', () => { Whisper.events.on('password-updated', () => {
if (appView && appView.inboxView) { if (appView && appView.inboxView) {
appView.inboxView.trigger('password-updated'); appView.inboxView.trigger('password-updated');

@ -37,7 +37,7 @@
const conversation = message.getConversation(); const conversation = message.getConversation();
if (conversation) { if (conversation) {
conversation.trigger('expired', message); conversation.onExpired(message);
} }
}) })
); );

@ -22,7 +22,7 @@ type Props = {
direction: 'incoming' | 'outgoing'; direction: 'incoming' | 'outgoing';
timestamp: number; timestamp: number;
serverTimestamp?: number; serverTimestamp?: number;
status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error' | 'pow'; status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
expirationLength?: number; expirationLength?: number;
expirationTimestamp?: number; expirationTimestamp?: number;
isPublic?: boolean; isPublic?: boolean;

@ -94,13 +94,12 @@ const MessageStatusError = (props: { theme: DefaultTheme }) => {
}; };
export const OutgoingMessageStatus = (props: { export const OutgoingMessageStatus = (props: {
status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error' | 'pow'; status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
theme: DefaultTheme; theme: DefaultTheme;
iconColor: string; iconColor: string;
isInMessageView?: boolean; isInMessageView?: boolean;
}) => { }) => {
switch (props.status) { switch (props.status) {
case 'pow':
case 'sending': case 'sending':
return <MessageStatusSending {...props} />; return <MessageStatusSending {...props} />;
case 'sent': case 'sent':

@ -312,18 +312,6 @@ class SettingsViewInner extends React.Component<SettingsViewProps, State> {
} }
} }
private getPubkeyName(pubKey: string | null) {
if (!pubKey) {
return {};
}
const secretWords = window.mnemonic.pubkey_to_secret_words(pubKey);
const conv = ConversationController.getInstance().get(pubKey);
const deviceAlias = conv ? conv.getNickname() : 'Unnamed Device';
return { deviceAlias, secretWords };
}
// tslint:disable-next-line: max-func-body-length // tslint:disable-next-line: max-func-body-length
private getLocalSettings(): Array<LocalSettingType> { private getLocalSettings(): Array<LocalSettingType> {
const { Settings } = window.Signal.Types; const { Settings } = window.Signal.Types;

@ -140,7 +140,6 @@ export const fillConvoAttributesWithDefaults = (
export class ConversationModel extends Backbone.Model<ConversationAttributes> { export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public updateLastMessage: () => any; public updateLastMessage: () => any;
public messageCollection: MessageCollection;
public throttledBumpTyping: any; public throttledBumpTyping: any;
public throttledNotify: any; public throttledNotify: any;
public markRead: any; public markRead: any;
@ -158,10 +157,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
// This may be overridden by ConversationController.getOrCreate, and signify // This may be overridden by ConversationController.getOrCreate, and signify
// our first save to the database. Or first fetch from the database. // our first save to the database. Or first fetch from the database.
this.initialPromise = Promise.resolve(); this.initialPromise = Promise.resolve();
this.messageCollection = new MessageCollection([], {
conversation: this,
});
autoBind(this); autoBind(this);
this.throttledBumpTyping = _.throttle(this.bumpTyping, 300); this.throttledBumpTyping = _.throttle(this.bumpTyping, 300);
@ -170,10 +165,9 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
1000 1000
); );
this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 });
this.markRead = _.debounce(this.markReadBouncy, 1000); //start right away the function is called, and wait 1sec before calling it again
this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true });
// Listening for out-of-band data updates // Listening for out-of-band data updates
this.on('expired', this.onExpired);
this.on('ourAvatarChanged', avatar => this.on('ourAvatarChanged', avatar =>
this.updateAvatarOnPublicChat(avatar) this.updateAvatarOnPublicChat(avatar)
); );
@ -376,42 +370,10 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
} }
public async onExpired(message: any) { public async onExpired(message: MessageModel) {
await this.updateLastMessage(); await this.updateLastMessage();
const removeMessage = () => { // removeMessage();
const { id } = message;
const existing = this.messageCollection.get(id);
if (!existing) {
return;
}
window.log.info('Remove expired message from collection', {
sentAt: existing.get('sent_at'),
});
this.messageCollection.remove(id);
existing.trigger('expired');
};
removeMessage();
}
// Get messages with the given timestamp
public getMessagesWithTimestamp(pubKey: string, timestamp: number) {
if (this.id !== pubKey) {
return [];
}
// Go through our messages and find the one that we need to update
return this.messageCollection.models.filter(
(m: any) => m.get('sent_at') === timestamp
);
}
public async onCalculatingPoW(pubKey: string, timestamp: number) {
const messages = this.getMessagesWithTimestamp(pubKey, timestamp);
await Promise.all(messages.map((m: any) => m.setCalculatingPoW()));
} }
public getGroupAdmins() { public getGroupAdmins() {
@ -915,7 +877,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const messageAttributes = { const messageAttributes = {
// Even though this isn't reflected to the user, we want to place the last seen // Even though this isn't reflected to the user, we want to place the last seen
// indicator above it. We set it to 'unread' to trigger that placement. // indicator above it. We set it to 'unread' to trigger that placement.
unread: true, unread: 1,
conversationId: this.id, conversationId: this.id,
// No type; 'incoming' messages are specially treated by conversation.markRead() // No type; 'incoming' messages are specially treated by conversation.markRead()
sent_at: timestamp, sent_at: timestamp,
@ -1048,37 +1010,29 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
); );
let read = []; let read = [];
console.time('markReadNOCommit');
// Build the list of updated message models so we can mark them all as read on a single sqlite call // Build the list of updated message models so we can mark them all as read on a single sqlite call
for (const nowRead of oldUnreadNowRead) { for (const nowRead of oldUnreadNowRead) {
const m = MessageController.getInstance().register(nowRead.id, nowRead); nowRead.markReadNoCommit(options.readAt);
await m.markRead(options.readAt);
const errors = m.get('errors'); const errors = nowRead.get('errors');
read.push({ read.push({
sender: m.get('source'), sender: nowRead.get('source'),
timestamp: m.get('sent_at'), timestamp: nowRead.get('sent_at'),
hasErrors: Boolean(errors && errors.length), hasErrors: Boolean(errors && errors.length),
}); });
} }
console.timeEnd('markReadNOCommit');
console.warn('oldUnreadNowRead', oldUnreadNowRead);
const oldUnreadNowReadAttrs = oldUnreadNowRead.map(m => m.attributes); const oldUnreadNowReadAttrs = oldUnreadNowRead.map(m => m.attributes);
console.warn('oldUnreadNowReadAttrs', oldUnreadNowReadAttrs);
await saveMessages(oldUnreadNowReadAttrs); await saveMessages(oldUnreadNowReadAttrs);
console.time('trigger');
for (const nowRead of oldUnreadNowRead) { for (const nowRead of oldUnreadNowRead) {
nowRead.generateProps(false); nowRead.generateProps(false);
} }
window.inboxStore?.dispatch( window.inboxStore?.dispatch(
conversationActions.messagesChanged(oldUnreadNowRead) conversationActions.messagesChanged(oldUnreadNowRead)
); );
console.timeEnd('trigger');
// Some messages we're marking read are local notifications with no sender // Some messages we're marking read are local notifications with no sender
read = _.filter(read, m => Boolean(m.sender)); read = _.filter(read, m => Boolean(m.sender));

@ -72,13 +72,9 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
this.propsForMessage = this.getPropsForMessage(); this.propsForMessage = this.getPropsForMessage();
} }
console.time(`messageChanged ${this.id}`);
if (triggerEvent) { if (triggerEvent) {
window.inboxStore?.dispatch(conversationActions.messageChanged(this)); window.inboxStore?.dispatch(conversationActions.messageChanged(this));
} }
console.timeEnd(`messageChanged ${this.id}`);
} }
public idForLogging() { public idForLogging() {
@ -117,7 +113,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
const { unread } = attributes; const { unread } = attributes;
if (unread === undefined) { if (unread === undefined) {
this.set({ unread: false }); this.set({ unread: 0 });
} }
this.set(attributes); this.set(attributes);
@ -432,10 +428,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (sent || sentTo.length > 0) { if (sent || sentTo.length > 0) {
return 'sent'; return 'sent';
} }
const calculatingPoW = this.get('calculatingPoW');
if (calculatingPoW) {
return 'pow';
}
return 'sending'; return 'sending';
} }
@ -1009,18 +1001,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
return null; return null;
} }
public async setCalculatingPoW() {
if (this.get('calculatingPoW')) {
return;
}
this.set({
calculatingPoW: true,
});
await this.commit();
}
public async sendSyncMessageOnly(dataMessage: DataMessage) { public async sendSyncMessageOnly(dataMessage: DataMessage) {
const now = Date.now(); const now = Date.now();
this.set({ this.set({
@ -1124,7 +1104,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
} }
public markReadNoCommit(readAt: number) { public markReadNoCommit(readAt: number) {
this.set({ unread: false }); this.set({ unread: 0 });
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) { if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) {
const expirationStartTimestamp = Math.min( const expirationStartTimestamp = Math.min(

@ -50,20 +50,57 @@ export interface MessageAttributes {
fromSync?: boolean; fromSync?: boolean;
fromGroupUpdate?: boolean; fromGroupUpdate?: boolean;
}; };
unread: boolean; /**
* 1 means unread, 0 or anything else is read.
*/
unread: number;
group?: any; group?: any;
/**
* timestamp is the sent_at timestamp, which is the envelope.timestamp
*/
timestamp?: number; timestamp?: number;
status: MessageDeliveryStatus; status: MessageDeliveryStatus;
dataMessage: any; dataMessage: any;
sent_to: any; sent_to: any;
sent: boolean; sent: boolean;
calculatingPoW: boolean;
/**
* The serverId is the id on the open group server itself.
* Each message sent to an open group gets a serverId.
* This is not the id for the server, but the id ON the server.
*
* This field is not set for a message not on an opengroup server.
*/
serverId?: number; serverId?: number;
/**
* This is the timestamp of that messages as it was saved by the Open group server.
* We rely on this one to order Open Group messages.
* This field is not set for a message not on an opengroup server.
*/
serverTimestamp?: number; serverTimestamp?: number;
/**
* This field is set to true if the message is for a public server.
* This is useful to make the Badge `Public` Appear on a sent message to a server, even if we did not get
* the response from the server yet that this message was successfully added.
*/
isPublic: boolean; isPublic: boolean;
/**
* sentSync set to true means we just triggered the sync message for this Private Chat message.
* We did not yet get the message sent confirmation, it was just added to the Outgoing MessageQueue
*/
sentSync: boolean; sentSync: boolean;
/**
* synced set to true means that this message was successfully sent by our current device to our other devices.
* It is set to true when the MessageQueue did effectively sent our sync message without errors.
*/
synced: boolean; synced: boolean;
sync: boolean; sync: boolean;
/**
* This field is used for search only
*/
snippet?: any; snippet?: any;
direction: any; direction: any;
} }
@ -103,14 +140,13 @@ export interface MessageAttributesOptionals {
fromSync?: boolean; fromSync?: boolean;
fromGroupUpdate?: boolean; fromGroupUpdate?: boolean;
}; };
unread?: boolean; unread?: number;
group?: any; group?: any;
timestamp?: number; timestamp?: number;
status?: MessageDeliveryStatus; status?: MessageDeliveryStatus;
dataMessage?: any; dataMessage?: any;
sent_to?: Array<string>; sent_to?: Array<string>;
sent?: boolean; sent?: boolean;
calculatingPoW?: boolean;
serverId?: number; serverId?: number;
serverTimestamp?: number; serverTimestamp?: number;
isPublic?: boolean; isPublic?: boolean;
@ -133,6 +169,7 @@ export const fillMessageAttributesWithDefaults = (
expireTimer: 0, // disabled expireTimer: 0, // disabled
id: uuidv4(), id: uuidv4(),
schemaVersion: window.Signal.Types.Message.CURRENT_SCHEMA_VERSION, schemaVersion: window.Signal.Types.Message.CURRENT_SCHEMA_VERSION,
unread: 0, // if nothing is set, this message is considered read
}); });
}; };
@ -147,7 +184,7 @@ export interface MessageRegularProps {
direction: 'incoming' | 'outgoing'; direction: 'incoming' | 'outgoing';
timestamp: number; timestamp: number;
serverTimestamp?: number; serverTimestamp?: number;
status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error' | 'pow'; status?: 'sending' | 'sent' | 'delivered' | 'read' | 'error';
// What if changed this over to a single contact like quote, and put the events on it? // What if changed this over to a single contact like quote, and put the events on it?
contact?: Contact & { contact?: Contact & {
onSendMessage?: () => void; onSendMessage?: () => void;

@ -289,7 +289,7 @@ function updateReadStatus(
} }
} }
if (readSync || message.isExpirationTimerUpdate()) { if (readSync || message.isExpirationTimerUpdate()) {
message.set({ unread: false }); message.set({ unread: 0 });
// This is primarily to allow the conversation to mark all older // This is primarily to allow the conversation to mark all older
// messages as read, as is done when we receive a read sync for // messages as read, as is done when we receive a read sync for

@ -206,7 +206,7 @@ export async function addUpdateMessage(
sent_at: sentAt, sent_at: sentAt,
received_at: now, received_at: now,
group_update: groupUpdate, group_update: groupUpdate,
unread, unread: unread ? 1 : 0,
expireTimer: 0, expireTimer: 0,
}); });

@ -536,7 +536,6 @@ function handleMessageChanged(
action: MessageChangedActionType action: MessageChangedActionType
) { ) {
const { payload } = action; const { payload } = action;
console.time('handleMessageChanged' + payload.id);
const messageInStoreIndex = state?.messages?.findIndex( const messageInStoreIndex = state?.messages?.findIndex(
m => m.id === payload.id m => m.id === payload.id

Loading…
Cancel
Save