-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathUserAvatarData.cs
More file actions
105 lines (91 loc) · 2.2 KB
/
UserAvatarData.cs
File metadata and controls
105 lines (91 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Waher.Content;
using Waher.Content.Xml;
using Waher.Security;
namespace Waher.Networking.XMPP.PEP
{
/// <summary>
/// User Avatar data event, as defined in XEP-0084:
/// https://xmpp.org/extensions/xep-0084.html
/// </summary>
public class UserAvatarData : PersonalEvent
{
/// <summary>
/// urn:xmpp:avatar:data
/// </summary>
public const string AvatarDataNamespace = "urn:xmpp:avatar:data";
private byte[] data = null;
private string sha1Hash = null;
/// <summary>
/// User Avatar data event, as defined in XEP-0084:
/// https://xmpp.org/extensions/xep-0084.html
/// </summary>
public UserAvatarData()
{
}
/// <summary>
/// Local name of the event element.
/// </summary>
public override string LocalName => "data";
/// <summary>
/// Namespace of the event element.
/// </summary>
public override string Namespace => AvatarDataNamespace;
/// <summary>
/// XML representation of the event.
/// </summary>
public override string PayloadXml
{
get
{
StringBuilder Xml = new StringBuilder();
Xml.Append("<data xmlns='");
Xml.Append(this.Namespace);
Xml.Append("'>");
Xml.Append(Convert.ToBase64String(this.data));
Xml.Append("</data>");
return Xml.ToString();
}
}
/// <summary>
/// Optional Item ID of event. If null, a new will automatically be generated by the server.
/// </summary>
public override string ItemId
{
get
{
if (this.sha1Hash is null)
this.sha1Hash = Hashes.ComputeSHA1HashString(this.data);
return this.sha1Hash;
}
}
/// <summary>
/// Parses a personal event from its XML representation
/// </summary>
/// <param name="E">XML representation of personal event.</param>
/// <returns>Personal event object.</returns>
public override IPersonalEvent Parse(XmlElement E)
{
UserAvatarData Result = new UserAvatarData()
{
data = Convert.FromBase64String(E.InnerText)
};
return Result;
}
/// <summary>
/// Binary representation of avatar
/// </summary>
public byte[] Data
{
get => this.data;
set
{
this.data = value;
this.sha1Hash = null;
}
}
}
}