@@ -50,7 +50,7 @@ def __init__(self):
5050 self .channel_items : dict [str , tuple [ListItem , tuple [Channel , Optional [User ]]]] = {}
5151 self .check_record : dict [str , float ] = {} # 用于记录频道的最后活动时间
5252 self .is_bot_mode = self .app .is_bot_mode
53- self ._current_channel : Optional [Channel ] = None
53+ self .current_channel : Optional [Channel ] = None
5454
5555 @property
5656 def app (self ) -> "Frontend" :
@@ -87,7 +87,6 @@ async def update_channel_list(self):
8787 await channel_list .clear ()
8888 self .channel_items .clear ()
8989
90- # 普通模式:显示频道列表
9190 channels_times = [
9291 (
9392 channel ,
@@ -106,14 +105,12 @@ async def update_channel_list(self):
106105 if time != channel ._created_at .timestamp ():
107106 color = (
108107 "auto"
109- if self ._current_channel and channel .id == self ._current_channel .id
108+ if self .current_channel and channel .id == self .current_channel .id
110109 else "lime blink"
111110 )
112111 elif time > self .check_record [channel .id ]:
113112 color = (
114- "auto"
115- if self ._current_channel and channel .id == self ._current_channel .id
116- else "lime blink"
113+ "auto" if self .current_channel and channel .id == self .current_channel .id else "lime blink"
117114 )
118115
119116 if channel .id .startswith ("private:" ):
@@ -136,41 +133,36 @@ async def update_channel_list(self):
136133
137134 self .channel_items [channel .id ] = (item , (channel , orig_user ))
138135 await channel_list .append (item )
139- if self ._current_channel and channel .id == self ._current_channel .id :
136+ if self .current_channel and channel .id == self .current_channel .id :
140137 item .highlighted = True
141138
142139 async def on_list_view_selected (self , event : ListView .Selected ):
143140 """处理列表项选择事件"""
144141 if event .item and event .item .id and event .item .id .startswith ("channel-" ):
145142 # 查找对应的频道
146143 for item , slots in self .channel_items .values ():
144+ channel , orig_user = slots
145+ if channel .id == DIRECT .id :
146+ ev = ChannelSelectorPressed (
147+ await self .app .backend .create_dm (self .app .backend .current_user ),
148+ self .app .backend .current_user ,
149+ )
150+ else :
151+ ev = ChannelSelectorPressed (channel , orig_user )
147152 if item == event .item :
148- channel , orig_user = slots
149- self ._current_channel = channel # 更新当前频道
150- self .check_record [channel .id ] = datetime .now ().timestamp () # 更新最后活动时间
151153 key = (
152154 f"dm-{ channel .id [8 :]} "
153155 if channel .id .startswith ("private:" )
154- else (
155- f"dm-{ self .app .backend .current_user .id } "
156- if channel .id == DIRECT .id
157- else channel .id
158- )
156+ else ("dm-direct" if channel .id == DIRECT .id else channel .id )
159157 )
160158 label = self .query_one (f"#label-{ key } " , Label )
161159 label .update (label .renderable .replace ("lime blink" , "auto" )) # type: ignore
162- if channel .id == DIRECT .id :
163- self .post_message (
164- ChannelSelectorPressed (
165- await self .app .backend .create_dm (self .app .backend .current_user ),
166- self .app .backend .current_user ,
167- )
168- )
169- else :
170- self .post_message (ChannelSelectorPressed (channel , orig_user ))
160+ self .post_message (ev )
171161 item .highlighted = True
162+ self .current_channel = ev .channel
172163 else :
173164 item .highlighted = False
165+ self .check_record [ev .channel .id ] = datetime .now ().timestamp () # 更新最后活动时间
174166
175167 async def add_new_channel (self ):
176168 """添加新频道的逻辑"""
0 commit comments