From 452005b98cb5289a182b1edffdebf49994e8beee Mon Sep 17 00:00:00 2001 From: "Ivan I. Ovchinnikov" Date: Sat, 21 Nov 2026 11:26:25 +0300 Subject: [PATCH] feat(bridge,ui): sort channels by last activity - Add last_post_at field to Channel model (Rust) - Sort channels by last_post_at descending in dashboard (Emacs) --- bridge/crates/mm-core/src/model/mod.rs | 6 ++++-- lisp/mattermost-dashboard.el | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/bridge/crates/mm-core/src/model/mod.rs b/bridge/crates/mm-core/src/model/mod.rs index 6256f1f..6feb5ed 100644 --- a/bridge/crates/mm-core/src/model/mod.rs +++ b/bridge/crates/mm-core/src/model/mod.rs @@ -85,9 +85,12 @@ pub struct Channel { pub id: ChannelId, pub team_id: TeamId, #[serde(rename = "type")] - pub channel_type: String, // "O" (Open), "P" (Private), "D" (Direct), "G" (Group) + pub channel_type: String, pub display_name: String, pub name: String, + /// Timestamp of the last post in this channel (milliseconds since epoch). + #[serde(default)] + pub last_post_at: i64, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -103,7 +106,6 @@ pub struct Post { #[serde(default)] pub file_ids: Vec, /// Populated by the bridge after resolving user_id via /users/ids. - /// Skipped during deserialization from Mattermost API. #[serde(default, skip_deserializing)] pub user_display_name: String, } diff --git a/lisp/mattermost-dashboard.el b/lisp/mattermost-dashboard.el index 3edc2be..6f79df4 100644 --- a/lisp/mattermost-dashboard.el +++ b/lisp/mattermost-dashboard.el @@ -97,11 +97,20 @@ 'mm-channel-name label 'mouse-face 'highlight)))) +(defun mattermost--sort-channels-by-activity (channels) + "Sort CHANNELS by last_post_at descending (most recent first)." + (sort channels + (lambda (a b) + (> (or (plist-get a :last_post_at) 0) + (or (plist-get b :last_post_at) 0))))) + (defun mattermost--render-dashboard (server-id channels teams) "Render CHANNELS grouped by TEAMS for SERVER-ID." (let ((buf (get-buffer-create "*Mattermost Dashboard*")) (by-team (make-hash-table :test 'equal)) (dms nil)) + ;; Сортируем каналы по активности + (setq channels (mattermost--sort-channels-by-activity channels)) (dolist (ch channels) (let ((type (plist-get ch :type))) (if (member type '("D" "G")) @@ -124,6 +133,7 @@ (when chs (puthash tid t rendered) (mattermost--insert-team-header (plist-get team :display_name)) + ;; Каналы уже отсортированы, просто реверсим для правильного порядка (dolist (ch (nreverse chs)) (mattermost--insert-channel-line ch)) (insert "\n"))))