Documentation ¶
Index ¶
- Constants
- Variables
- func EnrichNewPeer(handle string, ph *PeerHelper, ev *EventProfileEnvelope) error
- func GetPicturePath(pic *image) string
- func ImageToString(img *image) string
- func InitGlobalSettingsFile(directory string, password string) error
- func NewImage(val, t string) *image
- func RandomGroupImage(handle string) string
- func RandomProfileImage(onion string) string
- func StringToImage(str string) (*image, error)
- func WriteGlobalSettings(globalSettings GlobalSettings)
- type Contact
- type EventHandler
- type EventProfileEnvelope
- type GlobalSettings
- type PeerHelper
- func (p *PeerHelper) CountUnread(messages []model.Message, lastRead time.Time) int
- func (p *PeerHelper) GetNick(id string) string
- func (p *PeerHelper) GetProfilePic(id string) string
- func (p *PeerHelper) GetTimeline(handle string) *model.Timeline
- func (p *PeerHelper) GetWithSetDefault(id string, key string, defaultVal string) string
- func (p *PeerHelper) InitLastReadTime(id string) time.Time
- func (p *PeerHelper) IsGroup(id string) bool
- func (p *PeerHelper) IsPeer(id string) bool
- func (p *PeerHelper) IsServer(id string) bool
Constants ¶
const ( // TypeImageDistro is a reletive path to any of the distributed images in cwtch/ui in the assets folder TypeImageDistro = "distro" // TypeImageComposition will be an face image composed of a recipe of parts like faceType, eyeType, etc TypeImageComposition = "composition" )
Image types we support
const ( Warn = event.Field("Warn") Error = event.Field("Error") Debug = event.Field("Debug") Info = event.Field("Info") )
Logging Levels as Event Fields. Note: Unlike most event we don't cae about the *value* of the field, only the presence. If more than one of these fields is present in a single SetLoggingLevel event then the highest logging level is used. INFO < WARN < ERROR < DEBUG
const ( CwtchStarted = event.Type("CwtchStarted") CwtchStartError = event.Type("CwtchStartError") UpdateGlobalSettings = event.Type("UpdateGlobalSettings") )
const GlobalSettingsFilename = "ui.globals"
const (
SetLoggingLevel = event.Type("SetLoggingLevel")
)
An event to set the logging level dynamically from the UI
Variables ¶
var DefaultGlobalSettings = GlobalSettings{ Locale: "en", Theme: "dark", PreviousPid: -1, ExperimentsEnabled: false, Experiments: make(map[string]bool), StateRootPane: 0, FirstTime: true, BlockUnknownConnections: false, StreamerMode: false, UIColumnModePortrait: "DualpaneMode.Single", UIColumnModeLandscape: "DualpaneMode.CopyPortrait", }
var GlobalSettingsFile v1.FileStore
Functions ¶
func EnrichNewPeer ¶
func EnrichNewPeer(handle string, ph *PeerHelper, ev *EventProfileEnvelope) error
// AddProfile adds a new profile to the UI
func AddProfile(gcd *GrandCentralDispatcher, handle string) { p := the.CwtchApp.GetPeer(handle) if p != nil { nick, exists := p.GetAttribute(attr.GetPublicScope(constants.Name)) if !exists { nick = handle } picVal, ok := p.GetAttribute(attr.GetPublicScope(constants.Picture)) if !ok { picVal = ImageToString(NewImage(RandomProfileImage(handle), TypeImageDistro)) } pic, err := StringToImage(picVal) if err != nil { pic = NewImage(RandomProfileImage(handle), TypeImageDistro) } picPath := getPicturePath(pic) tag, _ := p.GetAttribute(app.AttributeTag) online, _ := p.GetAttribute(attr.GetLocalScope(constants.PeerOnline)) log.Debugf("AddProfile %v %v %v %v %v\n", handle, nick, picPath, tag, online) gcd.AddProfile(handle, nick, picPath, tag, online == event.True) } }
type manager struct { gcd *GrandCentralDispatcher profile string }
// Manager is a middleware helper for entities like peer event listeners wishing to trigger ui changes (via the gcd) // each manager is for one profile/peer // manager takes minimal arguments and builds the full struct of data (usually pulled from a cwtch peer) required to call the GCD to perform the ui action // manager also performs call filtering based on UI state: users of manager can safely always call it on events and not have to worry about weather the relevant ui is active // ie: you can always safely call AddMessage even if in the ui a different profile is selected. manager will check with gcd, and if the correct conditions are not met, it will not call on gcd to update the ui incorrectly
type Manager interface { Acknowledge(handle, mID string) AddContact(Handle string) AddSendMessageError(peer string, signature string, err string) AddMessage(handle string, from string, message string, fromMe bool, messageID string, timestamp time.Time, Acknowledged bool) ReloadProfiles() UpdateContactDisplayName(handle string) UpdateContactPicture(handle string) UpdateContactStatus(handle string, status int, loading bool) UpdateContactAttribute(handle, key, value string) ChangePasswordResponse(error bool) AboutToAddMessage() MessageJustAdded() StoreAndNotify(peer.CwtchPeer, string, string, time.Time, string) UpdateNetworkStatus(online bool) }
// NewManager returns a new Manager interface for a profile to the gcd
func NewManager(profile string, gcd *GrandCentralDispatcher) Manager { return &manager{gcd: gcd, profile: profile} }
EnrichNewPeer populates required data for use by frontend
uiManager.AddContact(onion) (handle string, displayName string, image string, badge int, status int, authorization string, loading bool, lastMsgTime int)
func GetPicturePath ¶
func GetPicturePath(pic *image) string
func ImageToString ¶
func ImageToString(img *image) string
func InitGlobalSettingsFile ¶
func RandomGroupImage ¶
func RandomProfileImage ¶
temporary until we do real picture selection
func StringToImage ¶
func WriteGlobalSettings ¶
func WriteGlobalSettings(globalSettings GlobalSettings)
Types ¶
type Contact ¶
type Contact struct { Name string `json:"name"` Onion string `json:"onion"` Status string `json:"status"` Picture string `json:"picture"` Authorization string `json:"authorization"` SaveHistory string `json:"saveConversationHistory"` Messages int `json:"numMessages"` Unread int `json:"numUnread"` LastMessage string `json:"lastMsgTime"` IsGroup bool `json:"isGroup"` GroupServer string `json:"groupServer"` IsArchived bool `json:"isArchived"` }
type EventHandler ¶
type EventHandler struct {
// contains filtered or unexported fields
}
func NewEventHandler ¶
func NewEventHandler() *EventHandler
func (*EventHandler) GetNextEvent ¶
func (eh *EventHandler) GetNextEvent() string
func (*EventHandler) HandleApp ¶
func (eh *EventHandler) HandleApp(application app.Application)
func (*EventHandler) PublishAppEvent ¶
func (eh *EventHandler) PublishAppEvent(event event.Event)
PublishAppEvent is a way for libCwtch-go to publish an event for consumption by a UI before a Cwtch app has been initialized
Main use: to signal an error before a cwtch app could be created
func (*EventHandler) Push ¶
func (eh *EventHandler) Push(newEvent event.Event)
type EventProfileEnvelope ¶
type GlobalSettings ¶
type GlobalSettings struct { Locale string Theme string PreviousPid int64 ExperimentsEnabled bool Experiments map[string]bool BlockUnknownConnections bool StreamerMode bool StateRootPane int FirstTime bool UIColumnModePortrait string UIColumnModeLandscape string }
func ReadGlobalSettings ¶
func ReadGlobalSettings() *GlobalSettings
type PeerHelper ¶
type PeerHelper struct {
// contains filtered or unexported fields
}
func NewPeerHelper ¶
func NewPeerHelper(profile peer.CwtchPeer) *PeerHelper
func (*PeerHelper) CountUnread ¶
func (*PeerHelper) GetNick ¶
func (p *PeerHelper) GetNick(id string) string
func (*PeerHelper) GetProfilePic ¶
func (p *PeerHelper) GetProfilePic(id string) string
GetProfilePic returns a string path to an image to display for hte given peer/group id
func (*PeerHelper) GetTimeline ¶
func (p *PeerHelper) GetTimeline(handle string) *model.Timeline
GetTimeline returns a pointer to the timeline associated with the conversation handle or nil if the handle does not exist (this can happen if the conversation has been deleted)
func (*PeerHelper) GetWithSetDefault ¶
func (p *PeerHelper) GetWithSetDefault(id string, key string, defaultVal string) string
func (*PeerHelper) InitLastReadTime ¶
func (p *PeerHelper) InitLastReadTime(id string) time.Time
InitLastReadTime checks and gets the Attributable's LastRead time or sets it to now
func (*PeerHelper) IsGroup ¶
func (p *PeerHelper) IsGroup(id string) bool
func (*PeerHelper) IsPeer ¶
func (p *PeerHelper) IsPeer(id string) bool
func (*PeerHelper) IsServer ¶
func (p *PeerHelper) IsServer(id string) bool
Check if the id is associated with a contact with a KeyTypeServerOnion attribute (which indicates that this is a server, not a regular contact or a group