Ejemplo n.º 1
0
        /// <summary>
        ///   Publishes the display name.
        /// </summary>
        /// <param name = "displayName">The display name.</param>
        public IXmppSession PublishDisplayName(string displayName)
        {
            // Publish the display name ( nickname )
            var iq = new IQ();
            var vcard = new VCardData();

            iq.ID = XmppIdentifierGenerator.Generate();
            iq.Type = IQType.Set;
            iq.From = UserId.ToString();

            vcard.NickName = displayName;

            iq.Items.Add(vcard);

            Send(iq);

            return this;
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Publishes the avatar.
        /// </summary>
        /// <param name = "mimetype">The mimetype.</param>
        /// <param name = "hash">The hash.</param>
        /// <param name = "avatarImage">The avatar image.</param>
        public IXmppSession PublishAvatar(string mimetype, string hash, Image avatarImage)
        {
            var avatarData = new MemoryStream();

            try
            {
                avatarImage.Save(avatarData, ImageFormat.Png);

                // Publish the avatar
                var iq = new IQ();
                var vcard = new VCardData();

                iq.ID = XmppIdentifierGenerator.Generate();
                iq.Type = IQType.Set;
                iq.From = UserId.ToString();

                vcard.Photo.Type = mimetype;
                vcard.Photo.Photo = avatarData.ToArray();

                iq.Items.Add(vcard);

                Send(iq);

                // Save the avatar
                avatarStorage.SaveAvatar(UserId.BareIdentifier, hash, avatarData);

                // Update session configuration
                avatarStorage.Save();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (avatarData != null)
                {
                    avatarData.Close();
                    avatarData.Dispose();
                    avatarData = null;
                }
            }

            return this;
        }