Documentation
¶
Index ¶
- type ChatEntry
- type ChatStore
- func (s *ChatStore) Count() int
- func (s *ChatStore) Get(chatID int64) (*ChatEntry, bool)
- func (s *ChatStore) MemberCount(chatID int64) int32
- func (s *ChatStore) Merge(chat *telegram.Chat)
- func (s *ChatStore) OrderedChats() []*ChatEntry
- func (s *ChatStore) Set(chat *telegram.Chat)
- func (s *ChatStore) SetMemberCount(chatID int64, count int32)
- func (s *ChatStore) SetMuted(chatID int64, muted bool)
- func (s *ChatStore) TotalUnread() int32
- func (s *ChatStore) UpdateLastMessage(chatID int64, msg *telegram.Message)
- func (s *ChatStore) UpdateReadInbox(chatID int64, unreadCount int32)
- type FileState
- type FileStore
- type MessageStore
- func (s *MessageStore) Activate(chatID int64)
- func (s *MessageStore) Append(chatID int64, msg *telegram.Message)
- func (s *MessageStore) Clear(chatID int64)
- func (s *MessageStore) Count(chatID int64) int
- func (s *MessageStore) Delete(chatID int64, messageIDs []int64)
- func (s *MessageStore) DeleteFromAll(messageIDs []int64)
- func (s *MessageStore) Get(chatID int64) []*telegram.Message
- func (s *MessageStore) OldestMessageId(chatID int64) int64
- func (s *MessageStore) Prepend(chatID int64, msgs []*telegram.Message) []*telegram.Message
- func (s *MessageStore) ReplaceMessageId(chatID int64, oldID int64, newMsg *telegram.Message)
- func (s *MessageStore) UpdateMessage(chatID int64, messageID int64, newMsg *telegram.Message)
- type Store
- type UserStore
- func (s *UserStore) All() []*telegram.User
- func (s *UserStore) DisplayName(userID int64) string
- func (s *UserStore) Get(userID int64) (*telegram.User, bool)
- func (s *UserStore) IsOnline(userID int64) bool
- func (s *UserStore) Set(user *telegram.User)
- func (s *UserStore) UpdateStatus(userID int64, status telegram.UserStatus)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatEntry ¶
type ChatEntry struct {
Chat *telegram.Chat
LastMessage *telegram.Message
UnreadCount int32
Pinned bool
Order int64
// Unresolved marks an entry this store INVENTED to hold a message for
// a chat nobody had described yet — see [ChatStore.UpdateLastMessage].
// It has an id and nothing else: no name, no type, no mute flag.
//
// The flag exists because "the title is empty" is not the same
// question. A real chat can have an empty title (a deleted account
// has no name at all), and a row for one of those must not spend the
// rest of the session claiming to be loading.
Unresolved bool
// MemberCount is a group or channel's total, 0 when nobody has asked
// yet. It is NOT part of a dialog — a dialog says who a chat is, not
// how many people are in it — so it arrives from a separate full-info
// call, and [ChatStore.Set] and [ChatStore.Merge] leave it alone.
//
// It lives here rather than in the two components that want it so
// they cannot disagree, and so the second one to need it does not
// make the call again.
MemberCount int32
}
ChatEntry holds chat metadata and its position in the main list.
type ChatStore ¶
type ChatStore struct {
// contains filtered or unexported fields
}
ChatStore is a thread-safe in-memory cache of chats.
func NewChatStore ¶
func NewChatStore() *ChatStore
func (*ChatStore) MemberCount ¶
MemberCount is a chat's total membership, 0 when it is not known.
func (*ChatStore) Merge ¶
Merge updates a chat entry from a PEER — a partial view.
Resolving a peer answers "who is this": the id, the type, the name, the username, the photo. It says nothing about the reader's relationship with the chat, because that lives in the dialog and in the account's notify settings, neither of which a peer lookup returns.
Handing such a chat to [Set] replaced the entry wholesale, so every field the peer lookup had no opinion about was overwritten with a zero value. Opening a chat calls GetChat, so opening a chat cleared its mute flag, its unread count, its pin and its last message — and the first symptom anybody noticed was desktop notifications from a chat they had muted, which had been muted right up until they read it.
The field list below is therefore explicit rather than "copy anything that looks set": a bool cannot tell "false" from "not known", and guessing from zero values is the same bug wearing a different hat. Muted IS in the list, because the fetch goes and asks for it — see Client.GetChat.
func (*ChatStore) OrderedChats ¶
OrderedChats returns all chats: pinned first, then by last message date (descending).
func (*ChatStore) Set ¶
Set adds or updates a chat entry from a DIALOG — a complete view.
A dialog knows everything about a chat: who it is, and also whether it is muted, pinned, how many messages are unread and where it sits in the list. So this replaces. [Merge] is for the other kind of update, and mixing the two up is what silently unmuted every chat the reader opened.
func (*ChatStore) SetMemberCount ¶
SetMemberCount records a chat's total membership.
A zero is dropped rather than stored: every caller gets it from a full-info call, and a call that failed hands back the zero value. Storing that would replace a number this client knows with one it does not, and the header would go from "24 members" to silence on a refresh.
func (*ChatStore) SetMuted ¶
SetMuted updates a chat's muted flag. It is a no-op if the chat is not yet known to the store.
func (*ChatStore) TotalUnread ¶
TotalUnread is how many unread messages there are across every chat.
Summed on demand rather than kept as a running total: an incremental counter has to be right on every path that changes a chat's unread count, and the one that forgets leaves a number on screen that drifts further from the truth the longer the session runs.
func (*ChatStore) UpdateLastMessage ¶
UpdateLastMessage updates a chat's last message and sort order.
func (*ChatStore) UpdateReadInbox ¶
UpdateReadInbox updates the unread count for a chat.
type FileState ¶
type FileState struct {
File *telegram.File
LocalPath string
IsComplete bool
Progress float64 // 0.0 to 1.0
}
FileState tracks the download state of a file.
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
FileStore tracks file download states.
func NewFileStore ¶
func NewFileStore() *FileStore
func (*FileStore) IsComplete ¶
IsComplete checks if a file download is complete.
type MessageStore ¶
type MessageStore struct {
// contains filtered or unexported fields
}
MessageStore caches messages per chat.
func NewMessageStore ¶
func NewMessageStore() *MessageStore
func (*MessageStore) Activate ¶
func (s *MessageStore) Activate(chatID int64)
Activate makes chatID the one pageable chat. Its history may grow while the reader explicitly walks backwards; when the reader leaves, the previous chat is reduced to the same newest-message bound as every background chat.
func (*MessageStore) Append ¶
func (s *MessageStore) Append(chatID int64, msg *telegram.Message)
Append adds a new message to the end of the chat's message list.
func (*MessageStore) Clear ¶
func (s *MessageStore) Clear(chatID int64)
Clear removes all cached messages for a chat.
func (*MessageStore) Count ¶
func (s *MessageStore) Count(chatID int64) int
Count returns the number of cached messages for a chat.
func (*MessageStore) Delete ¶
func (s *MessageStore) Delete(chatID int64, messageIDs []int64)
Delete removes messages from the store.
func (*MessageStore) DeleteFromAll ¶
func (s *MessageStore) DeleteFromAll(messageIDs []int64)
DeleteFromAll removes messages from every chat. Used for non-channel delete updates, which carry no peer (ChatId == 0).
func (*MessageStore) Get ¶
func (s *MessageStore) Get(chatID int64) []*telegram.Message
Get returns all cached messages for a chat.
func (*MessageStore) OldestMessageId ¶
func (s *MessageStore) OldestMessageId(chatID int64) int64
OldestMessageId returns the oldest cached message ID for a chat.
func (*MessageStore) Prepend ¶
Prepend adds older messages to the beginning of the chat's message list and returns the newly inserted messages that survived the cache policy.
func (*MessageStore) ReplaceMessageId ¶
func (s *MessageStore) ReplaceMessageId(chatID int64, oldID int64, newMsg *telegram.Message)
ReplaceMessageId replaces a temporary message ID with the real one (after send).
func (*MessageStore) UpdateMessage ¶
func (s *MessageStore) UpdateMessage(chatID int64, messageID int64, newMsg *telegram.Message)
UpdateMessage replaces a message in the store (for edits).
type Store ¶
type Store struct {
Chats *ChatStore
Messages *MessageStore
Users *UserStore
Files *FileStore
}
Store is the aggregate store holding all caches.
type UserStore ¶
type UserStore struct {
// contains filtered or unexported fields
}
UserStore caches user information.
func NewUserStore ¶
func NewUserStore() *UserStore
func (*UserStore) DisplayName ¶
DisplayName returns a formatted display name for a user.
func (*UserStore) UpdateStatus ¶
func (s *UserStore) UpdateStatus(userID int64, status telegram.UserStatus)
UpdateStatus updates a user's online status.