2
2
* Copyright (C) 2010 Collabora Ltd.
3
* Copyright (C) 2011 Philip Withnall
4
5
* This library is free software: you can redistribute it and/or modify
5
6
* it under the terms of the GNU Lesser General Public License as published by
37
* Object representing an IM address value that can have some parameters
40
* See {@link Folks.AbstractFieldDetails}.
44
public class Folks.ImFieldDetails : AbstractFieldDetails<string>
47
* Create a new ImFieldDetails.
49
* @param value the value of the field
50
* @param parameters initial parameters. See
51
* {@link AbstractFieldDetails.parameters}. A `null` value is equivalent to an
52
* empty map of parameters.
54
* @return a new ImFieldDetails
58
public ImFieldDetails (string value,
59
MultiMap<string, string>? parameters = null)
62
if (parameters != null)
63
this.parameters = parameters;
71
public override bool equal (AbstractFieldDetails<string> that)
73
return base.equal<string> (that);
81
public override uint hash ()
35
88
* IM addresses exposed by an object implementing {@link PresenceDetails}.
39
92
public interface Folks.ImDetails : Object
42
* A mapping of IM protocol to an ordered set of IM addresses.
95
* A mapping of IM protocol to an (unordered) set of IM addresses.
44
97
* Each mapping is from an arbitrary protocol identifier to a set of IM
45
* addresses on that protocol for the contact, listed in preference order.
46
* The most-preferred IM address for each protocol comes first in that
98
* addresses on that protocol for the contact, listed in no particular order.
49
* There must be no duplicate IM addresses in each ordered set, though a given
100
* There must be no duplicate IM addresses in each set, though a given
50
101
* IM address may be present in the sets for different protocols.
52
103
* All the IM addresses must be normalised using
53
104
* {@link ImDetails.normalise_im_address} before being added to this property.
57
public abstract HashTable<string, LinkedHashSet<string>> im_addresses
108
public abstract MultiMap<string, ImFieldDetails> im_addresses
114
* Change the contact's set of IM addresses.
116
* It's preferred to call this rather than setting
117
* {@link ImDetails.im_addresses} directly, as this method gives error
118
* notification and will only return once the IM addresses have been written
119
* to the relevant backing store (or the operation's failed).
121
* @param im_addresses the new map of protocols to IM addresses
122
* @throws PropertyError if setting the IM addresses failed
125
public virtual async void change_im_addresses (
126
MultiMap<string, ImFieldDetails> im_addresses) throws PropertyError
128
/* Default implementation. */
129
throw new PropertyError.NOT_WRITEABLE (
130
_("IM addresses are not writeable on this contact."));
63
134
* Normalise an IM address so that it's suitable for string comparison.
65
136
* IM addresses for various protocols can be represented in different ways,
67
138
* of IM addresses to work, the IM addresses must be normalised beforehand.
69
140
* If the provided IM address is invalid,
70
* {@link Folks.ImDetailsError.INVALID_IM_ADDRESS} will be thrown. Note that this
71
* isn't guaranteed to be thrown for all invalid addresses, but if it is
141
* {@link Folks.ImDetailsError.INVALID_IM_ADDRESS} will be thrown. Note that
142
* this isn't guaranteed to be thrown for all invalid addresses, but if it is
72
143
* thrown, the address is guaranteed to be invalid.
74
145
* @param im_address the address to normalise
80
151
public static string normalise_im_address (string im_address, string protocol)
81
152
throws Folks.ImDetailsError
85
154
if (protocol == "aim" || protocol == "myspace")
87
normalised = im_address.replace (" ", "").down ();
156
return im_address.replace (" ", "").down ().normalize ();
89
158
else if (protocol == "irc" || protocol == "yahoo" ||
90
159
protocol == "yahoojp" || protocol == "groupwise")
92
normalised = im_address.down ();
161
return im_address.down ().normalize ();
94
163
else if (protocol == "jabber")
164
235
_("The IM address '%s' could not be understood."),
239
return normalised.normalize (-1, NormalizeMode.NFKC);
171
normalised = im_address;
244
return im_address.normalize ();
174
return normalised.normalize ();