Log address with username on connect if we know the name.

This commit is contained in:
Felix Ableitner 2016-01-24 14:03:07 +01:00
parent 3cbba72117
commit dc55d74f9b

View file

@ -145,7 +145,12 @@ final class ConnectionHandler(settings: SettingsInterface, database: DatabaseInt
}
}
Log.i(Tag, "Node " + sender + " connected")
// Log with username if we know it.
if (allKnownUsers().map(_.address).contains(sender))
Log.i(Tag, "Node " + getUser(sender).name + " (" + sender + ") connected")
else
Log.i(Tag, "Node " + sender + " connected")
sendTo(sender, new UserInfo(settings.get(SettingsInterface.KeyUserName, ""),
settings.get(SettingsInterface.KeyUserStatus, "")))
callbacks.onConnectionsChanged()
@ -156,8 +161,15 @@ final class ConnectionHandler(settings: SettingsInterface, database: DatabaseInt
def connections(): Set[Address] = transmissionInterfaces.flatMap(_.getConnections)
private def allKnownUsers() = database.getContacts ++ knownUsers
/**
* Returns [[User]] object containing the user's name (if we know it).
*/
def getUser(address: Address) =
knownUsers.find(_.address == address).getOrElse(new User(address, address.toString, ""))
allKnownUsers()
.find(_.address == address)
.getOrElse(new User(address, address.toString(), ""))
def internetConnectionChanged(): Unit = {
transmissionInterfaces