Merge branch 'trunk' of git.openprivacy.ca:flutter/libcwtch-go into rinnmar17
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
erinn 2021-03-17 15:51:48 -07:00
commit f3870163db
4 changed files with 43 additions and 41 deletions

View File

@ -6,6 +6,9 @@ name: default
steps: steps:
- name: fetch - name: fetch
image: golang image: golang
volumes:
- name: deps
path: /go
when: when:
repo: flutter/libcwtch-go repo: flutter/libcwtch-go
branch: trunk branch: trunk
@ -15,9 +18,16 @@ steps:
- wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/torrc - wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/torrc
- chmod a+x tor - chmod a+x tor
- go get -u golang.org/x/lint/golint - 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 - name: quality
image: golang image: golang
volumes:
- name: deps
path: /go
when: when:
repo: flutter/libcwtch-go repo: flutter/libcwtch-go
branch: trunk branch: trunk
@ -26,16 +36,22 @@ steps:
- go list ./... | xargs go vet - go list ./... | xargs go vet
- go list ./... | xargs golint - go list ./... | xargs golint
#Todo: fix all the lint errors and add `-set_exit_status` above to enforce linting #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 image: openpriv/android-go-mobile:2021
volumes:
- name: deps
path: /go
when: when:
repo: flutter/libcwtch-go repo: flutter/libcwtch-go
branch: trunk branch: trunk
event: [ push, pull_request ] event: [ push, pull_request ]
commands: commands:
- make linux - make linux
- name: build-androiud - name: build-android
image: openpriv/android-go-mobile:2021 image: openpriv/android-go-mobile:2021
volumes:
- name: deps
path: /go
when: when:
repo: flutter/libcwtch-go repo: flutter/libcwtch-go
branch: trunk branch: trunk
@ -62,3 +78,7 @@ steps:
status: [ success, changed, failure ] status: [ success, changed, failure ]
secrets: [gogs_account_token] secrets: [gogs_account_token]
gogs_url: https://git.openprivacy.ca gogs_url: https://git.openprivacy.ca
volumes:
- name: deps
temp: {}

30
lib.go
View File

@ -7,6 +7,7 @@ import (
"crypto/rand" "crypto/rand"
"cwtch.im/cwtch/app" "cwtch.im/cwtch/app"
"cwtch.im/cwtch/event" "cwtch.im/cwtch/event"
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr" "cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/peer" "cwtch.im/cwtch/peer"
@ -183,6 +184,10 @@ func SendProfileEvent(onion string, eventJson string) {
switch new_event.EventType { switch new_event.EventType {
case event.SetAttribute: case event.SetAttribute:
peer.SetAttribute(new_event.Data[event.Key], new_event.Data[event.Data]) 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: case event.SendMessageToGroup:
// TODO Uncomment and integrate once contacts/messages are loaded. // TODO Uncomment and integrate once contacts/messages are loaded.
//groupHandler,err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments) //groupHandler,err := groups.ExperimentGate(utils.ReadGlobalSettings().Experiments)
@ -252,29 +257,6 @@ func GetProfiles() string {
return string(jsonBytes) 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 //export c_CreateProfile
func c_CreateProfile(nick_ptr *C.char, nick_len C.int, pass_ptr *C.char, pass_len C.int) { 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)) 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) { func NumMessages(profile, handle string) (n int) {
n = len(application.GetPeer(profile).GetContact(handle).Timeline.Messages) 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 return
} }

View File

@ -1,10 +1,12 @@
package utils package utils
type Contact struct { type Contact struct {
Name string `json:"name"` Name string `json:"name"`
Onion string `json:"onion"` Onion string `json:"onion"`
Status string `json:"status"` Status string `json:"status"`
Picture string `json:"picture"` Picture string `json:"picture"`
Messages int `json:"numMessages"` Authorization string `json:"authorization"`
Unread int `json:"numUnread"` SaveHistory string `json:"saveConversationHistory"`
Messages int `json:"numMessages"`
Unread int `json:"numUnread"`
} }

View File

@ -106,14 +106,12 @@ func (eh *EventHandler) handleAppBusEvent(e *event.Event) string {
} }
cpicPath := GetPicturePath(cpic) cpicPath := GetPicturePath(cpic)
contactInfo := profile.GetContact(contact) contactInfo := profile.GetContact(contact)
contacts = append(contacts, Contact{ name, _ := contactInfo.GetAttribute(attr.GetLocalScope(constants.Name))
Name: contactInfo.Name, saveHistory, set := contactInfo.GetAttribute(event.SaveHistoryKey)
Onion: contactInfo.Onion, if !set {
Status: contactInfo.State, saveHistory = event.DeleteHistoryDefault
Picture: cpicPath, }
Messages: contactInfo.Timeline.Len(), 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,})
Unread: 0,
})
} }
bytes, _ := json.Marshal(contacts) bytes, _ := json.Marshal(contacts)