Skip to content

Commit abf2950

Browse files
authored
Prefer server-level display names when available (#888)
Signed-off-by: Bob Arctor <[email protected]>
1 parent ece29f4 commit abf2950

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

changelog.d/888.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Prefer server-level display names when available.

src/bot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ export class DiscordBot {
10271027
}
10281028

10291029
// Update presence because sometimes discord misses people.
1030-
await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID));
1030+
await this.userSync.OnUpdateUser(msg.author, Boolean(msg.webhookID), msg);
10311031
let rooms: string[];
10321032
try {
10331033
rooms = await this.channelSync.GetRoomIdsFromChannel(msg.channel);

src/usersyncroniser.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
import { User, GuildMember } from "better-discord.js";
17+
import { User, GuildMember, Message } from "better-discord.js";
1818
import { DiscordBot } from "./bot";
1919
import { Util } from "./util";
2020
import { DiscordBridgeConfig } from "./config";
@@ -96,8 +96,8 @@ export class UserSyncroniser {
9696
* @returns {Promise<void>}
9797
* @constructor
9898
*/
99-
public async OnUpdateUser(discordUser: User, isWebhook: boolean = false) {
100-
const userState = await this.GetUserUpdateState(discordUser, isWebhook);
99+
public async OnUpdateUser(discordUser: User, isWebhook: boolean = false, msg?: Message) {
100+
const userState = await this.GetUserUpdateState(discordUser, isWebhook, msg);
101101
try {
102102
await this.ApplyStateToProfile(userState);
103103
} catch (e) {
@@ -230,7 +230,7 @@ export class UserSyncroniser {
230230
}
231231
}
232232

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

0 commit comments

Comments
 (0)