use the same naming convetions for name changes as on writing messages

This commit is contained in:
HF 2023-03-18 17:07:39 +01:00
parent bc9af04820
commit 79cb946ef4

View File

@ -140,13 +140,14 @@ class PPfunMatrixBridge {
// user joined or set displayname
if (event.type === "m.room.member"
&& event.user_id
&& event.content
&& event.content.displayname
&& event.content?.displayname
) {
const name = event.content.displayname;
const { displayname } = event.content;
const userId = event.user_id;
const name = await this.getNameForPP(userId, displayname);
console.log(`User ${userId} joined or set displayname to ${name}`);
this.idToNameMap.set(userId, name);
return;
}
// Only room messages from bridged rooms past this point
if (event.type !== "m.room.message" || !event.content) {
@ -184,11 +185,7 @@ class PPfunMatrixBridge {
}
let name = this.idToNameMap.get(userId);
if (!name) {
if (uid) {
name = `[mx] ${await this.getDisplayName(userId)}`;
} else {
name = userId.substring(1);
}
name = await this.getNameForPP(userId);
this.idToNameMap.set(userId, name);
}
if (name === 'event' || name === 'info') {
@ -208,6 +205,17 @@ class PPfunMatrixBridge {
return;
}
/*
* get name to use for pixelplanet messages
*/
async getNameForPP(userId, displayname) {
// is ppfun user
if (userId.startsWith(`@${this.prefix}_`) && userId.endsWith(this.domain)) {
return `[mx] ${displayname || await this.getDisplayName(userId)}`;
}
return userId.substring(1);
}
/*
* get displayname of matrix user
*/