Commit 3bbd8e52 authored by V V's avatar V V

fixed json

parent 70b0aed3
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "json-tg.h" #include "json-tg.h"
#include <tgl/tgl.h> #include <tgl/tgl.h>
#include <tgl/tgl-layout.h> #include <tgl/tgl-layout.h>
#include "interface.h"
#include <assert.h> #include <assert.h>
//format time: //format time:
#include <time.h> #include <time.h>
...@@ -27,6 +28,9 @@ void json_pack_peer_type (json_t *res, tgl_peer_id_t id) { ...@@ -27,6 +28,9 @@ void json_pack_peer_type (json_t *res, tgl_peer_id_t id) {
case TGL_PEER_ENCR_CHAT: case TGL_PEER_ENCR_CHAT:
assert (json_object_set (res, "type", json_string ("encr_chat")) >= 0); assert (json_object_set (res, "type", json_string ("encr_chat")) >= 0);
break; break;
case TGL_PEER_CHANNEL:
assert (json_object_set (res, "type", json_string ("channel")) >= 0);
break;
default: default:
assert (0); assert (0);
} }
...@@ -77,6 +81,14 @@ void json_pack_chat (json_t *res, tgl_peer_t *P) { ...@@ -77,6 +81,14 @@ void json_pack_chat (json_t *res, tgl_peer_t *P) {
} }
} }
void json_pack_channel (json_t *res, tgl_peer_t *P) {
assert (P->channel.title);
assert (json_object_set (res, "title", json_string (P->channel.title)) >= 0);
assert (json_object_set (res, "participants_count", json_integer (P->channel.participants_count)) >= 0);
assert (json_object_set (res, "admins_count", json_integer (P->channel.admins_count)) >= 0);
assert (json_object_set (res, "kicked_count", json_integer (P->channel.kicked_count)) >= 0);
}
void json_pack_encr_chat (json_t *res, tgl_peer_t *P) { void json_pack_encr_chat (json_t *res, tgl_peer_t *P) {
assert (json_object_set (res, "user", json_pack_peer (TGL_MK_USER (P->encr_chat.user_id))) >= 0); assert (json_object_set (res, "user", json_pack_peer (TGL_MK_USER (P->encr_chat.user_id))) >= 0);
...@@ -86,7 +98,7 @@ json_t *json_pack_peer (tgl_peer_id_t id) { ...@@ -86,7 +98,7 @@ json_t *json_pack_peer (tgl_peer_id_t id) {
tgl_peer_t *P = tgl_peer_get (TLS, id); tgl_peer_t *P = tgl_peer_get (TLS, id);
//assert (P); //assert (P);
json_t *res = json_object (); json_t *res = json_object ();
assert (json_object_set (res, "id", json_integer (tgl_get_peer_id (id))) >= 0); assert (json_object_set (res, "id", json_string (print_permanent_peer_id (id))) >= 0);
json_pack_peer_type (res, id); json_pack_peer_type (res, id);
...@@ -101,6 +113,9 @@ json_t *json_pack_peer (tgl_peer_id_t id) { ...@@ -101,6 +113,9 @@ json_t *json_pack_peer (tgl_peer_id_t id) {
case TGL_PEER_CHAT: case TGL_PEER_CHAT:
sprintf (s, "chat#%d", tgl_get_peer_id (id)); sprintf (s, "chat#%d", tgl_get_peer_id (id));
break; break;
case TGL_PEER_CHANNEL:
sprintf (s, "channel#%d", tgl_get_peer_id (id));
break;
case TGL_PEER_ENCR_CHAT: case TGL_PEER_ENCR_CHAT:
sprintf (s, "encr_chat#%d", tgl_get_peer_id (id)); sprintf (s, "encr_chat#%d", tgl_get_peer_id (id));
break; break;
...@@ -128,6 +143,9 @@ json_t *json_pack_peer (tgl_peer_id_t id) { ...@@ -128,6 +143,9 @@ json_t *json_pack_peer (tgl_peer_id_t id) {
case TGL_PEER_ENCR_CHAT: case TGL_PEER_ENCR_CHAT:
json_pack_encr_chat (res, P); json_pack_encr_chat (res, P);
break; break;
case TGL_PEER_CHANNEL:
json_pack_channel (res, P);
break;
default: default:
assert (0); assert (0);
} }
...@@ -377,6 +395,10 @@ json_t *json_pack_service (struct tgl_message *M) { ...@@ -377,6 +395,10 @@ json_t *json_pack_service (struct tgl_message *M) {
case tgl_message_action_abort_key: case tgl_message_action_abort_key:
assert (json_object_set (res, "type", json_string ("abort_key")) >= 0); assert (json_object_set (res, "type", json_string ("abort_key")) >= 0);
break; break;
case tgl_message_action_channel_create:
assert (json_object_set (res, "type", json_string ("channel_created")) >= 0);
assert (json_object_set (res, "title", json_string (M->action.title)) >= 0);
break;
default: default:
assert (json_object_set (res, "type", json_string ("???")) >= 0); assert (json_object_set (res, "type", json_string ("???")) >= 0);
break; break;
...@@ -389,7 +411,7 @@ json_t *json_pack_message (struct tgl_message *M) { ...@@ -389,7 +411,7 @@ json_t *json_pack_message (struct tgl_message *M) {
assert (json_object_set (res, "event", json_string ("message")) >= 0); assert (json_object_set (res, "event", json_string ("message")) >= 0);
//will overwriten to service, if service. //will overwriten to service, if service.
assert (json_object_set (res, "id", json_integer (M->id)) >= 0); assert (json_object_set (res, "id", json_string (print_permanent_msg_id (M->permanent_id))) >= 0);
if (!(M->flags & TGLMF_CREATED)) { return res; } if (!(M->flags & TGLMF_CREATED)) { return res; }
assert (json_object_set (res, "flags", json_integer (M->flags)) >= 0); assert (json_object_set (res, "flags", json_integer (M->flags)) >= 0);
......
This diff is collapsed.
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
void lua_init (const char *file); void lua_init (const char *file);
void lua_new_msg (struct tgl_message *M); void lua_new_msg (struct tgl_message *M);
void lua_our_id (int id); void lua_our_id (tgl_peer_id_t id);
void lua_secret_chat_update (struct tgl_secret_chat *U, unsigned flags); void lua_secret_chat_update (struct tgl_secret_chat *U, unsigned flags);
void lua_user_update (struct tgl_user *U, unsigned flags); void lua_user_update (struct tgl_user *U, unsigned flags);
void lua_chat_update (struct tgl_chat *C, unsigned flags); void lua_chat_update (struct tgl_chat *C, unsigned flags);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment