merge master
This commit is contained in:
commit
a08cbde7b0
45 changed files with 881 additions and 462 deletions
|
|
@ -53,16 +53,16 @@ export function registerServiceWorker() {
|
|||
}
|
||||
}
|
||||
|
||||
export function requestNotificationPermission() {
|
||||
export async function requestNotificationPermission() {
|
||||
if("PushManager" in window) {
|
||||
window.Notification.requestPermission();
|
||||
return Notification?.requestPermission().then((permission) => permission);
|
||||
} else {
|
||||
console.log("No Push API Support!");
|
||||
}
|
||||
}
|
||||
|
||||
export function windowNotificationPermission() {
|
||||
return window.Notification.permission
|
||||
return window?.Notification?.permission ?? 'Not_supported'
|
||||
}
|
||||
|
||||
export function notificationCount() {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ import axios from 'axios';
|
|||
import * as ContentHelpers from "matrix-js-sdk/lib/content-helpers";
|
||||
import dataUriToBuffer from "data-uri-to-buffer";
|
||||
import ImageResize from "image-resize";
|
||||
import { AutoDiscovery } from 'matrix-js-sdk';
|
||||
import User from '../models/user';
|
||||
const prettyBytes = require("pretty-bytes");
|
||||
|
||||
export const STATE_EVENT_ROOM_DELETION_NOTICE = "im.keanu.room_deletion_notice";
|
||||
export const STATE_EVENT_ROOM_DELETED = "im.keanu.room_deleted";
|
||||
|
|
@ -127,7 +130,7 @@ class Util {
|
|||
});
|
||||
}
|
||||
|
||||
getThumbnail(matrixClient, event, ignoredw, ignoredh) {
|
||||
getThumbnail(matrixClient, event, config, ignoredw, ignoredh) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const content = event.getContent();
|
||||
if (content.url != null) {
|
||||
|
|
@ -157,7 +160,7 @@ class Util {
|
|||
// true
|
||||
// );
|
||||
url = matrixClient.mxcUrlToHttp(file.url);
|
||||
} else if (content.file && content.file.url) {
|
||||
} else if (content.file && content.file.url && this.getFileSize(event) > 0 && this.getFileSize(event) < config.maxSizeAutoDownloads) {
|
||||
// No thumb, use real url
|
||||
file = content.file;
|
||||
url = matrixClient.mxcUrlToHttp(file.url);
|
||||
|
|
@ -346,7 +349,7 @@ class Util {
|
|||
});
|
||||
}
|
||||
|
||||
sendImage(matrixClient, roomId, file, onUploadProgress, threadRoot) {
|
||||
sendFile(matrixClient, roomId, file, onUploadProgress, threadRoot) {
|
||||
const uploadPromise = new UploadPromise(undefined);
|
||||
uploadPromise.wrappedPromise = new Promise((resolve, reject) => {
|
||||
var reader = new FileReader();
|
||||
|
|
@ -369,13 +372,13 @@ class Util {
|
|||
}
|
||||
|
||||
var description = file.name;
|
||||
var msgtype = 'm.image';
|
||||
if (file.type.startsWith("audio/")) {
|
||||
var msgtype = 'm.file';
|
||||
if (file.type.startsWith("image/")) {
|
||||
msgtype = 'm.image';
|
||||
} else if (file.type.startsWith("audio/")) {
|
||||
msgtype = 'm.audio';
|
||||
} else if (file.type.startsWith("video/")) {
|
||||
msgtype = 'm.video';
|
||||
} else if (file.type.startsWith("application/pdf")) {
|
||||
msgtype = 'm.file';
|
||||
}
|
||||
|
||||
const opts = {
|
||||
|
|
@ -867,10 +870,10 @@ class Util {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
getUniqueAliasForRoomName(matrixClient, roomName, homeServer, iterationCount) {
|
||||
getUniqueAliasForRoomName(matrixClient, roomName, defaultMatrixDomainPart, iterationCount) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var preferredAlias = roomName.replace(/\s/g, "").toLowerCase();
|
||||
var tryAlias = "#" + preferredAlias + ":" + homeServer;
|
||||
var tryAlias = "#" + preferredAlias + ":" + defaultMatrixDomainPart;
|
||||
matrixClient.getRoomIdForAlias(tryAlias)
|
||||
.then(ignoredid => {
|
||||
// We got a response, this means the tryAlias already exists.
|
||||
|
|
@ -885,7 +888,7 @@ class Util {
|
|||
roomName = roomName.substring(0, roomName.length - 5);
|
||||
}
|
||||
const randomChars = this.randomString(4, "abcdefghijklmnopqrstuvwxyz0123456789");
|
||||
resolve(this.getUniqueAliasForRoomName(matrixClient, roomName + "-" + randomChars, homeServer, (iterationCount || 0) + 1))
|
||||
resolve(this.getUniqueAliasForRoomName(matrixClient, roomName + "-" + randomChars, defaultMatrixDomainPart, (iterationCount || 0) + 1))
|
||||
})
|
||||
.catch(err => {
|
||||
if (err.errcode == 'M_NOT_FOUND') {
|
||||
|
|
@ -911,7 +914,6 @@ class Util {
|
|||
link.download = event.getContent().body || this.$t("fallbacks.download_name");
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
setTimeout(function () {
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
|
|
@ -932,6 +934,96 @@ class Util {
|
|||
// Check if the user agent matches the pattern for mobile or tablet browsers
|
||||
return mobileTabletPattern.test(userAgent);
|
||||
}
|
||||
|
||||
getMatrixBaseUrl(user, config) {
|
||||
if (user) {
|
||||
const domain = User.domainPart(user.user_id);
|
||||
if (domain) {
|
||||
const endpoint = config.getMatrixDomainPartMapping(domain);
|
||||
if (endpoint) {
|
||||
console.log("Mapped to", endpoint);
|
||||
return Promise.resolve(endpoint);
|
||||
}
|
||||
return AutoDiscovery.findClientConfig(domain)
|
||||
.then((clientConfig) => {
|
||||
const hs = clientConfig['m.homeserver'];
|
||||
if (hs && !hs.error && hs.base_url) {
|
||||
console.log("Use home server returned from well-known", hs.base_url);
|
||||
return hs.base_url;
|
||||
}
|
||||
console.log("Fallback to default server");
|
||||
return config.defaultBaseUrl;
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Failed well-known lookup", err);
|
||||
return config.defaultBaseUrl;
|
||||
});
|
||||
}
|
||||
}
|
||||
return Promise.resolve(config.defaultBaseUrl);
|
||||
}
|
||||
|
||||
getMimeType(event) {
|
||||
const content = event.getContent();
|
||||
return (content.info && content.info.mimetype) ? content.info.mimetype : (content.file && content.file.mimetype) ? content.file.mimetype : "";
|
||||
}
|
||||
|
||||
getFileName(event) {
|
||||
const content = event.getContent();
|
||||
return (content.body || content.filename || "").toLowerCase();
|
||||
}
|
||||
|
||||
getFileExtension(event) {
|
||||
const fileName = this.getFileName(event);
|
||||
const parts = fileName.split(".");
|
||||
if (parts.length > 1) {
|
||||
return "." + parts[parts.length - 1].toLowerCase();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
getFileSize(event) {
|
||||
const content = event.getContent();
|
||||
if (content.info) {
|
||||
return content.info.size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
getFileSizeFormatted(event) {
|
||||
return prettyBytes(this.getFileSize(event));
|
||||
}
|
||||
|
||||
isFileTypeAPK(event) {
|
||||
const mime = this.getMimeType(event);
|
||||
if (mime === "application/vnd.android.package-archive" || this.getFileName(event).endsWith(".apk")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isFileTypeIPA(event) {
|
||||
if (this.getFileName(event).endsWith(".ipa")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isFileTypePDF(event) {
|
||||
const mime = this.getMimeType(event);
|
||||
if (mime === "application/pdf" || this.getFileName(event).endsWith(".pdf")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
isFileTypeZip(event) {
|
||||
const mime = this.getMimeType(event);
|
||||
if (["application/zip", "application/x-zip-compressed", "multipart/x-zip"].includes(mime) || this.getFileName(event).endsWith(".zip")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
export default new Util();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue