|
|
@ -1,5 +1,6 @@
|
|
|
|
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;
|
|
|
@ -10,10 +11,16 @@ export function getMxcFromUserId(userId){
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getMxcFromRoom(room){
|
|
|
|
export function getMxcFromRoom(room){
|
|
|
|
let avatarState = room.getLiveTimeline().getState(sdk.EventTimeline.FORWARDS).getStateEvents("m.room.avatar");
|
|
|
|
let avatarState = room.getLiveTimeline().getState(sdk.EventTimeline.FORWARDS).getStateEvents('m.room.avatar');
|
|
|
|
return avatarState.length>0?avatarState[avatarState.length-1].getContent().url:undefined;
|
|
|
|
return avatarState.length>0?avatarState[avatarState.length-1].getContent().url:undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function getMxcFromRoomId(roomId){
|
|
|
|
export function getMxcFromRoomId(roomId){
|
|
|
|
return getMxcFromRoom(matrix.client.getRoom(roomId));
|
|
|
|
return getMxcFromRoom(matrix.client.getRoom(roomId));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function getAvatarUrl(mxcUrl, size = 64, resizeMethod = 'crop'){
|
|
|
|
|
|
|
|
let mxc = parseMXC.parse(mxcUrl);
|
|
|
|
|
|
|
|
return `${matrix.baseUrl}/_matrix/media/v1/thumbnail/${
|
|
|
|
|
|
|
|
mxc.homeserver}/${mxc.id}?width=${size}&height=${size}&method=${resizeMethod}`;
|
|
|
|
|
|
|
|
}
|