Merge branch 'trunk' of git.openprivacy.ca:flutter/libcwtch-go into rinnmar17
This commit is contained in:
commit
f3870163db
26
.drone.yml
26
.drone.yml
|
@ -6,6 +6,9 @@ name: default
|
|||
steps:
|
||||
- name: fetch
|
||||
image: golang
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
when:
|
||||
repo: flutter/libcwtch-go
|
||||
branch: trunk
|
||||
|
@ -15,9 +18,16 @@ steps:
|
|||
- wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/torrc
|
||||
- chmod a+x tor
|
||||
- go get -u golang.org/x/lint/golint
|
||||
# go install for 1.16
|
||||
#- export GO111MODULE=on
|
||||
#- go mod vendor
|
||||
- go get
|
||||
# TODO: upgrade to go1.16, remove mod/vendor, add go install for 1.16
|
||||
# go vendor so packages aren't refetched each new stage which loses this working dir, or restructure workspace to include pkg
|
||||
- name: quality
|
||||
image: golang
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
when:
|
||||
repo: flutter/libcwtch-go
|
||||
branch: trunk
|
||||
|
@ -26,16 +36,22 @@ steps:
|
|||
- go list ./... | xargs go vet
|
||||
- go list ./... | xargs golint
|
||||
#Todo: fix all the lint errors and add `-set_exit_status` above to enforce linting
|
||||
- name: buildLinux
|
||||
- name: build-linux
|
||||
image: openpriv/android-go-mobile:2021
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
when:
|
||||
repo: flutter/libcwtch-go
|
||||
branch: trunk
|
||||
event: [ push, pull_request ]
|
||||
commands:
|
||||
- make linux
|
||||
- name: build-androiud
|
||||
- name: build-android
|
||||
image: openpriv/android-go-mobile:2021
|
||||
volumes:
|
||||
- name: deps
|
||||
path: /go
|
||||
when:
|
||||
repo: flutter/libcwtch-go
|
||||
branch: trunk
|
||||
|
@ -62,3 +78,7 @@ steps:
|
|||
status: [ success, changed, failure ]
|
||||
secrets: [gogs_account_token]
|
||||
gogs_url: https://git.openprivacy.ca
|
||||
|
||||
volumes:
|
||||
- name: deps
|
||||
temp: {}
|
||||
|
|
30
lib.go
30
lib.go
|
@ -7,6 +7,7 @@ import (
|
|||
"crypto/rand"
|
||||
"cwtch.im/cwtch/app"
|
||||
"cwtch.im/cwtch/event"
|
||||
"cwtch.im/cwtch/model"
|
||||
"cwtch.im/cwtch/model/attr"
|
||||
"cwtch.im/cwtch/peer"
|
||||
|
||||
|
@ -183,6 +184,10 @@ func SendProfileEvent(onion string, eventJson string) {
|
|||
switch new_event.EventType {
|
||||
case event.SetAttribute:
|
||||
peer.SetAttribute(new_event.Data[event.Key], new_event.Data[event.Data])
|
||||
case event.SetPeerAttribute:
|
||||
peer.SetContactAttribute(new_event.Data[event.RemotePeer], new_event.Data[event.Key], new_event.Data[event.Data])
|
||||
case event.SetPeerAuthorization:
|
||||
peer.SetContactAuthorization(new_event.Data[event.RemotePeer], model.Authorization(new_event.Data[event.Authorization]))
|
||||
case event.SendMessageToGroup:
|
||||
// TODO Uncomment and integrate once contacts/messages are loaded.
|
||||
//groupHandler,err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments)
|
||||
|
@ -252,29 +257,6 @@ func GetProfiles() string {
|
|||
return string(jsonBytes)
|
||||
}
|
||||
|
||||
//export c_GetContacts
|
||||
func c_GetContacts(onion_ptr *C.char, onion_len C.int) *C.char {
|
||||
return C.CString(GetContacts(C.GoStringN(onion_ptr, onion_len)))
|
||||
}
|
||||
|
||||
func GetContacts(onion string) string {
|
||||
log.Infof("Get Contacts for %v", onion)
|
||||
mypeer := application.GetPeer(onion)
|
||||
|
||||
contactEventsQueue = event.NewQueue()
|
||||
application.GetEventBus(onion).Subscribe(event.PeerStateChange, contactEventsQueue)
|
||||
|
||||
var contacts []utils.Contact
|
||||
for _, contact := range mypeer.GetContacts() {
|
||||
contactInfo := mypeer.GetContact(contact)
|
||||
log.Infof("contactInfo %v", contactInfo)
|
||||
contacts = append(contacts, utils.Contact{Name: contactInfo.Name, Onion: contactInfo.Onion, Status: contactInfo.State})
|
||||
}
|
||||
|
||||
bytes, _ := json.Marshal(contacts)
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
//export c_CreateProfile
|
||||
func c_CreateProfile(nick_ptr *C.char, nick_len C.int, pass_ptr *C.char, pass_len C.int) {
|
||||
CreateProfile(C.GoStringN(nick_ptr, nick_len), C.GoStringN(pass_ptr, pass_len))
|
||||
|
@ -328,7 +310,7 @@ func c_NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, h
|
|||
|
||||
func NumMessages(profile, handle string) (n int) {
|
||||
n = len(application.GetPeer(profile).GetContact(handle).Timeline.Messages)
|
||||
log.Infof("NumMessagse(%s, %s) = %d", profile, handle, n)
|
||||
//log.Infof("NumMessagse(%s, %s) = %d", profile, handle, n)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package utils
|
||||
|
||||
type Contact struct {
|
||||
Name string `json:"name"`
|
||||
Onion string `json:"onion"`
|
||||
Status string `json:"status"`
|
||||
Picture string `json:"picture"`
|
||||
Messages int `json:"numMessages"`
|
||||
Unread int `json:"numUnread"`
|
||||
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"`
|
||||
}
|
||||
|
|
|
@ -106,14 +106,12 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
|
|||
}
|
||||
cpicPath := GetPicturePath(cpic)
|
||||
contactInfo := profile.GetContact(contact)
|
||||
contacts = append(contacts, Contact{
|
||||
Name: contactInfo.Name,
|
||||
Onion: contactInfo.Onion,
|
||||
Status: contactInfo.State,
|
||||
Picture: cpicPath,
|
||||
Messages: contactInfo.Timeline.Len(),
|
||||
Unread: 0,
|
||||
})
|
||||
name, _ := contactInfo.GetAttribute(attr.GetLocalScope(constants.Name))
|
||||
saveHistory, set := contactInfo.GetAttribute(event.SaveHistoryKey)
|
||||
if !set {
|
||||
saveHistory = event.DeleteHistoryDefault
|
||||
}
|
||||
contacts = append(contacts, Contact{Name: name, Onion: contactInfo.Onion, Status: contactInfo.State, Picture: cpicPath, Authorization: string(contactInfo.Authorization), SaveHistory: saveHistory, Messages: contactInfo.Timeline.Len(), Unread: 0,})
|
||||
}
|
||||
|
||||
bytes, _ := json.Marshal(contacts)
|
||||
|
|
Loading…
Reference in New Issue