Add UpdatedConversationAttribute Event for the UI #509
|
@ -212,9 +212,10 @@ const (
|
|||
|
||||
// Profile Attribute Event
|
||||
UpdatedProfileAttribute = Type("UpdatedProfileAttribute")
|
||||
|
||||
StartingStorageMiragtion = Type("StartingStorageMigration")
|
||||
DoneStorageMigration = Type("DoneStorageMigration")
|
||||
// Conversation Attribute Update...
|
||||
UpdatedConversationAttribute = Type("UpdatedConversationAttribute")
|
||||
StartingStorageMiragtion = Type("StartingStorageMigration")
|
||||
DoneStorageMigration = Type("DoneStorageMigration")
|
||||
|
||||
TokenManagerInfo = Type("TokenManagerInfo")
|
||||
TriggerAntispamCheck = Type("TriggerAntispamCheck")
|
||||
|
|
|
@ -64,10 +64,29 @@ func (pne ProfileValueExtension) OnContactReceiveValue(profile peer.CwtchPeer, c
|
|||
// Allow public profile parameters to be added as contact specific attributes...
|
||||
scope, zone, _ := szp.GetScopeZonePath()
|
||||
if exists && scope.IsPublic() && zone == attr.ProfileZone {
|
||||
err := profile.SetConversationAttribute(conversation.ID, szp, value)
|
||||
if err != nil {
|
||||
log.Errorf("error setting conversation attribute %v", err)
|
||||
|
||||
// Check the current value of the attribute
|
||||
currentValue, err := profile.GetConversationAttribute(conversation.ID, szp)
|
||||
if err == nil && currentValue == value {
|
||||
// Value exists and the value is the same, short-circuit
|
||||
return
|
||||
}
|
||||
|
||||
// Save the new Attribute
|
||||
err = profile.SetConversationAttribute(conversation.ID, szp, value)
|
||||
if err != nil {
|
||||
// Something else wen't wrong.. short-circuit
|
||||
log.Errorf("error setting conversation attribute %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Finally publish an update for listeners to react to.
|
||||
scope, zone, zpath := szp.GetScopeZonePath()
|
||||
profile.PublishEvent(event.NewEvent(event.UpdatedConversationAttribute, map[event.Field]string{
|
||||
event.Scope: string(scope),
|
||||
event.Path: string(zone.ConstructZonedPath(zpath)),
|
||||
event.Data: value,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue