mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
use logAndCatch in RoomViewModel, everything reporting errors also logs
This commit is contained in:
parent
a2c44484b2
commit
0dbb7d4e50
@ -74,9 +74,9 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
|
this.logAndCatch("Room.load", async log => {
|
||||||
this._room.on("change", this._onRoomChange);
|
this._room.on("change", this._onRoomChange);
|
||||||
try {
|
const timeline = await this._room.openTimeline(log);
|
||||||
const timeline = await this._room.openTimeline();
|
|
||||||
this._tileOptions = this.childOptions({
|
this._tileOptions = this.childOptions({
|
||||||
session: this.getOption("session"),
|
session: this.getOption("session"),
|
||||||
roomVM: this,
|
roomVM: this,
|
||||||
@ -88,13 +88,11 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
timeline,
|
timeline,
|
||||||
})));
|
})));
|
||||||
this.emitChange("timelineViewModel");
|
this.emitChange("timelineViewModel");
|
||||||
} catch (error) {
|
await this._clearUnreadAfterDelay(log);
|
||||||
this.reportError(error);
|
});
|
||||||
}
|
|
||||||
this._clearUnreadAfterDelay();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _clearUnreadAfterDelay() {
|
async _clearUnreadAfterDelay(log) {
|
||||||
if (this._room.isArchived || this._clearUnreadTimout) {
|
if (this._room.isArchived || this._clearUnreadTimout) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -104,7 +102,9 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
await this._room.clearUnread();
|
await this._room.clearUnread();
|
||||||
this._clearUnreadTimout = null;
|
this._clearUnreadTimout = null;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name !== "AbortError") {
|
if (err.name === "AbortError") {
|
||||||
|
log.set("clearUnreadCancelled", true);
|
||||||
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,62 +190,61 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _sendMessage(message, replyingTo) {
|
_sendMessage(message, replyingTo) {
|
||||||
|
return this.logAndCatch("sendMessage", async log => {
|
||||||
|
let success = false;
|
||||||
if (!this._room.isArchived && message) {
|
if (!this._room.isArchived && message) {
|
||||||
try {
|
|
||||||
let msgtype = "m.text";
|
let msgtype = "m.text";
|
||||||
if (message.startsWith("/me ")) {
|
if (message.startsWith("/me ")) {
|
||||||
message = message.substr(4).trim();
|
message = message.substr(4).trim();
|
||||||
msgtype = "m.emote";
|
msgtype = "m.emote";
|
||||||
}
|
}
|
||||||
if (replyingTo) {
|
if (replyingTo) {
|
||||||
|
log.set("replyingTo", replyingTo.eventId);
|
||||||
|
// TODO: reply should not send? it should just return the content for the reply and we send it ourselves
|
||||||
await replyingTo.reply(msgtype, message);
|
await replyingTo.reply(msgtype, message);
|
||||||
} else {
|
} else {
|
||||||
await this._room.sendEvent("m.room.message", {msgtype, body: message});
|
await this._room.sendEvent("m.room.message", {msgtype, body: message}, undefined, log);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
success = true;
|
||||||
this.reportError(error);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
log.set("success", success);
|
||||||
}
|
return success;
|
||||||
return false;
|
}, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _pickAndSendFile() {
|
_pickAndSendFile() {
|
||||||
try {
|
return this.logAndCatch("sendFile", async log => {
|
||||||
const file = await this.platform.openFile();
|
const file = await this.platform.openFile();
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
log.set("cancelled", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return this._sendFile(file);
|
return this._sendFile(file, log);
|
||||||
} catch (err) {
|
});
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _sendFile(file) {
|
async _sendFile(file, log) {
|
||||||
const content = {
|
const content = {
|
||||||
body: file.name,
|
body: file.name,
|
||||||
msgtype: "m.file"
|
msgtype: "m.file"
|
||||||
};
|
};
|
||||||
await this._room.sendEvent("m.room.message", content, {
|
await this._room.sendEvent("m.room.message", content, {
|
||||||
"url": this._room.createAttachment(file.blob, file.name)
|
"url": this._room.createAttachment(file.blob, file.name)
|
||||||
});
|
}, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _pickAndSendVideo() {
|
_pickAndSendVideo() {
|
||||||
try {
|
return this.logAndCatch("sendVideo", async log => {
|
||||||
if (!this.platform.hasReadPixelPermission()) {
|
if (!this.platform.hasReadPixelPermission()) {
|
||||||
alert("Please allow canvas image data access, so we can scale your images down.");
|
throw new Error("Please allow canvas image data access, so we can scale your images down.");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const file = await this.platform.openFile("video/*");
|
const file = await this.platform.openFile("video/*");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!file.blob.mimeType.startsWith("video/")) {
|
if (!file.blob.mimeType.startsWith("video/")) {
|
||||||
return this._sendFile(file);
|
return this._sendFile(file, log);
|
||||||
}
|
}
|
||||||
let video;
|
let video;
|
||||||
try {
|
try {
|
||||||
@ -273,24 +272,23 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
content.info.thumbnail_info = imageToInfo(thumbnail);
|
content.info.thumbnail_info = imageToInfo(thumbnail);
|
||||||
attachments["info.thumbnail_url"] =
|
attachments["info.thumbnail_url"] =
|
||||||
this._room.createAttachment(thumbnail.blob, file.name);
|
this._room.createAttachment(thumbnail.blob, file.name);
|
||||||
await this._room.sendEvent("m.room.message", content, attachments);
|
await this._room.sendEvent("m.room.message", content, attachments, log);
|
||||||
} catch (error) {
|
});
|
||||||
this.reportError(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async _pickAndSendPicture() {
|
async _pickAndSendPicture() {
|
||||||
try {
|
this.logAndCatch("sendPicture", async log => {
|
||||||
if (!this.platform.hasReadPixelPermission()) {
|
if (!this.platform.hasReadPixelPermission()) {
|
||||||
alert("Please allow canvas image data access, so we can scale your images down.");
|
alert("Please allow canvas image data access, so we can scale your images down.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const file = await this.platform.openFile("image/*");
|
const file = await this.platform.openFile("image/*");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
log.set("cancelled", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!file.blob.mimeType.startsWith("image/")) {
|
if (!file.blob.mimeType.startsWith("image/")) {
|
||||||
return this._sendFile(file);
|
return this._sendFile(file, log);
|
||||||
}
|
}
|
||||||
let image = await this.platform.loadImage(file.blob);
|
let image = await this.platform.loadImage(file.blob);
|
||||||
const limit = await this.platform.settingsStorage.getInt("sentImageSizeLimit");
|
const limit = await this.platform.settingsStorage.getInt("sentImageSizeLimit");
|
||||||
@ -313,10 +311,8 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
attachments["info.thumbnail_url"] =
|
attachments["info.thumbnail_url"] =
|
||||||
this._room.createAttachment(thumbnail.blob, file.name);
|
this._room.createAttachment(thumbnail.blob, file.name);
|
||||||
}
|
}
|
||||||
await this._room.sendEvent("m.room.message", content, attachments);
|
await this._room.sendEvent("m.room.message", content, attachments, log);
|
||||||
} catch (error) {
|
});
|
||||||
this.reportError(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get room() {
|
get room() {
|
||||||
@ -344,14 +340,14 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async startCall() {
|
startCall() {
|
||||||
|
return this.logAndCatch("startCall", async log => {
|
||||||
let localMedia;
|
let localMedia;
|
||||||
try {
|
try {
|
||||||
const stream = await this.platform.mediaDevices.getMediaTracks(false, true);
|
const stream = await this.platform.mediaDevices.getMediaTracks(false, true);
|
||||||
localMedia = new LocalMedia().withUserMedia(stream);
|
localMedia = new LocalMedia().withUserMedia(stream);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.reportError(new Error(`Could not get local audio and/or video stream: ${err.message}`));
|
throw new Error(`Could not get local audio and/or video stream: ${err.message}`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
const session = this.getOption("session");
|
const session = this.getOption("session");
|
||||||
let call;
|
let call;
|
||||||
@ -359,15 +355,14 @@ export class RoomViewModel extends ErrorReportViewModel {
|
|||||||
// this will set the callViewModel above as a call will be added to callHandler.calls
|
// this will set the callViewModel above as a call will be added to callHandler.calls
|
||||||
call = await session.callHandler.createCall(this._room.id, "m.video", "A call " + Math.round(this.platform.random() * 100));
|
call = await session.callHandler.createCall(this._room.id, "m.video", "A call " + Math.round(this.platform.random() * 100));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.reportError(new Error(`Could not create call: ${err.message}`));
|
throw new Error(`Could not create call: ${err.message}`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await call.join(localMedia);
|
await call.join(localMedia);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.reportError(new Error(`Could not join call: ${err.message}`));
|
throw new Error(`Could not join call: ${err.message}`);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user