contact_service

Attributes

logger

Logger for the contact service module

Classes

ContactService

A service class for managing user-related operations such as adding, retrieving, updating,

Module Contents

logger

Logger for the contact service module

class ContactService

A service class for managing user-related operations such as adding, retrieving, updating, and deleting contacts, as well as handling contact requests.

static get_contacts(user_id: int) list[tuple[int, str, bool]]

Retrieve the contact information for a user.

Parameters:

user_id (int) – The ID of the user whose contacts are being retrieved.

Returns:

A list of tuples containing the contact ID, tag, and pair status for each contact.

Return type:

list[tuple[int, str, bool]]

static add_contacts(user_id: int, username: str, target_usernames: list[str]) list[dict]

Add new contacts for a user and handle contact requests.

Parameters:
  • user_id (int) – The ID of the user adding contacts.

  • username (str) – The username of the user adding contacts.

  • target_usernames (list[str]) – A list of usernames to add as contacts.

Returns:

A list of notifications with contact IDs and tags for successfully added contacts.

Return type:

list[dict]

static delete_contact(user_id: int, target_usernames: list[str]) None

Delete contacts from the user’s contact list.

Parameters:
  • user_id (int) – The ID of the user from whom contacts will be deleted.

  • target_usernames (list[str]) – A list of usernames to delete from the contacts.

static get_contact_requests(user_id: int) list[tuple[int, str]]

Retrieve the contact requests for a user.

Parameters:

user_id (int) – The ID of the user whose contact requests are being retrieved.

Returns:

A list of tuples containing the requester ID and requester tag for each contact request.

Return type:

list[tuple[int, str]]

static delete_contact_request(user_id: int, requester_user_id: int) None

Delete contact request from the user’s contact requests list.

Parameters:
  • user_id (int) – The ID of the user from whom contact request will be deleted.

  • requester_user_id (int) – The ID of the user whose will be deleted from the contact requests.

static update_contacts_property(user_id: int, target_username: str, key: str, value: int | bool) None

Update a specific property of a contact in the ‘contacts’ table.

Parameters:
  • user_id (int) – The ID of the user who owns the contact.

  • target_username (str) – The username of the contact.

  • key (str) – The column name in the ‘contacts’ table to update.

  • value (int | bool) – The new value for the property.

static update_contact_pairing(user_id: int, contact_id: int, key: str, value: int | bool) None

Update a specific property of a contact in the ‘contacts’ table.

Parameters:
  • user_id (int) – The ID of the user who owns the contact.

  • contact_id (int) – The ID of the contact.

  • key (str) – The column name in the ‘contacts’ table to update.

  • value (int | bool) – The new value for the property.

static update_contacts_reload(username: str, user_id: int) None

Reload the contact_id property when a user reconnects.

Parameters:
  • username (str) – The username of the user that just reconnected.

  • user_id (int) – The contact_id of the user that just reconnected.

static get_paired_contacts(user_id: int) list[tuple[int, str]]

Retrieve the paired contacts information for a user.

Parameters:

user_id (int) – The ID of the user whose contacts are being retrieved.

Returns:

A list of tuples containing the contact ID and tag for each paired contact.

Return type:

list[tuple[int, str]]

static transfer_pending_requests(user_id: int, target_username: str) list[tuple[int, str]]

Transfer pending requests to the ‘contact_requests’ table and delete them from the ‘pending_requests’ table.

Parameters:
  • user_id (int) – The ID of the user receiving the pending requests.

  • target_username (str) – The username associated with the pending requests.

Returns:

A list of tuples containing requester IDs and tags whose requests were transferred.

Return type:

list[tuple[int, str]]