Fix status update for users who blacklisted you or were online long time ago
This commit is contained in:
parent
5a48600b7a
commit
32036e3f90
|
@ -133,14 +133,14 @@ func (c *Client) updateHandler() {
|
||||||
// new user discovered
|
// new user discovered
|
||||||
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 := 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)
|
go c.ProcessStatusUpdate(update.User.Id, status, show, 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 := 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))
|
go c.ProcessStatusUpdate(update.UserId, status, show, gateway.SPImmed(false), gateway.SPType(presenceType))
|
||||||
}
|
}
|
||||||
|
|
||||||
// new chat discovered
|
// new chat discovered
|
||||||
|
|
|
@ -106,8 +106,8 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli
|
||||||
return chat, user, nil
|
return chat, user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) userStatusToText(status client.UserStatus, chatID int64) (string, string) {
|
func (c *Client) userStatusToText(status client.UserStatus, chatID int64) (string, string, string) {
|
||||||
var show, textStatus string
|
var show, textStatus, presenceType string
|
||||||
|
|
||||||
switch status.UserStatusType() {
|
switch status.UserStatusType() {
|
||||||
case client.TypeUserStatusOnline:
|
case client.TypeUserStatusOnline:
|
||||||
|
@ -128,11 +128,11 @@ func (c *Client) userStatusToText(status client.UserStatus, chatID int64) (strin
|
||||||
delete(c.DelayedStatuses, chatID)
|
delete(c.DelayedStatuses, chatID)
|
||||||
c.DelayedStatusesLock.Unlock()
|
c.DelayedStatusesLock.Unlock()
|
||||||
case client.TypeUserStatusLastWeek:
|
case client.TypeUserStatusLastWeek:
|
||||||
show, textStatus = "unavailable", "Last seen last week"
|
show, textStatus = "xa", "Last seen last week"
|
||||||
case client.TypeUserStatusLastMonth:
|
case client.TypeUserStatusLastMonth:
|
||||||
show, textStatus = "unavailable", "Last seen last month"
|
show, textStatus = "xa", "Last seen last month"
|
||||||
case client.TypeUserStatusEmpty:
|
case client.TypeUserStatusEmpty:
|
||||||
show, textStatus = "unavailable", "Last seen a long time ago"
|
presenceType, textStatus = "unavailable", "Last seen a long time ago"
|
||||||
case client.TypeUserStatusOffline:
|
case client.TypeUserStatusOffline:
|
||||||
offlineStatus, _ := status.(*client.UserStatusOffline)
|
offlineStatus, _ := status.(*client.UserStatusOffline)
|
||||||
// this will stop working in 2038 O\
|
// this will stop working in 2038 O\
|
||||||
|
@ -150,7 +150,7 @@ func (c *Client) userStatusToText(status client.UserStatus, chatID int64) (strin
|
||||||
c.DelayedStatusesLock.Unlock()
|
c.DelayedStatusesLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
return show, textStatus
|
return show, textStatus, presenceType
|
||||||
}
|
}
|
||||||
|
|
||||||
// LastSeenStatus formats a timestamp to a "Last seen at" string
|
// LastSeenStatus formats a timestamp to a "Last seen at" string
|
||||||
|
@ -161,7 +161,7 @@ func (c *Client) LastSeenStatus(timestamp int64) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessStatusUpdate sets contact status
|
// ProcessStatusUpdate sets contact status
|
||||||
func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, args ...args.V) error {
|
func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, oldArgs ...args.V) error {
|
||||||
if !c.Online() {
|
if !c.Online() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -194,12 +194,17 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var presenceType string
|
||||||
|
if gateway.SPType.IsSet(oldArgs) {
|
||||||
|
presenceType = gateway.SPType.Get(oldArgs)
|
||||||
|
}
|
||||||
|
|
||||||
cachedStatus, ok := c.cache.GetStatus(chatID)
|
cachedStatus, ok := c.cache.GetStatus(chatID)
|
||||||
if status == "" {
|
if status == "" {
|
||||||
if ok {
|
if ok {
|
||||||
show, status = cachedStatus.XMPP, cachedStatus.Description
|
show, status = cachedStatus.XMPP, cachedStatus.Description
|
||||||
} else if user != nil && user.Status != nil {
|
} else if user != nil && user.Status != nil {
|
||||||
show, status = c.userStatusToText(user.Status, chatID)
|
show, status, presenceType = c.userStatusToText(user.Status, chatID)
|
||||||
} else {
|
} else {
|
||||||
show, status = "chat", chat.Title
|
show, status = "chat", chat.Title
|
||||||
}
|
}
|
||||||
|
@ -207,14 +212,21 @@ func (c *Client) ProcessStatusUpdate(chatID int64, status string, show string, a
|
||||||
|
|
||||||
c.cache.SetStatus(chatID, show, status)
|
c.cache.SetStatus(chatID, show, status)
|
||||||
|
|
||||||
return gateway.SendPresence(
|
newArgs := []args.V {
|
||||||
c.xmpp,
|
|
||||||
c.jid,
|
|
||||||
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
|
gateway.SPFrom(strconv.FormatInt(chatID, 10)),
|
||||||
gateway.SPShow(show),
|
gateway.SPShow(show),
|
||||||
gateway.SPStatus(status),
|
gateway.SPStatus(status),
|
||||||
gateway.SPPhoto(photo),
|
gateway.SPPhoto(photo),
|
||||||
gateway.SPImmed(gateway.SPImmed.Get(args)),
|
gateway.SPImmed(gateway.SPImmed.Get(oldArgs)),
|
||||||
|
}
|
||||||
|
if presenceType != "" {
|
||||||
|
newArgs = append(newArgs, gateway.SPType(presenceType))
|
||||||
|
}
|
||||||
|
|
||||||
|
return gateway.SendPresence(
|
||||||
|
c.xmpp,
|
||||||
|
c.jid,
|
||||||
|
newArgs...,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue