mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-01 16:06:47 +00:00
Support for video account attributes
// FREEBIE
This commit is contained in:
1 parent
5b28594189
commit
2dfe9eea94
17 files changed
+91
-31
No files matched your search
@@ -307,6 +307,7 @@ public class AccountController {
|
||||
device.setName(attributes.getName());
|
||||
device.setLastSeen(Util.todayInMillis());
|
||||
device.setVoiceSupported(attributes.getVoice());
|
||||
device.setVideoSupported(attributes.getVideo());
|
||||
device.setRegistrationId(attributes.getRegistrationId());
|
||||
device.setSignalingKey(attributes.getSignalingKey());
|
||||
device.setUserAgent(userAgent);
|
||||
@@ -332,6 +333,7 @@ public class AccountController {
|
||||
device.setRegistrationId(accountAttributes.getRegistrationId());
|
||||
device.setName(accountAttributes.getName());
|
||||
device.setVoiceSupported(accountAttributes.getVoice());
|
||||
device.setVideoSupported(accountAttributes.getVideo());
|
||||
device.setCreated(System.currentTimeMillis());
|
||||
device.setLastSeen(Util.todayInMillis());
|
||||
device.setUserAgent(userAgent);
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ public class FederationControllerV1 extends FederationController {
|
||||
|
||||
for (Account account : accountList) {
|
||||
byte[] token = Util.getContactToken(account.getNumber());
|
||||
ClientContact clientContact = new ClientContact(token, null, account.isVoiceSupported());
|
||||
ClientContact clientContact = new ClientContact(token, null, account.isVoiceSupported(), account.isVideoSupported());
|
||||
|
||||
if (!account.isActive()) {
|
||||
clientContact.setInactive(true);
|
||||
|
||||
@@ -40,20 +40,24 @@ public class AccountAttributes {
|
||||
@JsonProperty
|
||||
private boolean voice;
|
||||
|
||||
@JsonProperty
|
||||
private boolean video;
|
||||
|
||||
public AccountAttributes() {}
|
||||
|
||||
@VisibleForTesting
|
||||
public AccountAttributes(String signalingKey, boolean fetchesMessages, int registrationId) {
|
||||
this(signalingKey, fetchesMessages, registrationId, null, false);
|
||||
this(signalingKey, fetchesMessages, registrationId, null, false, false);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public AccountAttributes(String signalingKey, boolean fetchesMessages, int registrationId, String name, boolean voice) {
|
||||
public AccountAttributes(String signalingKey, boolean fetchesMessages, int registrationId, String name, boolean voice, boolean video) {
|
||||
this.signalingKey = signalingKey;
|
||||
this.fetchesMessages = fetchesMessages;
|
||||
this.registrationId = registrationId;
|
||||
this.name = name;
|
||||
this.voice = voice;
|
||||
this.video = video;
|
||||
}
|
||||
|
||||
public String getSignalingKey() {
|
||||
@@ -76,4 +80,8 @@ public class AccountAttributes {
|
||||
return voice;
|
||||
}
|
||||
|
||||
public boolean getVideo() {
|
||||
return video;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,13 +35,17 @@ public class ClientContact {
|
||||
@JsonProperty
|
||||
private boolean voice;
|
||||
|
||||
@JsonProperty
|
||||
private boolean video;
|
||||
|
||||
private String relay;
|
||||
private boolean inactive;
|
||||
|
||||
public ClientContact(byte[] token, String relay, boolean voice) {
|
||||
public ClientContact(byte[] token, String relay, boolean voice, boolean video) {
|
||||
this.token = token;
|
||||
this.relay = relay;
|
||||
this.voice = voice;
|
||||
this.video = video;
|
||||
}
|
||||
|
||||
public ClientContact() {}
|
||||
@@ -74,6 +78,14 @@ public class ClientContact {
|
||||
this.voice = voice;
|
||||
}
|
||||
|
||||
public boolean isVideo() {
|
||||
return video;
|
||||
}
|
||||
|
||||
public void setVideo(boolean video) {
|
||||
this.video = video;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) return false;
|
||||
@@ -85,6 +97,7 @@ public class ClientContact {
|
||||
Arrays.equals(this.token, that.token) &&
|
||||
this.inactive == that.inactive &&
|
||||
this.voice == that.voice &&
|
||||
this.video == that.video &&
|
||||
(this.relay == null ? (that.relay == null) : this.relay.equals(that.relay));
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,6 @@ public class NonLimitedAccount extends Account {
|
||||
|
||||
@Override
|
||||
public Optional<Device> getAuthenticatedDevice() {
|
||||
return Optional.of(new Device(deviceId, null, null, null, null, null, null, null, false, 0, null, System.currentTimeMillis(), System.currentTimeMillis(), false, "NA"));
|
||||
return Optional.of(new Device(deviceId, null, null, null, null, null, null, null, false, 0, null, System.currentTimeMillis(), System.currentTimeMillis(), false, false, "NA"));
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class Account {
|
||||
}
|
||||
|
||||
public void removeDevice(long deviceId) {
|
||||
this.devices.remove(new Device(deviceId, null, null, null, null, null, null, null, false, 0, null, 0, 0, false, "NA"));
|
||||
this.devices.remove(new Device(deviceId, null, null, null, null, null, null, null, false, 0, null, 0, 0, false, false, "NA"));
|
||||
}
|
||||
|
||||
public Set<Device> getDevices() {
|
||||
@@ -103,6 +103,16 @@ public class Account {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isVideoSupported() {
|
||||
for (Device device : devices) {
|
||||
if (device.isActive() && device.isVideoSupported()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return
|
||||
getMasterDevice().isPresent() &&
|
||||
|
||||
@@ -102,7 +102,7 @@ public class AccountsManager {
|
||||
private void updateDirectory(Account account) {
|
||||
if (account.isActive()) {
|
||||
byte[] token = Util.getContactToken(account.getNumber());
|
||||
ClientContact clientContact = new ClientContact(token, null, account.isVoiceSupported());
|
||||
ClientContact clientContact = new ClientContact(token, null, account.isVoiceSupported(), account.isVideoSupported());
|
||||
directory.add(clientContact);
|
||||
} else {
|
||||
directory.remove(account.getNumber());
|
||||
|
||||
@@ -73,6 +73,9 @@ public class Device {
|
||||
@JsonProperty
|
||||
private boolean voice;
|
||||
|
||||
@JsonProperty
|
||||
private boolean video;
|
||||
|
||||
@JsonProperty
|
||||
private String userAgent;
|
||||
|
||||
@@ -82,7 +85,7 @@ public class Device {
|
||||
String signalingKey, String gcmId, String apnId,
|
||||
String voipApnId, boolean fetchesMessages,
|
||||
int registrationId, SignedPreKey signedPreKey,
|
||||
long lastSeen, long created, boolean voice,
|
||||
long lastSeen, long created, boolean voice, boolean video,
|
||||
String userAgent)
|
||||
{
|
||||
this.id = id;
|
||||
@@ -99,6 +102,7 @@ public class Device {
|
||||
this.lastSeen = lastSeen;
|
||||
this.created = created;
|
||||
this.voice = voice;
|
||||
this.video = video;
|
||||
this.userAgent = userAgent;
|
||||
}
|
||||
|
||||
@@ -174,6 +178,14 @@ public class Device {
|
||||
this.voice = voice;
|
||||
}
|
||||
|
||||
public boolean isVideoSupported() {
|
||||
return video;
|
||||
}
|
||||
|
||||
public void setVideoSupported(boolean video) {
|
||||
this.video = video;
|
||||
}
|
||||
|
||||
public void setAuthenticationCredentials(AuthenticationCredentials credentials) {
|
||||
this.authToken = credentials.getHashedAuthenticationToken();
|
||||
this.salt = credentials.getSalt();
|
||||
|
||||
@@ -72,7 +72,7 @@ public class DirectoryManager {
|
||||
}
|
||||
|
||||
public void add(ClientContact contact) {
|
||||
TokenValue tokenValue = new TokenValue(contact.getRelay(), contact.isVoice());
|
||||
TokenValue tokenValue = new TokenValue(contact.getRelay(), contact.isVoice(), contact.isVideo());
|
||||
|
||||
try (Jedis jedis = redisPool.getResource()) {
|
||||
jedis.hset(DIRECTORY_KEY, contact.getToken(), objectMapper.writeValueAsBytes(tokenValue));
|
||||
@@ -84,7 +84,7 @@ public class DirectoryManager {
|
||||
public void add(BatchOperationHandle handle, ClientContact contact) {
|
||||
try {
|
||||
Pipeline pipeline = handle.pipeline;
|
||||
TokenValue tokenValue = new TokenValue(contact.getRelay(), contact.isVoice());
|
||||
TokenValue tokenValue = new TokenValue(contact.getRelay(), contact.isVoice(), contact.isVideo());
|
||||
|
||||
pipeline.hset(DIRECTORY_KEY, contact.getToken(), objectMapper.writeValueAsBytes(tokenValue));
|
||||
} catch (JsonProcessingException e) {
|
||||
@@ -106,7 +106,7 @@ public class DirectoryManager {
|
||||
}
|
||||
|
||||
TokenValue tokenValue = objectMapper.readValue(result, TokenValue.class);
|
||||
return Optional.of(new ClientContact(token, tokenValue.relay, tokenValue.voice));
|
||||
return Optional.of(new ClientContact(token, tokenValue.relay, tokenValue.voice, tokenValue.video));
|
||||
} catch (IOException e) {
|
||||
logger.warn("JSON Error", e);
|
||||
return Optional.absent();
|
||||
@@ -133,7 +133,7 @@ public class DirectoryManager {
|
||||
try {
|
||||
if (pair.second().get() != null) {
|
||||
TokenValue tokenValue = objectMapper.readValue(pair.second().get(), TokenValue.class);
|
||||
ClientContact clientContact = new ClientContact(pair.first(), tokenValue.relay, tokenValue.voice);
|
||||
ClientContact clientContact = new ClientContact(pair.first(), tokenValue.relay, tokenValue.voice, tokenValue.video);
|
||||
|
||||
results.add(clientContact);
|
||||
}
|
||||
@@ -178,11 +178,15 @@ public class DirectoryManager {
|
||||
@JsonProperty(value = "v")
|
||||
private boolean voice;
|
||||
|
||||
@JsonProperty(value = "w")
|
||||
private boolean video;
|
||||
|
||||
public TokenValue() {}
|
||||
|
||||
public TokenValue(String relay, boolean voice) {
|
||||
public TokenValue(String relay, boolean voice, boolean video) {
|
||||
this.relay = relay;
|
||||
this.voice = voice;
|
||||
this.video = video;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +209,7 @@ public class DirectoryManager {
|
||||
}
|
||||
|
||||
TokenValue tokenValue = objectMapper.readValue(result, TokenValue.class);
|
||||
return Optional.of(new ClientContact(token, tokenValue.relay, tokenValue.voice));
|
||||
return Optional.of(new ClientContact(token, tokenValue.relay, tokenValue.voice, tokenValue.video));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DirectoryUpdater {
|
||||
for (Account account : accounts) {
|
||||
if (account.isActive()) {
|
||||
byte[] token = Util.getContactToken(account.getNumber());
|
||||
ClientContact clientContact = new ClientContact(token, null, account.isVoiceSupported());
|
||||
ClientContact clientContact = new ClientContact(token, null, account.isVoiceSupported(), account.isVideoSupported());
|
||||
|
||||
directory.add(batchOperation, clientContact);
|
||||
contactsAdded++;
|
||||
|
||||
Reference in new issue
Block a user