Pass around MatrixClients instead of using MatrixClientPeg (#11000)
This commit is contained in:
parent
aa5a2e1363
commit
938aefc51c
28 changed files with 176 additions and 141 deletions
|
@ -17,8 +17,8 @@ limitations under the License.
|
|||
import { MatrixEvent, EventStatus } from "matrix-js-sdk/src/models/event";
|
||||
import { Room } from "matrix-js-sdk/src/models/room";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import { MatrixClientPeg } from "./MatrixClientPeg";
|
||||
import dis from "./dispatcher/dispatcher";
|
||||
|
||||
export default class Resend {
|
||||
|
@ -30,7 +30,7 @@ export default class Resend {
|
|||
return ev.status === EventStatus.NOT_SENT;
|
||||
})
|
||||
.map(function (event: MatrixEvent) {
|
||||
return Resend.resend(event);
|
||||
return Resend.resend(room.client, event);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
@ -41,30 +41,28 @@ export default class Resend {
|
|||
return ev.status === EventStatus.NOT_SENT;
|
||||
})
|
||||
.forEach(function (event: MatrixEvent) {
|
||||
Resend.removeFromQueue(event);
|
||||
Resend.removeFromQueue(room.client, event);
|
||||
});
|
||||
}
|
||||
|
||||
public static resend(event: MatrixEvent): Promise<void> {
|
||||
const room = MatrixClientPeg.get().getRoom(event.getRoomId())!;
|
||||
return MatrixClientPeg.get()
|
||||
.resendEvent(event, room)
|
||||
.then(
|
||||
function (res) {
|
||||
dis.dispatch({
|
||||
action: "message_sent",
|
||||
event: event,
|
||||
});
|
||||
},
|
||||
function (err: Error) {
|
||||
// XXX: temporary logging to try to diagnose
|
||||
// https://github.com/vector-im/element-web/issues/3148
|
||||
logger.log("Resend got send failure: " + err.name + "(" + err + ")");
|
||||
},
|
||||
);
|
||||
public static resend(client: MatrixClient, event: MatrixEvent): Promise<void> {
|
||||
const room = client.getRoom(event.getRoomId())!;
|
||||
return client.resendEvent(event, room).then(
|
||||
function (res) {
|
||||
dis.dispatch({
|
||||
action: "message_sent",
|
||||
event: event,
|
||||
});
|
||||
},
|
||||
function (err: Error) {
|
||||
// XXX: temporary logging to try to diagnose
|
||||
// https://github.com/vector-im/element-web/issues/3148
|
||||
logger.log("Resend got send failure: " + err.name + "(" + err + ")");
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
public static removeFromQueue(event: MatrixEvent): void {
|
||||
MatrixClientPeg.get().cancelPendingEvent(event);
|
||||
public static removeFromQueue(client: MatrixClient, event: MatrixEvent): void {
|
||||
client.cancelPendingEvent(event);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue