1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51

ash / quick_insert / model / quick_insert_emoji_history_model.h [blame]

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_QUICK_INSERT_MODEL_QUICK_INSERT_EMOJI_HISTORY_MODEL_H_
#define ASH_QUICK_INSERT_MODEL_QUICK_INSERT_EMOJI_HISTORY_MODEL_H_

#include <string>
#include <string_view>
#include <vector>

#include "ash/ash_export.h"
#include "base/memory/raw_ref.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "ui/base/emoji/emoji_panel_helper.h"

class PrefService;

namespace ash {

class ASH_EXPORT QuickInsertEmojiHistoryModel {
 public:
  struct EmojiHistoryItem {
    std::string text;
    ui::EmojiPickerCategory category;
    base::Time timestamp;

    bool operator==(const EmojiHistoryItem&) const;
  };

  explicit QuickInsertEmojiHistoryModel(
      PrefService* prefs,
      base::Clock* clock = base::DefaultClock::GetInstance());

  // Returns the list of recent emojis for `category`.
  std::vector<EmojiHistoryItem> GetRecentEmojis(
      ui::EmojiPickerCategory category) const;

  // Updates the recent emojis for `category` with `latest_emoji`.
  void UpdateRecentEmoji(ui::EmojiPickerCategory category,
                         std::string_view latest_emoji);

 private:
  raw_ref<PrefService> prefs_;
  raw_ptr<base::Clock> clock_;
};

}  // namespace ash

#endif  // ASH_QUICK_INSERT_MODEL_QUICK_INSERT_EMOJI_HISTORY_MODEL_H_