Implement username links

This commit is contained in:
AsamK 2023-11-16 20:18:15 +01:00
parent 77f284661b
commit 37c65ca6b4
10 changed files with 214 additions and 24 deletions

View file

@ -49,10 +49,15 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
var username = ns.getString("username");
if (username != null) {
try {
final var newUsername = m.setUsername(username);
m.setUsername(username);
final var newUsername = m.getUsername();
final var newUsernameLink = m.getUsernameLink();
switch (outputWriter) {
case PlainTextWriter w -> w.println("Your new username: {}", newUsername);
case JsonWriter w -> w.write(new JsonAccountResponse(newUsername));
case PlainTextWriter w -> w.println("Your new username: {} ({})",
newUsername,
newUsernameLink == null ? "-" : newUsernameLink.getUrl());
case JsonWriter w -> w.write(new JsonAccountResponse(newUsername,
newUsernameLink == null ? null : newUsernameLink.getUrl()));
}
} catch (IOException e) {
throw new IOErrorException("Failed to set username: " + e.getMessage(), e);
@ -72,6 +77,7 @@ public class UpdateAccountCommand implements JsonRpcLocalCommand {
}
private record JsonAccountResponse(
@JsonInclude(JsonInclude.Include.NON_NULL) String username
@JsonInclude(JsonInclude.Include.NON_NULL) String username,
@JsonInclude(JsonInclude.Include.NON_NULL) String usernameLink
) {}
}

View file

@ -46,6 +46,7 @@ import org.asamk.signal.manager.api.UnregisteredRecipientException;
import org.asamk.signal.manager.api.UpdateGroup;
import org.asamk.signal.manager.api.UpdateProfile;
import org.asamk.signal.manager.api.UserStatus;
import org.asamk.signal.manager.api.UsernameLinkUrl;
import org.freedesktop.dbus.DBusMap;
import org.freedesktop.dbus.DBusPath;
import org.freedesktop.dbus.connections.impl.DBusConnection;
@ -164,7 +165,17 @@ public class DbusManagerImpl implements Manager {
}
@Override
public String setUsername(final String username) throws IOException, InvalidUsernameException {
public String getUsername() {
throw new UnsupportedOperationException();
}
@Override
public UsernameLinkUrl getUsernameLink() {
throw new UnsupportedOperationException();
}
@Override
public void setUsername(final String username) throws IOException, InvalidUsernameException {
throw new UnsupportedOperationException();
}