Merge remote-tracking branch 'upstream/clearnet' into disable-search-for-now

pull/1792/head
audric 4 years ago
commit 5b487b0fec

@ -164,7 +164,7 @@ class MessageInner extends React.PureComponent<Props, State> {
public checkExpired() { public checkExpired() {
const now = Date.now(); const now = Date.now();
const { isExpired, expirationTimestamp, expirationLength } = this.props; const { isExpired, expirationTimestamp, expirationLength, convoId, id } = this.props;
if (!expirationTimestamp || !expirationLength) { if (!expirationTimestamp || !expirationLength) {
return; return;
@ -178,17 +178,23 @@ class MessageInner extends React.PureComponent<Props, State> {
expiring: true, expiring: true,
}); });
const setExpired = () => { const setExpired = async () => {
this.setState({ this.setState({
expired: true, expired: true,
}); });
await window.Signal.Data.removeMessage(id);
window.inboxStore?.dispatch( window.inboxStore?.dispatch(
messageExpired({ messageId: this.props.id, conversationKey: this.props.convoId }) messageExpired({
conversationKey: convoId,
messageId: id,
})
); );
getConversationController() const convo = getConversationController().get(convoId);
.get(this.props.convoId) convo?.updateLastMessage();
?.updateLastMessage();
}; };
// as 'checkExpired' is potentially called more than once (componentDidUpdate & componentDidMount),
// we need to clear the timeout call to 'setExpired' first to avoid multiple calls to 'setExpired'.
global.clearTimeout(this.expiredTimeout);
this.expiredTimeout = setTimeout(setExpired, EXPIRED_DELAY); this.expiredTimeout = setTimeout(setExpired, EXPIRED_DELAY);
} }
} }

@ -625,7 +625,7 @@ export async function saveMessages(arrayOfMessages: Array<MessageAttributes>): P
} }
export async function removeMessage(id: string): Promise<void> { export async function removeMessage(id: string): Promise<void> {
const message = await getMessageById(id); const message = await getMessageById(id, true);
// Note: It's important to have a fully database-hydrated model to delete here because // Note: It's important to have a fully database-hydrated model to delete here because
// it needs to delete all associated on-disk files along with the database delete. // it needs to delete all associated on-disk files along with the database delete.
@ -647,11 +647,17 @@ export async function getMessageIdsFromServerIds(
return channels.getMessageIdsFromServerIds(serverIds, conversationId); return channels.getMessageIdsFromServerIds(serverIds, conversationId);
} }
export async function getMessageById(id: string): Promise<MessageModel | null> { export async function getMessageById(
id: string,
skipTimerInit: boolean = false
): Promise<MessageModel | null> {
const message = await channels.getMessageById(id); const message = await channels.getMessageById(id);
if (!message) { if (!message) {
return null; return null;
} }
if (skipTimerInit) {
message.skipTimerInit = skipTimerInit;
}
return new MessageModel(message); return new MessageModel(message);
} }
@ -725,13 +731,18 @@ export async function getUnreadCountByConversation(conversationId: string): Prom
export async function getMessagesByConversation( export async function getMessagesByConversation(
conversationId: string, conversationId: string,
{ limit = 100, receivedAt = Number.MAX_VALUE, type = '%' } { limit = 100, receivedAt = Number.MAX_VALUE, type = '%', skipTimerInit = false }
): Promise<MessageCollection> { ): Promise<MessageCollection> {
const messages = await channels.getMessagesByConversation(conversationId, { const messages = await channels.getMessagesByConversation(conversationId, {
limit, limit,
receivedAt, receivedAt,
type, type,
}); });
if (skipTimerInit) {
for (const message of messages) {
message.skipTimerInit = skipTimerInit;
}
}
return new MessageCollection(messages); return new MessageCollection(messages);
} }

@ -439,7 +439,9 @@ export async function deleteMessagesById(
askUserForConfirmation: boolean askUserForConfirmation: boolean
) { ) {
const conversationModel = getConversationController().getOrThrow(conversationId); const conversationModel = getConversationController().getOrThrow(conversationId);
const selectedMessages = _.compact(await Promise.all(messageIds.map(getMessageById))); const selectedMessages = _.compact(
await Promise.all(messageIds.map(m => getMessageById(m, false)))
);
const moreThanOne = selectedMessages.length > 1; const moreThanOne = selectedMessages.length > 1;

@ -785,6 +785,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
} }
const messages = await getMessagesByConversation(this.id, { const messages = await getMessagesByConversation(this.id, {
limit: 1, limit: 1,
skipTimerInit: true,
}); });
const lastMessageModel = messages.at(0); const lastMessageModel = messages.at(0);
const lastMessageJSON = lastMessageModel ? lastMessageModel.toJSON() : null; const lastMessageJSON = lastMessageModel ? lastMessageModel.toJSON() : null;

@ -57,7 +57,7 @@ import { perfEnd, perfStart } from '../session/utils/Performance';
import { AttachmentTypeWithPath } from '../types/Attachment'; import { AttachmentTypeWithPath } from '../types/Attachment';
export class MessageModel extends Backbone.Model<MessageAttributes> { export class MessageModel extends Backbone.Model<MessageAttributes> {
constructor(attributes: MessageAttributesOptionals) { constructor(attributes: MessageAttributesOptionals & { skipTimerInit?: boolean }) {
const filledAttrs = fillMessageAttributesWithDefaults(attributes); const filledAttrs = fillMessageAttributesWithDefaults(attributes);
super(filledAttrs); super(filledAttrs);
@ -76,7 +76,9 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
} }
// this.on('expired', this.onExpired); // this.on('expired', this.onExpired);
void this.setToExpire(); if (!attributes.skipTimerInit) {
void this.setToExpire();
}
autoBind(this); autoBind(this);
this.dispatchMessageUpdate = _.throttle(this.dispatchMessageUpdate, 300); this.dispatchMessageUpdate = _.throttle(this.dispatchMessageUpdate, 300);

Loading…
Cancel
Save