Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer server-level display names when available #888

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/888.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prefer server-level display names when available.
2 changes: 1 addition & 1 deletion src/bot.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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