Merge commit '11090500b2f97abe3c2abce1d2ff1bf27164fb6a' into fix_json_more_chat_info

* commit '11090500b2f97abe3c2abce1d2ff1bf27164fb6a':
  Fix typo
  Add install instructions for openSUSE
  lua: added import_chat_link()
  Implement msg.load_*
  Add msg action type enum
  Implement load_ functions
  Add constants for peer types and action types.
This commit is contained in:
luckydonald 2015-06-09 20:35:25 +02:00
commit 4afe21e98a
4 changed files with 148 additions and 17 deletions

View File

@ -53,6 +53,10 @@ On OpenBSD:
pkg_add libconfig libexecinfo lua python pkg_add libconfig libexecinfo lua python
On openSUSE:
sudo zypper in lua-devel libconfig-devel readline-devel libevent-devel libjansson-devel python-devel libopenssl-devel
Then, Then,
./configure ./configure

View File

@ -653,7 +653,8 @@ enum lua_query_type {
lq_status_online, lq_status_online,
lq_status_offline, lq_status_offline,
lq_send_location, lq_send_location,
lq_extf lq_extf,
lq_import_chat_link
}; };
struct lua_query_extra { struct lua_query_extra {
@ -1235,6 +1236,12 @@ void lua_do_all (void) {
free (s); free (s);
p += 2; p += 2;
break; break;
case lq_import_chat_link:
s = lua_ptr[p + 1];
tgl_do_import_chat_link (TLS, s, strlen (s), lua_empty_cb, lua_ptr[p]);
free (s);
p += 2;
break;
case lq_send_location: case lq_send_location:
if (sizeof (void *) == 4) { if (sizeof (void *) == 4) {
tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(float *)(lua_ptr + p + 2), *(float *)(lua_ptr + p + 3), 0, lua_msg_cb, lua_ptr[p]); tgl_do_send_location (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id , *(float *)(lua_ptr + p + 2), *(float *)(lua_ptr + p + 3), 0, lua_msg_cb, lua_ptr[p]);
@ -1332,6 +1339,7 @@ struct lua_function functions[] = {
{"status_offline", lq_status_offline, { lfp_none }}, {"status_offline", lq_status_offline, { lfp_none }},
{"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }}, {"send_location", lq_send_location, { lfp_peer, lfp_double, lfp_double, lfp_none }},
{"ext_function", lq_extf, { lfp_string, lfp_none }}, {"ext_function", lq_extf, { lfp_string, lfp_none }},
{"import_chat_link", lq_import_chat_link, { lfp_string, lfp_none }},
{ 0, 0, { lfp_none}} { 0, 0, { lfp_none}}
}; };

View File

@ -774,16 +774,21 @@ void py_do_all (void) {
int preview = 0; int preview = 0;
int reply_id = 0; int reply_id = 0;
unsigned long long flags = 0; unsigned long long flags = 0;
Py_ssize_t i; Py_ssize_t i;
tgl_user_id_t *ids; tgl_user_id_t *ids;
struct tgl_message *M;
int len, len1, len2, len3; int len, len1, len2, len3;
int limit, offset; int limit, offset;
long msg_id = 0; long msg_id = 0;
PyObject *pyObj1 = NULL; PyObject *pyObj1 = NULL;
PyObject *pyObj2 = NULL; PyObject *pyObj2 = NULL;
PyObject *cb_extra = NULL; PyObject *cb_extra = NULL;
PyObject *msg = NULL;
PyObject *peer = NULL; PyObject *peer = NULL;
PyObject *peer1 = NULL; PyObject *peer1 = NULL;
@ -877,33 +882,40 @@ void py_do_all (void) {
else else
PyErr_Print(); PyErr_Print();
break; break;
/* case pq_load_photo: case pq_load_photo:
case pq_load_video: case pq_load_video:
case pq_load_audio: case pq_load_audio:
case pq_load_document: case pq_load_document:
M = py_ptr[p + 1]; if(PyArg_ParseTuple(args, "O!O", &tgl_MsgType, &msg, &cb_extra))
if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_photo_encr && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) { {
py_file_cb (TLS, py_ptr[p], 0, 0); M = ((tgl_Msg*)msg)->msg;
} else { if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) {
, limit, offse, limit, offsettif (M->media.type == tgl_message_media_photo) { py_file_cb (TLS, cb_extra, 0, 0);
tgl_do_load_photo (TLS, &M->media.photo, py_file_cb, py_ptr[p]);
} else if (M->media.type == tgl_message_media_document) {
tgl_do_load_document (TLS, &M->media.document, py_file_cb, py_ptr[p]);
} else { } else {
tgl_do_load_encr_document (TLS, &M->media.encr_document, py_file_cb, py_ptr[p]); if (M->media.type == tgl_message_media_photo) {
assert (M->media.photo);
tgl_do_load_photo (TLS, M->media.photo, py_file_cb, cb_extra);
} else if (M->media.type == tgl_message_media_document) {
tgl_do_load_document (TLS, M->media.document, py_file_cb, cb_extra);
} else {
tgl_do_load_encr_document (TLS, M->media.encr_document, py_file_cb, cb_extra);
}
} }
} }
break; break;
case pq_load_video_thumb: case pq_load_video_thumb:
case pq_load_document_thumb: case pq_load_document_thumb:
M = py_ptr[p + 1]; if(PyArg_ParseTuple(args, "O!O", &tgl_MsgType, &msg, &cb_extra))
if (!M || (M->media.type != tgl_message_media_document)) { {
py_file_cb (TLS, py_ptr[p], 0, 0); M = ((tgl_Msg*)msg)->msg;
} else { if (!M || (M->media.type != tgl_message_media_document)) {
tgl_do_load_document_thumb (TLS, &M->media.document, py_file_cb, py_ptr[p]); py_file_cb (TLS, cb_extra, 0, 0);
} else {
tgl_do_load_document_thumb (TLS, M->media.document, py_file_cb, cb_extra);
}
} }
break; break;
*/
case pq_fwd: case pq_fwd:
if(PyArg_ParseTuple(args, "O!l|O", &tgl_PeerType, &peer, &msg_id, &cb_extra)) if(PyArg_ParseTuple(args, "O!l|O", &tgl_PeerType, &peer, &msg_id, &cb_extra))
tgl_do_forward_message (TLS, PY_PEER_ID(peer), msg_id, 0, py_msg_cb, cb_extra); tgl_do_forward_message (TLS, PY_PEER_ID(peer), msg_id, 0, py_msg_cb, cb_extra);
@ -1234,6 +1246,41 @@ static PyMethodDef py_tgl_methods[] = {
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
void py_add_action_enums(PyObject *m)
{
PyModule_AddIntConstant(m, "ACTION_NONE", tgl_message_action_none);
PyModule_AddIntConstant(m, "ACTION_GEO_CHAT_CREATE", tgl_message_action_geo_chat_create);
PyModule_AddIntConstant(m, "ACTION_GEO_CHAT_CHECKIN", tgl_message_action_geo_chat_checkin);
PyModule_AddIntConstant(m, "ACTION_CHAT_CREATE", tgl_message_action_chat_create);
PyModule_AddIntConstant(m, "ACTION_CHAT_EDIT_TITLE", tgl_message_action_chat_edit_title);
PyModule_AddIntConstant(m, "ACTION_CHAT_EDIT_PHOTO", tgl_message_action_chat_edit_photo);
PyModule_AddIntConstant(m, "ACTION_CHAT_DELETE_PHOTO", tgl_message_action_chat_delete_photo);
PyModule_AddIntConstant(m, "ACTION_CHAT_ADD_USER", tgl_message_action_chat_add_user);
PyModule_AddIntConstant(m, "ACTION_CHAT_ADD_USER_BY_LINK", tgl_message_action_chat_add_user_by_link);
PyModule_AddIntConstant(m, "ACTION_CHAT_DELETE_USER", tgl_message_action_chat_delete_user);
PyModule_AddIntConstant(m, "ACTION_SET_MESSAGE_TTL", tgl_message_action_set_message_ttl);
PyModule_AddIntConstant(m, "ACTION_READ_MESSAGES", tgl_message_action_read_messages);
PyModule_AddIntConstant(m, "ACTION_DELETE_MESSAGES", tgl_message_action_delete_messages);
PyModule_AddIntConstant(m, "ACTION_SCREENSHOT_MESSAGES", tgl_message_action_screenshot_messages);
PyModule_AddIntConstant(m, "ACTION_FLUSH_HISTORY", tgl_message_action_flush_history);
PyModule_AddIntConstant(m, "ACTION_RESEND", tgl_message_action_resend);
PyModule_AddIntConstant(m, "ACTION_NOTIFY_LAYER", tgl_message_action_notify_layer);
PyModule_AddIntConstant(m, "ACTION_TYPING", tgl_message_action_typing);
PyModule_AddIntConstant(m, "ACTION_NOOP", tgl_message_action_noop);
PyModule_AddIntConstant(m, "ACTION_COMMIT_KEY", tgl_message_action_commit_key);
PyModule_AddIntConstant(m, "ACTION_ABORT_KEY", tgl_message_action_abort_key);
PyModule_AddIntConstant(m, "ACTION_REQUEST_KEY", tgl_message_action_request_key);
PyModule_AddIntConstant(m, "ACTION_ACCEPT_KEY", tgl_message_action_accept_key);
}
void py_add_peer_type_enums(PyObject *m)
{
PyModule_AddIntConstant(m, "PEER_USER", TGL_PEER_USER);
PyModule_AddIntConstant(m, "PEER_CHAT", TGL_PEER_CHAT);
PyModule_AddIntConstant(m, "PEER_ENCR_CHAT", TGL_PEER_ENCR_CHAT);
}
MOD_INIT(tgl) MOD_INIT(tgl)
{ {
PyObject *m; PyObject *m;
@ -1243,6 +1290,9 @@ MOD_INIT(tgl)
if (m == NULL) if (m == NULL)
return MOD_ERROR_VAL; return MOD_ERROR_VAL;
py_add_action_enums(m);
py_add_peer_type_enums(m);
if (PyType_Ready(&tgl_PeerType) < 0) if (PyType_Ready(&tgl_PeerType) < 0)
return MOD_ERROR_VAL; return MOD_ERROR_VAL;

View File

@ -1151,6 +1151,17 @@ tgl_Msg_getservice (tgl_Msg *self, void *closure)
return ret; return ret;
} }
static PyObject *
tgl_Msg_getaction (tgl_Msg *self, void *closure)
{
PyObject *ret;
ret = PyLong_FromLong(self->msg->action.type);
Py_XINCREF(ret);
return ret;
}
static PyObject * static PyObject *
tgl_Msg_getsrc (tgl_Msg *self, void *closure) tgl_Msg_getsrc (tgl_Msg *self, void *closure)
@ -1210,6 +1221,8 @@ tgl_Msg_gettext (tgl_Msg *self, void *closure)
return ret; return ret;
} }
static PyObject * static PyObject *
tgl_Msg_getmedia (tgl_Msg *self, void *closure) tgl_Msg_getmedia (tgl_Msg *self, void *closure)
{ {
@ -1357,6 +1370,55 @@ tgl_Msg_getreply_id (tgl_Msg *self, void *closure)
return ret; return ret;
} }
// All load methods are implemented the same, just alias load_document
static PyObject *
tgl_Msg_load_document (tgl_Msg *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"callback", NULL};
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &callback)) {
PyObject *api_call;
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_load_document(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Msg_load_document_thumb (tgl_Msg *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"callback", NULL};
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &callback)) {
PyObject *api_call;
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_load_document_thumb(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject * static PyObject *
tgl_Msg_repr(tgl_Msg *self) tgl_Msg_repr(tgl_Msg *self)
{ {
@ -1400,6 +1462,7 @@ static PyGetSetDef tgl_Msg_getseters[] = {
{"fwd_date", (getter)tgl_Msg_getfwd_date, NULL, "", NULL}, {"fwd_date", (getter)tgl_Msg_getfwd_date, NULL, "", NULL},
{"reply", (getter)tgl_Msg_getreply, NULL, "", NULL}, {"reply", (getter)tgl_Msg_getreply, NULL, "", NULL},
{"reply_id", (getter)tgl_Msg_getreply_id, NULL, "", NULL}, {"reply_id", (getter)tgl_Msg_getreply_id, NULL, "", NULL},
{"action", (getter)tgl_Msg_getaction, NULL, "", NULL},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
@ -1410,6 +1473,12 @@ static PyMemberDef tgl_Msg_members[] = {
static PyMethodDef tgl_Msg_methods[] = { static PyMethodDef tgl_Msg_methods[] = {
{"load_document", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_photo", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_audio", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_video", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_document_thumb", (PyCFunction)tgl_Msg_load_document_thumb, METH_VARARGS | METH_KEYWORDS, ""},
{"load_video_thumb", (PyCFunction)tgl_Msg_load_document_thumb, METH_VARARGS | METH_KEYWORDS, ""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };