diaspora-vines 0.1.24 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vines/storage/sql.rb +56 -9
- data/lib/vines/version.rb +1 -1
- data/test/storage/sql_schema.rb +24 -1
- data/test/storage/sql_test.rb +33 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ce3ef9b28f9b71a58588bba5547b7be71c9d93d
|
4
|
+
data.tar.gz: 46863f581edbf9da56a588fb2ab005f28c13827f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e136a59ff668bc14016e34cbe85a45cff9a5d5eb844d1b7a8d9d984f5db33741f1cba3790a36ed9ac63e86188f0f44531f81640beb215a91fa27af5af977548c
|
7
|
+
data.tar.gz: 497a8b3b3928c39be34f1cd0cbfee2f8132168977cf48a4a8ffdb809cb28f97a08afebee8f0881ccf97bf6d4355808f0f4ef21fec443b41681dbbb62d66ca95b
|
data/lib/vines/storage/sql.rb
CHANGED
@@ -7,7 +7,22 @@ module Vines
|
|
7
7
|
|
8
8
|
register :sql
|
9
9
|
|
10
|
-
class
|
10
|
+
class Profile < ActiveRecord::Base
|
11
|
+
belongs_to :person
|
12
|
+
end
|
13
|
+
class Person < ActiveRecord::Base
|
14
|
+
has_one :profile
|
15
|
+
|
16
|
+
def local?
|
17
|
+
!self.owner_id.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def name(opts = {})
|
21
|
+
self.profile.first_name.blank? && self.profile.last_name.blank? ?
|
22
|
+
self.diaspora_handle : "#{self.profile.first_name.to_s.strip} #{self.profile.last_name.to_s.strip}".strip
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
11
26
|
class Aspect < ActiveRecord::Base
|
12
27
|
belongs_to :users
|
13
28
|
|
@@ -43,8 +58,6 @@ module Vines
|
|
43
58
|
|
44
59
|
class ChatContact < ActiveRecord::Base
|
45
60
|
belongs_to :users
|
46
|
-
|
47
|
-
serialize :groups, JSON
|
48
61
|
end
|
49
62
|
|
50
63
|
class ChatFragment < ActiveRecord::Base
|
@@ -113,7 +126,7 @@ module Vines
|
|
113
126
|
jid: contact.jid,
|
114
127
|
name: contact.name,
|
115
128
|
subscription: contact.subscription,
|
116
|
-
groups:
|
129
|
+
groups: get_external_groups,
|
117
130
|
ask: contact.ask)
|
118
131
|
end
|
119
132
|
end if xuser
|
@@ -148,7 +161,7 @@ module Vines
|
|
148
161
|
name: fresh.name,
|
149
162
|
ask: fresh.ask,
|
150
163
|
subscription: fresh.subscription,
|
151
|
-
groups:
|
164
|
+
groups: get_external_groups)
|
152
165
|
end
|
153
166
|
|
154
167
|
# add new contacts to roster
|
@@ -163,7 +176,7 @@ module Vines
|
|
163
176
|
name: contact.name,
|
164
177
|
ask: contact.ask,
|
165
178
|
subscription: contact.subscription,
|
166
|
-
groups:
|
179
|
+
groups: get_external_groups) unless jids.include?(contact.jid.bare.to_s)
|
167
180
|
end
|
168
181
|
}
|
169
182
|
xuser.save
|
@@ -171,13 +184,19 @@ module Vines
|
|
171
184
|
with_connection :save_user
|
172
185
|
|
173
186
|
def find_vcard(jid)
|
174
|
-
|
175
|
-
nil
|
187
|
+
jid = JID.new(jid).bare.to_s
|
188
|
+
return nil if jid.empty?
|
189
|
+
person = Sql::Person.find_by_diaspora_handle(jid)
|
190
|
+
return nil unless person.nil? || person.local?
|
191
|
+
|
192
|
+
build_vcard(person)
|
176
193
|
end
|
177
194
|
with_connection :find_vcard
|
178
195
|
|
179
196
|
def save_vcard(jid, card)
|
180
|
-
# not supported
|
197
|
+
# NOTE this is not supported. If you'd like to change your
|
198
|
+
# vcard details you can edit it via diaspora-web-interface
|
199
|
+
nil
|
181
200
|
end
|
182
201
|
with_connection :save_vcard
|
183
202
|
|
@@ -213,12 +232,40 @@ module Vines
|
|
213
232
|
Sql::User.find_by_username(name)
|
214
233
|
end
|
215
234
|
|
235
|
+
def get_external_groups
|
236
|
+
# TODO Make the group name configurable by the user
|
237
|
+
# https://github.com/diaspora/vines/issues/39
|
238
|
+
group_name = "External XMPP Contacts"
|
239
|
+
matches = Sql::Aspect.where(:name => group_name).count
|
240
|
+
if matches > 0
|
241
|
+
group_name = "#{group_name} (#{matches + 1})"
|
242
|
+
end
|
243
|
+
[ group_name ]
|
244
|
+
end
|
245
|
+
|
216
246
|
def fragment_by_jid(jid, node)
|
217
247
|
jid = JID.new(jid).bare.to_s
|
218
248
|
clause = 'user_id=(select id from users where jid=?) and root=? and namespace=?'
|
219
249
|
Sql::ChatFragment.where(clause, jid, node.name, node.namespace.href).first
|
220
250
|
end
|
221
251
|
|
252
|
+
def build_vcard(person)
|
253
|
+
builder = Nokogiri::XML::Builder.new
|
254
|
+
builder.vCard('xmlns' => 'vcard-temp') do |xml|
|
255
|
+
xml.send(:"FN", person.name) if person.name
|
256
|
+
xml.send(:"N") do |sub|
|
257
|
+
sub.send(:"FAMILY", person.profile.last_name) if person.profile.last_name
|
258
|
+
sub.send(:"GIVEN", person.profile.first_name) if person.profile.first_name
|
259
|
+
end if (person.profile.last_name? || person.profile.first_name?)
|
260
|
+
xml.send(:"URL", person.url) if person.url
|
261
|
+
xml.send(:"PHOTO") do |sub|
|
262
|
+
sub.send(:"EXTVAL", person.profile.image_url)
|
263
|
+
end if person.profile.image_url
|
264
|
+
end
|
265
|
+
|
266
|
+
builder.to_xml :save_with => Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
|
267
|
+
end
|
268
|
+
|
222
269
|
def get_diaspora_flags(contact)
|
223
270
|
groups = Array.new
|
224
271
|
ask, subscription = 'none', 'none'
|
data/lib/vines/version.rb
CHANGED
data/test/storage/sql_schema.rb
CHANGED
@@ -41,11 +41,34 @@ module SqlSchema
|
|
41
41
|
t.boolean "closed_account", :default => false
|
42
42
|
t.integer "fetch_status", :default => 0
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
add_index "people", ["diaspora_handle"], :name => "index_people_on_diaspora_handle", :unique => true
|
46
46
|
add_index "people", ["guid"], :name => "index_people_on_guid", :unique => true
|
47
47
|
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
48
48
|
|
49
|
+
create_table "profiles", force: true do |t|
|
50
|
+
t.string "diaspora_handle"
|
51
|
+
t.string "first_name", limit: 127
|
52
|
+
t.string "last_name", limit: 127
|
53
|
+
t.string "image_url"
|
54
|
+
t.string "image_url_small"
|
55
|
+
t.string "image_url_medium"
|
56
|
+
t.date "birthday"
|
57
|
+
t.string "gender"
|
58
|
+
t.text "bio"
|
59
|
+
t.boolean "searchable", default: true, null: false
|
60
|
+
t.integer "person_id", null: false
|
61
|
+
t.datetime "created_at", null: false
|
62
|
+
t.datetime "updated_at", null: false
|
63
|
+
t.string "location"
|
64
|
+
t.string "full_name", limit: 70
|
65
|
+
t.boolean "nsfw", default: false
|
66
|
+
end
|
67
|
+
|
68
|
+
add_index "profiles", ["full_name", "searchable"], name: "index_profiles_on_full_name_and_searchable", using: :btree
|
69
|
+
add_index "profiles", ["full_name"], name: "index_profiles_on_full_name", using: :btree
|
70
|
+
add_index "profiles", ["person_id"], name: "index_profiles_on_person_id", using: :btree
|
71
|
+
|
49
72
|
create_table "aspects", :force => true do |t|
|
50
73
|
t.string "name", :null => false
|
51
74
|
t.integer "user_id", :null => false
|
data/test/storage/sql_test.rb
CHANGED
@@ -22,6 +22,8 @@ describe Vines::Storage::Sql do
|
|
22
22
|
before do
|
23
23
|
@test_user = {
|
24
24
|
:name => "test",
|
25
|
+
:url => "http://remote.host/",
|
26
|
+
:image_url => "http://path.to/image.png",
|
25
27
|
:jid => "test@local.host",
|
26
28
|
:email => "test@test.de",
|
27
29
|
:password => "$2a$10$c2G6rHjGeamQIOFI0c1/b.4mvFBw4AfOtgVrAkO1QPMuAyporj5e6", # pppppp
|
@@ -37,10 +39,18 @@ describe Vines::Storage::Sql do
|
|
37
39
|
authentication_token: @test_user[:token]
|
38
40
|
).save
|
39
41
|
Vines::Storage::Sql::Person.new(
|
42
|
+
owner_id: 1,
|
40
43
|
guid: "1697a4b0198901321e9b10e6ba921ce9",
|
41
|
-
url:
|
44
|
+
url: @test_user[:url],
|
42
45
|
serialized_public_key: "some pub key",
|
43
|
-
diaspora_handle:
|
46
|
+
diaspora_handle: @test_user[:jid]
|
47
|
+
).save
|
48
|
+
Vines::Storage::Sql::Profile.new(
|
49
|
+
person_id: 1,
|
50
|
+
last_name: "Hirsch",
|
51
|
+
first_name: "Harry",
|
52
|
+
diaspora_handle: @test_user[:jid],
|
53
|
+
image_url: @test_user[:image_url]
|
44
54
|
).save
|
45
55
|
Vines::Storage::Sql::Contact.new(
|
46
56
|
user_id: 1,
|
@@ -134,6 +144,27 @@ describe Vines::Storage::Sql do
|
|
134
144
|
end
|
135
145
|
end
|
136
146
|
|
147
|
+
def test_find_vcard
|
148
|
+
fibered do
|
149
|
+
db = storage
|
150
|
+
xml = db.find_vcard(@test_user[:jid])
|
151
|
+
assert (xml != nil), "no vcard found"
|
152
|
+
|
153
|
+
doc = node(xml)
|
154
|
+
assert_equal "Harry Hirsch", doc.search("FN").text
|
155
|
+
assert_equal "Harry", doc.search("GIVEN").text
|
156
|
+
assert_equal "Hirsch", doc.search("FAMILY").text
|
157
|
+
assert_equal @test_user[:url], doc.search("URL").text
|
158
|
+
assert_equal @test_user[:image_url], doc.search("EXTVAL").text
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_save_vcard
|
163
|
+
fibered do
|
164
|
+
assert_nil storage.save_vcard(@test_user[:jid], "<vCard></vCard>")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
137
168
|
def test_find_fragment
|
138
169
|
skip("not working probably")
|
139
170
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diaspora-vines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Graham
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-10-
|
12
|
+
date: 2014-10-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bcrypt
|