some fixes

dev
adb 4 years ago
parent 1d50bae135
commit 286bc25446

@ -14,13 +14,13 @@
</template> </template>
<script> <script>
import avatar from "@/components/avatar"; import avatar from '@/components/avatar';
import {getMxcFromRoom} from "@/lib/getMxc"; import {getMxcFromRoom} from '@/lib/getMxc';
import {getTime} from "@/lib/getTimeStrings"; import {getTime} from '@/lib/getTimeStrings';
import {calcUserName} from "@/lib/matrixUtils"; import {calcUserName} from '@/lib/matrixUtils';
export default { export default {
name: "userListElement", name: 'roomListElement',
components:{ components:{
avatar avatar
}, },
@ -34,8 +34,8 @@ export default {
return `${this.calcUserName(event.sender)}: ${event.content.body||'unknown event'} ${getTime(event.origin_server_ts)}`; return `${this.calcUserName(event.sender)}: ${event.content.body||'unknown event'} ${getTime(event.origin_server_ts)}`;
}, },
getLatestEvent(room){ getLatestEvent(room){
if (!room.timeline[room.timeline.length-1]) return undefined; return room.timeline[room.timeline.length-1]
return room.timeline[room.timeline.length-1].event; && room.timeline[room.timeline.length-1].event;
}, },
calcUserName, calcUserName,
getMxcFromRoom getMxcFromRoom

@ -15,10 +15,10 @@
</template> </template>
<script> <script>
import avatar from "@/components/avatar"; import avatar from '@/components/avatar';
export default { export default {
name: "userListElement", name: 'userListElement',
components:{ components:{
avatar avatar
}, },

@ -1,6 +1,5 @@
import sdk from 'matrix-js-sdk' import sdk from 'matrix-js-sdk'
import {matrix} from '@/main'; import {matrix} from '@/main';
import parseMXC from '@modular-matrix/parse-mxc';
export function getMxcFromUser(user){ export function getMxcFromUser(user){
return user.avatarUrl; return user.avatarUrl;
@ -20,14 +19,9 @@ export function getMxcFromRoomId(roomId){
} }
export function getPreviewUrl(mxcUrl, size = 64, resizeMethod = 'crop'){ export function getPreviewUrl(mxcUrl, size = 64, resizeMethod = 'crop'){
let mxc = parseMXC.parse(mxcUrl); return matrix.client.mxcUrlToHttp(mxcUrl, size, size, resizeMethod);
return `${matrix.baseUrl}/_matrix/media/v1/thumbnail/${
mxc.homeserver}/${mxc.id}?width=${size}&height=${size}&method=${resizeMethod}`;
} }
export function getMediaUrl(mxcUrl){ export function getMediaUrl(mxcUrl){
if (!mxcUrl) return undefined; return matrix.client.mxcUrlToHttp(mxcUrl);
let mxc = parseMXC.parse(mxcUrl);
return `${matrix.baseUrl}/_matrix/media/r0/download/${
mxc.homeserver}/${mxc.id}`;
} }

@ -67,7 +67,7 @@ export class MatrixHandler {
this.rooms = this.client.getRooms(); this.rooms = this.client.getRooms();
this.loading = false; this.loading = false;
callback(); callback();
this.listenToPushEvents() this.listenToPushEvents();
}); });
} }
listenToPushEvents(){ listenToPushEvents(){

@ -9,4 +9,10 @@ export function calcUserName(userId){
} }
export function getRoom(roomId){ export function getRoom(roomId){
return matrix.client.getRoom(roomId); return matrix.client.getRoom(roomId);
}
export function isValidUserId(id){
return id.match(/^@[a-zA-Z0-9_.+-]+:[a-z0-9.-]+\.[a-z]+$/);
}
export function isValidRoomId(id){
return id.match(/^(#|!)[a-zA-Z0-9_.+-]+:[a-z0-9.-]+\.[a-z]+$/);
} }

@ -22,11 +22,12 @@
<script> <script>
import textbtn from '@/components/textbtn'; import textbtn from '@/components/textbtn';
import {matrix} from '@/main.js'; import {matrix} from '@/main.js';
import {cookieHandler} from "@/lib/cookieHandler"; import {cookieHandler} from '@/lib/cookieHandler';
import ThrobberOverlay from "@/components/throbberOverlay"; import ThrobberOverlay from '@/components/throbberOverlay';
import {isValidUserId} from '@/lib/matrixUtils';
export default { export default {
name: "login.vue", name: 'login.vue',
components: { components: {
ThrobberOverlay, ThrobberOverlay,
textbtn textbtn
@ -42,7 +43,7 @@ export default {
} if (this.password === '') { } if (this.password === '') {
this.loginError = 'password is empty'; this.loginError = 'password is empty';
return; return;
} if (!(this.user.match(/^@[a-zA-Z0-9_.+-]+:[a-z0-9.-]+\.[a-z]+$/))) { } if (!isValidUserId(this.user)) {
this.loginError = 'username is in wrong style'; this.loginError = 'username is in wrong style';
return; return;
} }
@ -83,10 +84,10 @@ export default {
}, },
data(){ data(){
return { return {
user: "", user: '',
password: "", password: '',
homeServer: "https://adb.sh", homeServer: 'https://adb.sh',
loginError: "", loginError: '',
cookie: new cookieHandler(), cookie: new cookieHandler(),
loading: false loading: false
} }

Loading…
Cancel
Save