mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-05 04:07:07 +00:00
Keep two chat caches to avoid unnecessary presences
This commit is contained in:
parent
326c94973a
commit
140cf7fa4a
9 changed files with 94 additions and 61 deletions
2
Makefile
2
Makefile
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
COMMIT := $(shell git rev-parse --short HEAD)
|
COMMIT := $(shell git rev-parse --short HEAD)
|
||||||
TD_COMMIT := "5bbfc1cf5dab94f82e02f3430ded7241d4653551"
|
TD_COMMIT := "5bbfc1cf5dab94f82e02f3430ded7241d4653551"
|
||||||
VERSION := "v1.12.5"
|
VERSION := "v1.12.6"
|
||||||
MAKEOPTS := "-j4"
|
MAKEOPTS := "-j4"
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import (
|
||||||
goxmpp "gosrc.io/xmpp"
|
goxmpp "gosrc.io/xmpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string = "1.12.5"
|
var version string = "1.12.6"
|
||||||
var commit string
|
var commit string
|
||||||
|
|
||||||
var sm *goxmpp.StreamManager
|
var sm *goxmpp.StreamManager
|
||||||
|
|
|
||||||
43
telegram/cache/cache.go
vendored
43
telegram/cache/cache.go
vendored
|
|
@ -16,7 +16,8 @@ type Status struct {
|
||||||
// Cache allows operating the chats and users cache in
|
// Cache allows operating the chats and users cache in
|
||||||
// a thread-safe manner
|
// a thread-safe manner
|
||||||
type Cache struct {
|
type Cache struct {
|
||||||
chats map[int64]*client.Chat
|
ownChats map[int64]*client.Chat
|
||||||
|
auxChats map[int64]*client.Chat
|
||||||
users map[int64]*client.User
|
users map[int64]*client.User
|
||||||
statuses map[int64]*Status
|
statuses map[int64]*Status
|
||||||
chatsLock sync.Mutex
|
chatsLock sync.Mutex
|
||||||
|
|
@ -27,7 +28,8 @@ type Cache struct {
|
||||||
// NewCache initializes a cache
|
// NewCache initializes a cache
|
||||||
func NewCache() *Cache {
|
func NewCache() *Cache {
|
||||||
return &Cache{
|
return &Cache{
|
||||||
chats: map[int64]*client.Chat{},
|
ownChats: map[int64]*client.Chat{},
|
||||||
|
auxChats: map[int64]*client.Chat{},
|
||||||
users: map[int64]*client.User{},
|
users: map[int64]*client.User{},
|
||||||
statuses: map[int64]*Status{},
|
statuses: map[int64]*Status{},
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +42,23 @@ func (cache *Cache) ChatsKeys() []int64 {
|
||||||
defer cache.chatsLock.Unlock()
|
defer cache.chatsLock.Unlock()
|
||||||
|
|
||||||
var keys []int64
|
var keys []int64
|
||||||
for id := range cache.chats {
|
for id := range cache.ownChats {
|
||||||
|
keys = append(keys, id)
|
||||||
|
}
|
||||||
|
for id := range cache.auxChats {
|
||||||
|
keys = append(keys, id)
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
// OwnChatsKeys grabs only own chat ids synchronously to avoid lockups
|
||||||
|
// while they are used
|
||||||
|
func (cache *Cache) OwnChatsKeys() []int64 {
|
||||||
|
cache.chatsLock.Lock()
|
||||||
|
defer cache.chatsLock.Unlock()
|
||||||
|
|
||||||
|
var keys []int64
|
||||||
|
for id := range cache.ownChats {
|
||||||
keys = append(keys, id)
|
keys = append(keys, id)
|
||||||
}
|
}
|
||||||
return keys
|
return keys
|
||||||
|
|
@ -84,7 +102,10 @@ func (cache *Cache) GetChat(id int64) (*client.Chat, bool) {
|
||||||
cache.chatsLock.Lock()
|
cache.chatsLock.Lock()
|
||||||
defer cache.chatsLock.Unlock()
|
defer cache.chatsLock.Unlock()
|
||||||
|
|
||||||
chat, ok := cache.chats[id]
|
chat, ok := cache.ownChats[id]
|
||||||
|
if !ok {
|
||||||
|
chat, ok = cache.auxChats[id]
|
||||||
|
}
|
||||||
return chat, ok
|
return chat, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,11 +128,21 @@ func (cache *Cache) GetStatus(id int64) (*Status, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetChat stores a chat in the cache
|
// SetChat stores a chat in the cache
|
||||||
func (cache *Cache) SetChat(id int64, chat *client.Chat) {
|
func (cache *Cache) SetChat(id int64, chat *client.Chat, own bool) {
|
||||||
cache.chatsLock.Lock()
|
cache.chatsLock.Lock()
|
||||||
defer cache.chatsLock.Unlock()
|
defer cache.chatsLock.Unlock()
|
||||||
|
|
||||||
cache.chats[id] = chat
|
if own {
|
||||||
|
cache.ownChats[id] = chat
|
||||||
|
// move from aux to own, but not vice versa
|
||||||
|
// (own: true means that presences for the chat are needed
|
||||||
|
// for sure, false means just "not necessarily")
|
||||||
|
if _, ok := cache.auxChats[id]; ok {
|
||||||
|
delete(cache.auxChats, id)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cache.auxChats[id] = chat
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUser stores a user in the cache
|
// SetUser stores a user in the cache
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,7 @@ func (c *Client) helpString(typ CommandType, chatId int64) string {
|
||||||
var str strings.Builder
|
var str strings.Builder
|
||||||
|
|
||||||
commandMap := GetCommands(typ)
|
commandMap := GetCommands(typ)
|
||||||
chatType, chatTypeErr := c.GetChatType(chatId)
|
chatType, chatTypeErr := c.GetChatType(chatId, true)
|
||||||
|
|
||||||
str.WriteString("Available commands:\n")
|
str.WriteString("Available commands:\n")
|
||||||
for _, name := range SortedCommandKeys(commandMap) {
|
for _, name := range SortedCommandKeys(commandMap) {
|
||||||
|
|
@ -378,7 +378,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) (strin
|
||||||
return errors.Wrap(err, "Logout error").Error(), false
|
return errors.Wrap(err, "Logout error").Error(), false
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, id := range c.cache.ChatsKeys() {
|
for _, id := range c.cache.OwnChatsKeys() {
|
||||||
c.unsubscribe(id)
|
c.unsubscribe(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -505,7 +505,7 @@ func (c *Client) ProcessTransportCommand(cmdline string, resource string) (strin
|
||||||
|
|
||||||
return strings.Join(entries, "\n"), true
|
return strings.Join(entries, "\n"), true
|
||||||
case "report":
|
case "report":
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), false
|
return err.Error(), false
|
||||||
}
|
}
|
||||||
|
|
@ -555,7 +555,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
return notEnoughArguments, true, false
|
return notEnoughArguments, true, false
|
||||||
}
|
}
|
||||||
|
|
||||||
chatType, chatTypeErr := c.GetChatType(chatID)
|
chatType, chatTypeErr := c.GetChatType(chatID, true)
|
||||||
if chatTypeErr == nil && !IsCommandForChatType(command, chatType) {
|
if chatTypeErr == nil && !IsCommandForChatType(command, chatType) {
|
||||||
return "Not applicable for this chat type", true, false
|
return "Not applicable for this chat type", true, false
|
||||||
}
|
}
|
||||||
|
|
@ -835,7 +835,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
}
|
}
|
||||||
// invite @username to current groupchat
|
// invite @username to current groupchat
|
||||||
case "invite":
|
case "invite":
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
@ -862,7 +862,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
return link.InviteLink, true, true
|
return link.InviteLink, true, true
|
||||||
// kick @username from current group chat
|
// kick @username from current group chat
|
||||||
case "kick":
|
case "kick":
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
@ -881,7 +881,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
// mute [@username [n hours]]
|
// mute [@username [n hours]]
|
||||||
case "mute":
|
case "mute":
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
@ -918,7 +918,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
// unmute [@username]
|
// unmute [@username]
|
||||||
case "unmute":
|
case "unmute":
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
@ -946,7 +946,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
}
|
}
|
||||||
// ban @username from current chat [for N hours]
|
// ban @username from current chat [for N hours]
|
||||||
case "ban":
|
case "ban":
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
@ -974,7 +974,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
}
|
}
|
||||||
// unban @username
|
// unban @username
|
||||||
case "unban":
|
case "unban":
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
@ -992,7 +992,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
}
|
}
|
||||||
// promote @username to admin
|
// promote @username to admin
|
||||||
case "promote":
|
case "promote":
|
||||||
contact, _, err := c.GetContactByUsername(args[0])
|
contact, _, err := c.GetContactByUsername(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
@ -1064,7 +1064,7 @@ func (c *Client) ProcessChatCommand(chatID int64, cmdline string) (string, bool,
|
||||||
}
|
}
|
||||||
// close secret chat
|
// close secret chat
|
||||||
case "close":
|
case "close":
|
||||||
chat, _, err := c.GetContactByID(chatID, nil)
|
chat, _, err := c.GetContactByID(chatID, nil, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error(), true, false
|
return err.Error(), true, false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ func (c *Client) Disconnect(resource string, quit bool) bool {
|
||||||
log.Warn("Disconnecting from Telegram network...")
|
log.Warn("Disconnecting from Telegram network...")
|
||||||
|
|
||||||
// we're offline (unsubscribe if logout)
|
// we're offline (unsubscribe if logout)
|
||||||
for _, id := range c.cache.ChatsKeys() {
|
for _, id := range c.cache.OwnChatsKeys() {
|
||||||
args := gateway.SimplePresence(id, "unavailable")
|
args := gateway.SimplePresence(id, "unavailable")
|
||||||
c.sendPresence(args...)
|
c.sendPresence(args...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -186,13 +186,13 @@ func (c *Client) updateHandler() {
|
||||||
func (c *Client) updateUser(update *client.UpdateUser) {
|
func (c *Client) updateUser(update *client.UpdateUser) {
|
||||||
c.cache.SetUser(update.User.Id, update.User)
|
c.cache.SetUser(update.User.Id, update.User)
|
||||||
show, status, presenceType := c.userStatusToText(update.User.Status, update.User.Id)
|
show, status, presenceType := c.userStatusToText(update.User.Status, update.User.Id)
|
||||||
go c.ProcessStatusUpdate(update.User.Id, status, show, gateway.SPType(presenceType))
|
go c.ProcessStatusUpdate(update.User.Id, status, show, false, gateway.SPType(presenceType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// user status changed
|
// user status changed
|
||||||
func (c *Client) updateUserStatus(update *client.UpdateUserStatus) {
|
func (c *Client) updateUserStatus(update *client.UpdateUserStatus) {
|
||||||
show, status, presenceType := c.userStatusToText(update.Status, update.UserId)
|
show, status, presenceType := c.userStatusToText(update.Status, update.UserId)
|
||||||
go c.ProcessStatusUpdate(update.UserId, status, show, gateway.SPImmed(false), gateway.SPType(presenceType))
|
go c.ProcessStatusUpdate(update.UserId, status, show, false, gateway.SPImmed(false), gateway.SPType(presenceType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// new chat discovered
|
// new chat discovered
|
||||||
|
|
@ -206,14 +206,14 @@ func (c *Client) updateNewChat(update *client.UpdateNewChat) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.cache.SetChat(update.Chat.Id, update.Chat)
|
c.cache.SetChat(update.Chat.Id, update.Chat, true)
|
||||||
|
|
||||||
if update.Chat.Positions != nil && len(update.Chat.Positions) > 0 {
|
if update.Chat.Positions != nil && len(update.Chat.Positions) > 0 {
|
||||||
c.subscribeToID(update.Chat.Id, update.Chat)
|
c.subscribeToID(update.Chat.Id, update.Chat)
|
||||||
}
|
}
|
||||||
|
|
||||||
if update.Chat.Id < 0 {
|
if update.Chat.Id < 0 {
|
||||||
c.ProcessStatusUpdate(update.Chat.Id, update.Chat.Title, "chat")
|
c.ProcessStatusUpdate(update.Chat.Id, update.Chat.Title, "chat", true)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
@ -377,7 +377,7 @@ func (c *Client) updateDeleteMessages(update *client.UpdateDeleteMessages) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c.Session.IgnoreGroupDeletions {
|
if c.Session.IgnoreGroupDeletions {
|
||||||
chatType, chatTypeErr := c.GetChatType(update.ChatId)
|
chatType, chatTypeErr := c.GetChatType(update.ChatId, false)
|
||||||
if chatTypeErr == nil && (chatType == ChatTypeBasicGroup || chatType == ChatTypeSupergroup) {
|
if chatTypeErr == nil && (chatType == ChatTypeBasicGroup || chatType == ChatTypeSupergroup) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -432,9 +432,9 @@ func (c *Client) updateChatTitle(update *client.UpdateChatTitle) {
|
||||||
gateway.SetNickname(c.jid, strconv.FormatInt(update.ChatId, 10), update.Title, c.xmpp)
|
gateway.SetNickname(c.jid, strconv.FormatInt(update.ChatId, 10), update.Title, c.xmpp)
|
||||||
|
|
||||||
// set also the status (for group chats only)
|
// set also the status (for group chats only)
|
||||||
chat, user, _ := c.GetContactByID(update.ChatId, nil)
|
chat, user, _ := c.GetContactByID(update.ChatId, nil, false)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
c.ProcessStatusUpdate(update.ChatId, update.Title, "chat", gateway.SPImmed(true))
|
c.ProcessStatusUpdate(update.ChatId, update.Title, "chat", false, gateway.SPImmed(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
// update chat title in the cache
|
// update chat title in the cache
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ const (
|
||||||
const AVATAR_SIZE_LIMIT int64 = 128 * 1024
|
const AVATAR_SIZE_LIMIT int64 = 128 * 1024
|
||||||
|
|
||||||
// GetContactByUsername resolves username to user id retrieves user and chat information
|
// GetContactByUsername resolves username to user id retrieves user and chat information
|
||||||
func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.User, error) {
|
func (c *Client) GetContactByUsername(username string, own bool) (*client.Chat, *client.User, error) {
|
||||||
if !c.Online() {
|
if !c.Online() {
|
||||||
return nil, nil, errOffline
|
return nil, nil, errOffline
|
||||||
}
|
}
|
||||||
|
|
@ -119,11 +119,11 @@ func (c *Client) GetContactByUsername(username string) (*client.Chat, *client.Us
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.GetContactByID(userID, chat)
|
return c.GetContactByID(userID, chat, own)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetContactByID gets user and chat information from cache (or tries to retrieve it, if missing)
|
// GetContactByID gets user and chat information from cache (or tries to retrieve it, if missing)
|
||||||
func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *client.User, error) {
|
func (c *Client) GetContactByID(id int64, chat *client.Chat, own bool) (*client.Chat, *client.User, error) {
|
||||||
if !c.Online() || id == 0 {
|
if !c.Online() || id == 0 {
|
||||||
return nil, nil, errOffline
|
return nil, nil, errOffline
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +158,9 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.cache.SetChat(id, cacheChat)
|
c.cache.SetChat(id, cacheChat, own)
|
||||||
} else {
|
} else {
|
||||||
c.cache.SetChat(id, chat)
|
c.cache.SetChat(id, chat, own)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if chat == nil {
|
if chat == nil {
|
||||||
|
|
@ -171,7 +171,7 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetChatType obtains chat type from its information
|
// GetChatType obtains chat type from its information
|
||||||
func (c *Client) GetChatType(id int64) (ChatType, error) {
|
func (c *Client) GetChatType(id int64, own bool) (ChatType, error) {
|
||||||
if !c.Online() || id == 0 {
|
if !c.Online() || id == 0 {
|
||||||
return ChatTypeUnknown, errOffline
|
return ChatTypeUnknown, errOffline
|
||||||
}
|
}
|
||||||
|
|
@ -187,7 +187,7 @@ func (c *Client) GetChatType(id int64) (ChatType, error) {
|
||||||
return ChatTypeUnknown, err
|
return ChatTypeUnknown, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.cache.SetChat(id, chat)
|
c.cache.SetChat(id, chat, own)
|
||||||
}
|
}
|
||||||
|
|
||||||
chatType := chat.Type.ChatTypeType()
|
chatType := chat.Type.ChatTypeType()
|
||||||
|
|
@ -209,8 +209,8 @@ func (c *Client) GetChatType(id int64) (ChatType, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsPM checks if a chat is PM
|
// IsPM checks if a chat is PM
|
||||||
func (c *Client) IsPM(id int64) (bool, error) {
|
func (c *Client) IsPM(id int64, own bool) (bool, error) {
|
||||||
typ, err := c.GetChatType(id)
|
typ, err := c.GetChatType(id, own)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
@ -222,8 +222,8 @@ func (c *Client) IsPM(id int64) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsBot checks if a chat is a bot
|
// IsBot checks if a chat is a bot
|
||||||
func (c *Client) IsBot(id int64) (bool, error) {
|
func (c *Client) IsBot(id int64, own bool) (bool, error) {
|
||||||
_, user, err := c.GetContactByID(id, nil)
|
_, user, err := c.GetContactByID(id, nil, own)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
@ -395,7 +395,7 @@ func (c *Client) GetPhotoBase64(photo *client.File) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessStatusUpdate sets contact status
|
// ProcessStatusUpdate sets contact status
|
||||||
func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, oldArgs ...args.V) error {
|
func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, own bool, oldArgs ...args.V) error {
|
||||||
if !c.Online() {
|
if !c.Online() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -404,7 +404,7 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, o
|
||||||
"chat_id": chatID,
|
"chat_id": chatID,
|
||||||
}).Info("Status update for")
|
}).Info("Status update for")
|
||||||
|
|
||||||
chat, user, err := c.GetContactByID(chatID, nil)
|
chat, user, err := c.GetContactByID(chatID, nil, own)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -470,7 +470,7 @@ func (c *Client) FormatContact(chatID int64) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
chat, user, err := c.GetContactByID(chatID, nil)
|
chat, user, err := c.GetContactByID(chatID, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "unknown contact: " + err.Error()
|
return "unknown contact: " + err.Error()
|
||||||
}
|
}
|
||||||
|
|
@ -1091,7 +1091,7 @@ func (c *Client) isCarbonsEnabled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string, suppressReply bool) (string, *gateway.Reply) {
|
func (c *Client) messageToPrefix(message *client.Message, previewString string, fileString string, suppressReply bool) (string, *gateway.Reply) {
|
||||||
isPM, err := c.IsPM(message.ChatId)
|
isPM, err := c.IsPM(message.ChatId, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Could not determine if chat is PM: %v", err)
|
log.Errorf("Could not determine if chat is PM: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1215,8 +1215,8 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
||||||
ChatId: chatId,
|
ChatId: chatId,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.cache.SetChat(chatId, chat)
|
c.cache.SetChat(chatId, chat, true)
|
||||||
go c.ProcessStatusUpdate(chatId, "", "", gateway.SPImmed(true))
|
go c.ProcessStatusUpdate(chatId, "", "", true, gateway.SPImmed(true))
|
||||||
text = "<Chat photo has changed>"
|
text = "<Chat photo has changed>"
|
||||||
|
|
||||||
if chat.Photo == nil {
|
if chat.Photo == nil {
|
||||||
|
|
@ -1258,7 +1258,7 @@ func (c *Client) ProcessIncomingMessage(chatId int64, message *client.Message) {
|
||||||
var ignorePrefix bool
|
var ignorePrefix bool
|
||||||
if oobSwap {
|
if oobSwap {
|
||||||
if text == "" || message.Content.MessageContentType() == client.TypeMessageSticker {
|
if text == "" || message.Content.MessageContentType() == client.TypeMessageSticker {
|
||||||
chatType, err := c.GetChatType(chatId)
|
chatType, err := c.GetChatType(chatId, true)
|
||||||
ignorePrefix = err == nil && (chatType != ChatTypeBasicGroup && chatType != ChatTypeSupergroup) && c.isCarbonsEnabled()
|
ignorePrefix = err == nil && (chatType != ChatTypeBasicGroup && chatType != ChatTypeSupergroup) && c.isCarbonsEnabled()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1456,9 +1456,9 @@ func (c *Client) prepareOutgoingMessageContent(text string, file *client.InputFi
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChatsKeys proxies the following function from unexported cache
|
// OwnChatsKeys proxies the following function from unexported cache
|
||||||
func (c *Client) ChatsKeys() []int64 {
|
func (c *Client) OwnChatsKeys() []int64 {
|
||||||
return c.cache.ChatsKeys()
|
return c.cache.OwnChatsKeys()
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusesRange proxies the following function from unexported cache
|
// StatusesRange proxies the following function from unexported cache
|
||||||
|
|
@ -1515,8 +1515,8 @@ func (c *Client) roster(resource string) {
|
||||||
|
|
||||||
log.Warnf("Sending roster for %v", resource)
|
log.Warnf("Sending roster for %v", resource)
|
||||||
|
|
||||||
for _, chat := range c.cache.ChatsKeys() {
|
for _, chat := range c.cache.OwnChatsKeys() {
|
||||||
c.ProcessStatusUpdate(chat, "", "")
|
c.ProcessStatusUpdate(chat, "", "", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.sendPresence(gateway.SPStatus("Logged in as: " + c.Session.Login))
|
c.sendPresence(gateway.SPStatus("Logged in as: " + c.Session.Login))
|
||||||
|
|
@ -1630,7 +1630,7 @@ func (c *Client) subscribeToID(id int64, chat *client.Chat) {
|
||||||
args := gateway.SimplePresence(id, "subscribe")
|
args := gateway.SimplePresence(id, "subscribe")
|
||||||
|
|
||||||
if chat == nil {
|
if chat == nil {
|
||||||
chat, _, _ = c.GetContactByID(id, nil)
|
chat, _, _ = c.GetContactByID(id, nil, true)
|
||||||
}
|
}
|
||||||
if chat != nil {
|
if chat != nil {
|
||||||
args = append(args, gateway.SPNickname(chat.Title))
|
args = append(args, gateway.SPNickname(chat.Title))
|
||||||
|
|
@ -1660,7 +1660,7 @@ func (c *Client) prepareDiskSpace(size uint64) {
|
||||||
|
|
||||||
func (c *Client) GetVcardInfo(toID int64) (VCardInfo, error) {
|
func (c *Client) GetVcardInfo(toID int64) (VCardInfo, error) {
|
||||||
var info VCardInfo
|
var info VCardInfo
|
||||||
chat, user, err := c.GetContactByID(toID, nil)
|
chat, user, err := c.GetContactByID(toID, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
@ -1687,7 +1687,7 @@ func (c *Client) GetVcardInfo(toID int64) (VCardInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UpdateChatNicknames() {
|
func (c *Client) UpdateChatNicknames() {
|
||||||
for _, id := range c.cache.ChatsKeys() {
|
for _, id := range c.cache.OwnChatsKeys() {
|
||||||
chat, ok := c.cache.GetChat(id)
|
chat, ok := c.cache.GetChat(id)
|
||||||
if ok {
|
if ok {
|
||||||
newArgs := []args.V{
|
newArgs := []args.V{
|
||||||
|
|
@ -1810,7 +1810,7 @@ func (c *Client) GetChatMembers(chatID int64, limited bool, query string, member
|
||||||
if limited {
|
if limited {
|
||||||
limit = 20
|
limit = 20
|
||||||
|
|
||||||
chat, _, err := c.GetContactByID(chatID, nil)
|
chat, _, err := c.GetContactByID(chatID, nil, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if chat == nil {
|
} else if chat == nil {
|
||||||
|
|
|
||||||
|
|
@ -141,6 +141,7 @@ func heartbeat(component *xmpp.Component) {
|
||||||
chatID,
|
chatID,
|
||||||
session.LastSeenStatus(delayedStatus.TimestampOnline),
|
session.LastSeenStatus(delayedStatus.TimestampOnline),
|
||||||
"away",
|
"away",
|
||||||
|
true,
|
||||||
)
|
)
|
||||||
delete(session.DelayedStatuses, chatID)
|
delete(session.DelayedStatuses, chatID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -363,7 +363,7 @@ func handleSubscription(s xmpp.Sender, p stanza.Presence) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go session.ProcessStatusUpdate(toID, "", "", gateway.SPImmed(false))
|
go session.ProcessStatusUpdate(toID, "", "", true, gateway.SPImmed(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
||||||
|
|
@ -434,6 +434,7 @@ func handlePresence(s xmpp.Sender, p stanza.Presence) {
|
||||||
status.ID,
|
status.ID,
|
||||||
description,
|
description,
|
||||||
show,
|
show,
|
||||||
|
true,
|
||||||
newArgs...,
|
newArgs...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -548,7 +549,7 @@ func handleGetAvatarDataIq(s xmpp.Sender, iq *stanza.IQ, pubsub *stanza.PubSubGe
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Info("Could not find avatar in cache, fetching immediately")
|
log.Info("Could not find avatar in cache, fetching immediately")
|
||||||
|
|
||||||
chat, _, err := session.GetContactByID(chatId, nil)
|
chat, _, err := session.GetContactByID(chatId, nil, true)
|
||||||
if err != nil || chat == nil || chat.Photo == nil {
|
if err != nil || chat == nil || chat.Photo == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -609,7 +610,7 @@ func getTelegramChatType(from string, to string) (telegram.ChatType, error) {
|
||||||
if ok {
|
if ok {
|
||||||
session, ok := sessions[bare]
|
session, ok := sessions[bare]
|
||||||
if ok {
|
if ok {
|
||||||
return session.GetChatType(toId)
|
return session.GetChatType(toId, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -713,7 +714,7 @@ func handleGetDiscoItems(s xmpp.Sender, iq *stanza.IQ, di *stanza.DiscoItems) {
|
||||||
isOnline = session.Online()
|
isOnline = session.Online()
|
||||||
|
|
||||||
if toOk {
|
if toOk {
|
||||||
isBot, err := session.IsBot(toID)
|
isBot, err := session.IsBot(toID, true)
|
||||||
if err == nil && isBot {
|
if err == nil && isBot {
|
||||||
di.AddItem(iq.To, "botmenu", "Bot Menu")
|
di.AddItem(iq.To, "botmenu", "Bot Menu")
|
||||||
}
|
}
|
||||||
|
|
@ -1377,8 +1378,8 @@ func sendPubSubAvatarNotifications(s xmpp.Sender, jid string, session *telegram.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, chatId := range session.ChatsKeys() {
|
for _, chatId := range session.OwnChatsKeys() {
|
||||||
chat, _, err := session.GetContactByID(chatId, nil)
|
chat, _, err := session.GetContactByID(chatId, nil, true)
|
||||||
if err != nil || chat == nil {
|
if err != nil || chat == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue