Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PyMatchaV2.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -6065,7 +6065,7 @@
"tests[\"Message is correct\"] = response.new_messages.length == 1",
"tests[\"New message content is correct\"] = response.new_messages[0].content == \"My Reply\"",
"tests[\"New message is_seen\"] = response.new_messages[0].is_seen == 0",
"tests[\"New message seen timestamp is null\"] = response.new_messages[0].seen_timestamp == null"
"tests[\"New message seen timestamp is null\"] = response.new_messages[0].dt_seen == null"
],
"type": "text/javascript"
}
Expand Down
10 changes: 5 additions & 5 deletions backend/PyMatcha/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ class Image(Model):
id = Field(int, modifiable=False)
user_id = Field(int)
link = Field(str)
timestamp = Field(datetime, fmt="%Y-%m-%d %H:%M:%S")
dt_added = Field(datetime, fmt="%Y-%m-%d %H:%M:%S")
is_primary = Field(bool)

@staticmethod
def create(user_id: int, link: str, is_primary: bool = False, timestamp: Optional[datetime] = None) -> Image:
if not timestamp:
timestamp = datetime.utcnow()
new_image = Image(user_id=user_id, link=link, is_primary=is_primary, timestamp=timestamp)
def create(user_id: int, link: str, is_primary: bool = False, dt_added: Optional[datetime] = None) -> Image:
if not dt_added:
dt_added = datetime.utcnow()
new_image = Image(user_id=user_id, link=link, is_primary=is_primary, dt_added=dt_added)
new_image.save()
logging.debug("Creating new image")
return new_image
Expand Down
24 changes: 12 additions & 12 deletions backend/PyMatcha/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Message(Model):
id = Field(int, modifiable=False)
from_id = Field(int)
to_id = Field(int)
timestamp = Field(datetime, fmt="%Y-%m-%d %H:%M:%S")
seen_timestamp = Field(datetime, fmt="%Y-%m-%d %H:%M:%S")
dt_sent = Field(datetime, fmt="%Y-%m-%d %H:%M:%S")
dt_seen = Field(datetime, fmt="%Y-%m-%d %H:%M:%S")
content = Field(str)
is_seen = Field(bool)
is_liked = Field(bool)
Expand All @@ -46,19 +46,19 @@ def create(
from_id: int,
to_id: int,
content: str,
timestamp: Optional[datetime] = None,
seen_timestamp: Optional[datetime] = None,
dt_sent: Optional[datetime] = None,
dt_seen: Optional[datetime] = None,
is_seen: bool = False,
is_liked: bool = False,
) -> Message:
if not timestamp:
timestamp = datetime.utcnow()
if not dt_sent:
dt_sent = datetime.utcnow()
new_message = Message(
from_id=from_id,
to_id=to_id,
content=content,
timestamp=timestamp,
seen_timestamp=seen_timestamp,
dt_sent=dt_sent,
dt_seen=dt_seen,
is_seen=is_seen,
is_liked=is_liked,
)
Expand All @@ -68,11 +68,11 @@ def create(

def to_dict(self) -> Dict:
returned_dict = super().to_dict()
returned_dict["timestamp_ago"] = timeago_format(self.timestamp, datetime.utcnow())
if self.seen_timestamp:
returned_dict["seen_timestamp_ago"] = timeago_format(self.seen_timestamp, datetime.utcnow())
returned_dict["dt_sent_ago"] = timeago_format(self.dt_sent, datetime.utcnow())
if self.dt_seen:
returned_dict["dt_seen_ago"] = timeago_format(self.dt_seen, datetime.utcnow())
else:
returned_dict["seen_timestamp_ago"] = None
returned_dict["dt_seen_ago"] = None

return returned_dict

Expand Down
42 changes: 21 additions & 21 deletions backend/PyMatcha/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ class User(Model):
geohash = Field(str)
heat_score = Field(int)
is_online = Field(bool)
date_joined = Field(datetime.datetime, fmt="%Y-%m-%d %H:%M:%S")
date_lastseen = Field(datetime.datetime, fmt="%Y-%m-%d %H:%M:%S")
dt_joined = Field(datetime.datetime, fmt="%Y-%m-%d %H:%M:%S")
dt_lastseen = Field(datetime.datetime, fmt="%Y-%m-%d %H:%M:%S")
is_profile_completed = Field(bool)
is_confirmed = Field(bool)
confirmed_on = Field(datetime.datetime, fmt="%Y-%m-%d %H:%M:%S")
Expand All @@ -84,8 +84,8 @@ def create(
geohash: str,
heat_score: int = 0,
is_online: bool = False,
date_joined: Optional[datetime.datetime] = None,
date_lastseen: Optional[datetime.datetime] = None,
dt_joined: Optional[datetime.datetime] = None,
dt_lastseen: Optional[datetime.datetime] = None,
is_profile_completed: bool = False,
is_confirmed: bool = False,
confirmed_on: datetime.datetime = None,
Expand Down Expand Up @@ -126,11 +126,11 @@ def create(
# Encrypt password
password = hash_password(password)

if not date_joined:
date_joined = datetime.datetime.utcnow()
if not dt_joined:
dt_joined = datetime.datetime.utcnow()

if not date_lastseen:
date_lastseen = datetime.datetime.utcnow()
if not dt_lastseen:
dt_lastseen = datetime.datetime.utcnow()

new_user = User(
first_name=first_name,
Expand All @@ -145,8 +145,8 @@ def create(
geohash=geohash,
heat_score=heat_score,
is_online=is_online,
date_joined=date_joined,
date_lastseen=date_lastseen,
dt_joined=dt_joined,
dt_lastseen=dt_lastseen,
is_profile_completed=is_profile_completed,
is_confirmed=is_confirmed,
confirmed_on=confirmed_on,
Expand Down Expand Up @@ -187,8 +187,8 @@ def register(email: str, username: str, password: str, first_name: str, last_nam
geohash=None,
heat_score=0,
is_online=False,
date_joined=datetime.datetime.utcnow(),
date_lastseen=datetime.datetime.utcnow(),
dt_joined=datetime.datetime.utcnow(),
dt_lastseen=datetime.datetime.utcnow(),
is_profile_completed=False,
is_confirmed=False,
confirmed_on=None,
Expand All @@ -211,7 +211,7 @@ def to_dict(self) -> Dict:
returned_dict["likes"] = {"sent": [], "received": []}
returned_dict["likes"]["sent"] = [like.to_dict() for like in self.get_likes_sent()]
returned_dict["likes"]["received"] = [like.to_dict() for like in self.get_likes_received()]
returned_dict["last_seen"] = timeago_format(self.date_lastseen, datetime.datetime.utcnow())
returned_dict["last_seen"] = timeago_format(self.dt_lastseen, datetime.datetime.utcnow())
returned_dict["blocks"] = [block.to_dict() for block in self.get_blocks()]
returned_dict.pop("password")
returned_dict.pop("previous_reset_token")
Expand All @@ -237,7 +237,7 @@ def get_jwt_info(self):
"email": self.email,
"username": self.username,
"is_online": self.is_online,
"date_lastseen": self.date_lastseen,
"dt_lastseen": self.dt_lastseen,
}

def get_images(self):
Expand Down Expand Up @@ -318,7 +318,7 @@ def get_matches(self):
return match_list

def send_message(self, to_id, content):
Message.create(from_id=self.id, to_id=to_id, content=content, timestamp=datetime.datetime.utcnow())
Message.create(from_id=self.id, to_id=to_id, content=content, dt_sent=datetime.datetime.utcnow())

def get_messages(self) -> List[Message]:
with self.db.cursor() as c:
Expand All @@ -328,8 +328,8 @@ def get_messages(self) -> List[Message]:
messages.from_id as from_id,
messages.to_id as to_id,
messages.id as id,
messages.timestamp as timestamp,
messages.seen_timestamp as seen_timestamp,
messages.dt_sent as dt_sent,
messages.dt_seen as dt_seen,
messages.content as content,
messages.is_liked as is_liked,
messages.is_seen as is_seen
Expand Down Expand Up @@ -386,8 +386,8 @@ def get_messages_with_user(self, with_user_id) -> List[Message]:
messages.from_id as from_id,
messages.to_id as to_id,
messages.id as id,
messages.timestamp as timestamp,
messages.seen_timestamp as seen_timestamp,
messages.dt_sent as dt_sent,
messages.dt_seen as dt_seen,
messages.content as content,
messages.is_liked as is_liked,
messages.is_seen as is_seen
Expand All @@ -399,8 +399,8 @@ def get_messages_with_user(self, with_user_id) -> List[Message]:
SELECT messages.from_id as from_id,
messages.to_id as to_id,
messages.id as id,
messages.timestamp as timestamp,
messages.seen_timestamp as seen_timestamp,
messages.dt_sent as dt_sent,
messages.dt_seen as dt_seen,
messages.content as content,
messages.is_liked as is_liked,
messages.is_seen as is_seen
Expand Down
2 changes: 1 addition & 1 deletion backend/PyMatcha/routes/api/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def auth_login():

current_app.logger.debug("/auth/login -> Returning access token for user {}".format(username))
u.is_online = True
u.date_lastseen = datetime.datetime.utcnow()
u.dt_lastseen = datetime.datetime.utcnow()
u.save()
ret = {"access_token": access_token, "refresh_token": refresh_token, "is_profile_completed": u.is_profile_completed}
return SuccessOutput("return", ret)
Expand Down
10 changes: 5 additions & 5 deletions backend/PyMatcha/routes/api/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def get_opened_conversations():
returned_list = [
{
"last_message_id": c.id,
"last_message_timestamp": c.timestamp,
"last_message_timestamp_ago": timeago_format(c.timestamp, datetime.datetime.utcnow()),
"last_message_dt_sent": c.dt_sent,
"last_message_dt_sent_ago": timeago_format(c.dt_sent, datetime.datetime.utcnow()),
"last_message_content": c.content,
"is_unseen": True if not c.is_seen and c.to_id == current_user.id else False,
"with_user": get_user(c.to_id if c.to_id != current_user.id else c.from_id).to_dict(),
Expand Down Expand Up @@ -90,7 +90,7 @@ def send_message():

if to_user.is_bot:
new_message.is_seen = True
new_message.seen_timestamp = datetime.datetime.utcnow()
new_message.dt_seen = datetime.datetime.utcnow()
new_message.save()
bot_respond_to_message.delay(bot_id=to_user.id, from_id=current_user.id, message_content=content)

Expand All @@ -110,7 +110,7 @@ def get_conversation_messsages(with_uid):

message_list = current_user.get_messages_with_user(with_user.id)
message_list = [m.to_dict() for m in message_list]
message_list = sorted(message_list, key=lambda item: item["timestamp"])
message_list = sorted(message_list, key=lambda item: item["dt_sent"])
return SuccessOutput("messages", message_list)


Expand All @@ -124,7 +124,7 @@ def see_conversation_messages(with_uid):
unseen_messages = Message.get_multis(from_id=with_user.id, to_id=current_user.id, is_seen=False)
for message in unseen_messages:
message.is_seen = True
message.seen_timestamp = datetime.datetime.utcnow()
message.dt_seen = datetime.datetime.utcnow()
message.save()
return Success("Messages marked as seen.")

Expand Down
2 changes: 1 addition & 1 deletion backend/PyMatcha/utils/jwt_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def jwt_user_callback(identity):
with configure_scope() as scope:
scope.user = {"email": user.email, "id": user.id, "username": user.username}
user.is_online = True
user.date_lastseen = datetime.datetime.utcnow()
user.dt_lastseen = datetime.datetime.utcnow()
user.save()
return user

Expand Down
8 changes: 4 additions & 4 deletions backend/PyMatcha/utils/populate_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ def populate_users(amount=150, drop_user_table=False):
old = geohash[0:2]
geohash = geohash.replace(old, FRANCE_GEOHASH_START[0], 1)

date_joined = gen_datetime(min_year=2017, max_year=datetime.datetime.now().year)
dt_joined = gen_datetime(min_year=2017, max_year=datetime.datetime.now().year)

date_lastseen = gen_datetime(min_year=2017, max_year=datetime.datetime.now().year)
dt_lastseen = gen_datetime(min_year=2017, max_year=datetime.datetime.now().year)
username = user.get_username()

birthdate = gen_datetime(min_year=1985, max_year=datetime.datetime.now().year - 18).date()
Expand All @@ -90,8 +90,8 @@ def populate_users(amount=150, drop_user_table=False):
geohash=geohash,
heat_score=random.randint(0, 150),
is_online=random.choice([True, False]),
date_joined=date_joined,
date_lastseen=date_lastseen,
dt_joined=dt_joined,
dt_lastseen=dt_lastseen,
is_profile_completed=True,
is_confirmed=True,
confirmed_on=datetime.datetime.utcnow(),
Expand Down
10 changes: 5 additions & 5 deletions backend/PyMatcha/utils/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def _create_user_table(db):
birthdate DATE DEFAULT NULL,
geohash VARCHAR(256) DEFAULT NULL,
heat_score INT DEFAULT NULL,
date_joined DATETIME DEFAULT NOW(),
date_lastseen DATETIME DEFAULT NOW(),
dt_joined DATETIME DEFAULT NOW(),
dt_lastseen DATETIME DEFAULT NOW(),
previous_reset_token VARCHAR(256),
is_online BOOLEAN DEFAULT (FALSE),
is_profile_completed BOOLEAN DEFAULT (FALSE),
Expand Down Expand Up @@ -168,8 +168,8 @@ def _create_messages_table(db):
id INT auto_increment PRIMARY KEY,
from_id INT NOT NULL,
to_id INT NOT NULL,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
seen_timestamp TIMESTAMP,
dt_sent DATETIME DEFAULT NOW(),
dt_seen DATETIME DEFAULT NOW(),
content LONGTEXT NOT NULL,
is_liked BOOLEAN DEFAULT FALSE,
is_seen BOOLEAN DEFAULT FALSE
Expand All @@ -190,7 +190,7 @@ def _create_images_table(db):
(
id INT auto_increment PRIMARY KEY,
user_id INT NOT NULL,
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
dt_added DATETIME DEFAULT NOW(),
link VARCHAR(256) NOT NULL,
is_primary BOOLEAN DEFAULT FALSE
) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ;
Expand Down
6 changes: 3 additions & 3 deletions backend/PyMatcha/utils/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update_heat_scores():

now = datetime.datetime.utcnow()
monday1 = now - datetime.timedelta(days=now.weekday())
monday2 = user.date_lastseen - datetime.timedelta(days=user.date_lastseen.weekday())
monday2 = user.dt_lastseen - datetime.timedelta(days=user.dt_lastseen.weekday())
weeks_passed_since_last_activity = int((monday1 - monday2).days / 7)

score -= weeks_passed_since_last_activity * INACTIVITY_DIVIDER
Expand All @@ -78,7 +78,7 @@ def take_users_offline():
went_offline_count = 0
stayed_online_count = 0
for user in User.get_multis(is_online=True):
if user.date_lastseen + datetime.timedelta(minutes=2) < datetime.datetime.utcnow():
if user.dt_lastseen + datetime.timedelta(minutes=2) < datetime.datetime.utcnow():
user.is_online = False
user.save()
went_offline_count += 1
Expand Down Expand Up @@ -142,7 +142,7 @@ def take_random_users_online():
# User isn't a bot, so skip him
continue
user.is_online = True
user.date_lastseen = datetime.datetime.utcnow()
user.dt_lastseen = datetime.datetime.utcnow()
user.save()
return "Successfully set 250 users online"

Expand Down
Loading