diff options
| -rw-r--r-- | Swift/Controllers/StatusCache.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Swift/Controllers/StatusCache.cpp b/Swift/Controllers/StatusCache.cpp index 0e8c34d..ce69440 100644 --- a/Swift/Controllers/StatusCache.cpp +++ b/Swift/Controllers/StatusCache.cpp @@ -33,27 +33,38 @@ std::vector<StatusCache::PreviousStatus> StatusCache::getMatches(const std::stri foreach (const PreviousStatus& status, previousStatuses_) { if (substring.empty() || boost::algorithm::ifind_first(status.first, substring)) { matches.push_back(status); if (matches.size() == maxCount) { break; } } } return matches; } void StatusCache::addRecent(const std::string& text, StatusShow::Type type) { - previousStatuses_.push_back(PreviousStatus(text, type)); + if (text.empty()) { + return; + } + for (std::list<PreviousStatus>::iterator i = previousStatuses_.begin(); i != previousStatuses_.end(); ) { + if ((*i).first == text && (*i).second == type) { + previousStatuses_.erase(i++); + } + else { + ++i; + } + } + previousStatuses_.push_front(PreviousStatus(text, type)); for (size_t i = previousStatuses_.size(); i > MAX_ENTRIES; i--) { - previousStatuses_.pop_front(); + previousStatuses_.pop_back(); } saveRecents(); } void StatusCache::loadRecents() { try { if (boost::filesystem::exists(path_)) { ByteArray data; readByteArrayFromFile(data, path_.string()); std::string stringData = byteArrayToString(data); std::vector<std::string> lines; boost::split(lines, stringData, boost::is_any_of("\n")); |
Swift