fix sendEvent, update eventContent file
This commit is contained in:
		
							parent
							
								
									64d6273a52
								
							
						
					
					
						commit
						c35b5ba446
					
				@ -6,14 +6,20 @@
 | 
				
			|||||||
    {{content.body}}
 | 
					    {{content.body}}
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <div v-else-if="content.msgtype==='m.file'" :class="`file ${compact?'compact':''}`">
 | 
					  <div v-else-if="content.msgtype==='m.file'" :class="`file ${compact?'compact':''}`">
 | 
				
			||||||
    <icon
 | 
					    <a :href="getSource(content.url)" target="_blank">
 | 
				
			||||||
      title="file"
 | 
					    <div class="fileContent">
 | 
				
			||||||
      ic="./sym/ic_attach_file_white.svg"
 | 
					      <icon
 | 
				
			||||||
    />
 | 
					        title="file"
 | 
				
			||||||
 | 
					        ic="./sym/ic_attach_file_white.svg"
 | 
				
			||||||
 | 
					        class="download"
 | 
				
			||||||
 | 
					      />
 | 
				
			||||||
 | 
					      <div class="filename">
 | 
				
			||||||
 | 
					          {{content.filename || getSource(content.url)}}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    </a>
 | 
				
			||||||
    <div class="text">
 | 
					    <div class="text">
 | 
				
			||||||
      <a :href="getSource(content.url)">
 | 
					      {{content.body}}
 | 
				
			||||||
        {{content.filename || getSource(content.url)}}
 | 
					 | 
				
			||||||
      </a><br>{{content.body}}
 | 
					 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <div v-else-if="content.msgtype==='m.audio'" :class="`audio ${compact?'compact':''}`">
 | 
					  <div v-else-if="content.msgtype==='m.audio'" :class="`audio ${compact?'compact':''}`">
 | 
				
			||||||
@ -59,11 +65,26 @@ export default {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<style scoped lang="scss">
 | 
					<style scoped lang="scss">
 | 
				
			||||||
.file{
 | 
					.file{
 | 
				
			||||||
  .text{
 | 
					  max-width: 30rem;
 | 
				
			||||||
 | 
					  .fileContent{
 | 
				
			||||||
    position: relative;
 | 
					    position: relative;
 | 
				
			||||||
    left: 4rem;
 | 
					    background-color: #1d1d1d;
 | 
				
			||||||
    top: 0;
 | 
					    padding: 0.5rem;
 | 
				
			||||||
    width: 100%;
 | 
					    border-radius: 0.5rem;
 | 
				
			||||||
 | 
					    min-height: 3rem;
 | 
				
			||||||
 | 
					    .filename{
 | 
				
			||||||
 | 
					      display: inline-block;
 | 
				
			||||||
 | 
					      position: relative;
 | 
				
			||||||
 | 
					      margin-left: 4rem;
 | 
				
			||||||
 | 
					      top: 0;
 | 
				
			||||||
 | 
					      height: 100%;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    .download{
 | 
				
			||||||
 | 
					      position: absolute;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  .compact{
 | 
				
			||||||
 | 
					    max-width: 20rem;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.image{
 | 
					.image{
 | 
				
			||||||
 | 
				
			|||||||
@ -105,8 +105,8 @@ export default {
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    async sendEvent(event){
 | 
					    async sendEvent(event){
 | 
				
			||||||
      if (!event.content.body.trim()) return;
 | 
					      if (!event.content.body.trim()) return;
 | 
				
			||||||
      await matrix.sendEvent(this.event, this.roomId, this.replyTo);
 | 
					      if (this.replyTo) this.setReplyTo(this.replyTo);
 | 
				
			||||||
      //await matrix.sendEvent(new Proxy(this.event, this.eventProxy), this.roomId, this.replyTo);
 | 
					      matrix.sendEvent(new Proxy(this.event, this.eventProxyHandler), this.roomId);
 | 
				
			||||||
      event.content.body = '';
 | 
					      event.content.body = '';
 | 
				
			||||||
      this.resetAttachment();
 | 
					      this.resetAttachment();
 | 
				
			||||||
      this.resetReplyTo();
 | 
					      this.resetReplyTo();
 | 
				
			||||||
@ -125,6 +125,11 @@ export default {
 | 
				
			|||||||
      matrix.client.sendTyping(this.roomId, true, timeout+100);
 | 
					      matrix.client.sendTyping(this.roomId, true, timeout+100);
 | 
				
			||||||
      setTimeout(()=>this.waitForSendTyping=false, timeout);
 | 
					      setTimeout(()=>this.waitForSendTyping=false, timeout);
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    setReplyTo(event){
 | 
				
			||||||
 | 
					      this.event.content['m.relates_to'] = {
 | 
				
			||||||
 | 
					        'm.in_reply_to': event
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    resizeMessageBanner(){
 | 
					    resizeMessageBanner(){
 | 
				
			||||||
      let id = this.$refs.newMessageInput;
 | 
					      let id = this.$refs.newMessageInput;
 | 
				
			||||||
      id.style.height = '1.25rem';
 | 
					      id.style.height = '1.25rem';
 | 
				
			||||||
@ -177,12 +182,14 @@ export default {
 | 
				
			|||||||
        mimetype: file.type,
 | 
					        mimetype: file.type,
 | 
				
			||||||
        url: window.URL.createObjectURL(file),
 | 
					        url: window.URL.createObjectURL(file),
 | 
				
			||||||
        blob: blob || await this.readFile(file),
 | 
					        blob: blob || await this.readFile(file),
 | 
				
			||||||
 | 
					        filename: file.name,
 | 
				
			||||||
        file
 | 
					        file
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
      this.event.content = {
 | 
					      this.event.content = {
 | 
				
			||||||
        body: file.name,
 | 
					        body: file.name,
 | 
				
			||||||
        msgtype: this.attachment.msgtype,
 | 
					        msgtype: this.attachment.msgtype,
 | 
				
			||||||
        mimetype: this.attachment.mimetype
 | 
					        mimetype: this.attachment.mimetype,
 | 
				
			||||||
 | 
					        filename: file.name
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    resetAttachment(){
 | 
					    resetAttachment(){
 | 
				
			||||||
@ -212,7 +219,7 @@ export default {
 | 
				
			|||||||
          body: '',
 | 
					          body: '',
 | 
				
			||||||
          msgtype: 'm.text',
 | 
					          msgtype: 'm.text',
 | 
				
			||||||
          'm.relates_to': {
 | 
					          'm.relates_to': {
 | 
				
			||||||
            'm.in_reply_to': this.replyTo
 | 
					            'm.in_reply_to': undefined
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
@ -224,10 +231,10 @@ export default {
 | 
				
			|||||||
      isRecording: false,
 | 
					      isRecording: false,
 | 
				
			||||||
      recBlob: undefined,
 | 
					      recBlob: undefined,
 | 
				
			||||||
      attachment: undefined,
 | 
					      attachment: undefined,
 | 
				
			||||||
      eventProxy: {
 | 
					      eventProxyHandler: {
 | 
				
			||||||
        set: ()=>{},
 | 
					        set: () => true,
 | 
				
			||||||
        get: (target, key) => {
 | 
					        get: (target, key) => {
 | 
				
			||||||
          if (typeof target[key] === 'object') return new Proxy(target[key], this.eventProxy);
 | 
					          if (typeof target[key] === 'object') return new Proxy(Object.assign({}, target[key]), this.eventProxyHandler);
 | 
				
			||||||
          return target[key];
 | 
					          return target[key];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
@ -77,22 +77,9 @@ export class MatrixHandler {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  async sendEvent({content, type}, roomId, replyTo = undefined){
 | 
					  async sendEvent({content, type}, roomId){
 | 
				
			||||||
    console.log(replyTo, content)
 | 
					    return await this.client.sendEvent(roomId, type, content)
 | 
				
			||||||
    await this.client.sendEvent(roomId, type, {
 | 
					 | 
				
			||||||
      body: content.body.trim(),
 | 
					 | 
				
			||||||
      msgtype: content.msgtype,
 | 
					 | 
				
			||||||
      mimetype: content.mimetype,
 | 
					 | 
				
			||||||
      url: content.url,
 | 
					 | 
				
			||||||
      'm.relates_to': {
 | 
					 | 
				
			||||||
        'm.in_reply_to': {
 | 
					 | 
				
			||||||
          event_id: replyTo?replyTo.event_id:undefined
 | 
					 | 
				
			||||||
        },
 | 
					 | 
				
			||||||
      },
 | 
					 | 
				
			||||||
    }).then(() => console.log('message sent successfully'))
 | 
					 | 
				
			||||||
      .catch((err) => console.log(`error while sending message => ${err}`));
 | 
					 | 
				
			||||||
    /*return await this.client.sendEvent(roomId, type, content)
 | 
					 | 
				
			||||||
      .then(() => console.log('message sent successfully'))
 | 
					      .then(() => console.log('message sent successfully'))
 | 
				
			||||||
      .catch((err) => console.log(`error while sending message => ${err}`));*/
 | 
					      .catch((err) => console.log(`error while sending message => ${err}`));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user