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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ class ConversationRestGet(OutputSchema):
project_uuid: ProjectID | None
user_group_id: GroupID
type: ConversationType
fogbugz_case_id: str | None
created: datetime
modified: datetime
extra_context: dict[str, str]
is_read_by_user: bool
is_read_by_support: bool
last_message_created_at: datetime

@classmethod
def from_domain_model(cls, domain: ConversationGetDB) -> Self:
Expand All @@ -39,15 +43,21 @@ def from_domain_model(cls, domain: ConversationGetDB) -> Self:
project_uuid=domain.project_uuid,
user_group_id=domain.user_group_id,
type=domain.type,
fogbugz_case_id=domain.fogbugz_case_id,
created=domain.created,
modified=domain.modified,
extra_context=domain.extra_context,
is_read_by_user=domain.is_read_by_user,
is_read_by_support=domain.is_read_by_support,
last_message_created_at=domain.last_message_created_at,
)


class ConversationPatch(InputSchema):
name: str | None = None
extra_context: dict[str, Any] | None = None
is_read_by_user: bool | None = None
is_read_by_support: bool | None = None


### CONVERSATION MESSAGES ---------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions packages/models-library/src/models_library/conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ConversationMessageType(StrAutoEnum):
#


IsSupportUser: TypeAlias = bool


class ConversationGetDB(BaseModel):
conversation_id: ConversationID
product_name: ProductName
Expand All @@ -46,10 +49,14 @@ class ConversationGetDB(BaseModel):
user_group_id: GroupID
type: ConversationType
extra_context: dict[str, Any]
fogbugz_case_id: str | None
is_read_by_user: bool
is_read_by_support: bool

# states
created: datetime
modified: datetime
last_message_created_at: datetime

model_config = ConfigDict(from_attributes=True)

Expand All @@ -71,6 +78,10 @@ class ConversationMessageGetDB(BaseModel):
class ConversationPatchDB(BaseModel):
name: ConversationName | None = None
extra_context: dict[str, Any] | None = None
fogbugz_case_id: str | None = None
is_read_by_user: bool | None = None
is_read_by_support: bool | None = None
last_message_created_at: datetime | None = None


class ConversationMessagePatchDB(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""add last_message_created_at column

Revision ID: a6289977e057
Revises: dfdd4f8d4870
Create Date: 2025-10-13 08:39:24.912539+00:00

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "a6289977e057"
down_revision = "dfdd4f8d4870"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"conversations",
sa.Column(
"last_message_created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
)
# ### end Alembic commands ###

# Data migration: populate last_message_created_at with modified column values
op.execute("UPDATE conversations SET last_message_created_at = modified")


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("conversations", "last_message_created_at")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""add read by user/support columns

Revision ID: dfdd4f8d4870
Revises: 9dddb16914a4
Create Date: 2025-10-10 12:07:12.014847+00:00

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "dfdd4f8d4870"
down_revision = "9dddb16914a4"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"conversations", sa.Column("fogbugz_case_id", sa.String(), nullable=True)
)
op.add_column(
"conversations",
sa.Column(
"is_read_by_user",
sa.Boolean(),
server_default=sa.text("true"),
nullable=False,
),
)
op.add_column(
"conversations",
sa.Column(
"is_read_by_support",
sa.Boolean(),
server_default=sa.text("true"),
nullable=False,
),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("conversations", "is_read_by_support")
op.drop_column("conversations", "is_read_by_user")
op.drop_column("conversations", "fogbugz_case_id")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,33 @@ class ConversationType(enum.Enum):
server_default=sa.text("'{}'::jsonb"),
doc="Free JSON to store extra context",
),
sa.Column(
"fogbugz_case_id",
sa.String,
nullable=True,
doc="Fogbugz case ID associated with the conversation",
),
sa.Column(
"is_read_by_user",
sa.Boolean,
nullable=False,
server_default=sa.text("true"),
doc="Indicates if the message has been read by the user (true) or not (false)",
),
sa.Column(
"is_read_by_support",
sa.Boolean,
nullable=False,
server_default=sa.text("true"),
doc="Indicates if the message has been read by the support user (true) or not (false)",
),
sa.Column(
"last_message_created_at",
sa.DateTime(timezone=True),
nullable=False,
server_default=sa.sql.func.now(),
doc="Timestamp of the last message created in this conversation",
),
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
)
Original file line number Diff line number Diff line change
Expand Up @@ -10327,6 +10327,16 @@ components:
type: object
- type: 'null'
title: Extracontext
isReadByUser:
anyOf:
- type: boolean
- type: 'null'
title: Isreadbyuser
isReadBySupport:
anyOf:
- type: boolean
- type: 'null'
title: Isreadbysupport
type: object
title: ConversationPatch
ConversationRestGet:
Expand Down Expand Up @@ -10355,6 +10365,11 @@ components:
minimum: 0
type:
$ref: '#/components/schemas/ConversationType'
fogbugzCaseId:
anyOf:
- type: string
- type: 'null'
title: Fogbugzcaseid
created:
type: string
format: date-time
Expand All @@ -10368,6 +10383,16 @@ components:
type: string
type: object
title: Extracontext
isReadByUser:
type: boolean
title: Isreadbyuser
isReadBySupport:
type: boolean
title: Isreadbysupport
lastMessageCreatedAt:
type: string
format: date-time
title: Lastmessagecreatedat
type: object
required:
- conversationId
Expand All @@ -10376,9 +10401,13 @@ components:
- projectUuid
- userGroupId
- type
- fogbugzCaseId
- created
- modified
- extraContext
- isReadByUser
- isReadBySupport
- lastMessageCreatedAt
title: ConversationRestGet
ConversationType:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ def create_application(tracing_config: TracingConfig) -> web.Application:
setup_projects(app)

# conversations
setup_conversations(app)
setup_fogbugz(app) # Needed for support conversations
setup_conversations(app)

# licenses
setup_licenses(app)
Expand Down
Loading
Loading