-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_chat_list_fix.py
More file actions
100 lines (84 loc) · 3.17 KB
/
demo_chat_list_fix.py
File metadata and controls
100 lines (84 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
"""
Visual demonstration of the fix - showing before and after
"""
import os
import django
# Set up Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'GUBlogs.settings')
django.setup()
from users.models import CustomUser, ChatMessage
from django.utils import timezone
def demonstrate_fix():
"""Demonstrate the difference between old and new chat list display"""
# Get or create test users
try:
alice = CustomUser.objects.get(username='alice_demo')
except CustomUser.DoesNotExist:
alice = CustomUser.objects.create_user(
username='alice_demo',
email='alice_demo@test.com',
password='testpass123'
)
try:
bob = CustomUser.objects.get(username='bob_demo')
except CustomUser.DoesNotExist:
bob = CustomUser.objects.create_user(
username='bob_demo',
email='bob_demo@test.com',
password='testpass123'
)
# Make them follow each other
alice.following.add(bob)
bob.following.add(alice)
# Create encrypted messages
messages = [
"Hey Bob! Want to grab lunch today? 🍕",
"Sure thing! How about that new Italian place?",
"Perfect! Meet you there at 12:30 PM 😊"
]
print("=" * 70)
print("CHAT LIST DISPLAY FIX DEMONSTRATION")
print("=" * 70)
saved_messages = []
for i, msg_text in enumerate(messages):
# Create encrypted message
chat_msg = ChatMessage(
sender=alice if i % 2 == 0 else bob,
receiver=bob if i % 2 == 0 else alice,
timestamp=timezone.now() + timezone.timedelta(minutes=i)
)
chat_msg.set_message(msg_text)
chat_msg.save()
saved_messages.append(chat_msg)
print(f"\n📨 Message {i+1}: '{msg_text}'")
print(f"🔒 Encrypted in DB: {chat_msg.message[:30]}...")
print(f"👁️ Decrypted for display: {chat_msg.get_display_message()}")
print(f"\n" + "="*50)
print("CHAT LIST PREVIEW (What users see now)")
print("="*50)
# Show what the chat list looks like for both users
for user in [alice, bob]:
conversations = user.get_conversations()
if conversations:
conv = conversations[0]
other_user = conv['user']
preview = conv['message_preview']
print(f"\n👤 {user.username}'s chat list:")
print(f" 💬 Conversation with {other_user.username}")
print(f" 📝 Preview: \"{preview[:50]}{'...' if len(preview) > 50 else ''}\"")
print(f" ✅ Shows readable text instead of encrypted gibberish!")
# Clean up
for msg in saved_messages:
msg.delete()
alice.following.remove(bob)
bob.following.remove(alice)
print(f"\n🧹 Demo completed and cleaned up")
print("=" * 70)
print("🎉 PROBLEM SOLVED!")
print("✅ Chat list now shows readable message previews")
print("🔒 Messages are still encrypted in the database")
print("👀 Users see decrypted previews in the chat list")
print("=" * 70)
if __name__ == "__main__":
demonstrate_fix()