refactor(notification): streamline notification handling by updating API endpoints, improving unread count logic, and enhancing notification click behavior
This commit is contained in:
@@ -94,17 +94,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="text-sm text-gray-600 dark:text-gray-400 line-clamp-2"
|
class="text-sm text-gray-600 dark:text-gray-400 line-clamp-2"
|
||||||
:title="
|
:title="notification.latest_message_preview ?? notification.content ?? 'No preview'"
|
||||||
notification.latest_message_preview ??
|
|
||||||
notification.latest_message_title ??
|
|
||||||
'No message preview'
|
|
||||||
"
|
|
||||||
>
|
>
|
||||||
{{
|
{{ notification.latest_message_preview ?? notification.content ?? "No preview" }}
|
||||||
notification.latest_message_preview ??
|
|
||||||
notification.latest_message_title ??
|
|
||||||
"No message preview"
|
|
||||||
}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -145,14 +137,11 @@ export default {
|
|||||||
isDropdownOpen: false,
|
isDropdownOpen: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
notifications: [],
|
notifications: [],
|
||||||
|
unreadCount: 0,
|
||||||
reloadInterval: null,
|
reloadInterval: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {},
|
||||||
unreadCount() {
|
|
||||||
return this.notifications.length;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
beforeUnmount() {
|
beforeUnmount() {
|
||||||
if (this.reloadInterval) {
|
if (this.reloadInterval) {
|
||||||
clearInterval(this.reloadInterval);
|
clearInterval(this.reloadInterval);
|
||||||
@@ -182,15 +171,16 @@ export default {
|
|||||||
async loadNotifications() {
|
async loadNotifications() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
try {
|
try {
|
||||||
const response = await window.axios.get(`/api/v1/lxmf/conversations`, {
|
const response = await window.axios.get(`/api/v1/notifications`, {
|
||||||
params: {
|
params: {
|
||||||
filter_unread: true,
|
unread: true,
|
||||||
limit: 10,
|
limit: 10,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const newNotifications = response.data.conversations || [];
|
const newNotifications = response.data.notifications || [];
|
||||||
|
|
||||||
this.notifications = newNotifications;
|
this.notifications = newNotifications;
|
||||||
|
this.unreadCount = response.data.unread_count || 0;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to load notifications", e);
|
console.error("Failed to load notifications", e);
|
||||||
this.notifications = [];
|
this.notifications = [];
|
||||||
@@ -203,9 +193,14 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const destination_hashes = this.notifications.map((n) => n.destination_hash);
|
const destination_hashes = this.notifications
|
||||||
|
.filter((n) => n.type === "lxmf_message")
|
||||||
|
.map((n) => n.destination_hash);
|
||||||
|
const notification_ids = this.notifications.filter((n) => n.type !== "lxmf_message").map((n) => n.id);
|
||||||
|
|
||||||
await window.axios.post("/api/v1/notifications/mark-as-viewed", {
|
await window.axios.post("/api/v1/notifications/mark-as-viewed", {
|
||||||
destination_hashes: destination_hashes,
|
destination_hashes: destination_hashes,
|
||||||
|
notification_ids: notification_ids,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to mark notifications as viewed", e);
|
console.error("Failed to mark notifications as viewed", e);
|
||||||
@@ -213,10 +208,17 @@ export default {
|
|||||||
},
|
},
|
||||||
onNotificationClick(notification) {
|
onNotificationClick(notification) {
|
||||||
this.closeDropdown();
|
this.closeDropdown();
|
||||||
this.$router.push({
|
if (notification.type === "lxmf_message") {
|
||||||
name: "messages",
|
this.$router.push({
|
||||||
params: { destinationHash: notification.destination_hash },
|
name: "messages",
|
||||||
});
|
params: { destinationHash: notification.destination_hash },
|
||||||
|
});
|
||||||
|
} else if (notification.type === "telephone_missed_call") {
|
||||||
|
this.$router.push({
|
||||||
|
name: "call",
|
||||||
|
query: { tab: "history" },
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
formatTimeAgo(datetimeString) {
|
formatTimeAgo(datetimeString) {
|
||||||
return Utils.formatTimeAgo(datetimeString);
|
return Utils.formatTimeAgo(datetimeString);
|
||||||
|
|||||||
Reference in New Issue
Block a user