Commit 1b732024 authored by Gautier Pelloux-Prayer's avatar Gautier Pelloux-Prayer
Browse files

presence: fix bugs when fetching latest activity

parent 82e2e647
......@@ -231,8 +231,12 @@ static void presence_person_add_note(LinphonePresencePerson *person, LinphonePre
person->notes = ms_list_append(person->notes, note);
}
static int presence_model_insert_person_by_timestamp(LinphonePresencePerson *current, LinphonePresencePerson *to_insert) {
return current->timestamp > to_insert->timestamp;
}
static void presence_model_add_person(LinphonePresenceModel *model, LinphonePresencePerson *person) {
model->persons = ms_list_append(model->persons, person);
model->persons = ms_list_insert_sorted(model->persons, linphone_presence_person_ref(person), (MSCompareFunc)presence_model_insert_person_by_timestamp);
}
static void presence_model_add_note(LinphonePresenceModel *model, LinphonePresenceNote *note) {
......@@ -365,8 +369,9 @@ struct _get_activity_st {
static void presence_model_get_activity(const LinphonePresencePerson *person, struct _get_activity_st *st) {
unsigned int size = ms_list_size(person->activities);
if (st->requested_idx < (st->current_idx + size)) {
if ((st->current_idx != (unsigned)-1) && (st->requested_idx < (st->current_idx + size))) {
st->activity = (LinphonePresenceActivity *)ms_list_nth_data(person->activities, st->requested_idx - st->current_idx);
st->current_idx = (unsigned)-1;
} else {
st->current_idx += size;
}
......@@ -660,7 +665,7 @@ LinphonePresencePerson * linphone_presence_model_get_nth_person(const LinphonePr
int linphone_presence_model_add_person(LinphonePresenceModel *model, LinphonePresencePerson *person) {
if ((model == NULL) || (person == NULL)) return -1;
model->persons = ms_list_append(model->persons, linphone_presence_person_ref(person));
presence_model_add_person(model, person);
return 0;
}
......@@ -674,7 +679,7 @@ int linphone_presence_model_clear_persons(LinphonePresenceModel *model) {
}
int linphone_presence_model_set_presentity(LinphonePresenceModel *model, const LinphoneAddress *presentity) {
if (model->presentity) {
linphone_address_unref(model->presentity);
model->presentity = NULL;
......@@ -816,7 +821,8 @@ LinphonePresenceActivity * linphone_presence_person_get_nth_activity(const Linph
int linphone_presence_person_add_activity(LinphonePresencePerson *person, LinphonePresenceActivity *activity) {
if ((person == NULL) || (activity == NULL)) return -1;
person->activities = ms_list_append(person->activities, linphone_presence_activity_ref(activity));
// insert in first position since its the most recent activity!
person->activities = ms_list_prepend(person->activities, linphone_presence_activity_ref(activity));
return 0;
}
......@@ -1376,12 +1382,14 @@ static int process_pidf_xml_presence_persons(xmlparsing_context_t *xml_ctx, Linp
else
timestamp = parse_timestamp(person_timestamp_str);
person = presence_person_new(person_id_str, timestamp);
if (person != NULL) {
err = process_pidf_xml_presence_person_activities(xml_ctx, person, i);
if (err == 0) {
err = process_pidf_xml_presence_person_notes(xml_ctx, person, i);
}
if (err == 0) {
ms_error("one more at %s: %s", person_timestamp_str, linphone_presence_activity_to_string(person->activities->data));
presence_model_add_person(model, person);
} else {
linphone_presence_person_unref(person);
......@@ -1462,7 +1470,7 @@ static LinphonePresenceModel * process_pidf_xml_presence_notification(xmlparsing
void linphone_core_add_subscriber(LinphoneCore *lc, const char *subscriber, SalOp *op){
LinphoneFriend *fl=linphone_core_create_friend_with_address(lc,subscriber);
char *tmp;
if (fl==NULL) return ;
fl->lc = lc;
linphone_friend_add_incoming_subscription(fl, op);
......@@ -1470,11 +1478,11 @@ void linphone_core_add_subscriber(LinphoneCore *lc, const char *subscriber, SalO
fl->inc_subscribe_pending=TRUE;
/* the newly created "not yet" friend ownership is transfered to the lc->subscribers list*/
lc->subscribers=ms_list_append(lc->subscribers,fl);
tmp = linphone_address_as_string(fl->uri);
linphone_core_notify_new_subscription_requested(lc,fl,tmp);
ms_free(tmp);
}
void linphone_core_reject_subscriber(LinphoneCore *lc, LinphoneFriend *lf){
......@@ -1795,7 +1803,7 @@ char *linphone_presence_model_to_xml(LinphonePresenceModel *model) {
int err;
char *contact = NULL;
char * content = NULL;
if (model->presentity) {
contact = linphone_address_as_string_uri_only(model->presentity);
} else {
......
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