Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions json-tg.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,11 @@ void json_pack_peer_type (json_t *res, tgl_peer_id_t id) {
}
}

int str_format_time(long when, char* string)
{
struct tm *tm = localtime ((void *)&when);
return sprintf (string, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
}

void json_pack_user (json_t *res, tgl_peer_t *P) {
if (P->user.first_name) {
assert (json_object_set (res, "first_name", json_string (P->user.first_name)) >= 0);
}

if (P->user.status.when) {
static char s[20];
str_format_time(P->user.status.when, s);
assert (json_object_set (res, "when", json_string (s)) >= 0);
}

if (P->user.last_name) {
assert (json_object_set (res, "last_name", json_string (P->user.last_name)) >= 0);
}
Expand Down Expand Up @@ -482,6 +470,12 @@ json_t *json_pack_read (struct tgl_message *M) {
return res;
}

int str_format_time(long when, char* string)
{
struct tm *tm = localtime ((void *)&when);
return sprintf (string, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
}

json_t *json_pack_user_status (struct tgl_user *U) {
json_t *res = json_object ();
assert (json_object_set (res, "user", json_pack_peer (U->id)) >= 0);
Expand Down