-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing documentation #5
Comments
Before I finish documentation, here you have short examples. Just after connection is established, Halcyon asks for roster itself. You no need to do anything. // Registering events listener before you connect to server
client.eventBus.register<RosterEvent>(RosterEvent.TYPE) { event ->
when (event) {
is RosterEvent.ItemAdded -> println("Item ${event.item.jid} was pushed to local roster store")
is RosterEvent.ItemUpdated -> println("Item ${event.item.jid} was updated in local roster store")
is RosterEvent.ItemRemoved -> println("Item ${event.item.jid} was removed from local roster store")
}
}
val rosterModule = client.getModule<RosterModule>(RosterModule.TYPE)!!
val presenceModule = client.getModule<PresenceModule>(PresenceModule.TYPE)!!
// Adding item to roster
rosterModule.addItem(RosterItem("[email protected]".toBareJID(), "Rob Doe")).response {
it.onSuccess {
println("Request is accepted by server. Listen for ItemAdded event.")
}
}.send()
// Updating item in roster
val item = rosterModule.store.getItem("[email protected]".toBareJID())!!
val itemNew = item.copy(name = "Rob")
rosterModule.addItem(itemNew).response {
it.onSuccess {
println("Request is accepted by server. Listen for ItemUpdated event.")
}
}.send()
// Removing item from roster
rosterModule.deleteItem("[email protected]".toBareJID()).response {
it.onSuccess {
println("Request is accepted by server. Listen for ItemRemoved event.")
}
}.send() Simple presence example: client.eventBus.register<ContactChangeStatusEvent> { event->
// $presence is "best presence for contact", not just received presence. Best presence is presence with high priority.
println("This is presence of contact ${event.jid}: ${event.presence}")
}
// Displaying presence of all items from roster:
rosterModule.getAllItems().forEach { rosterItem ->
val presence: Presence? = presenceModule.getBestPresenceOf(rosterItem.jid)
} Note, that presence may be null. You have to calculate "logic presence state" from presence stanza. You may use code like this: enum class Status {
Away,
Chat,
Dnd,
Error,
Offline,
Online,
Unknown,
Xa,
None
}
private fun calculateStatus(presence: Presence?): Status {
if (presence == null) return Status.Offline
val type = presence.type
val show = presence.show
return when (type) {
PresenceType.Error -> Status.Error
PresenceType.Unavailable -> Status.Offline
null -> when (show) {
null -> Status.Online
Show.XA -> Status.Xa
Show.DnD -> Status.Dnd
Show.Away -> Status.Away
Show.Chat -> Status.Chat
}
else -> Status.Unknown
}
} I will add similar code to library. |
Thank you. What about vCard? What would be the best code to request vCard for each roster item that is being retrieved? |
There is no documentation or example code on how to retrieve user's roster.
Please add code example on retrieving user's roster as well as other typical XMPP use cases:
The text was updated successfully, but these errors were encountered: