LeechCraft Azoth  0.6.70-18450-gabe19ee3b0
Modular multiprotocol IM plugin for LeechCraft
ihistoryplugin.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include <QList>
12 #include <util/threads/coro/taskfwd.h>
13 #include "imessage.h"
14 
15 class QDateTime;
16 class QObject;
17 
19 {
20  enum class EntryKind : std::uint8_t
21  {
22  Chat,
23  MUC,
25  };
26 
27  template<template<EntryKind K> typename Kinded>
28  using KindedGADT = std::variant<
29  Kinded<EntryKind::Chat>,
30  Kinded<EntryKind::MUC>,
31  Kinded<EntryKind::PrivateChat>
32  >;
33 
34  template<EntryKind> struct EntryDescr;
35  template<> struct EntryDescr<EntryKind::Chat> { QString Nick_; };
36  template<> struct EntryDescr<EntryKind::MUC> { QString MucName_; };
37  template<> struct EntryDescr<EntryKind::PrivateChat> { QString MucName_; QString Nick_; std::optional<QByteArray> PersistentId_; };
38 
40 
41  template<template<EntryKind K> typename EntryKinded>
43  {
44  return static_cast<EntryKind> (gadt.index ());
45  }
46 
47  template<EntryKind K>
48  struct Entry
49  {
50  QByteArray AccountId_;
51  QString AccountName_;
53 
55  };
56 
57  struct SelfEndpoint { QString Name_; std::optional<QString> Variant_; };
58 
59  template<EntryKind> struct EntryEndpoint;
60  template<> struct EntryEndpoint<EntryKind::Chat> { std::optional<QString> Variant_; };
61  template<> struct EntryEndpoint<EntryKind::MUC> { QString Nick_; std::optional<QByteArray> PersistentId_; };
62  template<> struct EntryEndpoint<EntryKind::PrivateChat> {};
63 
64  template<EntryKind K>
65  using Endpoint = std::variant<SelfEndpoint, EntryEndpoint<K>>;
66 
67  template<EntryKind K>
69  {
72  };
74 
75  template<EntryKind K>
76  struct NewMessage
77  {
79 
80  QDateTime TS_;
81  QString Body_;
82  std::optional<QString> RichBody_;
83  };
84 
85  template<EntryKind K>
86  using EntryWithMessages = std::pair<Entry<K>, QList<NewMessage<K>>>;
87 
89 }
90 
91 namespace LC::Azoth
92 {
93  class IAccount;
94 
102  {
103  protected:
104  virtual ~IHistoryPlugin () = default;
105  public:
114  virtual bool IsHistoryEnabledFor (ICLEntry& entry) const = 0;
115 
130  virtual Util::ContextTask<void> RequestLastMessages (ICLEntry& entry, int count) = 0;
131 
132  virtual Util::ContextTask<std::optional<QDateTime>> RequestMaxTimestamp (IAccount& acc) = 0;
133 
136  virtual void AddMessages (const History::SomeEntryWithMessages&) = 0;
137  protected:
152  virtual void gotLastMessages (QObject *entry, const QList<QObject*>& messages) = 0;
153  };
154 }
155 
156 Q_DECLARE_INTERFACE (LC::Azoth::IHistoryPlugin,
157  "org.Deviant.LeechCraft.Azoth.IHistoryPlugin/1.0")
EntryKind GetEntryKind(const KindedGADT< EntryKinded > &gadt)
std::pair< Entry< K >, QList< NewMessage< K > >> EntryWithMessages
KindedGADT< EntryDescrWithEndpoint > SomeEntryDescrWithEndpoint
QString MucName_
QString Nick_
virtual void AddMessages(const History::SomeEntryWithMessages &)=0
Adds a set of messages to the history.
std::optional< QString > RichBody_
virtual void gotLastMessages(QObject *entry, const QList< QObject *> &messages)=0
Notifies about last messages for the given entry.
virtual Util::ContextTask< void > RequestLastMessages(ICLEntry &entry, int count)=0
Requests last messages for the given entry.
std::variant< SelfEndpoint, EntryEndpoint< K > > Endpoint
virtual bool IsHistoryEnabledFor(ICLEntry &entry) const =0
Whether history is enabled for the given entry.
QString AccountName_
KindedGADT< EntryWithMessages > SomeEntryWithMessages
QByteArray AccountId_
virtual ~IHistoryPlugin()=default
Interface for plugins storing chat history.
Endpoint< K > Endpoint_
virtual Util::ContextTask< std::optional< QDateTime > > RequestMaxTimestamp(IAccount &acc)=0
std::optional< QString > Variant_
EntryDescr< K > Description_
QString EntryHumanReadableId_
std::variant< Kinded< EntryKind::Chat >, Kinded< EntryKind::MUC >, Kinded< EntryKind::PrivateChat > > KindedGADT
KindedGADT< EntryDescr > SomeEntryDescr
std::optional< QByteArray > PersistentId_
std::optional< QByteArray > PersistentId_
EntryDescr< K > Description_
Interface representing a single account.
Definition: iaccount.h:45
Represents a single entry in contact list.
Definition: iclentry.h:56
std::optional< QString > Variant_