@@ -10,6 +10,8 @@ use tokio::net::TcpStream;
1010use tokio:: sync:: mpsc;
1111use tokio_util:: codec:: Framed ;
1212
13+ use crate :: args:: { args, AutoJoinOptions } ;
14+ use crate :: matrix:: room_mappings:: RoomTargetType ;
1315use crate :: { matrirc:: Matrirc , matrix:: MatrixMessageType } ;
1416
1517/// it's a bit of a pain to redo the work twice for notice/privmsg,
@@ -163,6 +165,10 @@ pub async fn ircd_sync_write(
163165}
164166
165167pub async fn join_channels ( matrirc : & Matrirc ) -> Result < ( ) > {
168+ if args ( ) . autojoin == AutoJoinOptions :: None {
169+ return Ok ( ( ) ) ;
170+ }
171+
166172 let irc = matrirc. irc ( ) ;
167173 let matrix = matrirc. matrix ( ) ;
168174 let mapping = matrirc. mappings ( ) ;
@@ -178,7 +184,20 @@ pub async fn join_channels(matrirc: &Matrirc) -> Result<()> {
178184 continue ;
179185 }
180186 let roomtarget = mapping. try_room_target ( & joined) . await ?;
181- roomtarget. join_chan ( irc) . await ;
187+ let chantype = roomtarget. target_type ( ) . await ;
188+ if [ RoomTargetType :: Chan , RoomTargetType :: LeftChan ] . contains ( & chantype)
189+ && args ( ) . autojoin . join_channels ( )
190+ {
191+ roomtarget. join_chan ( irc) . await ;
192+ } else if chantype == RoomTargetType :: Query && args ( ) . autojoin . join_queries ( ) {
193+ let _ = irc
194+ . send ( privmsg (
195+ roomtarget. target ( ) . await ,
196+ & irc. nick ,
197+ "* <Resumed connection to matrirc>" ,
198+ ) )
199+ . await ;
200+ }
182201 }
183202 Ok ( ( ) )
184203}
0 commit comments