Browse Source

Stop using cookies that aren't set anymore

Tulir Asokan 2 years ago
parent
commit
83cb3ab8f4

+ 2 - 2
mauigpapi/http/account.py

@@ -90,7 +90,7 @@ class AccountAPI(BaseAndroidAPI):
     ) -> T:
         req = {
             "_csrftoken": self.state.cookies.csrf_token,
-            "_uid": self.state.cookies.user_id,
+            "_uid": self.state.session.ds_user_id,
             "_uuid": self.state.device.uuid,
             **kwargs,
         }
@@ -135,7 +135,7 @@ class AccountAPI(BaseAndroidAPI):
         req = {
             "phone_id": self.state.device.phone_id,
             "_csrftoken": self.state.cookies.csrf_token,
-            "_uid": self.state.cookies.user_id,
+            "_uid": self.state.session.ds_user_id,
             "device_id": self.state.device.uuid,
             "_uuid": self.state.device.uuid,
             "google_tokens": json.dumps([]),

+ 1 - 1
mauigpapi/http/login.py

@@ -137,7 +137,7 @@ class LoginAPI(BaseAndroidAPI):
     ):
         req = {
             "_csrftoken": self.state.cookies.csrf_token,
-            "_uid": self.state.cookies.user_id,
+            "_uid": self.state.session.ds_user_id,
             "_uuid": self.state.device.uuid,
             "enc_old_password": old_password,
             "enc_new_password1": new_password1,

+ 5 - 8
mauigpapi/http/qe.py

@@ -13,7 +13,6 @@
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
-from ..errors import IGCookieNotFoundError
 from ..types import QeSyncResponse
 from .base import BaseAndroidAPI
 
@@ -26,17 +25,15 @@ class QeSyncAPI(BaseAndroidAPI):
         return await self.__sync(self.state.application.LOGIN_EXPERIMENTS)
 
     async def __sync(self, experiments: str) -> QeSyncResponse:
-        try:
-            uid = self.state.cookies.user_id
-        except IGCookieNotFoundError:
-            req = {"id": self.state.device.uuid}
-        else:
+        if self.state.session.ds_user_id:
             req = {
                 "_csrftoken": self.state.cookies.csrf_token,
-                "id": uid,
-                "_uid": uid,
+                "id": self.state.session.ds_user_id,
+                "_uid": self.state.session.ds_user_id,
                 "_uuid": self.state.device.uuid,
             }
+        else:
+            req = {"id": self.state.device.uuid}
         req["experiments"] = experiments
         resp = await self.std_http_post("/api/v1/qe/sync/", data=req, response_type=QeSyncResponse)
         self.state.experiments.update(resp)

+ 1 - 1
mauigpapi/http/thread.py

@@ -121,7 +121,7 @@ class ThreadAPI(BaseAndroidAPI):
             data={
                 "_csrftoken": self.state.cookies.csrf_token,
                 "_uuid": self.state.device.uuid,
-                "_uid": self.state.cookies.user_id,
+                "_uid": self.state.session.ds_user_id,
                 "recipient_users": json.dumps(
                     [str(user) for user in recipient_users], separators=(",", ":")
                 ),

+ 1 - 1
mauigpapi/http/upload.py

@@ -148,7 +148,7 @@ class UploadAPI(BaseAndroidAPI):
             "timezone_offset": self.state.device.timezone_offset,
             "_csrftoken": self.state.cookies.csrf_token,
             "source_type": source_type,
-            "_uid": self.state.cookies.user_id,
+            "_uid": self.state.session.ds_user_id,
             "device_id": self.state.device.id,
             "_uuid": self.state.device.uuid,
             "upload_id": upload_id,

+ 0 - 8
mauigpapi/state/cookies.py

@@ -59,14 +59,6 @@ class Cookies(Serializable):
         except IGCookieNotFoundError:
             return "missing"
 
-    @property
-    def user_id(self) -> str:
-        return self["ds_user_id"]
-
-    @property
-    def username(self) -> str:
-        return self["ds_username"]
-
     def get(self, key: str) -> Morsel:
         filtered = self.jar.filter_cookies(ig_url)
         return filtered.get(key)

+ 6 - 6
mauigpapi/state/state.py

@@ -22,7 +22,7 @@ from attr import dataclass
 
 from mautrix.types import SerializableAttrs, field
 
-from ..errors import IGCookieNotFoundError, IGNoChallengeError, IGUserIDNotFoundError
+from ..errors import IGNoChallengeError, IGUserIDNotFoundError
 from ..types import ChallengeStateResponse
 from .application import AndroidApplication
 from .cookies import Cookies
@@ -64,12 +64,12 @@ class AndroidState(SerializableAttrs):
 
     @property
     def user_id(self) -> str:
-        try:
-            return self.cookies.user_id
-        except IGCookieNotFoundError:
-            if not self.challenge or not self.challenge.user_id:
-                raise IGUserIDNotFoundError()
+        if self.session.ds_user_id:
+            return self.session.ds_user_id
+        elif self.challenge and self.challenge.user_id:
             return str(self.challenge.user_id)
+        else:
+            raise IGUserIDNotFoundError()
 
     @property
     def challenge_path(self) -> str: