Audio attachments
And touch events for mobile quick reactions.
This commit is contained in:
parent
3ad4083312
commit
a19082e2ea
10 changed files with 1324 additions and 1172 deletions
2214
package-lock.json
generated
2214
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -21,6 +21,7 @@
|
||||||
"roboto-fontface": "*",
|
"roboto-fontface": "*",
|
||||||
"v-emoji-picker": "^2.3.1",
|
"v-emoji-picker": "^2.3.1",
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
|
"vue-mobile-event": "^1.2.6",
|
||||||
"vue-router": "^3.2.0",
|
"vue-router": "^3.2.0",
|
||||||
"vuetify": "^2.2.11",
|
"vuetify": "^2.2.11",
|
||||||
"vuex": "^3.5.1"
|
"vuex": "^3.5.1"
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ $chat-text-size: 0.7pt;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 22 * $chat-text-size;
|
font-size: 22 * $chat-text-size;
|
||||||
color: #000000;
|
color: #000000;
|
||||||
|
overflow-wrap: break-word;
|
||||||
.edit-marker {
|
.edit-marker {
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
color: #888888;
|
color: #888888;
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,12 @@
|
||||||
v-on:scroll="onScroll"
|
v-on:scroll="onScroll"
|
||||||
>
|
>
|
||||||
<div v-for="event in events" :key="event.getId()">
|
<div v-for="event in events" :key="event.getId()">
|
||||||
<v-hover v-slot="{ hover }" v-if="!event.isRelation() && !event.isRedacted() && !event.isRedaction()">
|
<div v-event:tap.self="(e) => { touchTap(event); } " v-event:longTap="(e) => { touchLongTap(event); } " v-if="!event.isRelation() && !event.isRedacted() && !event.isRedaction()">
|
||||||
<div style="position: relative">
|
<div style="position:relative;user-select:none">
|
||||||
<component
|
<component
|
||||||
:is="componentForEvent(event)"
|
:is="componentForEvent(event)"
|
||||||
:room="room"
|
:room="room"
|
||||||
:event="event"
|
:event="event"
|
||||||
:reactions="
|
:reactions="
|
||||||
timelineWindow._timelineSet.getRelationsForEvent(
|
timelineWindow._timelineSet.getRelationsForEvent(
|
||||||
event.getId(),
|
event.getId(),
|
||||||
|
|
@ -23,13 +23,13 @@
|
||||||
v-on:send-quick-reaction="sendQuickReaction"
|
v-on:send-quick-reaction="sendQuickReaction"
|
||||||
/>
|
/>
|
||||||
<message-operations
|
<message-operations
|
||||||
v-if="hover"
|
v-if="selectedEvent == event && showContextMenu"
|
||||||
v-on:addreaction="addReaction"
|
v-on:addreaction="addReaction"
|
||||||
:event="event"
|
:event="event"
|
||||||
:incoming="event.getSender() != $matrix.currentUserId"
|
:incoming="event.getSender() != $matrix.currentUserId"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</v-hover>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@
|
||||||
type="file"
|
type="file"
|
||||||
name="attachment"
|
name="attachment"
|
||||||
@change="pickAttachment($event)"
|
@change="pickAttachment($event)"
|
||||||
accept="image/*"
|
accept="image/*|audio/*|video/*|application/pdf"
|
||||||
style="display: none"
|
style="display: none"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
@ -113,7 +113,11 @@
|
||||||
<script>
|
<script>
|
||||||
import { TimelineWindow, EventTimeline } from "matrix-js-sdk";
|
import { TimelineWindow, EventTimeline } from "matrix-js-sdk";
|
||||||
import MessageIncomingText from "./messages/MessageIncomingText";
|
import MessageIncomingText from "./messages/MessageIncomingText";
|
||||||
|
import MessageIncomingImage from "./messages/MessageIncomingImage.vue";
|
||||||
|
import MessageIncomingAudio from "./messages/MessageIncomingAudio.vue";
|
||||||
import MessageOutgoingText from "./messages/MessageOutgoingText";
|
import MessageOutgoingText from "./messages/MessageOutgoingText";
|
||||||
|
import MessageOutgoingImage from "./messages/MessageOutgoingImage.vue";
|
||||||
|
import MessageOutgoingAudio from "./messages/MessageOutgoingAudio.vue";
|
||||||
import ContactJoin from "./messages/ContactJoin.vue";
|
import ContactJoin from "./messages/ContactJoin.vue";
|
||||||
import ContactLeave from "./messages/ContactLeave.vue";
|
import ContactLeave from "./messages/ContactLeave.vue";
|
||||||
import ContactInvited from "./messages/ContactInvited.vue";
|
import ContactInvited from "./messages/ContactInvited.vue";
|
||||||
|
|
@ -121,8 +125,6 @@ import RoomNameChanged from "./messages/RoomNameChanged.vue";
|
||||||
import RoomTopicChanged from "./messages/RoomTopicChanged.vue";
|
import RoomTopicChanged from "./messages/RoomTopicChanged.vue";
|
||||||
import RoomAvatarChanged from "./messages/RoomAvatarChanged.vue";
|
import RoomAvatarChanged from "./messages/RoomAvatarChanged.vue";
|
||||||
import DebugEvent from "./messages/DebugEvent.vue";
|
import DebugEvent from "./messages/DebugEvent.vue";
|
||||||
import MessageOutgoingImage from "./messages/MessageOutgoingImage.vue";
|
|
||||||
import MessageIncomingImage from "./messages/MessageIncomingImage.vue";
|
|
||||||
import util from "../plugins/utils";
|
import util from "../plugins/utils";
|
||||||
import MessageOperations from "./messages/MessageOperations.vue";
|
import MessageOperations from "./messages/MessageOperations.vue";
|
||||||
|
|
||||||
|
|
@ -158,7 +160,11 @@ export default {
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
MessageIncomingText,
|
MessageIncomingText,
|
||||||
|
MessageIncomingImage,
|
||||||
|
MessageIncomingAudio,
|
||||||
MessageOutgoingText,
|
MessageOutgoingText,
|
||||||
|
MessageOutgoingImage,
|
||||||
|
MessageOutgoingAudio,
|
||||||
ContactJoin,
|
ContactJoin,
|
||||||
ContactLeave,
|
ContactLeave,
|
||||||
ContactInvited,
|
ContactInvited,
|
||||||
|
|
@ -166,8 +172,6 @@ export default {
|
||||||
RoomTopicChanged,
|
RoomTopicChanged,
|
||||||
RoomAvatarChanged,
|
RoomAvatarChanged,
|
||||||
DebugEvent,
|
DebugEvent,
|
||||||
MessageOutgoingImage,
|
|
||||||
MessageIncomingImage,
|
|
||||||
MessageOperations,
|
MessageOperations,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -186,6 +190,7 @@ export default {
|
||||||
currentSendError: null,
|
currentSendError: null,
|
||||||
showEmojiPicker: false,
|
showEmojiPicker: false,
|
||||||
selectedEvent: null,
|
selectedEvent: null,
|
||||||
|
showContextMenu: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -246,6 +251,19 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
touchTap(ignoredEvent) {
|
||||||
|
if (this.selectedEvent && this.showContextMenu) {
|
||||||
|
// If anything is selected, unselect
|
||||||
|
this.selectedEvent = null;
|
||||||
|
this.showContextMenu = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
touchLongTap(event) {
|
||||||
|
this.selectedEvent = event;
|
||||||
|
this.showContextMenu = true;
|
||||||
|
},
|
||||||
|
|
||||||
componentForEvent(event) {
|
componentForEvent(event) {
|
||||||
switch (event.getType()) {
|
switch (event.getType()) {
|
||||||
case "m.room.member":
|
case "m.room.member":
|
||||||
|
|
@ -262,11 +280,15 @@ export default {
|
||||||
if (event.getSender() != this.$matrix.currentUserId) {
|
if (event.getSender() != this.$matrix.currentUserId) {
|
||||||
if (event.getContent().msgtype == "m.image") {
|
if (event.getContent().msgtype == "m.image") {
|
||||||
return MessageIncomingImage;
|
return MessageIncomingImage;
|
||||||
|
} else if (event.getContent().msgtype == "m.audio") {
|
||||||
|
return MessageIncomingAudio;
|
||||||
}
|
}
|
||||||
return MessageIncomingText;
|
return MessageIncomingText;
|
||||||
} else {
|
} else {
|
||||||
if (event.getContent().msgtype == "m.image") {
|
if (event.getContent().msgtype == "m.image") {
|
||||||
return MessageOutgoingImage;
|
return MessageOutgoingImage;
|
||||||
|
} else if (event.getContent().msgtype == "m.audio") {
|
||||||
|
return MessageOutgoingAudio;
|
||||||
}
|
}
|
||||||
return MessageOutgoingText;
|
return MessageOutgoingText;
|
||||||
}
|
}
|
||||||
|
|
@ -394,7 +416,10 @@ export default {
|
||||||
if (this.currentSendOperation) {
|
if (this.currentSendOperation) {
|
||||||
this.currentSendOperation.reject("Canceled");
|
this.currentSendOperation.reject("Canceled");
|
||||||
}
|
}
|
||||||
|
this.currentSendOperation = null;
|
||||||
this.currentImageInput = null;
|
this.currentImageInput = null;
|
||||||
|
this.currentSendProgress = 0;
|
||||||
|
this.currentSendError = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
handleScrolledToTop() {
|
handleScrolledToTop() {
|
||||||
|
|
|
||||||
36
src/components/messages/MessageIncomingAudio.vue
Normal file
36
src/components/messages/MessageIncomingAudio.vue
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="messageIn">
|
||||||
|
<div class="sender">{{ messageEventDisplayName(event) }}</div>
|
||||||
|
<div class="audio-bubble">
|
||||||
|
<audio controls :src="src">Audio file</audio>
|
||||||
|
<QuickReactions :event="event" :reactions="reactions" />
|
||||||
|
</div>
|
||||||
|
<v-avatar class="avatar" size="40" color="grey">
|
||||||
|
<img
|
||||||
|
v-if="messageEventAvatar(event)"
|
||||||
|
:src="messageEventAvatar(event)"
|
||||||
|
/>
|
||||||
|
<span v-else class="white--text headline">{{
|
||||||
|
messageEventDisplayName(event).substring(0, 1).toUpperCase()
|
||||||
|
}}</span>
|
||||||
|
</v-avatar>
|
||||||
|
</div>
|
||||||
|
<div class="time">
|
||||||
|
{{ formatTime(event.event.origin_server_ts) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import messageMixin from "./messageMixin";
|
||||||
|
import attachmentMixin from "./attachmentMixin";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mixins: [messageMixin, attachmentMixin],
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@import "@/assets/css/chat.scss";
|
||||||
|
</style>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div :class="{'messageOperations':true,'incoming':incoming,'outgoing':!incoming}">
|
<div :class="{'messageOperations':true,'incoming':incoming,'outgoing':!incoming}">
|
||||||
<v-btn icon @click="addReaction" class="ma-0 pa-0">
|
<v-btn icon v-event:tap.self="(e) => { addReaction() }" class="ma-0 pa-0">
|
||||||
<v-icon>mood</v-icon>
|
<v-icon>mood</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
28
src/components/messages/MessageOutgoingAudio.vue
Normal file
28
src/components/messages/MessageOutgoingAudio.vue
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div class="messageOut">
|
||||||
|
<div class="sender">{{ "You" }}</div>
|
||||||
|
<div class="audio-bubble">
|
||||||
|
<audio controls :src="src">Audio file</audio>
|
||||||
|
<QuickReactions :event="event" :reactions="reactions" />
|
||||||
|
</div>
|
||||||
|
<div class="status">{{ event.status }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="time">
|
||||||
|
{{ formatTime(event.event.origin_server_ts) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import messageMixin from "./messageMixin";
|
||||||
|
import attachmentMixin from "./attachmentMixin";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
mixins: [messageMixin, attachmentMixin],
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
@import "@/assets/css/chat.scss";
|
||||||
|
</style>
|
||||||
27
src/components/messages/attachmentMixin.js
Normal file
27
src/components/messages/attachmentMixin.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import util from "../../plugins/utils";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
src: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
console.log("Mounted with event:", JSON.stringify(this.event.getContent()))
|
||||||
|
util
|
||||||
|
.getAttachment(this.$matrix.matrixClient, this.event)
|
||||||
|
.then((url) => {
|
||||||
|
this.src = url;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log("Failed to fetch attachment: ", err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
if (this.src) {
|
||||||
|
const objectUrl = this.src;
|
||||||
|
this.src = null;
|
||||||
|
URL.revokeObjectURL(objectUrl);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -7,9 +7,11 @@ import matrix from './services/matrix.service'
|
||||||
import 'roboto-fontface/css/roboto/roboto-fontface.css'
|
import 'roboto-fontface/css/roboto/roboto-fontface.css'
|
||||||
import 'material-design-icons-iconfont/dist/material-design-icons.css'
|
import 'material-design-icons-iconfont/dist/material-design-icons.css'
|
||||||
import VEmojiPicker from 'v-emoji-picker';
|
import VEmojiPicker from 'v-emoji-picker';
|
||||||
|
import VueMobileEvent from 'vue-mobile-event';
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
|
Vue.use(VueMobileEvent);
|
||||||
Vue.use(VEmojiPicker);
|
Vue.use(VEmojiPicker);
|
||||||
Vue.use(matrix, {store: store});
|
Vue.use(matrix, {store: store});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,39 @@ var aesjs = require('aes-js');
|
||||||
var base64Url = require('json-web-key/lib/base64url');
|
var base64Url = require('json-web-key/lib/base64url');
|
||||||
|
|
||||||
class Util {
|
class Util {
|
||||||
|
getAttachment(matrixClient, event) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const content = event.getContent();
|
||||||
|
if (content.url != null) {
|
||||||
|
// Unencrypted, just return!
|
||||||
|
resolve(matrixClient.mxcUrlToHttp(content.url));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var url = null;
|
||||||
|
var file = null;
|
||||||
|
if (content.file && content.file.url) {
|
||||||
|
file = content.file;
|
||||||
|
url = matrixClient.mxcUrlToHttp(file.url);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url == null) {
|
||||||
|
reject("No url found!");
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.get(url, { responseType: 'arraybuffer' })
|
||||||
|
.then(response => {
|
||||||
|
return this.decryptIfNeeded(file, response);
|
||||||
|
})
|
||||||
|
.then(bytes => {
|
||||||
|
resolve(URL.createObjectURL(new Blob([bytes.buffer], { type: file.mimetype })));
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log("Download error: ", err);
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getThumbnail(matrixClient, event, ignoredw, ignoredh) {
|
getThumbnail(matrixClient, event, ignoredw, ignoredh) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const content = event.getContent();
|
const content = event.getContent();
|
||||||
|
|
@ -46,24 +79,7 @@ class Util {
|
||||||
}
|
}
|
||||||
axios.get(url, { responseType: 'arraybuffer' })
|
axios.get(url, { responseType: 'arraybuffer' })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return new Promise((resolve, ignoredReject) => {
|
return this.decryptIfNeeded(file, response);
|
||||||
var key = base64Url.decode(file.key.k);
|
|
||||||
var iv = base64Url.decode(file.iv);
|
|
||||||
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(iv));
|
|
||||||
|
|
||||||
const data = new Uint8Array(response.data);
|
|
||||||
|
|
||||||
// Calculate sha256 and compare hashes
|
|
||||||
var hash = new Uint8Array(sha256.create().update(data).arrayBuffer());
|
|
||||||
const originalHash = base64Url.decode(file.hashes.sha256);
|
|
||||||
if (Buffer.compare(Buffer.from(hash), Buffer.from(originalHash.buffer)) != 0) {
|
|
||||||
reject("Hashes don't match!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var decryptedBytes = aesCtr.decrypt(data);
|
|
||||||
resolve(decryptedBytes);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.then(bytes => {
|
.then(bytes => {
|
||||||
resolve(URL.createObjectURL(new Blob([bytes.buffer], { type: file.mimetype })));
|
resolve(URL.createObjectURL(new Blob([bytes.buffer], { type: file.mimetype })));
|
||||||
|
|
@ -75,6 +91,27 @@ class Util {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decryptIfNeeded(file, response) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var key = base64Url.decode(file.key.k);
|
||||||
|
var iv = base64Url.decode(file.iv);
|
||||||
|
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(iv));
|
||||||
|
|
||||||
|
const data = new Uint8Array(response.data);
|
||||||
|
|
||||||
|
// Calculate sha256 and compare hashes
|
||||||
|
var hash = new Uint8Array(sha256.create().update(data).arrayBuffer());
|
||||||
|
const originalHash = base64Url.decode(file.hashes.sha256);
|
||||||
|
if (Buffer.compare(Buffer.from(hash), Buffer.from(originalHash.buffer)) != 0) {
|
||||||
|
reject("Hashes don't match!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var decryptedBytes = aesCtr.decrypt(data);
|
||||||
|
resolve(decryptedBytes);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
sendTextMessage(matrixClient, roomId, text) {
|
sendTextMessage(matrixClient, roomId, text) {
|
||||||
return this.sendMessage(matrixClient, roomId, "m.room.message", ContentHelpers.makeTextMessage(text));
|
return this.sendMessage(matrixClient, roomId, "m.room.message", ContentHelpers.makeTextMessage(text));
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +123,7 @@ class Util {
|
||||||
rel_type: 'm.annotation',
|
rel_type: 'm.annotation',
|
||||||
event_id: event.getId()
|
event_id: event.getId()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return this.sendMessage(matrixClient, roomId, "m.reaction", content);
|
return this.sendMessage(matrixClient, roomId, "m.reaction", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,38 +186,54 @@ class Util {
|
||||||
mimetype: file.type,
|
mimetype: file.type,
|
||||||
size: file.size
|
size: file.size
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var description = file.name;
|
||||||
|
var msgtype = 'm.image';
|
||||||
|
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 = {
|
const opts = {
|
||||||
type: file.type,
|
type: file.type,
|
||||||
name: 'Image',
|
name: description,
|
||||||
progressHandler: onUploadProgress,
|
progressHandler: onUploadProgress,
|
||||||
onlyContentUri: false
|
onlyContentUri: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var messageContent = {
|
||||||
|
body: description,
|
||||||
|
info: info,
|
||||||
|
msgtype: msgtype
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set filename for files
|
||||||
|
if (msgtype == 'm.file') {
|
||||||
|
messageContent.filename = file.name;
|
||||||
|
}
|
||||||
|
|
||||||
if (!matrixClient.isRoomEncrypted(roomId)) {
|
if (!matrixClient.isRoomEncrypted(roomId)) {
|
||||||
// Not encrypted.
|
// Not encrypted.
|
||||||
matrixClient.uploadContent(data, opts)
|
matrixClient.uploadContent(data, opts)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const messageContent = {
|
messageContent.url = response.content_uri;
|
||||||
body: 'Image',
|
return this.sendMessage(matrixClient, roomId, "m.room.message", messageContent)
|
||||||
url: response.content_uri,
|
})
|
||||||
info: info,
|
.then(result => {
|
||||||
msgtype: 'm.image'
|
resolve(result);
|
||||||
}
|
})
|
||||||
return this.sendMessage(matrixClient, roomId, "m.room.message", messageContent)
|
.catch(err => {
|
||||||
})
|
reject(err);
|
||||||
.then(result => {
|
});
|
||||||
resolve(result);
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
reject(err);
|
|
||||||
});
|
|
||||||
return; // Don't fall through
|
return; // Don't fall through
|
||||||
}
|
}
|
||||||
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
let key = crypto.randomBytes(256 / 8);
|
let key = crypto.randomBytes(256 / 8);
|
||||||
let iv = Buffer.concat([crypto.randomBytes(8),Buffer.alloc(8)]); // Initialization vector.
|
let iv = Buffer.concat([crypto.randomBytes(8), Buffer.alloc(8)]); // Initialization vector.
|
||||||
|
|
||||||
// Encrypt
|
// Encrypt
|
||||||
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(iv));
|
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(iv));
|
||||||
|
|
@ -201,17 +254,12 @@ class Util {
|
||||||
const encryptedFile = {
|
const encryptedFile = {
|
||||||
mimetype: file.type,
|
mimetype: file.type,
|
||||||
key: jwk,
|
key: jwk,
|
||||||
iv: Buffer.from(iv).toString('base64').replace( /=/g, '' ),
|
iv: Buffer.from(iv).toString('base64').replace(/=/g, ''),
|
||||||
hashes: { sha256: Buffer.from(hash).toString('base64').replace( /=/g, '' )},
|
hashes: { sha256: Buffer.from(hash).toString('base64').replace(/=/g, '') },
|
||||||
v: 'v2'
|
v: 'v2'
|
||||||
};
|
};
|
||||||
|
|
||||||
const messageContent = {
|
messageContent.file = encryptedFile;
|
||||||
body: 'Image',
|
|
||||||
file: encryptedFile,
|
|
||||||
info: info,
|
|
||||||
msgtype: 'm.image'
|
|
||||||
}
|
|
||||||
|
|
||||||
matrixClient.uploadContent(data, opts)
|
matrixClient.uploadContent(data, opts)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue