Changeset 6277

Show
Ignore:
Timestamp:
06/13/08 03:16:28 (7 months ago)
Author:
flynd
Message:

Added more general user group editing function to user manager so allow simpler group membership code in plugins.

Location:
trunk/licq
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/licq/include/licq_icqd.h

    r6227 r6277  
    481481 
    482482  // Visible/Invisible/Ignore list functions 
     483  /** 
     484   * Set visible list status for a contact 
     485   * 
     486   * @param id User id 
     487   * @param ppid User protocol id 
     488   * @param visible True to add user to visible list or false to remove 
     489   */ 
     490  void ProtoSetInVisibleList(const char* id, unsigned long ppid, bool visible); 
     491 
     492  /** 
     493   * Set invisible list status for a contact 
     494   * 
     495   * @param id User id 
     496   * @param ppid User protocol id 
     497   * @param invisible True to add user to invisible list or false to remove 
     498   */ 
     499  void ProtoSetInInvisibleList(const char* id, unsigned long ppid, bool invisible); 
     500 
     501  /** 
     502   * Set invisible list status for a contact 
     503   * 
     504   * @param id User id 
     505   * @param ppid User protocol id 
     506   * @param ignore True to add user to ignore list or false to remove 
     507   */ 
     508  void ProtoSetInIgnoreList(const char* id, unsigned long ppid, bool ignore); 
     509 
    483510  void ProtoToggleInvisibleList(const char *_szId, unsigned long _nPPID); 
    484511  void ProtoToggleVisibleList(const char *_szId, unsigned long _nPPID); 
  • trunk/licq/include/licq_user.h

    r6248 r6277  
    11281128  unsigned short GenerateSID(); 
    11291129 
     1130  /** 
     1131   * Set user group membership and (optionally) update server 
     1132   * 
     1133   * @param id User id 
     1134   * @param ppid User protocol id 
     1135   * @param groupType Group type 
     1136   * @param groupId Group id 
     1137   * @param inGroup True to add user to group or false to remove 
     1138   * @param updateServer True if server list should be updated 
     1139   */ 
     1140  void SetUserInGroup(const char* id, unsigned long ppid, GroupType groupType, 
     1141      unsigned short groupId, bool inGroup, bool updateServer = true); 
     1142 
     1143  // Deprecated group manipulation functions 
    11301144  void AddUserToGroup(unsigned long _nUin, unsigned short _nGroup); 
    11311145  void RemoveUserFromGroup(unsigned long _nUin, unsigned short _nGroup); 
    1132   void AddUserToGroup(const char *, unsigned long, unsigned short); 
    1133   void RemoveUserFromGroup(const char *, unsigned long, unsigned short); 
     1146 
     1147  /** 
     1148   * Add user to a group and update server group 
     1149   * 
     1150   * @param id User id 
     1151   * @param ppid User protocol id 
     1152   * @param groupId Group id 
     1153   */ 
     1154  void AddUserToGroup(const char* id, unsigned long ppid, unsigned short groupId) 
     1155  { SetUserInGroup(id, ppid, GROUPS_USER, groupId, true, true); } 
     1156 
     1157  /** 
     1158   * Remove user from a group 
     1159   * 
     1160   * @param id User id 
     1161   * @param ppid User protocol id 
     1162   * @param groupId Group id 
     1163   */ 
     1164  void RemoveUserFromGroup(const char* id, unsigned long ppid, unsigned short groupId) 
     1165  { SetUserInGroup(id, ppid, GROUPS_USER, groupId, false); } 
     1166 
    11341167  void SaveAllUsers(); 
    11351168 
  • trunk/licq/src/icqd-srv.cpp

    r6246 r6277  
    13201320  bool b = u->VisibleList(); 
    13211321  gUserManager.DropUser(u); 
    1322  
    1323   if (b) 
     1322  ProtoSetInVisibleList(_szId, _nPPID, !b); 
     1323} 
     1324 
     1325void CICQDaemon::ProtoSetInVisibleList(const char* _szId, unsigned long _nPPID, bool visible) 
     1326{ 
     1327  if (!visible) 
    13241328    if (_nPPID == LICQ_PPID) 
    13251329      icqRemoveFromVisibleList(_szId, _nPPID); 
     
    13491353  bool b = u->InvisibleList(); 
    13501354  gUserManager.DropUser(u); 
    1351  
    1352   if (b) 
     1355  ProtoSetInInvisibleList(_szId, _nPPID, !b); 
     1356} 
     1357 
     1358void CICQDaemon::ProtoSetInInvisibleList(const char* _szId, unsigned long _nPPID, bool invisible) 
     1359{ 
     1360  if (!invisible) 
    13531361    if (_nPPID == LICQ_PPID) 
    13541362      icqRemoveFromInvisibleList(_szId, _nPPID); 
     
    13781386  bool b = u->IgnoreList(); 
    13791387  gUserManager.DropUser(u); 
    1380  
     1388  ProtoSetInIgnoreList(_szId, _nPPID, b); 
     1389} 
     1390 
     1391void CICQDaemon::ProtoSetInIgnoreList(const char* _szId, unsigned long _nPPID, bool b) 
     1392{ 
    13811393  if (_nPPID == LICQ_PPID) 
    13821394  { 
  • trunk/licq/src/user.cpp

    r6271 r6277  
    16021602} 
    16031603 
    1604 /*--------------------------------------------------------------------------- 
    1605  * CUserManager::AddUserToGroup 
    1606  *-------------------------------------------------------------------------*/ 
    1607 void CUserManager::AddUserToGroup(const char *szId, unsigned long nPPID, 
    1608   unsigned short _nGroup) 
    1609 { 
    1610   //TODO: For other protocols 
    1611   ICQUser *u = FetchUser(szId, nPPID, LOCK_W); 
    1612   if (u == NULL) return; 
    1613   u->AddToGroup(GROUPS_USER, _nGroup); 
    1614   int nGSID = u->GetGSID(); 
    1615   DropUser(u); 
    1616   if (gLicqDaemon && nPPID == LICQ_PPID) 
    1617     gLicqDaemon->icqChangeGroup(szId, nPPID, _nGroup, 
    1618       nGSID, ICQ_ROSTxNORMAL, ICQ_ROSTxNORMAL); 
     1604void CUserManager::SetUserInGroup(const char* id, unsigned long ppid, 
     1605    GroupType groupType, unsigned short groupId, bool inGroup, bool updateServer) 
     1606{ 
     1607  ICQUser* u = gUserManager.FetchUser(id, ppid, LOCK_W); 
     1608  if (u == NULL) 
     1609    return; 
     1610 
     1611  int gsid = u->GetGSID(); 
     1612 
     1613  if (!inGroup && u->GetSID() != 0 && GetGroupFromID(gsid) == groupId) 
     1614  { 
     1615    // Don't remove user from local group if member of the same server group 
     1616    gUserManager.DropUser(u); 
     1617    return; 
     1618  } 
     1619 
     1620  // Update user object 
     1621  u->SetInGroup(groupType, groupId, inGroup); 
     1622  gUserManager.DropUser(u); 
     1623 
     1624  // Notify server 
     1625  if (updateServer && gLicqDaemon != NULL) 
     1626  { 
     1627    if (groupType == GROUPS_SYSTEM) 
     1628    { 
     1629      if (groupId == GROUP_VISIBLE_LIST) 
     1630        gLicqDaemon->ProtoSetInVisibleList(id, ppid, inGroup); 
     1631 
     1632      else if (groupId == GROUP_INVISIBLE_LIST) 
     1633        gLicqDaemon->ProtoSetInInvisibleList(id, ppid, inGroup); 
     1634 
     1635      else if (groupId == GROUP_IGNORE_LIST) 
     1636        gLicqDaemon->ProtoSetInIgnoreList(id, ppid, inGroup); 
     1637    } 
     1638    else 
     1639    { 
     1640      // Server group currently only supported for ICQ protocol 
     1641      // Group can only be changed, not removed 
     1642      if (ppid == LICQ_PPID && inGroup) 
     1643        gLicqDaemon->icqChangeGroup(id, ppid, groupId, gsid, 
     1644            ICQ_ROSTxNORMAL, ICQ_ROSTxNORMAL); 
     1645    } 
     1646  } 
    16191647} 
    16201648 
    16211649void CUserManager::AddUserToGroup(unsigned long _nUin, unsigned short _nGroup) 
    16221650{ 
    1623   ICQUser *u = FetchUser(_nUin, LOCK_W); 
    1624   if (u == NULL) return; 
    1625   u->AddToGroup(GROUPS_USER, _nGroup); 
    1626   int nGSID = u->GetGSID(); 
    1627   DropUser(u); 
    1628   if (gLicqDaemon) 
    1629     gLicqDaemon->icqChangeGroup(_nUin, _nGroup, nGSID, ICQ_ROSTxNORMAL, 
    1630       ICQ_ROSTxNORMAL); 
    1631 } 
    1632  
    1633  
    1634 /*--------------------------------------------------------------------------- 
    1635  * CUserManager::RemoveUserFromGroup 
    1636  *-------------------------------------------------------------------------*/ 
    1637 void CUserManager::RemoveUserFromGroup(const char *szId, unsigned long nPPID, 
    1638   unsigned short _nGroup) 
    1639 { 
    1640   ICQUser *u = FetchUser(szId, nPPID, LOCK_W); 
    1641   if (u == NULL) return; 
    1642   u->RemoveFromGroup(GROUPS_USER, _nGroup); 
    1643   DropUser(u); 
    1644 } 
    1645  
     1651  char id[13]; 
     1652  snprintf(id, 12, "%lu", _nUin); 
     1653  id[12] = '\0'; 
     1654  AddUserToGroup(id, LICQ_PPID, _nGroup); 
     1655} 
    16461656 
    16471657void CUserManager::RemoveUserFromGroup(unsigned long _nUin, unsigned short _nGroup) 
    16481658{ 
    1649   ICQUser *u = FetchUser(_nUin, LOCK_W); 
    1650   if (u == NULL) return; 
    1651   u->RemoveFromGroup(GROUPS_USER, _nGroup); 
    1652   DropUser(u); 
    1653 } 
    1654  
     1659  char id[13]; 
     1660  snprintf(id, 12, "%lu", _nUin); 
     1661  id[12] = '\0'; 
     1662  RemoveUserFromGroup(id, LICQ_PPID, _nGroup); 
     1663} 
    16551664 
    16561665void CUserManager::SetDefaultUserEncoding(const char* defaultEncoding)