Skip to content

Commit

Permalink
Prefer server-level display names when available
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Arctor <neetzsche@tutanota.com>
  • Loading branch information
TheStranjer committed Jun 19, 2023
1 parent ece29f4 commit 17ebb66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.d/888.bugfix
@@ -0,0 +1 @@
Prefer server-level display names when available.
2 changes: 1 addition & 1 deletion src/bot.ts
Expand Up @@ -1027,7 +1027,7 @@ export class DiscordBot {
}

// Update presence because sometimes discord misses people.
await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID));
await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID), msg);
let rooms: string[];
try {
rooms = await this.channelSync.GetRoomIdsFromChannel(msg.channel);
Expand Down
10 changes: 5 additions & 5 deletions src/usersyncroniser.ts
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { User, GuildMember } from "better-discord.js";
import { User, GuildMember, Message } from "better-discord.js";
import { DiscordBot } from "./bot";
import { Util } from "./util";
import { DiscordBridgeConfig } from "./config";
Expand Down Expand Up @@ -96,8 +96,8 @@ export class UserSyncroniser {
* @returns {Promise<void>}
* @constructor
*/
public async OnUpdateUser(discordUser: User, isWebhook: boolean = false) {
const userState = await this.GetUserUpdateState(discordUser, isWebhook);
public async OnUpdateUser(discordUser: User, isWebhook: boolean = false, msg?: Message) {
const userState = await this.GetUserUpdateState(discordUser, isWebhook, msg);
try {
await this.ApplyStateToProfile(userState);
} catch (e) {
Expand Down Expand Up @@ -230,7 +230,7 @@ export class UserSyncroniser {
}
}

public async GetUserUpdateState(discordUser: User, isWebhook: boolean = false): Promise<IUserState> {
public async GetUserUpdateState(discordUser: User, isWebhook: boolean = false, msg?: Message): Promise<IUserState> {
log.verbose(`State update requested for ${discordUser.id}`);
let mxidExtra = "";
if (isWebhook) {
Expand All @@ -244,7 +244,7 @@ export class UserSyncroniser {
id: discordUser.id + mxidExtra,
mxUserId: `@_discord_${discordUser.id}${mxidExtra}:${this.config.bridge.domain}`,
});
const displayName = Util.ApplyPatternString(this.config.ghosts.usernamePattern, {
const displayName = msg?.member?.nickname || Util.ApplyPatternString(this.config.ghosts.usernamePattern, {
id: discordUser.id,
tag: discordUser.discriminator,
username: discordUser.username,
Expand Down

0 comments on commit 17ebb66

Please sign in to comment.