Using latest stable version (willing to test any bleeding edge version), I cannot find a way to setup group avatar. I can set user avatar just fine but I need to change user avatar. Is there a way to do that with Smack? If no how difficult to achieve that?
Am not good at the dirty XMPP Stuffs yet, but am willing to try if it is not beyond noob thing!
I think there is no “native” way to do this in Smack yet. However, I guess you can implement this quite easily by transferring this guide over to Smack.
Basically you Base64-encode the image and create a VCard item with the image data, but addressed to the MUC.
Openfires unreleased master branch will allow an image to be set. There is, however, no user interface to do this. You can use a third party client to set an avatar for a MUC room (Conversations is known to work)
Hi Paul,
your post was useful to help me find the solution. I here by put full solution for others to Copy and paste when they face the same issue. wonder if it can be incorporated in Smack, but it is simple for once to use it directly on his/her project. Here it is
import org.jivesoftware.smack.SmackException.NoResponseException
import org.jivesoftware.smack.SmackException.NotConnectedException
import org.jivesoftware.smack.XMPPException.XMPPErrorException
import org.jivesoftware.smack.packet.IQ
import org.jivesoftware.smack.tcp.XMPPTCPConnection
import org.jivesoftware.smackx.vcardtemp.packet.VCard
import org.jxmpp.jid.impl.JidCreate
object XMPPUtils {
@Throws(
NoResponseException::class,
XMPPErrorException::class,
NotConnectedException::class,
InterruptedException::class
)
fun saveMUCVCard(groupId: String, data: ByteArray, connection: XMPPTCPConnection) {
val vCard = VCard()
vCard.to = JidCreate.entityBareFrom(groupId)
vCard.type = IQ.Type.set
vCard.avatar = data
// Also make sure to generate a new stanza id (the given vcard could be a vcard result), in which case we don't
// want to use the same stanza id again (although it wouldn't break if we did)
vCard.setStanzaId()
connection.createStanzaCollectorAndSend(vCard).nextResultOrThrow<VCard>()
}
}
One have to be careful to limit avatar size or he might face issues!