Commit f08ec1f0 authored by Seif Lotfy's avatar Seif Lotfy
Browse files

Add new properties to Individual and Persona:



Added new im_interaction_count and last_im_interaction_timestamp to Persona and Individual
Added new call_interaction_count and last_call_interaction_timestamp to Persona and Individual
Signed-off-by: default avatarSeif Lotfy <seif.lotfy@collabora.co.uk>
Signed-off-by: default avatarSeif Lotfy <seif@lotfy.com>
parent 8974b442
......@@ -66,6 +66,7 @@ libfolks_la_SOURCES = \
group-details.vala \
web-service-details.vala \
im-details.vala \
interaction-details.vala \
local-id-details.vala \
name-details.vala \
note-details.vala \
......
......@@ -89,6 +89,7 @@ public class Folks.Individual : Object,
GenderDetails,
GroupDetails,
ImDetails,
InteractionDetails,
LocalIdDetails,
NameDetails,
NoteDetails,
......@@ -775,6 +776,110 @@ public class Folks.Individual : Object,
set { this.change_web_service_addresses.begin (value); }
}
/**
* {@inheritDoc}
*/
public uint im_interaction_count
{
get
{
uint counter = 0;
/* Iterate over all personas and sum up their IM interaction counts*/
foreach (var persona in this._persona_set)
{
var my_interaction_details = persona as InteractionDetails;
if (my_interaction_details != null)
{
counter = counter + my_interaction_details.im_interaction_count;
}
}
return counter;
}
}
/**
* {@inheritDoc}
*/
private DateTime? _last_im_interaction_datetime = null;
public DateTime? last_im_interaction_datetime
{
get
{
if (this._last_im_interaction_datetime == null)
{
/* Iterate over all personas and get the latest IM interaction datetime */
foreach (var persona in this._persona_set)
{
var my_interaction_details = persona as InteractionDetails;
if (my_interaction_details != null &&
my_interaction_details.last_im_interaction_datetime != null)
{
DateTime interaction_datetime = my_interaction_details.last_im_interaction_datetime;
if (this._last_im_interaction_datetime == null ||
interaction_datetime.compare (this._last_im_interaction_datetime) == 1)
{
this._last_im_interaction_datetime = my_interaction_details.last_im_interaction_datetime;
}
}
}
}
return this._last_im_interaction_datetime;
}
}
/**
* {@inheritDoc}
*/
public uint call_interaction_count
{
get
{
uint counter = 0;
/* Iterate over all personas and sum up their call interaction counts*/
foreach (var persona in this._persona_set)
{
var my_interaction_details = persona as InteractionDetails;
if (my_interaction_details != null)
{
counter = counter + my_interaction_details.call_interaction_count;
}
}
return counter;
}
}
/**
* {@inheritDoc}
*/
private DateTime? _last_call_interaction_datetime = null;
public DateTime? last_call_interaction_datetime
{
get
{
if (this._last_call_interaction_datetime == null)
{
/* Iterate over all personas and get the latest IM interaction datetime */
foreach (var persona in this._persona_set)
{
var my_interaction_details = persona as InteractionDetails;
if (my_interaction_details != null &&
my_interaction_details.last_call_interaction_datetime != null)
{
var interaction_datetime = my_interaction_details.last_call_interaction_datetime;
if (this._last_call_interaction_datetime == null ||
interaction_datetime.compare (this._last_call_interaction_datetime) > 1)
{
this._last_call_interaction_datetime = my_interaction_details.last_call_interaction_datetime;
}
}
}
}
return this._last_call_interaction_datetime;
}
}
/**
* The set of {@link Persona}s encapsulated by this Individual.
*
......@@ -932,6 +1037,44 @@ public class Folks.Individual : Object,
this._update_is_favourite ();
}
private void _notify_im_interaction_count_cb (Object obj, ParamSpec ps)
{
/**
* The property is pull rather than push. This function is called in
* response to personas emitting a similar notification.
*/
this.notify_property ("im-interaction-count");
}
private void _notify_call_interaction_count_cb (Object obj, ParamSpec ps)
{
/**
* The property is pull rather than push. This function is called in
* response to personas emitting a similar notification.
*/
this.notify_property ("call-interaction-count");
}
private void _notify_last_im_interaction_datetime_cb (Object obj, ParamSpec ps)
{
/**
* The property is pull rather than push. This function is called in
* response to personas emitting a similar notification.
*/
this._last_im_interaction_datetime = null;
this.notify_property ("last-im-interaction-datetime");
}
private void _notify_last_call_interaction_datetime_cb (Object obj, ParamSpec ps)
{
/**
* The property is pull rather than push. This function is called in
* response to personas emitting a similar notification.
*/
this._last_call_interaction_datetime = null;
this.notify_property ("last-call-interaction-datetime");
}
/**
* Create a new Individual.
*
......@@ -1476,6 +1619,15 @@ public class Folks.Individual : Object,
((GroupDetails) persona).group_changed.connect (
this._persona_group_changed_cb);
}
/* Subscribe to the interactions signal for the persona */
var p_interaction_details = persona as InteractionDetails;
if (p_interaction_details != null)
{
persona.notify["im-interaction-count"].connect (this._notify_im_interaction_count_cb);
persona.notify["call-interaction-count"].connect (this._notify_call_interaction_count_cb);
persona.notify["last-im-interaction-datetime"].connect (this._notify_last_im_interaction_datetime_cb);
persona.notify["last-call-interaction-datetime"].connect (this._notify_last_call_interaction_datetime_cb);
}
}
private void _update_structured_name ()
......@@ -1608,6 +1760,16 @@ public class Folks.Individual : Object,
this._persona_group_changed_cb);
}
/* Unsubscribe from the interactions signal for the persona */
var p_interaction_details = persona as InteractionDetails;
if (p_interaction_details != null)
{
persona.notify["im-interaction-count"].disconnect (this._notify_im_interaction_count_cb);
persona.notify["call-interaction-count"].disconnect (this._notify_call_interaction_count_cb);
persona.notify["last-im-interaction-datetime"].disconnect (this._notify_last_im_interaction_datetime_cb);
persona.notify["last-call-interaction-datetime"].disconnect (this._notify_last_call_interaction_datetime_cb);
}
/* Don't update the individual if the persona's been added to the new one
* already (and thus the new individual has already changed
* persona.individual).
......
/*
* Copyright (C) 2012 Collabora Ltd.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Seif Lotfy <seif.lotfy@collabora.co.uk>
*/
using GLib;
/**
* Object representing interaction details for an Individual or Persona.
* Interaction details are the number of call or IM interactions with the a
* a {@link Persona} or an {@link Individual} as well as the the datetime of
* the last call and im interaction.
*
* @since UNRELEASED
*/
public interface Folks.InteractionDetails : Object
{
/**
* The IM interaction associated with a Persona
*
* @since UNRELEASED
*/
public abstract uint im_interaction_count
{
get;
}
/**
* The latest IM interaction timestamp associated with a Persona
*
* @since UNRELEASED
*/
public abstract DateTime? last_im_interaction_datetime
{
get;
}
/**
* The call interaction associated with a Persona
*
* @since UNRELEASED
*/
public abstract uint call_interaction_count
{
get;
}
/**
* The latest call interaction timestamp associated with a Persona
*
* @since UNRELEASED
*/
public abstract DateTime? last_call_interaction_datetime
{
get;
}
}
......@@ -266,7 +266,35 @@ public enum Folks.PersonaDetail
*
* @since 0.6.2
*/
GROUPS
GROUPS,
/**
* Field for {@link InteractionDetails.im_interaction_count}.
*
* @since UNRELEASED
*/
IM_INTERACTION_COUNT,
/**
* Field for {@link InteractionDetails.last_im_interaction_datetime}.
*
* @since UNRELEASED
*/
LAST_IM_INTERACTION_DATETIME,
/**
* Field for {@link InteractionDetails.call_interaction_count}.
*
* @since UNRELEASED
*/
CALL_INTERACTION_COUNT,
/**
* Field for {@link InteractionDetails.last_call_interaction_datetime}.
*
* @since UNRELEASED
*/
LAST_CALL_INTERACTION_DATETIME
}
/**
......@@ -321,7 +349,11 @@ public abstract class Folks.PersonaStore : Object
"structured-name",
"urls",
"web-service-addresses",
"groups"
"groups",
"im-interaction-count",
"last-im-interaction-datetime",
"call-interaction-count",
"last-call-interaction-datetime"
};
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment