(20241203) Working with labels.
This commit is contained in:
@@ -153,6 +153,40 @@ async def handle_gmail_callback() -> render_template:
|
||||
failure_hint = f"We were expecting authorization from '{placeholder_token['clientUserId']['email']}' but got authorization from '{tokens.email}' instead."
|
||||
)
|
||||
|
||||
# We create standard labels that we will use:
|
||||
labels = [
|
||||
{
|
||||
"name": "TCAOFF",
|
||||
"textColor": "#434343",
|
||||
"backgroundColor": "#cccccc"
|
||||
},
|
||||
{
|
||||
"name": "CA-Doc",
|
||||
"textColor": "#434343",
|
||||
"backgroundColor": "#cccccc"
|
||||
},
|
||||
{
|
||||
"name": "CA-AI",
|
||||
"textColor": "#434343",
|
||||
"backgroundColor": "#cccccc"
|
||||
}
|
||||
]
|
||||
tasks = [
|
||||
current_app.gmail_client.create_label(
|
||||
tokens = tokens,
|
||||
label_name = label["name"],
|
||||
label_visibility = "labelShow",
|
||||
message_visibility = "show",
|
||||
label_text_color = label["textColor"],
|
||||
label_background_color = label["backgroundColor"]
|
||||
) for label in labels
|
||||
]
|
||||
client_responses = await asyncio.gather(*tasks)
|
||||
|
||||
# Add the labels to the tokens data:
|
||||
client_response = await current_app.gmail_client.list_labels(tokens = tokens)
|
||||
tokens.labels = client_response.data if client_response.success else None
|
||||
|
||||
# Now that we have passed the check,
|
||||
# we save the tokens to the database:
|
||||
tokens_saved = await current_app.mail_oauth_model.set_token(
|
||||
|
||||
Reference in New Issue
Block a user