pidgin: ffa049c1: Between an offline presence with offline...
sadrul at pidgin.im
sadrul at pidgin.im
Fri Apr 4 02:05:45 EDT 2008
-----------------------------------------------------------------
Revision: ffa049c1806563e26f6a42e7480f11035b4321f4
Ancestor: 40eafa8cd448e1729d79513e98ab2854e3589e69
Author: sadrul at pidgin.im
Date: 2008-04-03T00:24:20
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/ffa049c1806563e26f6a42e7480f11035b4321f4
Modified files:
libpurple/status.c
ChangeLog:
Between an offline presence with offline-message capability, and a mobile online presence, choose the latter over the former when sending an instant message.
-------------- next part --------------
============================================================
--- libpurple/status.c 7b9223f99bc3107073a842afd4655617588c6c1f
+++ libpurple/status.c 1dd42f0631a73961af2cdc947176a0301a3547c2
@@ -1547,14 +1547,37 @@ purple_presence_get_login_time(const Pur
return purple_presence_is_online(presence) ? presence->login_time : 0;
}
+static int
+purple_presence_compute_score(const PurplePresence *presence)
+{
+ GList *l;
+ int score = 0;
+
+ for (l = purple_presence_get_statuses(presence); l != NULL; l = l->next) {
+ PurpleStatus *status = (PurpleStatus *)l->data;
+ PurpleStatusType *type = purple_status_get_type(status);
+
+ if (purple_status_is_active(status)) {
+ score += primitive_scores[purple_status_type_get_primitive(type)];
+ if (!purple_status_is_online(status)) {
+ PurpleBuddy *b = purple_presence_get_buddy(presence);
+ if (b && purple_account_supports_offline_message(purple_buddy_get_account(b), b))
+ score += primitive_scores[SCORE_OFFLINE_MESSAGE];
+ }
+ }
+ }
+ score += purple_account_get_int(purple_presence_get_account(presence), "score", 0);
+ if (purple_presence_is_idle(presence))
+ score += primitive_scores[SCORE_IDLE];
+ return score;
+}
+
gint
purple_presence_compare(const PurplePresence *presence1,
const PurplePresence *presence2)
{
- gboolean idle1, idle2;
time_t idle_time_1, idle_time_2;
int score1 = 0, score2 = 0;
- GList *l;
if (presence1 == presence2)
return 0;
@@ -1563,50 +1586,19 @@ purple_presence_compare(const PurplePres
else if (presence2 == NULL)
return -1;
- /* Compute the score of the first set of statuses. */
- for (l = purple_presence_get_statuses(presence1); l != NULL; l = l->next)
- {
- PurpleStatus *status = (PurpleStatus *)l->data;
- PurpleStatusType *type = purple_status_get_type(status);
+ if (purple_presence_is_online(presence1) &&
+ !purple_presence_is_online(presence2))
+ return -1;
+ else if (purple_presence_is_online(presence2) &&
+ !purple_presence_is_online(presence1))
+ return 1;
- if (purple_status_is_active(status)) {
- score1 += primitive_scores[purple_status_type_get_primitive(type)];
- if (!purple_status_is_online(status)) {
- PurpleBuddy *b = purple_presence_get_buddy(presence1);
- if (b && purple_account_supports_offline_message(purple_buddy_get_account(b),b))
- score1 += primitive_scores[SCORE_OFFLINE_MESSAGE];
- }
- }
- }
- score1 += purple_account_get_int(purple_presence_get_account(presence1), "score", 0);
+ /* Compute the score of the first set of statuses. */
+ score1 = purple_presence_compute_score(presence1);
/* Compute the score of the second set of statuses. */
- for (l = purple_presence_get_statuses(presence2); l != NULL; l = l->next)
- {
- PurpleStatus *status = (PurpleStatus *)l->data;
- PurpleStatusType *type = purple_status_get_type(status);
+ score2 = purple_presence_compute_score(presence2);
- if (purple_status_is_active(status)) {
- score2 += primitive_scores[purple_status_type_get_primitive(type)];
- if (!purple_status_is_online(status)) {
- PurpleBuddy *b = purple_presence_get_buddy(presence2);
- if (b && purple_account_supports_offline_message(purple_buddy_get_account(b),b))
- score2 += primitive_scores[SCORE_OFFLINE_MESSAGE];
- }
-
- }
- }
- score2 += purple_account_get_int(purple_presence_get_account(presence2), "score", 0);
-
- idle1 = purple_presence_is_idle(presence1);
- idle2 = purple_presence_is_idle(presence2);
-
- if (idle1)
- score1 += primitive_scores[SCORE_IDLE];
-
- if (idle2)
- score2 += primitive_scores[SCORE_IDLE];
-
idle_time_1 = time(NULL) - purple_presence_get_idle_time(presence1);
idle_time_2 = time(NULL) - purple_presence_get_idle_time(presence2);
More information about the Commits
mailing list