Merge pull request 'android service and notifications' (#51) from androidservice into trunk
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Reviewed-on: #51
This commit is contained in:
commit
033de73b6a
38
lib.go
38
lib.go
|
@ -13,6 +13,7 @@ import (
|
||||||
contact "git.openprivacy.ca/flutter/libcwtch-go/features/contacts"
|
contact "git.openprivacy.ca/flutter/libcwtch-go/features/contacts"
|
||||||
"git.openprivacy.ca/flutter/libcwtch-go/features/groups"
|
"git.openprivacy.ca/flutter/libcwtch-go/features/groups"
|
||||||
"git.openprivacy.ca/openprivacy/connectivity"
|
"git.openprivacy.ca/openprivacy/connectivity"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -54,15 +55,25 @@ type ChatMessage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//export c_StartCwtch
|
//export c_StartCwtch
|
||||||
func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) {
|
func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) int8 {
|
||||||
dir := C.GoStringN(dir_c, len)
|
dir := C.GoStringN(dir_c, len)
|
||||||
tor := C.GoStringN(tor_c, torLen)
|
tor := C.GoStringN(tor_c, torLen)
|
||||||
StartCwtch(dir, tor)
|
return StartCwtch(dir, tor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartCwtch(appDir string, torPath string) {
|
func StartCwtch(appDir string, torPath string) int8 {
|
||||||
log.SetLevel(log.LevelInfo)
|
log.SetLevel(log.LevelInfo)
|
||||||
|
|
||||||
|
if runtime.GOOS == "android" {
|
||||||
|
fh, err := os.Open(torPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("%v", err)
|
||||||
|
log.Errorf("failed to stat tor, skipping StartCwtch(). potentially normal if the app was reinstalled or the device was restarted; this workorder should get canceled soon")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
_ = fh.Close()
|
||||||
|
}
|
||||||
|
|
||||||
// Exclude Tapir wire Messages (We need a TRACE level)
|
// Exclude Tapir wire Messages (We need a TRACE level)
|
||||||
log.ExcludeFromPattern("service.go")
|
log.ExcludeFromPattern("service.go")
|
||||||
|
|
||||||
|
@ -126,6 +137,21 @@ func StartCwtch(appDir string, torPath string) {
|
||||||
// Send global settings to the UI...
|
// Send global settings to the UI...
|
||||||
application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
application.GetPrimaryBus().Publish(event.NewEvent(utils.UpdateGlobalSettings, map[event.Field]string{event.Data: string(settingsJson)}))
|
||||||
log.Infof("libcwtch-go application launched")
|
log.Infof("libcwtch-go application launched")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
//export c_ReconnectCwtchForeground
|
||||||
|
func c_ReconnectCwtchForeground() {
|
||||||
|
ReconnectCwtchForeground()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Like StartCwtch, but StartCwtch has already been called so we don't need to restart Tor etc (probably)
|
||||||
|
// Do need to re-send initial state tho, eg profiles that are already loaded
|
||||||
|
func ReconnectCwtchForeground() {
|
||||||
|
peerList := application.ListPeers()
|
||||||
|
for onion := range peerList {
|
||||||
|
eventHandler.Push(event.NewEvent(event.NewPeer, map[event.Field]string{event.Identity: onion, event.Created: event.False}))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//export c_ACNEvents
|
//export c_ACNEvents
|
||||||
|
@ -507,8 +533,10 @@ func GetMessage(profileOnion, handle string, message_index int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
|
if message_index < len(profile.GetContact(handle).Timeline.Messages) {
|
||||||
message.ContactImage = ph.GetProfilePic(handle)
|
message.Message = profile.GetContact(handle).Timeline.Messages[message_index]
|
||||||
|
message.ContactImage = ph.GetProfilePic(handle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bytes, _ := json.Marshal(message)
|
bytes, _ := json.Marshal(message)
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package utils
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"git.openprivacy.ca/openprivacy/connectivity"
|
"git.openprivacy.ca/openprivacy/connectivity"
|
||||||
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ func (e ErrorACN) SetStatusCallback(callback func(int, string)) {
|
||||||
|
|
||||||
func (e ErrorACN) Restart() {
|
func (e ErrorACN) Restart() {
|
||||||
// does nothing
|
// does nothing
|
||||||
|
log.Errorf("Called Restart() on ErrorACN, which does nothing")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrorACN) Open(hostname string) (net.Conn, string, error) {
|
func (e ErrorACN) Open(hostname string) (net.Conn, string, error) {
|
||||||
|
|
|
@ -222,21 +222,9 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
|
case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
|
||||||
// I Don't think we need to enrich
|
// only needs contact nickname and picture, for displaying on popup notifications
|
||||||
|
ev.Event.Data["Nick"] = ph.GetNick(ev.Event.Data["RemotePeer"])
|
||||||
// TODO: deprecate and move to dart
|
ev.Event.Data["Picture"] = ph.GetProfilePic(ev.Event.Data["RemotePeer"])
|
||||||
/*func (p *PeerHelper) updateLastReadTime(id string) {
|
|
||||||
lastRead, _ := time.Now().MarshalText()
|
|
||||||
if p.IsGroup(id) {
|
|
||||||
p.peer.SetGroupAttribute(id, attr.GetLocalScope(constants.LastRead), string(lastRead))
|
|
||||||
} else {
|
|
||||||
p.peer.SetContactAttribute(id, attr.GetLocalScope(constants.LastRead), string(lastRead))
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// legacy
|
|
||||||
//ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampReceived])
|
|
||||||
|
|
||||||
case event.PeerAcknowledgement:
|
case event.PeerAcknowledgement:
|
||||||
// No enrichement required
|
// No enrichement required
|
||||||
//Acknowledge(ev.Event.Data[event.RemotePeer], ev.Event.Data[event.EventID])
|
//Acknowledge(ev.Event.Data[event.RemotePeer], ev.Event.Data[event.EventID])
|
||||||
|
|
Loading…
Reference in New Issue