mirror of
https://dev.narayana.im/narayana/telegabber.git
synced 2026-08-04 19:57:07 +00:00
Prevent nil crashes on TelegramSession instances
This commit is contained in:
parent
0e6fbc652f
commit
cca759f255
3 changed files with 10 additions and 4 deletions
|
|
@ -137,6 +137,11 @@ const (
|
|||
)
|
||||
type ChatMemberStatus int
|
||||
|
||||
// IsNil is a simple check to use client objects via interfaces safely
|
||||
func (c *Client) IsNil() bool {
|
||||
return c == nil
|
||||
}
|
||||
|
||||
// GetContactByUsername resolves username to user id retrieves user and chat information
|
||||
func (c *Client) GetContactByUsername(username string, own bool) (*client.Chat, *client.User, error) {
|
||||
if !c.Online() {
|
||||
|
|
|
|||
|
|
@ -839,7 +839,7 @@ func GetDiscoInfo(session TelegramSession, node string, to string) (*stanza.Disc
|
|||
|
||||
if node == "" {
|
||||
var isMuc bool
|
||||
if session != nil {
|
||||
if !session.IsNil() {
|
||||
conf := session.GetPersistenceSession()
|
||||
if conf.MUC {
|
||||
if toOk && toIsGroup {
|
||||
|
|
@ -934,7 +934,7 @@ func GetDiscoInfo(session TelegramSession, node string, to string) (*stanza.Disc
|
|||
disco.AddFeatures("jabber:iq:version")
|
||||
disco.AddFeatures("urn:xmpp:time")
|
||||
} else if node == "x-roomuser-item" {
|
||||
if session != nil {
|
||||
if !session.IsNil() {
|
||||
conf := session.GetPersistenceSession()
|
||||
if conf.MUC {
|
||||
if toOk && toIsGroup {
|
||||
|
|
@ -950,7 +950,7 @@ func GetDiscoInfo(session TelegramSession, node string, to string) (*stanza.Disc
|
|||
// noop yet, empty result as intended, TODO: add XHTML whenever supported
|
||||
} else if strings.HasPrefix(node, capsNode) {
|
||||
nodeParts := strings.Split(node, "#")
|
||||
if session != nil && len(nodeParts) == 2 && nodeParts[0] == capsNode {
|
||||
if !session.IsNil() && len(nodeParts) == 2 && nodeParts[0] == capsNode {
|
||||
di, ok := session.GetVerDisco(nodeParts[1])
|
||||
if ok && di != nil {
|
||||
return di, 0
|
||||
|
|
@ -959,7 +959,7 @@ func GetDiscoInfo(session TelegramSession, node string, to string) (*stanza.Disc
|
|||
} else {
|
||||
var chatType ChatType
|
||||
var chatTypeErr error
|
||||
if session != nil {
|
||||
if !session.IsNil() {
|
||||
chatType, _, chatTypeErr = session.GetChatType(toID, true)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,6 +209,7 @@ func IsCommandForChatType(cmd command, chatType ChatType) bool {
|
|||
|
||||
// TelegramSession exists merely to circumvent a circular dependency
|
||||
type TelegramSession interface {
|
||||
IsNil() bool
|
||||
GetPersistenceSession() *persistence.Session
|
||||
GetContactByID(int64, *client.Chat, bool) (*client.Chat, *client.User, error)
|
||||
IsGroup(*client.Chat) bool
|
||||
|
|
|
|||
Loading…
Reference in a new issue