2023-01-20 03:54:19 +00:00
|
|
|
import options
|
2022-01-26 16:24:03 +00:00
|
|
|
import jsony
|
2022-01-26 16:57:46 +00:00
|
|
|
import user, ../types/[graphuser, graphlistmembers]
|
|
|
|
from ../../types import User, Result, Query, QueryKind
|
2022-01-26 16:24:03 +00:00
|
|
|
|
|
|
|
proc parseGraphUser*(json: string): User =
|
|
|
|
let raw = json.fromJson(GraphUser)
|
2023-01-20 03:54:19 +00:00
|
|
|
|
|
|
|
if raw.data.user.result.reason.get("") == "Suspended":
|
|
|
|
return User(suspended: true)
|
|
|
|
|
2022-01-26 16:24:03 +00:00
|
|
|
result = toUser raw.data.user.result.legacy
|
|
|
|
result.id = raw.data.user.result.restId
|
2023-04-21 12:41:30 +00:00
|
|
|
result.verified = result.verified or raw.data.user.result.isBlueVerified
|
2022-01-26 16:57:46 +00:00
|
|
|
|
|
|
|
proc parseGraphListMembers*(json, cursor: string): Result[User] =
|
|
|
|
result = Result[User](
|
|
|
|
beginning: cursor.len == 0,
|
|
|
|
query: Query(kind: userList)
|
|
|
|
)
|
|
|
|
|
|
|
|
let raw = json.fromJson(GraphListMembers)
|
|
|
|
for instruction in raw.data.list.membersTimeline.timeline.instructions:
|
|
|
|
if instruction.kind == "TimelineAddEntries":
|
|
|
|
for entry in instruction.entries:
|
|
|
|
case entry.content.entryType
|
|
|
|
of TimelineTimelineItem:
|
|
|
|
let userResult = entry.content.itemContent.userResults.result
|
|
|
|
if userResult.restId.len > 0:
|
|
|
|
result.content.add toUser userResult.legacy
|
|
|
|
of TimelineTimelineCursor:
|
|
|
|
if entry.content.cursorType == "Bottom":
|
|
|
|
result.bottom = entry.content.value
|