| 77 | } |
| 78 | |
| 79 | void Groups::refreshMessage( |
| 80 | not_null<HistoryItem*> item, |
| 81 | bool justRefreshViews) { |
| 82 | if (!isGrouped(item)) { |
| 83 | unregisterMessage(item); |
| 84 | _data->requestItemViewRefresh(item); |
| 85 | return; |
| 86 | } |
| 87 | if (!item->isRegular() && !item->isScheduled() && !item->isUploading()) { |
| 88 | return; |
| 89 | } |
| 90 | const auto groupId = item->groupId(); |
| 91 | const auto i = _groups.find(groupId); |
| 92 | if (i == end(_groups)) { |
| 93 | registerMessage(item); |
| 94 | return; |
| 95 | } |
| 96 | auto &items = i->second.items; |
| 97 | |
| 98 | if (justRefreshViews) { |
| 99 | refreshViews(items); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | const auto position = findPositionForItem(items, item); |
| 104 | auto current = ranges::find(items, item); |
| 105 | if (current == end(items)) { |
| 106 | items.insert(position, item); |
| 107 | } else if (position == current + 1) { |
| 108 | return; |
| 109 | } else if (position > current + 1) { |
| 110 | for (++current; current != position; ++current) { |
| 111 | std::swap(*(current - 1), *current); |
| 112 | } |
| 113 | } else if (position < current) { |
| 114 | for (; current != position; --current) { |
| 115 | std::swap(*(current - 1), *current); |
| 116 | } |
| 117 | } else { |
| 118 | Unexpected("Position of item in Groups::refreshMessage()."); |
| 119 | } |
| 120 | refreshViews(items); |
| 121 | } |
| 122 | |
| 123 | HistoryItemsList::const_iterator Groups::findPositionForItem( |
| 124 | const HistoryItemsList &group, |
no test coverage detected