+ if(addModes.isEmpty() && removeModes.isEmpty())
+ return;
+
+ if(!addModes.isEmpty())
+ addModes = '+' + addModes;
+ if(!removeModes.isEmpty())
+ removeModes = '-' + removeModes;
+
+ // don't use InputHandler::handleMode() as it keeps track of our persistent mode changes
+ putRawLine(serverEncode(QString("MODE %1 %2%3").arg(me_->nick()).arg(addModes).arg(removeModes)));
+}
+
+void CoreNetwork::updateIssuedModes(const QString &requestedModes) {
+ QString addModes;
+ QString removeModes;
+ bool addMode = true;
+
+ for(int i = 0; i < requestedModes.length(); i++) {
+ if(requestedModes[i] == '+') {
+ addMode = true;
+ continue;
+ }
+ if(requestedModes[i] == '-') {
+ addMode = false;
+ continue;
+ }
+ if(addMode) {
+ addModes += requestedModes[i];
+ } else {
+ removeModes += requestedModes[i];
+ }
+ }
+
+
+ QString addModesOld = _requestedUserModes.section('-', 0, 0);
+ QString removeModesOld = _requestedUserModes.section('-', 1);
+
+ addModes.remove(QRegExp(QString("[%1]").arg(addModesOld))); // deduplicate
+ addModesOld.remove(QRegExp(QString("[%1]").arg(removeModes))); // update
+ addModes += addModesOld;
+
+ removeModes.remove(QRegExp(QString("[%1]").arg(removeModesOld))); // deduplicate
+ removeModesOld.remove(QRegExp(QString("[%1]").arg(addModes))); // update
+ removeModes += removeModesOld;
+
+ _requestedUserModes = QString("%1-%2").arg(addModes).arg(removeModes);
+}
+
+void CoreNetwork::updatePersistentModes(QString addModes, QString removeModes) {
+ QString persistentUserModes = Core::userModes(userId(), networkId());
+
+ QString requestedAdd = _requestedUserModes.section('-', 0, 0);
+ QString requestedRemove = _requestedUserModes.section('-', 1);
+
+ QString persistentAdd, persistentRemove;
+ if(persistentUserModes.contains('-')) {
+ persistentAdd = persistentUserModes.section('-', 0, 0);
+ persistentRemove = persistentUserModes.section('-', 1);
+ } else {
+ persistentAdd = persistentUserModes;
+ }
+
+ // remove modes we didn't issue
+ if(requestedAdd.isEmpty())
+ addModes = QString();
+ else
+ addModes.remove(QRegExp(QString("[^%1]").arg(requestedAdd)));
+
+ if(requestedRemove.isEmpty())
+ removeModes = QString();
+ else
+ removeModes.remove(QRegExp(QString("[^%1]").arg(requestedRemove)));
+
+ // deduplicate
+ persistentAdd.remove(QRegExp(QString("[%1]").arg(addModes)));
+ persistentRemove.remove(QRegExp(QString("[%1]").arg(removeModes)));
+
+ // update
+ persistentAdd.remove(QRegExp(QString("[%1]").arg(removeModes)));
+ persistentRemove.remove(QRegExp(QString("[%1]").arg(addModes)));
+
+ // update issued mode list
+ requestedAdd.remove(QRegExp(QString("[%1]").arg(addModes)));
+ requestedRemove.remove(QRegExp(QString("[%1]").arg(removeModes)));
+ _requestedUserModes = QString("%1-%2").arg(requestedAdd).arg(requestedRemove);
+
+ persistentAdd += addModes;
+ persistentRemove += removeModes;
+ Core::setUserModes(userId(), networkId(), QString("%1-%2").arg(persistentAdd).arg(persistentRemove));
+}
+
+void CoreNetwork::resetPersistentModes() {
+ _requestedUserModes = QString('-');
+ Core::setUserModes(userId(), networkId(), QString());