From fdc5bdfae8a4a70cfd91ec0a8554005a3c0bbae2 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 13 Apr 2016 15:08:47 +0000 Subject: sorted lists are used now in Jabber instead of linear database lookup git-svn-id: http://svn.miranda-ng.org/main/trunk@16642 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/JabberG/src/jabber_iq_handlers.cpp | 67 ++++++++++++++-------------- 1 file changed, 33 insertions(+), 34 deletions(-) (limited to 'protocols/JabberG/src/jabber_iq_handlers.cpp') diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index b64cbfb12a..9d0bfde672 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -232,8 +232,6 @@ BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo) } } - JABBER_LIST_ITEM *item; - MCONTACT hContact = NULL; const TCHAR *jid, *str; debugLogA(" Got roster push, query has %d children", XmlGetChildCount(queryNode)); @@ -254,53 +252,54 @@ BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo) const TCHAR *name = XmlGetAttrValue(itemNode, _T("name")); ptrT nick((name != NULL) ? mir_tstrdup(name) : JabberNickFromJID(jid)); if (nick != NULL) { - if ((item = ListAdd(LIST_ROSTER, jid)) != NULL) { - replaceStrT(item->nick, nick); - - HXML groupNode = XmlGetChild(itemNode, "group"); - replaceStrT(item->group, XmlGetText(groupNode)); - - if ((hContact = HContactFromJID(jid, false)) == NULL) { - // Received roster has a new JID. - // Add the jid (with empty resource) to Miranda contact list. - hContact = DBCreateContact(jid, nick, FALSE, FALSE); + MCONTACT hContact = HContactFromJID(jid, false); + if (hContact == NULL) + hContact = DBCreateContact(jid, nick, false, false); + else + setTString(hContact, "jid", jid); + + JABBER_LIST_ITEM *item = ListAdd(LIST_ROSTER, jid, hContact); + replaceStrT(item->nick, nick); + + HXML groupNode = XmlGetChild(itemNode, "group"); + replaceStrT(item->group, XmlGetText(groupNode)); + + if (name != NULL) { + ptrT tszNick(getTStringA(hContact, "Nick")); + if (tszNick != NULL) { + if (mir_tstrcmp(nick, tszNick) != 0) + db_set_ts(hContact, "CList", "MyHandle", nick); + else + db_unset(hContact, "CList", "MyHandle"); } - else setTString(hContact, "jid", jid); - - if (name != NULL) { - ptrT tszNick(getTStringA(hContact, "Nick")); - if (tszNick != NULL) { - if (mir_tstrcmp(nick, tszNick) != 0) - db_set_ts(hContact, "CList", "MyHandle", nick); - else - db_unset(hContact, "CList", "MyHandle"); - } - else db_set_ts(hContact, "CList", "MyHandle", nick); - } - else db_unset(hContact, "CList", "MyHandle"); - - if (!m_options.IgnoreRosterGroups) { - if (item->group != NULL) { - Clist_CreateGroup(0, item->group); - db_set_ts(hContact, "CList", "Group", item->group); - } - else db_unset(hContact, "CList", "Group"); + else db_set_ts(hContact, "CList", "MyHandle", nick); + } + else db_unset(hContact, "CList", "MyHandle"); + + if (!m_options.IgnoreRosterGroups) { + if (item->group != NULL) { + Clist_CreateGroup(0, item->group); + db_set_ts(hContact, "CList", "Group", item->group); } + else db_unset(hContact, "CList", "Group"); } } } - if ((item = ListGetItemPtr(LIST_ROSTER, jid)) != NULL) { + if (JABBER_LIST_ITEM *item = ListGetItemPtr(LIST_ROSTER, jid)) { if (!mir_tstrcmp(str, _T("both"))) item->subscription = SUB_BOTH; else if (!mir_tstrcmp(str, _T("to"))) item->subscription = SUB_TO; else if (!mir_tstrcmp(str, _T("from"))) item->subscription = SUB_FROM; else item->subscription = SUB_NONE; debugLog(_T("Roster push for jid=%s, set subscription to %s"), jid, str); + + MCONTACT hContact = HContactFromJID(jid); + // subscription = remove is to remove from roster list // but we will just set the contact to offline and not actually // remove, so that history will be retained. if (!mir_tstrcmp(str, _T("remove"))) { - if ((hContact = HContactFromJID(jid)) != NULL) { + if (hContact) { SetContactOfflineStatus(hContact); ListRemove(LIST_ROSTER, jid); } -- cgit v1.2.3