Skip to content

Commit 70a16ca

Browse files
author
TeleGhost Dev
committed
Fix file transfer metadata (count/size) and mobile keyboard layout
1 parent 21cd551 commit 70a16ca

6 files changed

Lines changed: 71 additions & 14 deletions

File tree

frontend/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
<head>
55
<meta charset="UTF-8" />
6-
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
6+
<meta
7+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover, interactive-widget=resizes-content"
8+
name="viewport" />
79
<title>teleghost</title>
810
</head>
911

frontend/src/components/Chat.svelte

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@
253253
}
254254
}
255255
256+
// Auto-expand textarea
257+
function resizeTextarea() {
258+
if (!textarea) return;
259+
textarea.style.height = 'auto'; // Reset height to calculate scrollHeight
260+
textarea.style.height = textarea.scrollHeight + 'px';
261+
}
262+
263+
// Watch newMessage to resize (e.g. when cleared or pasted)
264+
$: if (newMessage !== undefined) {
265+
tick().then(resizeTextarea);
266+
}
256267
</script>
257268

258269
<div class="chat-area animate-fade-in" class:mobile={isMobile}>
@@ -415,10 +426,10 @@
415426
<div class="file-offer-card">
416427
<div class="file-icon-large">📁</div>
417428
<div class="file-info">
418-
<div class="file-title">Файлов: {msg.FileCount}</div>
419-
<div class="file-size">{(msg.TotalSize / (1024*1024)).toFixed(2)} MB</div>
420-
</div>
429+
<div class="file-title">Файлов: {msg.FileCount || (msg.Attachments ? msg.Attachments.length : (msg.Filenames ? msg.Filenames.length : 0))}</div>
430+
<div class="file-size">{((msg.TotalSize || 0) / (1024*1024)).toFixed(2)} MB</div>
421431
</div>
432+
</div>
422433
<div class="file-actions">
423434
{#if !msg.IsOutgoing}
424435
<button class="btn-small btn-success" on:click|stopPropagation={() => onAcceptTransfer(msg)}>Принять</button>
@@ -507,6 +518,7 @@
507518
bind:value={newMessage}
508519
on:keypress={onKeyPress}
509520
on:paste={onPaste}
521+
on:input={resizeTextarea}
510522
rows="1"
511523
style="width: 100%;"
512524
></textarea>
@@ -588,7 +600,7 @@
588600
589601
.input-area-wrapper { padding: 10px 20px 20px; background: var(--bg-primary); position: sticky; bottom: 0; z-index: 50; border-top: 1px solid var(--border); }
590602
.input-area { display: flex; align-items: center; gap: 10px; background: var(--bg-secondary); padding: 8px 12px; border-radius: 24px; }
591-
.message-input { flex: 1; background: transparent; border: none; color: white; outline: none; resize: none; font-size: 15px; max-height: 150px; padding: 8px 0; }
603+
.message-input { flex: 1; background: transparent; border: none; color: white; outline: none; resize: none; font-size: 15px; max-height: 120px; padding: 8px 0; overflow-y: auto; line-height: 1.4; }
592604
593605
.btn-icon { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: background 0.2s; }
594606
.btn-icon:hover { background: rgba(255,255,255,0.1); color: white; }

internal/appcore/appcore.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ type MessageInfo struct {
148148
ReplyToID string `json:"ReplyToID,omitempty"`
149149
ReplyPreview *ReplyPreview `json:"ReplyPreview,omitempty"`
150150
Attachments []map[string]interface{} `json:"Attachments,omitempty"`
151+
FileCount int `json:"FileCount,omitempty"`
152+
TotalSize int64 `json:"TotalSize,omitempty"`
151153
}
152154

153155
// UserInfo — информация о пользователе
@@ -866,6 +868,8 @@ func (a *AppCore) OnMessageReceived(msg *core.Message, senderPubKey, senderAddr
866868
"ReplyToID": msg.ReplyToID,
867869
"ReplyPreview": replyPreview,
868870
"Attachments": attachments,
871+
"FileCount": msg.FileCount,
872+
"TotalSize": msg.TotalSize,
869873
})
870874

871875
if !msg.IsOutgoing {

internal/appcore/messages.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ func (a *AppCore) GetMessages(contactID string, limit, offset int) ([]*MessageIn
173173
IsOutgoing: m.IsOutgoing,
174174
Status: m.Status.String(),
175175
ContentType: m.ContentType,
176+
FileCount: m.FileCount,
177+
TotalSize: m.TotalSize,
176178
}
177179

178180
if m.ReplyToID != nil && *m.ReplyToID != "" {
@@ -481,6 +483,8 @@ func (a *AppCore) SendFileMessage(chatID, text, replyToID string, files []string
481483
Timestamp: now,
482484
CreatedAt: time.Now(),
483485
UpdatedAt: time.Now(),
486+
FileCount: len(files), // Cast to int
487+
TotalSize: totalSize,
484488
}
485489
if replyToID != "" {
486490
msg.ReplyToID = &replyToID
@@ -614,6 +618,8 @@ func (a *AppCore) onFileOffer(senderPubKey, messageID, chatID string, filenames
614618
Timestamp: time.Now().UnixMilli(),
615619
CreatedAt: time.Now(),
616620
UpdatedAt: time.Now(),
621+
FileCount: int(fileCount),
622+
TotalSize: totalSize,
617623
}
618624
a.Repo.SaveMessage(a.Ctx, msg)
619625

internal/core/models.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ type Message struct {
173173

174174
// Attachments — список вложений
175175
Attachments []*Attachment `json:"attachments,omitempty" db:"-"`
176+
177+
// FileCount — количество файлов (для FileOffer)
178+
FileCount int `json:"file_count,omitempty" db:"file_count"`
179+
180+
// TotalSize — общий размер файлов (для FileOffer)
181+
TotalSize int64 `json:"total_size,omitempty" db:"total_size"`
176182
}
177183

178184
// Attachment представляет вложение (файл/изображение)

internal/repository/sqlite/repository.go

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ func (r *Repository) Migrate(ctx context.Context) error {
217217
if err == nil {
218218
defer rows.Close()
219219
hasIsRead := false
220+
hasFileCount := false
221+
hasTotalSize := false
222+
220223
for rows.Next() {
221224
var cid int
222225
var name, ctype string
@@ -225,7 +228,12 @@ func (r *Repository) Migrate(ctx context.Context) error {
225228
if err := rows.Scan(&cid, &name, &ctype, &notnull, &dflt_value, &pk); err == nil {
226229
if name == "is_read" {
227230
hasIsRead = true
228-
break
231+
}
232+
if name == "file_count" {
233+
hasFileCount = true
234+
}
235+
if name == "total_size" {
236+
hasTotalSize = true
229237
}
230238
}
231239
}
@@ -235,8 +243,22 @@ func (r *Repository) Migrate(ctx context.Context) error {
235243
_, err = r.db.ExecContext(ctx, "ALTER TABLE messages ADD COLUMN is_read INTEGER DEFAULT 0")
236244
if err != nil {
237245
log.Printf("[Repo] Failed to add is_read column: %v", err)
238-
} else {
239-
log.Println("[Repo] is_read column added successfully.")
246+
}
247+
}
248+
249+
if !hasFileCount {
250+
log.Println("[Repo] Adding file_count column to messages table...")
251+
_, err = r.db.ExecContext(ctx, "ALTER TABLE messages ADD COLUMN file_count INTEGER DEFAULT 0")
252+
if err != nil {
253+
log.Printf("[Repo] Failed to add file_count column: %v", err)
254+
}
255+
}
256+
257+
if !hasTotalSize {
258+
log.Println("[Repo] Adding total_size column to messages table...")
259+
_, err = r.db.ExecContext(ctx, "ALTER TABLE messages ADD COLUMN total_size INTEGER DEFAULT 0")
260+
if err != nil {
261+
log.Printf("[Repo] Failed to add total_size column: %v", err)
240262
}
241263
}
242264
}
@@ -738,13 +760,15 @@ func (r *Repository) DeleteContact(ctx context.Context, id string) error {
738760
func (r *Repository) SaveMessage(ctx context.Context, msg *core.Message) error {
739761
query := `
740762
INSERT INTO messages (id, chat_id, sender_id, content, content_type, status,
741-
is_outgoing, reply_to_id, timestamp, created_at, updated_at)
742-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
763+
is_outgoing, reply_to_id, timestamp, created_at, updated_at, file_count, total_size)
764+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
743765
ON CONFLICT(id) DO UPDATE SET
744766
content = excluded.content,
745767
content_type = excluded.content_type,
746768
status = excluded.status,
747-
updated_at = excluded.updated_at
769+
updated_at = excluded.updated_at,
770+
file_count = excluded.file_count,
771+
total_size = excluded.total_size
748772
`
749773

750774
now := time.Now()
@@ -764,6 +788,7 @@ func (r *Repository) SaveMessage(ctx context.Context, msg *core.Message) error {
764788
_, err := r.db.ExecContext(ctx, query,
765789
msg.ID, msg.ChatID, msg.SenderID, content, msg.ContentType, msg.Status,
766790
msg.IsOutgoing, msg.ReplyToID, msg.Timestamp, msg.CreatedAt, msg.UpdatedAt,
791+
msg.FileCount, msg.TotalSize,
767792
)
768793

769794
if err != nil {
@@ -806,7 +831,7 @@ func (r *Repository) SaveMessage(ctx context.Context, msg *core.Message) error {
806831
func (r *Repository) GetMessage(ctx context.Context, id string) (*core.Message, error) {
807832
query := `
808833
SELECT id, chat_id, sender_id, content, content_type, status,
809-
is_outgoing, reply_to_id, timestamp, created_at, updated_at
834+
is_outgoing, reply_to_id, timestamp, created_at, updated_at, file_count, total_size
810835
FROM messages WHERE id = ?
811836
`
812837

@@ -832,6 +857,7 @@ func (r *Repository) scanMessage(row interface {
832857
err := row.Scan(
833858
&msg.ID, &msg.ChatID, &msg.SenderID, &msg.Content, &msg.ContentType, &msg.Status,
834859
&msg.IsOutgoing, &msg.ReplyToID, &msg.Timestamp, &msg.CreatedAt, &msg.UpdatedAt,
860+
&msg.FileCount, &msg.TotalSize,
835861
)
836862
if err != nil {
837863
return nil, err
@@ -912,7 +938,7 @@ func (r *Repository) GetChatHistory(ctx context.Context, chatID string, limit, o
912938
query := `
913939
SELECT * FROM (
914940
SELECT id, chat_id, sender_id, content, content_type, status,
915-
is_outgoing, reply_to_id, timestamp, created_at, updated_at
941+
is_outgoing, reply_to_id, timestamp, created_at, updated_at, file_count, total_size
916942
FROM messages
917943
WHERE chat_id = ?
918944
ORDER BY timestamp DESC
@@ -982,7 +1008,7 @@ func (r *Repository) UpdateMessageContent(ctx context.Context, id, newContent st
9821008
func (r *Repository) SearchMessages(ctx context.Context, chatID, queryStr string) ([]*core.Message, error) {
9831009
query := `
9841010
SELECT id, chat_id, sender_id, content, content_type, status,
985-
is_outgoing, reply_to_id, timestamp, created_at, updated_at
1011+
is_outgoing, reply_to_id, timestamp, created_at, updated_at, file_count, total_size
9861012
FROM messages
9871013
WHERE chat_id = ? AND content LIKE ?
9881014
ORDER BY timestamp DESC
@@ -1001,6 +1027,7 @@ func (r *Repository) SearchMessages(ctx context.Context, chatID, queryStr string
10011027
err := rows.Scan(
10021028
&msg.ID, &msg.ChatID, &msg.SenderID, &msg.Content, &msg.ContentType, &msg.Status,
10031029
&msg.IsOutgoing, &msg.ReplyToID, &msg.Timestamp, &msg.CreatedAt, &msg.UpdatedAt,
1030+
&msg.FileCount, &msg.TotalSize,
10041031
)
10051032
if err != nil {
10061033
return nil, fmt.Errorf("failed to scan message: %w", err)

0 commit comments

Comments
 (0)