/* * Add a new chat room member to the room's roster */ gboolean muc_add_to_roster(const char * const room, const char * const nick, const char * const show, const char * const status, const char * const caps_str) { ChatRoom *chat_room = g_hash_table_lookup(rooms, room); gboolean updated = FALSE; if (chat_room != NULL) { PContact old = g_hash_table_lookup(chat_room->roster, nick); if (old == NULL) { updated = TRUE; autocomplete_add(chat_room->nick_ac, nick); } else if ((g_strcmp0(p_contact_presence(old), show) != 0) || (g_strcmp0(p_contact_status(old), status) != 0)) { updated = TRUE; } PContact contact = p_contact_new(nick, NULL, NULL, NULL, NULL, FALSE); resource_presence_t resource_presence = resource_presence_from_string(show); Resource *resource = resource_new(nick, resource_presence, status, 0, caps_str); p_contact_set_presence(contact, resource); g_hash_table_replace(chat_room->roster, strdup(nick), contact); } return updated; }
void contact_presence_xa_when_same_prioroty(void **state) { PContact contact = p_contact_new("*****@*****.**", "bob", NULL, "both", "is offline", FALSE); Resource *resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10); Resource *resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10); p_contact_set_presence(contact, resource_xa); p_contact_set_presence(contact, resource_dnd); const char *presence = p_contact_presence(contact); assert_string_equal("xa", presence); p_contact_free(contact); }
void contact_available_when_highest_priority_chat(void **state) { PContact contact = p_contact_new("*****@*****.**", "bob", NULL, NULL, "is offline", FALSE); Resource *resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10); Resource *resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 20); Resource *resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10); Resource *resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10); Resource *resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10); p_contact_set_presence(contact, resource_online); p_contact_set_presence(contact, resource_chat); p_contact_set_presence(contact, resource_away); p_contact_set_presence(contact, resource_xa); p_contact_set_presence(contact, resource_dnd); gboolean result = p_contact_is_available(contact); assert_true(result); p_contact_free(contact); }
void contact_presence_uses_highest_priority(void **state) { PContact contact = p_contact_new("*****@*****.**", "bob", NULL, "both", "is offline", FALSE); Resource *resource10 = resource_new("resource10", RESOURCE_ONLINE, NULL, 10); Resource *resource20 = resource_new("resource20", RESOURCE_CHAT, NULL, 20); Resource *resource30 = resource_new("resource30", RESOURCE_AWAY, NULL, 30); Resource *resource1 = resource_new("resource1", RESOURCE_XA, NULL, 1); Resource *resource2 = resource_new("resource2", RESOURCE_DND, NULL, 2); p_contact_set_presence(contact, resource10); p_contact_set_presence(contact, resource20); p_contact_set_presence(contact, resource30); p_contact_set_presence(contact, resource1); p_contact_set_presence(contact, resource2); const char *presence = p_contact_presence(contact); assert_string_equal("away", presence); p_contact_free(contact); }
void contact_presence_chat_when_same_prioroty(void **state) { PContact contact = p_contact_new("*****@*****.**", "bob", NULL, "both", "is offline", FALSE); Resource *resource_online = resource_new("resource_online", RESOURCE_ONLINE, NULL, 10, NULL); Resource *resource_chat = resource_new("resource_chat", RESOURCE_CHAT, NULL, 10, NULL); Resource *resource_away = resource_new("resource_away", RESOURCE_AWAY, NULL, 10, NULL); Resource *resource_xa = resource_new("resource_xa", RESOURCE_XA, NULL, 10, NULL); Resource *resource_dnd = resource_new("resource_dnd", RESOURCE_DND, NULL, 10, NULL); p_contact_set_presence(contact, resource_online); p_contact_set_presence(contact, resource_chat); p_contact_set_presence(contact, resource_away); p_contact_set_presence(contact, resource_xa); p_contact_set_presence(contact, resource_dnd); const char *presence = p_contact_presence(contact); assert_string_equal("chat", presence); p_contact_free(contact); }
gboolean roster_update_presence(const char *const barejid, Resource *resource, GDateTime *last_activity) { assert(barejid != NULL); assert(resource != NULL); PContact contact = roster_get_contact(barejid); if (contact == NULL) { return FALSE; } if (!_datetimes_equal(p_contact_last_activity(contact), last_activity)) { p_contact_set_last_activity(contact, last_activity); } p_contact_set_presence(contact, resource); Jid *jid = jid_create_from_bare_and_resource(barejid, resource->name); autocomplete_add(fulljid_ac, jid->fulljid); jid_destroy(jid); return TRUE; }