Add on/off switch for 3PID in directory lookups

This commit is contained in:
Max Dor
2018-08-15 11:25:41 +02:00
parent 1ab8a27fda
commit feb37112b2
3 changed files with 35 additions and 5 deletions

View File

@@ -140,3 +140,10 @@ To disable Homeserver results, set the following in mxisd configuration file:
```yaml
directory.exclude.homeserver: true
```
### 3PID exclusion in search
You can configure if the 3PID should also be included when doing a directory search.
By default, a search is performed on the 3PIDs. If you would like to not include them:
```yaml
directory.exclude.threepid: true
```

View File

@@ -25,6 +25,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
@Configuration
@ConfigurationProperties("directory")
public class DirectoryConfig {
@@ -34,6 +36,7 @@ public class DirectoryConfig {
public static class Exclude {
private boolean homeserver;
private boolean threepid;
public boolean getHomeserver() {
return homeserver;
@@ -44,6 +47,14 @@ public class DirectoryConfig {
return this;
}
public boolean getThreepid() {
return threepid;
}
public void setThreepid(boolean threepid) {
this.threepid = threepid;
}
}
private Exclude exclude = new Exclude();
@@ -56,4 +67,12 @@ public class DirectoryConfig {
this.exclude = exclude;
}
@PostConstruct
public void buid() {
log.info("--- Directory config ---");
log.info("Exclude:");
log.info("\tHomeserver: {}", getExclude().getHomeserver());
log.info("\t3PID: {}", getExclude().getThreepid());
}
}

View File

@@ -129,6 +129,9 @@ public class DirectoryManager {
result.setLimited(true);
}
if (cfg.getExclude().getThreepid()) {
log.info("Skipping 3PID data, disabled in config");
} else {
resultProvider = provider.searchBy3pid(query);
log.info("Threepid: found {} match(es) for '{}'", resultProvider.getResults().size(), query);
result.getResults().addAll(resultProvider.getResults());
@@ -136,6 +139,7 @@ public class DirectoryManager {
result.setLimited(true);
}
}
}
log.info("Total matches: {} - limited? {}", result.getResults().size(), result.isLimited());
return result;