-
Notifications
You must be signed in to change notification settings - Fork 3
/
input.cpp
89 lines (74 loc) · 2.29 KB
/
input.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <strophe.h>
#include <stdlib.h>
#include <stdint.h>
#include <weechat/weechat-plugin.h>
#include "plugin.hh"
#include "account.hh"
#include "channel.hh"
#include "buffer.hh"
#include "message.hh"
#include "input.hh"
int input__data(struct t_gui_buffer *buffer, const char *text)
{
weechat::account *account = NULL;
weechat::channel *channel = NULL;
buffer__get_account_and_channel(buffer, &account, &channel);
if (!account)
return WEECHAT_RC_ERROR;
if (channel)
{
if (!account->connected())
{
weechat_printf(buffer,
_("%s%s: you are not connected to server"),
weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME);
return WEECHAT_RC_OK;
}
if (channel->send_message(channel->id, text) == WEECHAT_RC_OK)
return WEECHAT_RC_OK;
else
{
return WEECHAT_RC_OK_EAT;
}
}
else
{
weechat_printf(buffer,
_("%s%s: this buffer is not a channel!"),
weechat_prefix("error"), WEECHAT_XMPP_PLUGIN_NAME);
return WEECHAT_RC_OK;
}
}
int input__data_cb(const void *pointer, void *data,
struct t_gui_buffer *buffer,
const char *text)
{
(void) pointer;
(void) data;
return input__data(buffer, text);
}
int input__typing(struct t_gui_buffer *buffer)
{
weechat::account *account = NULL;
weechat::channel *channel = NULL;
buffer__get_account_and_channel(buffer, &account, &channel);
if (account && account->connected() && channel)
{
channel->send_reads();
channel->send_typing(weechat::user::search(account, account->jid_device().data()));
}
return WEECHAT_RC_OK;
}
int input__text_changed_cb(const void *pointer, void *data,
const char *signal, const char *type_data,
void *signal_data)
{
(void) pointer;
(void) data;
(void) signal;
(void) type_data;
return input__typing((struct t_gui_buffer*)signal_data);
}