mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-08 05:43:04 +00:00
Add unread DM badge to profile button
This commit is contained in:
1 parent
52a1b886f1
commit
225c6a1674
6 files changed
+121
-6
No files matched your search
@@ -409,6 +409,7 @@ export default class ApplicationBootstrap {
|
||||
|
||||
app.profileButton = doc?.getElementById("profileButton") || null;
|
||||
app.profileAvatar = doc?.getElementById("profileAvatar") || null;
|
||||
app.profileUnreadDot = doc?.getElementById("profileUnreadDot") || null;
|
||||
|
||||
const modalManager = new ModalManager({
|
||||
app,
|
||||
@@ -685,12 +686,79 @@ export default class ApplicationBootstrap {
|
||||
};
|
||||
|
||||
app.videosMap = app.nostrService.getVideosMap();
|
||||
app.unsubscribeFromNostrService = app.nostrService.on(
|
||||
"subscription:changed",
|
||||
({ subscription }) => {
|
||||
app.refreshUnreadDmIndicator = async ({ reason = "" } = {}) => {
|
||||
if (
|
||||
!app.appChromeController ||
|
||||
typeof app.appChromeController.setUnreadDmIndicator !== "function"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof app.isUserLoggedIn === "function" && !app.isUserLoggedIn()) {
|
||||
app.appChromeController.setUnreadDmIndicator(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
!app.nostrService ||
|
||||
typeof app.nostrService.listDirectMessageConversationSummaries !==
|
||||
"function"
|
||||
) {
|
||||
app.appChromeController.setUnreadDmIndicator(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const summaries =
|
||||
await app.nostrService.listDirectMessageConversationSummaries();
|
||||
const totalUnseen = Array.isArray(summaries)
|
||||
? summaries.reduce((sum, summary) => {
|
||||
const count = Number(summary?.unseen_count);
|
||||
return sum + (Number.isFinite(count) ? count : 0);
|
||||
}, 0)
|
||||
: 0;
|
||||
app.appChromeController.setUnreadDmIndicator(totalUnseen > 0);
|
||||
} catch (error) {
|
||||
devLogger.warn(
|
||||
"[Application] Failed to refresh DM unread indicator",
|
||||
reason,
|
||||
error,
|
||||
);
|
||||
app.appChromeController.setUnreadDmIndicator(false);
|
||||
}
|
||||
};
|
||||
|
||||
const nostrUnsubscribes = [];
|
||||
nostrUnsubscribes.push(
|
||||
app.nostrService.on("subscription:changed", ({ subscription }) => {
|
||||
app.videoSubscription = subscription || null;
|
||||
},
|
||||
}),
|
||||
);
|
||||
nostrUnsubscribes.push(
|
||||
app.nostrService.on("directMessages:notification", () => {
|
||||
void app.refreshUnreadDmIndicator({ reason: "dm-notification" });
|
||||
}),
|
||||
);
|
||||
nostrUnsubscribes.push(
|
||||
app.nostrService.on("directMessages:conversationUpdated", () => {
|
||||
void app.refreshUnreadDmIndicator({ reason: "dm-conversation-update" });
|
||||
}),
|
||||
);
|
||||
nostrUnsubscribes.push(
|
||||
app.nostrService.on("directMessages:cleared", () => {
|
||||
if (app.appChromeController) {
|
||||
app.appChromeController.setUnreadDmIndicator(false);
|
||||
}
|
||||
}),
|
||||
);
|
||||
app.unsubscribeFromNostrService = () => {
|
||||
while (nostrUnsubscribes.length) {
|
||||
const unsubscribe = nostrUnsubscribes.pop();
|
||||
if (typeof unsubscribe === "function") {
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
};
|
||||
app.boundNwcSettingsToastHandler = null;
|
||||
Object.defineProperty(app, "savedProfiles", {
|
||||
configurable: false,
|
||||
@@ -926,6 +994,7 @@ export default class ApplicationBootstrap {
|
||||
elements: {
|
||||
logoutButton: app.logoutButton,
|
||||
profileButton: app.profileButton,
|
||||
profileUnreadDot: app.profileUnreadDot,
|
||||
uploadButton: app.uploadButton,
|
||||
loginButton: app.loginButton,
|
||||
closeLoginModalButton: app.closeLoginModalBtn,
|
||||
|
||||
Reference in new issue
Block a user