Add UpdatedConversationAttribute Event for the UI
continuous-integration/drone/pr Build is pending
Details
continuous-integration/drone/pr Build is pending
Details
This commit is contained in:
parent
d9298f84b2
commit
4e0fbbc1de
|
@ -212,7 +212,8 @@ const (
|
||||||
|
|
||||||
// Profile Attribute Event
|
// Profile Attribute Event
|
||||||
UpdatedProfileAttribute = Type("UpdatedProfileAttribute")
|
UpdatedProfileAttribute = Type("UpdatedProfileAttribute")
|
||||||
|
// Conversation Attribute Update...
|
||||||
|
UpdatedConversationAttribute = Type("UpdatedConversationAttribute")
|
||||||
StartingStorageMiragtion = Type("StartingStorageMigration")
|
StartingStorageMiragtion = Type("StartingStorageMigration")
|
||||||
DoneStorageMigration = Type("DoneStorageMigration")
|
DoneStorageMigration = Type("DoneStorageMigration")
|
||||||
|
|
||||||
|
|
|
@ -64,10 +64,29 @@ func (pne ProfileValueExtension) OnContactReceiveValue(profile peer.CwtchPeer, c
|
||||||
// Allow public profile parameters to be added as contact specific attributes...
|
// Allow public profile parameters to be added as contact specific attributes...
|
||||||
scope, zone, _ := szp.GetScopeZonePath()
|
scope, zone, _ := szp.GetScopeZonePath()
|
||||||
if exists && scope.IsPublic() && zone == attr.ProfileZone {
|
if exists && scope.IsPublic() && zone == attr.ProfileZone {
|
||||||
err := profile.SetConversationAttribute(conversation.ID, szp, value)
|
|
||||||
if err != nil {
|
// Check the current value of the attribute
|
||||||
log.Errorf("error setting conversation attribute %v", err)
|
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