Skip to content

Commit 99137a5

Browse files
Baohua Shanfacebook-github-bot
authored andcommitted
Use account id and convert igid to fbid v2
Summary: Per discussion with Shuang, user id could be many things, and we should use account id to report the usage. So use getAccountID for fb user. Regarding ig user, deltoid expectes FBIDv2 only. So if one igid is passed in, we need to convert it to FBIDv2. Differential Revision: D83168475 fbshipit-source-id: ec0d6f24615c6b3f0eada0680e3cd77e2c915d9b
1 parent 9079ef8 commit 99137a5

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

thrift/lib/hack/src/ThriftContextPropState.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private static function updateFBUserIdFromVC(
245245
);
246246
$user_id = ZERO_FBID;
247247
} else {
248-
$user_id = $vc->getUserID();
248+
$user_id = $vc->getAccountID();
249249
}
250250

251251
if ($user_id !== ZERO_FBID && self::updateFBUserId($user_id, $src)) {
@@ -263,6 +263,25 @@ private static function updateIGUserIdFromVC(
263263
return self::updateIGUserId($vc->getViewerID(), $src);
264264
}
265265

266+
private static function getIgUserId(int $ig_user_id): ?int {
267+
if (IgidUtils::isUserFbid($ig_user_id)) {
268+
return $ig_user_id;
269+
}
270+
try {
271+
if (IgidUtils::isUserIgid($ig_user_id)) {
272+
return IgidUtils::userIgidToFbid($ig_user_id);
273+
}
274+
} catch (\Exception $ex) {
275+
ope(
276+
$ex,
277+
causes_the('No valid fbid for ig user id')->to(
278+
'context proper user id',
279+
),
280+
);
281+
}
282+
return null;
283+
}
284+
266285
// returns id if it is valid (non-null, positive), and should match the type
267286
private static function coerceId(
268287
?int $user_id,
@@ -279,11 +298,7 @@ private static function coerceId(
279298
}
280299
break;
281300
case UserIdCategory::IG:
282-
if (
283-
IgidUtils::isUserFbid($user_id) || IgidUtils::isUserIgid($user_id)
284-
) {
285-
return $user_id;
286-
}
301+
return self::getIgUserId($user_id);
287302
}
288303
return null;
289304
}

thrift/lib/hack/src/__tests__/ThriftContextPropStateTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public function testInitialization()[defaults]: void {
231231
);
232232

233233
// set up mocks for VC
234-
$fb_vc = mock(IFBViewerContext::class)->mockReturn('getUserID', fbid(1));
234+
$fb_vc = mock(IFBViewerContext::class)->mockReturn('getAccountID', fbid(1));
235235
$ig_vc = mock(IIGViewerContext::class)->mockReturn('getViewerID', fbid(2));
236236

237237
$buf = new TMemoryBuffer();
@@ -260,7 +260,8 @@ public function testInitialization()[defaults]: void {
260260
);
261261

262262
// set up mocks for VC
263-
$fb_vc = mock(IFBViewerContext::class)->mockReturn('getUserID', fbid(123));
263+
$fb_vc =
264+
mock(IFBViewerContext::class)->mockReturn('getAccountID', fbid(123));
264265

265266
$buf = new TMemoryBuffer();
266267
$prot = new TCompactProtocolAccelerated($buf);
@@ -286,9 +287,8 @@ public function testInitialization()[defaults]: void {
286287
$tfm->baggage->user_ids = ContextProp\UserIds::fromShape(
287288
shape('fb_user_id' => 123, 'ig_user_id' => 456),
288289
);
289-
290290
// set up mocks for VC
291-
$fb_vc = mock(IFBViewerContext::class)->mockReturn('getUserID', fbid(1));
291+
$fb_vc = mock(IFBViewerContext::class)->mockReturn('getAccountID', fbid(1));
292292
$ig_vc = mock(IIGViewerContext::class)->mockReturn('getViewerID', fbid(2));
293293

294294
$buf = new TMemoryBuffer();

0 commit comments

Comments
 (0)