Skip to content

Commit

Permalink
feat: add timestamp to post follow [ UNICT-DMI#136 ]
Browse files Browse the repository at this point in the history
  • Loading branch information
TendTo committed Nov 23, 2023
1 parent b852398 commit 3d04866
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The python package name will be `telegram-spotted-dmi-bot` (hence `pip install telegram-spotted-dmi-bot`)
- The name of the main module will be `spotted` (hence `import spotted`)
- the project will be versioned, starting from 2.0.0. So you will need a tag with a new version to publish the new python package
- Timestamp to the user_follow table to keep track of when a user started following a post

### Fixed

Expand Down
6 changes: 4 additions & 2 deletions src/spotted/config/db/post_db_init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ CREATE TABLE IF NOT EXISTS user_follow
(
user_id BIGINT NOT NULL,
message_id BIGINT NOT NULL,
private_message_id BIGINT NOT NULL
);
private_message_id BIGINT NOT NULL,
follow_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (user_id, message_id)
);
6 changes: 4 additions & 2 deletions src/spotted/data/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class User:
user_id: id of the user
private_message_id: id of the private message sent by the user to the bot. Only used for following
ban_date: datetime of when the user was banned. Only used for banned users
follow_date: datetime of when the user started following a post. Only used for following users
"""

user_id: int
private_message_id: int | None = None
ban_date: datetime | None = None
follow_date: datetime | None = None

@property
def is_pending(self) -> bool:
Expand Down Expand Up @@ -67,10 +69,10 @@ def following_users(cls, message_id: int) -> "list[User]":
in the user's conversation with the bot
"""
return [
cls(user_id=row["user_id"], private_message_id=row["private_message_id"])
cls(user_id=row["user_id"], private_message_id=row["private_message_id"], follow_date=row["follow_date"])
for row in DbManager.select_from(
table_name="user_follow",
select="user_id, private_message_id",
select="user_id, private_message_id, follow_date",
where="message_id = %s",
where_args=(message_id,),
)
Expand Down

0 comments on commit 3d04866

Please sign in to comment.