You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Threads notifications after app startup (#2043)
This commit is contained in:
@@ -871,8 +871,7 @@ export class MatrixClient extends EventEmitter {
|
|||||||
// state, such as highlights when the user's name is mentioned.
|
// state, such as highlights when the user's name is mentioned.
|
||||||
this.on("Event.decrypted", (event) => {
|
this.on("Event.decrypted", (event) => {
|
||||||
const oldActions = event.getPushActions();
|
const oldActions = event.getPushActions();
|
||||||
const actions = this.pushProcessor.actionsForEvent(event);
|
const actions = this.getPushActionsForEvent(event, true);
|
||||||
event.setPushActions(actions); // Might as well while we're here
|
|
||||||
|
|
||||||
const room = this.getRoom(event.getRoomId());
|
const room = this.getRoom(event.getRoomId());
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
@@ -882,10 +881,8 @@ export class MatrixClient extends EventEmitter {
|
|||||||
// Ensure the unread counts are kept up to date if the event is encrypted
|
// Ensure the unread counts are kept up to date if the event is encrypted
|
||||||
// We also want to make sure that the notification count goes up if we already
|
// We also want to make sure that the notification count goes up if we already
|
||||||
// have encrypted events to avoid other code from resetting 'highlight' to zero.
|
// have encrypted events to avoid other code from resetting 'highlight' to zero.
|
||||||
const oldHighlight = oldActions && oldActions.tweaks
|
const oldHighlight = !!oldActions?.tweaks?.highlight;
|
||||||
? !!oldActions.tweaks.highlight : false;
|
const newHighlight = !!actions?.tweaks?.highlight;
|
||||||
const newHighlight = actions && actions.tweaks
|
|
||||||
? !!actions.tweaks.highlight : false;
|
|
||||||
if (oldHighlight !== newHighlight || currentCount > 0) {
|
if (oldHighlight !== newHighlight || currentCount > 0) {
|
||||||
// TODO: Handle mentions received while the client is offline
|
// TODO: Handle mentions received while the client is offline
|
||||||
// See also https://github.com/vector-im/element-web/issues/9069
|
// See also https://github.com/vector-im/element-web/issues/9069
|
||||||
@@ -4641,10 +4638,12 @@ export class MatrixClient extends EventEmitter {
|
|||||||
* Obtain a dict of actions which should be performed for this event according
|
* Obtain a dict of actions which should be performed for this event according
|
||||||
* to the push rules for this user. Caches the dict on the event.
|
* to the push rules for this user. Caches the dict on the event.
|
||||||
* @param {MatrixEvent} event The event to get push actions for.
|
* @param {MatrixEvent} event The event to get push actions for.
|
||||||
|
* @param {boolean} forceRecalculate forces to recalculate actions for an event
|
||||||
|
* Useful when an event just got decrypted
|
||||||
* @return {module:pushprocessor~PushAction} A dict of actions to perform.
|
* @return {module:pushprocessor~PushAction} A dict of actions to perform.
|
||||||
*/
|
*/
|
||||||
public getPushActionsForEvent(event: MatrixEvent): IActionsObject {
|
public getPushActionsForEvent(event: MatrixEvent, forceRecalculate = false): IActionsObject {
|
||||||
if (!event.getPushActions()) {
|
if (!event.getPushActions() || forceRecalculate) {
|
||||||
event.setPushActions(this.pushProcessor.actionsForEvent(event));
|
event.setPushActions(this.pushProcessor.actionsForEvent(event));
|
||||||
}
|
}
|
||||||
return event.getPushActions();
|
return event.getPushActions();
|
||||||
|
|||||||
@@ -1852,16 +1852,7 @@ export class Room extends EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public getReadReceiptForUserId(userId: string, ignoreSynthesized = false): IWrappedReceipt | null {
|
||||||
* Get the ID of the event that a given user has read up to, or null if we
|
|
||||||
* have received no read receipts from them.
|
|
||||||
* @param {String} userId The user ID to get read receipt event ID for
|
|
||||||
* @param {Boolean} ignoreSynthesized If true, return only receipts that have been
|
|
||||||
* sent by the server, not implicit ones generated
|
|
||||||
* by the JS SDK.
|
|
||||||
* @return {String} ID of the latest event that the given user has read, or null.
|
|
||||||
*/
|
|
||||||
public getEventReadUpTo(userId: string, ignoreSynthesized = false): string | null {
|
|
||||||
let receipts = this.receipts;
|
let receipts = this.receipts;
|
||||||
if (ignoreSynthesized) {
|
if (ignoreSynthesized) {
|
||||||
receipts = this.realReceipts;
|
receipts = this.realReceipts;
|
||||||
@@ -1874,7 +1865,21 @@ export class Room extends EventEmitter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return receipts["m.read"][userId].eventId;
|
return receipts["m.read"][userId];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the ID of the event that a given user has read up to, or null if we
|
||||||
|
* have received no read receipts from them.
|
||||||
|
* @param {String} userId The user ID to get read receipt event ID for
|
||||||
|
* @param {Boolean} ignoreSynthesized If true, return only receipts that have been
|
||||||
|
* sent by the server, not implicit ones generated
|
||||||
|
* by the JS SDK.
|
||||||
|
* @return {String} ID of the latest event that the given user has read, or null.
|
||||||
|
*/
|
||||||
|
public getEventReadUpTo(userId: string, ignoreSynthesized = false): string | null {
|
||||||
|
const readReceipt = this.getReadReceiptForUserId(userId, ignoreSynthesized);
|
||||||
|
return readReceipt?.eventId ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ export enum ThreadEvent {
|
|||||||
New = "Thread.new",
|
New = "Thread.new",
|
||||||
Ready = "Thread.ready",
|
Ready = "Thread.ready",
|
||||||
Update = "Thread.update",
|
Update = "Thread.update",
|
||||||
|
NewReply = "Thread.newReply",
|
||||||
|
ViewThread = "Thred.viewThread",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,6 +111,10 @@ export class Thread extends TypedEventEmitter<ThreadEvent> {
|
|||||||
|
|
||||||
await this.client.decryptEventIfNeeded(event, {});
|
await this.client.decryptEventIfNeeded(event, {});
|
||||||
this.emit(ThreadEvent.Update, this);
|
this.emit(ThreadEvent.Update, this);
|
||||||
|
|
||||||
|
if (event.isThreadRelation) {
|
||||||
|
this.emit(ThreadEvent.NewReply, this, event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user