@@ -3,11 +3,9 @@ package chat
33import (
44 "context"
55 "errors"
6- "fmt"
76 "log/slog"
87 "slices"
98 "strconv"
10- "time"
119
1210 tea "github.com/charmbracelet/bubbletea"
1311 "github.com/gotd/td/tg"
@@ -335,7 +333,6 @@ func (m *Manager) getAllDialogs(ctx context.Context, offsetDate, offsetID int) (
335333 slog .Error (err .Error ())
336334 return nil , err
337335 }
338-
339336 switch d := dialogs .(type ) {
340337 case * tg.MessagesDialogs :
341338 allChats = append (allChats , d .Chats ... )
@@ -363,7 +360,6 @@ func (m *Manager) getAllDialogs(ctx context.Context, offsetDate, offsetID int) (
363360 }, nil
364361 }
365362 last := d .Messages [len (d .Messages )- 1 ]
366-
367363 switch msg := last .(type ) {
368364 case * tg.Message :
369365 return & CligramGetDialogsResponse {
@@ -375,12 +371,13 @@ func (m *Manager) getAllDialogs(ctx context.Context, offsetDate, offsetID int) (
375371 }, nil
376372 default :
377373 return & CligramGetDialogsResponse {
378- Chats : allChats ,
379- Users : allUsers ,
380- Dialogs : allDialogs ,
374+ Chats : allChats ,
375+ Users : allUsers ,
376+ Dialogs : allDialogs ,
377+ OffsetDate : - 1 ,
378+ OffsetID : - 1 ,
381379 }, nil
382380 }
383-
384381 default :
385382 return & CligramGetDialogsResponse {
386383 Chats : allChats ,
@@ -435,50 +432,3 @@ type userOnlineStatus struct {
435432 IsOnline bool
436433 LastSeen * string
437434}
438-
439- func getUserOnlineStatus (status tg.UserStatusClass ) * userOnlineStatus {
440- if status == nil {
441- return & userOnlineStatus {
442- IsOnline : false ,
443- LastSeen : nil ,
444- }
445- }
446- switch s := status .(type ) {
447- case * tg.UserStatusOnline :
448- lastSeen := "online"
449- return & userOnlineStatus {
450- IsOnline : true ,
451- LastSeen : & lastSeen ,
452- }
453- case * tg.UserStatusOffline :
454- lastSeen := calculateLastSeenHumanReadable (s .WasOnline )
455- return & userOnlineStatus {
456- IsOnline : false ,
457- LastSeen : & lastSeen ,
458- }
459- default :
460- lastSeen := "last seen long time ago"
461- return & userOnlineStatus {
462- IsOnline : false ,
463- LastSeen : & lastSeen ,
464- }
465- }
466- }
467-
468- func calculateLastSeenHumanReadable (wasOnline int ) string {
469- lastSeenTime := time .Unix (int64 (wasOnline ), 0 )
470- currentTime := time .Now ()
471- diff := currentTime .Sub (lastSeenTime )
472-
473- if diff .Seconds () < 60 {
474- return "last seen just now"
475- }
476- if diff .Hours () < 24 {
477- return fmt .Sprintf ("last seen at %s" , lastSeenTime .Format ("03:04 PM" ))
478- }
479- if diff .Hours () < 48 {
480- return fmt .Sprintf ("last seen yesterday at %s" , lastSeenTime .Format ("03:04 PM" ))
481- }
482-
483- return fmt .Sprintf ("last seen on %s" , lastSeenTime .Format ("02/01/2006 03:04 PM" ))
484- }
0 commit comments