summaryrefslogtreecommitdiff
path: root/libs/tdlib/td/td/telegram/CallDiscardReason.cpp
blob: 2b6fbbc5d7862bc560fc1741fd3180a47d340718 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/CallDiscardReason.h"

#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"

#include "td/utils/logging.h"

namespace td {

CallDiscardReason get_call_discard_reason(const tl_object_ptr<telegram_api::PhoneCallDiscardReason> &reason) {
  if (reason == nullptr) {
    return CallDiscardReason::Empty;
  }
  switch (reason->get_id()) {
    case telegram_api::phoneCallDiscardReasonMissed::ID:
      return CallDiscardReason::Missed;
    case telegram_api::phoneCallDiscardReasonDisconnect::ID:
      return CallDiscardReason::Disconnected;
    case telegram_api::phoneCallDiscardReasonHangup::ID:
      return CallDiscardReason::HungUp;
    case telegram_api::phoneCallDiscardReasonBusy::ID:
      return CallDiscardReason::Declined;
    default:
      UNREACHABLE();
      return CallDiscardReason::Empty;
  }
}

tl_object_ptr<telegram_api::PhoneCallDiscardReason> get_input_phone_call_discard_reason(CallDiscardReason reason) {
  switch (reason) {
    case CallDiscardReason::Empty:
      return nullptr;
    case CallDiscardReason::Missed:
      return make_tl_object<telegram_api::phoneCallDiscardReasonMissed>();
    case CallDiscardReason::Disconnected:
      return make_tl_object<telegram_api::phoneCallDiscardReasonDisconnect>();
    case CallDiscardReason::HungUp:
      return make_tl_object<telegram_api::phoneCallDiscardReasonHangup>();
    case CallDiscardReason::Declined:
      return make_tl_object<telegram_api::phoneCallDiscardReasonBusy>();
    default:
      UNREACHABLE();
      return nullptr;
  }
}

tl_object_ptr<td_api::CallDiscardReason> get_call_discard_reason_object(CallDiscardReason reason) {
  switch (reason) {
    case CallDiscardReason::Empty:
      return make_tl_object<td_api::callDiscardReasonEmpty>();
    case CallDiscardReason::Missed:
      return make_tl_object<td_api::callDiscardReasonMissed>();
    case CallDiscardReason::Disconnected:
      return make_tl_object<td_api::callDiscardReasonDisconnected>();
    case CallDiscardReason::HungUp:
      return make_tl_object<td_api::callDiscardReasonHungUp>();
    case CallDiscardReason::Declined:
      return make_tl_object<td_api::callDiscardReasonDeclined>();
    default:
      UNREACHABLE();
      return nullptr;
  }
}

}  // namespace td