user-info now shows the primary platform of the user and it's more resilient
This commit is contained in:
parent
fcc76b05ca
commit
30182f9222
1 changed files with 17 additions and 10 deletions
|
@ -165,26 +165,33 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := p.Q().
|
pref, appErr := p.API.GetPreferenceForUser(user.Id, "pp_com.mattermost.msteams-sync", "platform")
|
||||||
|
if appErr != nil {
|
||||||
|
return p.sendEphemeralAndExit(fmt.Sprintf("ERROR getting user preferences: %s", appErr.Error()), args)
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, _ := p.Q().
|
||||||
Select("msteamsuserid, token, lastconnectat, lastdisconnectat").
|
Select("msteamsuserid, token, lastconnectat, lastdisconnectat").
|
||||||
From("msteamssync_users").
|
From("msteamssync_users").
|
||||||
Where(sq.Eq{"mmuserid": user.Id}).
|
Where(sq.Eq{"mmuserid": user.Id}).
|
||||||
Query()
|
Query()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return p.sendEphemeralAndExit(fmt.Sprintf("ERROR querying for msteamssync user: %s", err), args)
|
// return p.sendEphemeralAndExit(fmt.Sprintf("ERROR querying for msteamssync user: %s", err), args)
|
||||||
}
|
// }
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
var mmTeamsUserID string
|
var mmTeamsUserID string
|
||||||
var token string
|
var token string
|
||||||
var lastConnectAt int
|
var lastConnectAt int
|
||||||
var lastDisconnectAt int
|
var lastDisconnectAt int
|
||||||
if !rows.Next() {
|
// if !rows.Next() {
|
||||||
return p.sendEphemeralAndExit(fmt.Sprintf("User %q not found in the msteamssync_users table", email), args)
|
// return p.sendEphemeralAndExit(fmt.Sprintf("User %q not found in the msteamssync_users table", email), args)
|
||||||
}
|
// }
|
||||||
|
if rows.Next() {
|
||||||
if err := rows.Scan(&mmTeamsUserID, &token, &lastConnectAt, &lastDisconnectAt); err != nil {
|
if err := rows.Scan(&mmTeamsUserID, &token, &lastConnectAt, &lastDisconnectAt); err != nil {
|
||||||
return p.sendEphemeralAndExit(fmt.Sprintf("ERROR scanning rows: %s", err), args)
|
return p.sendEphemeralAndExit(fmt.Sprintf("ERROR scanning rows: %s", err), args)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var remoteID string
|
var remoteID string
|
||||||
if user.RemoteId != nil {
|
if user.RemoteId != nil {
|
||||||
|
@ -195,7 +202,7 @@ func (p *Plugin) ExecuteCommand(_ *plugin.Context, args *model.CommandArgs) (*mo
|
||||||
if token != "" {
|
if token != "" {
|
||||||
hasToken = true
|
hasToken = true
|
||||||
}
|
}
|
||||||
return p.sendEphemeralAndExit(fmt.Sprintf("User %q has\n - `mmTeamsUserID`: %s\n - `hasToken`: %v\n - `lastConnectAt`: %d\n - `lastDisconnectAt`: %d\n - `remoteID`: %s", email, mmTeamsUserID, hasToken, lastConnectAt, lastDisconnectAt, remoteID), args)
|
return p.sendEphemeralAndExit(fmt.Sprintf("User %q has\n - `mmTeamsUserID`: %s\n - `hasToken`: %v\n - `lastConnectAt`: %d\n - `lastDisconnectAt`: %d\n - `remoteID`: %s\n - `primaryPlatform preference`: %s", email, mmTeamsUserID, hasToken, lastConnectAt, lastDisconnectAt, remoteID, pref.Value), args)
|
||||||
case "channel-info":
|
case "channel-info":
|
||||||
if len(parameters) != 1 {
|
if len(parameters) != 1 {
|
||||||
return p.sendEphemeralAndExit("channel-info must receive the channel ID", args)
|
return p.sendEphemeralAndExit("channel-info must receive the channel ID", args)
|
||||||
|
|
Loading…
Reference in a new issue