Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
tg
Commits
b9cc0483
Commit
b9cc0483
authored
May 27, 2015
by
vysheng
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #539 from luckydonald/fix_json_user_status
[json] Add user online status event
parents
6ad4b232
3963eca8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
11 deletions
+57
-11
interface.c
interface.c
+19
-9
json-tg.c
json-tg.c
+35
-0
json-tg.h
json-tg.h
+3
-2
No files found.
interface.c
View file @
b9cc0483
...
...
@@ -1983,7 +1983,7 @@ void print_chat_info_gw (struct tgl_state *TLSR, void *extra, int success, struc
}
void
print_user_status
(
struct
tgl_user_status
*
S
,
struct
in_ev
*
ev
)
{
if
(
enable_json
)
{
return
;
}
assert
(
!
enable_json
);
//calling functions print_user_info_gw() and user_status_upd() already check.
if
(
S
->
online
>
0
)
{
mprintf
(
ev
,
"online (was online "
);
print_date_full
(
ev
,
S
->
when
);
...
...
@@ -2574,16 +2574,26 @@ void user_status_upd (struct tgl_state *TLS, struct tgl_user *U) {
if
(
disable_output
&&
!
notify_ev
)
{
return
;
}
if
(
!
binlog_read
)
{
return
;
}
if
(
log_level
<
3
)
{
return
;
}
if
(
enable_json
)
{
return
;
}
struct
in_ev
*
ev
=
notify_ev
;
mprint_start
(
ev
);
mpush_color
(
ev
,
COLOR_YELLOW
);
mprintf
(
ev
,
"User "
);
print_user_name
(
ev
,
U
->
id
,
(
void
*
)
U
);
mprintf
(
ev
,
" "
);
print_user_status
(
&
U
->
status
,
ev
);
mprintf
(
ev
,
"
\n
"
);
mpop_color
(
ev
);
if
(
!
enable_json
)
{
mpush_color
(
ev
,
COLOR_YELLOW
);
mprintf
(
ev
,
"User "
);
print_user_name
(
ev
,
U
->
id
,
(
void
*
)
U
);
mprintf
(
ev
,
" "
);
print_user_status
(
&
U
->
status
,
ev
);
mprintf
(
ev
,
"
\n
"
);
mpop_color
(
ev
);
}
else
{
#ifdef USE_JSON
json_t
*
res
=
json_pack_user_status
(
U
);
char
*
s
=
json_dumps
(
res
,
0
);
mprintf
(
ev
,
"%s
\n
"
,
s
);
json_decref
(
res
);
free
(
s
);
#endif
}
mprint_end
(
ev
);
}
...
...
json-tg.c
View file @
b9cc0483
...
...
@@ -6,6 +6,8 @@
#include <tgl/tgl.h>
#include <tgl/tgl-layout.h>
#include <assert.h>
//format time:
#include <time.h>
#ifndef json_boolean
#define json_boolean(val) ((val) ? json_true() : json_false())
...
...
@@ -381,4 +383,37 @@ 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
();
struct
tgl_user_status
*
S
=
&
U
->
status
;
json_object
();
json_t
*
user_res
=
json_object
();
json_pack_user
(
user_res
,
(
void
*
)
U
);
assert
(
json_object_set
(
res
,
"user"
,
user_res
)
>=
0
);
assert
(
json_object_set
(
res
,
"online"
,
json_boolean
(
S
->
online
==
1
))
>=
0
);
assert
(
json_object_set
(
res
,
"state"
,
json_integer
(
S
->
online
))
>=
0
);
if
(
S
->
online
>
0
||
S
->
online
==
-
1
)
{
static
char
s
[
20
];
str_format_time
(
S
->
when
,
s
);
assert
(
json_object_set
(
res
,
"when"
,
json_string
(
s
))
>=
0
);
}
else
if
(
S
->
online
==
0
)
{
assert
(
json_object_set
(
res
,
"when"
,
json_string
(
"long time ago"
))
>=
0
);
}
else
if
(
S
->
online
==
-
2
)
{
assert
(
json_object_set
(
res
,
"when"
,
json_string
(
"recently"
))
>=
0
);
}
else
if
(
S
->
online
==
-
3
)
{
assert
(
json_object_set
(
res
,
"when"
,
json_string
(
"last week"
))
>=
0
);
}
else
if
(
S
->
online
==
-
4
)
{
assert
(
json_object_set
(
res
,
"when"
,
json_string
(
"last month"
))
>=
0
);
}
assert
(
json_object_set
(
res
,
"event"
,
json_string
(
"online-status"
))
>=
0
);
//this will overwrite "event":"message" to "event":"read".
return
res
;
}
#endif
json-tg.h
View file @
b9cc0483
...
...
@@ -3,11 +3,12 @@
#include "config.h"
#ifdef USE_JSON
#include <jansson.h>
#include <tgl.h>
#include <tgl-layout.h>
#include <tgl
/tgl
.h>
#include <tgl
/tgl
-layout.h>
json_t
*
json_pack_message
(
struct
tgl_message
*
M
);
json_t
*
json_pack_updates
(
unsigned
flags
);
json_t
*
json_pack_peer
(
tgl_peer_id_t
id
,
tgl_peer_t
*
P
);
json_t
*
json_pack_read
(
struct
tgl_message
*
M
);
json_t
*
json_pack_user_status
(
struct
tgl_user
*
U
);
#endif
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment