Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chat-message

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chat-message

Streamlit component that styles a chat bubble.

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

chat-message

Streamlit component that allows you to style chat messages into chat bubbles. Uses daisyUI.

Installation instructions

pip install chat-message

Usage instructions

import streamlit as st
from chat_message import chat_message

user = {
  "id": 1,
  "name": "user1",
  "socket": "",
  "admin": False,
}

# simulated database data
rows = [
  {
    'message_id': 1,
    'message_msg': 'This is a test.',
    'message_roomId': 1,
    'message_time': datetime.datetime(2024, 7, 10, 6, 55, 59),
    'author_id': 1,
    'author_name': 'user1',
    'author_email': 'user1@example.com',
    'author_socket': ''
  },
  {
    'message_id': 2,
    'message_msg': 'This is only a test.',
    'message_roomId': 1,
    'message_time': datetime.datetime(2024, 7, 10, 6, 55, 59),
    'author_id': 2,
    'author_name': 'user2',
    'author_email': 'user2@example.com',
    'author_socket': ''
  }
]

result = []
for row in rows:
  obj = {
    "id": row["message_id"],
    "message": row["message_msg"],
    "room": row["message_roomId"],
    "time": row["message_time"].isoformat(),
    "author": {
      "id": row["author_id"],
      "name": row["author_name"],
      "socket": row["author_socket"]
    }
  }
  result.append(obj)

i = 0
for row in result:
  prev = None
  next = None

  if len(result) > 1:
    prev = result[i-1]

  if len(result) > i+1:
    next = result[i+1]

  appendTime = True
  appendUser = True

  if prev:
    if prev["author"]["id"] == row["author"]["id"]:
      diff = timeDiffInSecs(row["time"], prev["time"])
      if diff < 60:
        appendUser = False

  if next:
    if next["author"]["id"] == row["author"]["id"]:
      diff = timeDiffInSecs(next["time"], row["time"])
      if diff < 60:
        appendTime = False

  click = st_chat_message(row, user, appendUser, appendTime)
  print(click)

  i = i+1

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc