From 1b013146891116ab3b4e41480bf74e03b545c252 Mon Sep 17 00:00:00 2001 From: Vincent Castellano Date: Thu, 28 May 2015 00:53:41 -0700 Subject: [PATCH] Added reply= and preview= to tgl.Peer.send_msg() --- python-tg.c | 20 ++++++++++++++++---- python-types.c | 15 +++++++++++---- tg-test.py | 4 +--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/python-tg.c b/python-tg.c index a045bda..475c76e 100644 --- a/python-tg.c +++ b/python-tg.c @@ -744,7 +744,10 @@ void py_do_all (void) { PyObject *args = (PyObject *)py_ptr[p ++]; const char *str, *str1, *str2, *str3; - + + int preview = 0; + int reply_id = 0; + unsigned long long flags = 0; Py_ssize_t i; tgl_user_id_t *ids; @@ -772,10 +775,19 @@ void py_do_all (void) { PyErr_Print(); break; case pq_msg: - if(PyArg_ParseTuple(args, "O!s#|O", &tgl_PeerType, &peer, &str, &len, &cb_extra)) - tgl_do_send_message (TLS, PY_PEER_ID(peer), str, len, 0, py_msg_cb, cb_extra); - else + if(PyArg_ParseTuple(args, "O!s#|OO", &tgl_PeerType, &peer, &str, &len, &cb_extra, &pyObj1)) { + if(PyArg_ParseTuple(pyObj1, "ii", &preview, &reply_id)) { + if(preview) + flags |= TGL_SEND_MSG_FLAG_ENABLE_PREVIEW; + else + flags |= TGL_SEND_MSG_FLAG_DISABLE_PREVIEW; + flags |= TGL_SEND_MSG_FLAG_REPLY (reply_id); + } + tgl_do_send_message (TLS, PY_PEER_ID(peer), str, len, flags, py_msg_cb, cb_extra); + } else PyErr_Print(); + + Py_XDECREF(pyObj1); break; case pq_send_typing: if(PyArg_ParseTuple(args, "O!|O", &tgl_PeerType, &peer, &cb_extra)) diff --git a/python-types.c b/python-types.c index c073cdb..28fb9f5 100644 --- a/python-types.c +++ b/python-types.c @@ -375,21 +375,28 @@ static PyMemberDef tgl_Peer_members[] = { static PyObject * tgl_Peer_send_msg (tgl_Peer *self, PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"message", "callback", NULL}; + static char *kwlist[] = {"message", "callback", "preview", "reply", NULL}; char *message; + int preview = 1; + int reply = 0; PyObject *callback = NULL; - if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &message, &callback)) { + if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|Opi", kwlist, &message, &callback, &preview, &reply)) { PyObject *api_call; + PyObject *flags; + + flags = Py_BuildValue("(ii)", preview, reply); + if(callback) - api_call = Py_BuildValue("OsO", (PyObject*) self, message, callback); + api_call = Py_BuildValue("OsOO", (PyObject*) self, message, callback, flags); else - api_call = Py_BuildValue("Os", (PyObject*) self, message); + api_call = Py_BuildValue("OsOO", (PyObject*) self, message, Py_None, flags); Py_INCREF(Py_None); Py_XINCREF(api_call); + Py_XINCREF(flags); return py_send_msg(Py_None, api_call); } else { diff --git a/tg-test.py b/tg-test.py index fddd387..1e53a9e 100644 --- a/tg-test.py +++ b/tg-test.py @@ -46,9 +46,7 @@ def on_msg_receive(msg): pp.pprint(msg) if msg.text.startswith("!ping"): - print("SENDING PONG") - peer.send_msg("PONG!", msg_cb) - peer.send_contact(msg.src.phone, msg.src.first_name, msg.src.last_name , cb) + peer.send_msg("PONG! google.com", preview=False, reply=msg.id) def on_secret_chat_update(peer, types):