@ -46,9 +46,17 @@ impl<'a> ProcessMention<'a> {
Err ( e . into ( ) )
}
Ok ( Ok ( res ) ) = > {
debug ! ( "Result: {:#?}" , res ) ;
if let Some ( item ) = res . accounts . into_iter ( ) . next ( ) {
debug ! ( "Search done, account found" ) ;
Ok ( Some ( item . id ) )
let acct_normalized = normalize_acct ( & item . acct , & self . group_acct ) ? ;
if acct_normalized = = acct {
debug ! ( "Search done, account found: {}" , item . acct ) ;
Ok ( Some ( item . id ) )
} else {
warn ! ( "Search done but found wrong account: {}" , item . acct ) ;
Ok ( None )
}
} else {
debug ! ( "Search done, nothing found" ) ;
Ok ( None )
@ -80,12 +88,14 @@ impl<'a> ProcessMention<'a> {
}
}
async fn follow_user ( & self , id : & str ) -> Result < ( ) , GroupError > {
async fn follow_user_by_id ( & self , id : & str ) -> Result < ( ) , GroupError > {
debug ! ( "Trying to follow user #{}" , id ) ;
self . client . follow ( id ) . await ? ;
Ok ( ( ) )
}
async fn unfollow_user ( & self , id : & str ) -> Result < ( ) , GroupError > {
async fn unfollow_user_by_id ( & self , id : & str ) -> Result < ( ) , GroupError > {
debug ! ( "Trying to unfollow user #{}" , id ) ;
self . client . unfollow ( id ) . await ? ;
Ok ( ( ) )
}
@ -373,13 +383,15 @@ impl<'a> ProcessMention<'a> {
match self . config . set_member ( & u , true ) {
Ok ( _ ) = > {
self . add_reply ( format! ( "User {} added to the group!" , u ) ) ;
self . follow_user ( & self . stat us_user_id )
self . follow_by_acct ( & u )
. await . log_error ( "Failed to follow" ) ;
}
Err ( e ) = > {
self . add_reply ( format! ( "Failed to add user {} to group: {}" , u , e ) ) ;
}
}
} else {
debug ! ( "User was already a member" ) ;
}
} else {
self . add_reply ( "Only admins can manage members" ) ;
@ -505,49 +517,48 @@ impl<'a> ProcessMention<'a> {
self . add_reply ( "This is a public-access group. " ) ;
}
if self . config . can_write ( & self . status_acct ) {
if self . is_admin {
self . add_reply ( "*You are an admin.*" ) ;
} else {
self . add_reply ( "*You are a member.*" ) ;
}
if self . is_admin {
self . add_reply ( "*You are an admin.*" ) ;
} else if self . config . is_member ( & self . status_acct ) {
self . add_reply ( "*You are a member.*" ) ;
} else if self . config . is_member_only ( ) {
self . add_reply ( "*You are not a member, ask one of the admins to add you.*" ) ;
} else {
if self . config . is_member_only ( ) {
self . add_reply ( "*You are not a member, ask one of the admins to add you.*" ) ;
} else {
self . add_reply ( "*You are not a member, follow or use /join to join the group.*" ) ;
}
self . add_reply ( "*You are not a member, follow or use /join to join the group.*" ) ;
}
self . add_reply ( " \ n \
To share an original post , mention the group user . \ n \
To share a post , mention the group user or use one of the group hashtags . \
Replies and mentions with commands won ' t be shared . \ n \
\ n \
* * Supported commands :* * \ n \
` / boost , / b ` - boost the replied - to post into the group \ n \
` / ignore , / i ` - make the group completely ignore the post \ n \
` / ping ` - check that the service is alive \ n \
` / boost ` , ` / b ` - boost the replied - to post into the group \ n \
` / ignore ` , ` / i ` - make the group ignore the post \ n \
` / ping ` - check the service is alive \ n \
` / tags ` - show group hashtags \ n \
` / join ` - join the group \ n \
` / leave ` - leave the group " ) ;
if self . config . is_member_only ( ) {
self . add_reply ( "`/members, /who` - show group members / admins" ) ;
self . add_reply ( "`/members` , ` /who` - show group members / admins" ) ;
} else {
self . add_reply ( "`/members, /who` - show group admins" ) ;
self . add_reply ( "`/members` , ` /who` - show group admins" ) ;
}
if self . is_admin {
self . add_reply ( " \ n \
* * Admin commands :* * \ n \
` / add user ` - add a member ( use e - mail style address ) \ n \
` / kick , / remove user ` - kick a member \ n \
` / ban x ` - ban a user or a server \ n \
` / remove user ` - remove a member \ n \
` / add #hashtag ` - add a group hashtag \ n \
` / remove #hashtag ` - remove a group hashtag \ n \
` / ban x ` - ban a user or server \ n \
` / unban x ` - lift a ban \ n \
` / op , / admin user ` - grant admin rights \ n \
` / deop , / de admin user ` - revoke admin rights \ n \
` / admin user ` - grant admin rights \ n \
` / deadmin user ` - revoke admin rights \ n \
` / opengroup ` - make member - only \ n \
` / closegroup ` - make public - access \ n \
` / announce x ` - make a public announcement from the rest of the status " ) ;
` / announce x ` - make a public announcement from the rest of the status ( without formatting ) " ) ;
}
}
@ -575,7 +586,7 @@ impl<'a> ProcessMention<'a> {
// admin can leave but that's a bad idea
let _ = self . config . set_member ( & self . status_acct , false ) ;
self . add_reply ( "You're no longer a group member. Unfollow the group user to stop receiving group messages." ) ;
self . unfollow_user ( & self . status_user_id ) . await
self . unfollow_user_by_id ( & self . status_user_id ) . await
. log_error ( "Failed to unfollow" ) ;
}
}
@ -585,7 +596,7 @@ impl<'a> ProcessMention<'a> {
debug ! ( "Already member or admin, try to follow-back again" ) ;
// Already a member, so let's try to follow the user
// again, maybe first time it failed
self . follow_user ( & self . status_user_id ) . await
self . follow_user_by_id ( & self . status_user_id ) . await
. log_error ( "Failed to follow" ) ;
} else {
// Not a member yet
@ -598,7 +609,7 @@ impl<'a> ProcessMention<'a> {
self . append_admin_list_to_reply ( ) ;
} else {
// Open access, try to follow back
self . follow_user ( & self . status_user_id ) . await
self . follow_user_by_id ( & self . status_user_id ) . await
. log_error ( "Failed to follow" ) ;
// This only fails if the user is banned, but that is filtered above
@ -618,7 +629,15 @@ impl<'a> ProcessMention<'a> {
async fn unfollow_by_acct ( & self , acct : & str ) -> Result < ( ) , GroupError > {
// Try to unfollow
if let Ok ( Some ( id ) ) = self . lookup_acct_id ( acct , true ) . await {
self . unfollow_user ( & id ) . await ? ;
self . unfollow_user_by_id ( & id ) . await ? ;
}
Ok ( ( ) )
}
async fn follow_by_acct ( & self , acct : & str ) -> Result < ( ) , GroupError > {
// Try to unfollow
if let Ok ( Some ( id ) ) = self . lookup_acct_id ( acct , false ) . await {
self . follow_user_by_id ( & id ) . await ? ;
}
Ok ( ( ) )
}